diff --git a/plugins/com.thalesgroup.mde.openmbee.connector.fsmodel/emf-gen/com/thalesgroup/mde/openmbee/connector/fsmodel/filesystem/FilesystemPackage.java b/plugins/com.thalesgroup.mde.openmbee.connector.fsmodel/emf-gen/com/thalesgroup/mde/openmbee/connector/fsmodel/filesystem/FilesystemPackage.java index 6bb039f..17fc166 100644 --- a/plugins/com.thalesgroup.mde.openmbee.connector.fsmodel/emf-gen/com/thalesgroup/mde/openmbee/connector/fsmodel/filesystem/FilesystemPackage.java +++ b/plugins/com.thalesgroup.mde.openmbee.connector.fsmodel/emf-gen/com/thalesgroup/mde/openmbee/connector/fsmodel/filesystem/FilesystemPackage.java @@ -41,7 +41,7 @@ public interface FilesystemPackage extends EPackage { * * @generated */ - String eNAME = "filesystem"; + String eNAME = "filesystem"; //$NON-NLS-1$ /** * The package namespace URI. @@ -49,7 +49,7 @@ public interface FilesystemPackage extends EPackage { * * @generated */ - String eNS_URI = "http://www.thalesgroup.com/mde/openmbee/connector"; + String eNS_URI = "http://www.thalesgroup.com/mde/openmbee/connector"; //$NON-NLS-1$ /** * The package namespace name. @@ -57,7 +57,7 @@ public interface FilesystemPackage extends EPackage { * * @generated */ - String eNS_PREFIX = "com.thalesgroup.mde.openmbee.connector.fsmodel"; + String eNS_PREFIX = "com.thalesgroup.mde.openmbee.connector.fsmodel"; //$NON-NLS-1$ /** * The singleton instance of the package. diff --git a/plugins/com.thalesgroup.mde.openmbee.connector.fsmodel/emf-gen/com/thalesgroup/mde/openmbee/connector/fsmodel/filesystem/impl/FileImpl.java b/plugins/com.thalesgroup.mde.openmbee.connector.fsmodel/emf-gen/com/thalesgroup/mde/openmbee/connector/fsmodel/filesystem/impl/FileImpl.java index 928825b..77a8b4b 100644 --- a/plugins/com.thalesgroup.mde.openmbee.connector.fsmodel/emf-gen/com/thalesgroup/mde/openmbee/connector/fsmodel/filesystem/impl/FileImpl.java +++ b/plugins/com.thalesgroup.mde.openmbee.connector.fsmodel/emf-gen/com/thalesgroup/mde/openmbee/connector/fsmodel/filesystem/impl/FileImpl.java @@ -339,11 +339,11 @@ public String toString() { if (eIsProxy()) return super.toString(); StringBuilder result = new StringBuilder(super.toString()); - result.append(" (name: "); + result.append(" (name: "); //$NON-NLS-1$ result.append(name); - result.append(", path: "); + result.append(", path: "); //$NON-NLS-1$ result.append(path); - result.append(", content: "); + result.append(", content: "); //$NON-NLS-1$ result.append(content); result.append(')'); return result.toString(); diff --git a/plugins/com.thalesgroup.mde.openmbee.connector.fsmodel/emf-gen/com/thalesgroup/mde/openmbee/connector/fsmodel/filesystem/impl/FilesystemFactoryImpl.java b/plugins/com.thalesgroup.mde.openmbee.connector.fsmodel/emf-gen/com/thalesgroup/mde/openmbee/connector/fsmodel/filesystem/impl/FilesystemFactoryImpl.java index a9070a5..b2d8398 100644 --- a/plugins/com.thalesgroup.mde.openmbee.connector.fsmodel/emf-gen/com/thalesgroup/mde/openmbee/connector/fsmodel/filesystem/impl/FilesystemFactoryImpl.java +++ b/plugins/com.thalesgroup.mde.openmbee.connector.fsmodel/emf-gen/com/thalesgroup/mde/openmbee/connector/fsmodel/filesystem/impl/FilesystemFactoryImpl.java @@ -70,7 +70,7 @@ public EObject create(EClass eClass) { case FilesystemPackage.FILE: return createFile(); case FilesystemPackage.FOLDER: return createFolder(); default: - throw new IllegalArgumentException("The class '" + eClass.getName() + "' is not a valid classifier"); + throw new IllegalArgumentException("The class '" + eClass.getName() + "' is not a valid classifier"); //$NON-NLS-1$ //$NON-NLS-2$ } } diff --git a/plugins/com.thalesgroup.mde.openmbee.connector.fsmodel/emf-gen/com/thalesgroup/mde/openmbee/connector/fsmodel/filesystem/impl/FilesystemPackageImpl.java b/plugins/com.thalesgroup.mde.openmbee.connector.fsmodel/emf-gen/com/thalesgroup/mde/openmbee/connector/fsmodel/filesystem/impl/FilesystemPackageImpl.java index 2bd9663..f464fd3 100644 --- a/plugins/com.thalesgroup.mde.openmbee.connector.fsmodel/emf-gen/com/thalesgroup/mde/openmbee/connector/fsmodel/filesystem/impl/FilesystemPackageImpl.java +++ b/plugins/com.thalesgroup.mde.openmbee.connector.fsmodel/emf-gen/com/thalesgroup/mde/openmbee/connector/fsmodel/filesystem/impl/FilesystemPackageImpl.java @@ -257,15 +257,15 @@ public void initializePackageContents() { folderEClass.getESuperTypes().add(this.getFileSystemElement()); // Initialize classes, features, and operations; add parameters - initEClass(fileSystemElementEClass, FileSystemElement.class, "FileSystemElement", IS_ABSTRACT, IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS); - initEAttribute(getFileSystemElement_Name(), ecorePackage.getEString(), "name", null, 0, 1, FileSystemElement.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); - initEAttribute(getFileSystemElement_Path(), ecorePackage.getEString(), "path", null, 0, 1, FileSystemElement.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); - initEReference(getFileSystemElement_Owner(), this.getFolder(), null, "owner", null, 0, 1, FileSystemElement.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); + initEClass(fileSystemElementEClass, FileSystemElement.class, "FileSystemElement", IS_ABSTRACT, IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS); //$NON-NLS-1$ + initEAttribute(getFileSystemElement_Name(), ecorePackage.getEString(), "name", null, 0, 1, FileSystemElement.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); //$NON-NLS-1$ + initEAttribute(getFileSystemElement_Path(), ecorePackage.getEString(), "path", null, 0, 1, FileSystemElement.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); //$NON-NLS-1$ + initEReference(getFileSystemElement_Owner(), this.getFolder(), null, "owner", null, 0, 1, FileSystemElement.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); //$NON-NLS-1$ - initEClass(fileEClass, File.class, "File", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS); - initEAttribute(getFile_Content(), ecorePackage.getEString(), "content", null, 0, 1, File.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); + initEClass(fileEClass, File.class, "File", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS); //$NON-NLS-1$ + initEAttribute(getFile_Content(), ecorePackage.getEString(), "content", null, 0, 1, File.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); //$NON-NLS-1$ - initEClass(folderEClass, Folder.class, "Folder", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS); + initEClass(folderEClass, Folder.class, "Folder", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS); //$NON-NLS-1$ // Create resource createResource(eNS_URI); diff --git a/plugins/com.thalesgroup.mde.openmbee.connector.fsmodel/emf-gen/com/thalesgroup/mde/openmbee/connector/fsmodel/filesystem/impl/FolderImpl.java b/plugins/com.thalesgroup.mde.openmbee.connector.fsmodel/emf-gen/com/thalesgroup/mde/openmbee/connector/fsmodel/filesystem/impl/FolderImpl.java index b98d6b7..533a07a 100644 --- a/plugins/com.thalesgroup.mde.openmbee.connector.fsmodel/emf-gen/com/thalesgroup/mde/openmbee/connector/fsmodel/filesystem/impl/FolderImpl.java +++ b/plugins/com.thalesgroup.mde.openmbee.connector.fsmodel/emf-gen/com/thalesgroup/mde/openmbee/connector/fsmodel/filesystem/impl/FolderImpl.java @@ -284,9 +284,9 @@ public String toString() { if (eIsProxy()) return super.toString(); StringBuilder result = new StringBuilder(super.toString()); - result.append(" (name: "); + result.append(" (name: "); //$NON-NLS-1$ result.append(name); - result.append(", path: "); + result.append(", path: "); //$NON-NLS-1$ result.append(path); result.append(')'); return result.toString(); diff --git a/plugins/com.thalesgroup.mde.openmbee.connector.fsmodel/model/filesystem.genmodel b/plugins/com.thalesgroup.mde.openmbee.connector.fsmodel/model/filesystem.genmodel index ba4b465..236b22c 100644 --- a/plugins/com.thalesgroup.mde.openmbee.connector.fsmodel/model/filesystem.genmodel +++ b/plugins/com.thalesgroup.mde.openmbee.connector.fsmodel/model/filesystem.genmodel @@ -2,7 +2,7 @@ filesystem.ecore diff --git a/plugins/com.thalesgroup.mde.openmbee.connector.mms.doc/META-INF/MANIFEST.MF b/plugins/com.thalesgroup.mde.openmbee.connector.mms.doc/META-INF/MANIFEST.MF index 1ed5f62..30a89d5 100644 --- a/plugins/com.thalesgroup.mde.openmbee.connector.mms.doc/META-INF/MANIFEST.MF +++ b/plugins/com.thalesgroup.mde.openmbee.connector.mms.doc/META-INF/MANIFEST.MF @@ -6,3 +6,4 @@ Bundle-Version: 1.0.0.qualifier Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Bundle-Vendor: %providerName Bundle-Localization: plugin +Automatic-Module-Name: com.thalesgroup.mde.openmbee.connector.mms.doc diff --git a/plugins/com.thalesgroup.mde.openmbee.connector.mms.management.ui/src/com/thalesgroup/mde/openmbee/connector/mms/management/ui/MmsServerManagementUiPlugin.java b/plugins/com.thalesgroup.mde.openmbee.connector.mms.management.ui/src/com/thalesgroup/mde/openmbee/connector/mms/management/ui/MmsServerManagementUiPlugin.java index 770d324..dcefa9c 100644 --- a/plugins/com.thalesgroup.mde.openmbee.connector.mms.management.ui/src/com/thalesgroup/mde/openmbee/connector/mms/management/ui/MmsServerManagementUiPlugin.java +++ b/plugins/com.thalesgroup.mde.openmbee.connector.mms.management.ui/src/com/thalesgroup/mde/openmbee/connector/mms/management/ui/MmsServerManagementUiPlugin.java @@ -56,7 +56,7 @@ public static MmsServerManagementUiPlugin getInstance() { public MMSServerDescriptor[] getStoredMMSServerDescriptors() { try(StringReader stringReader = new StringReader(getStoredServerDataString())) { - return MMSJsonHelper.getPreparedGsonBuilder().create().fromJson(stringReader, MMSServerDescriptor[].class); + return MMSJsonHelper.getMMS3PreparedGsonBuilder().create().fromJson(stringReader, MMSServerDescriptor[].class); } catch (Exception e) { logHelper.error(e); } @@ -65,14 +65,14 @@ public MMSServerDescriptor[] getStoredMMSServerDescriptors() { public void addStoredMMSServerDescriptor(MMSServerDescriptor serverDescriptor) { try(StringReader stringReader = new StringReader(getStoredServerDataString())) { - MMSServerDescriptor[] fromJson = MMSJsonHelper.getPreparedGsonBuilder().create().fromJson(stringReader, MMSServerDescriptor[].class); + MMSServerDescriptor[] fromJson = MMSJsonHelper.getMMS3PreparedGsonBuilder().create().fromJson(stringReader, MMSServerDescriptor[].class); Set existingOnes = new HashSet<>(); if(fromJson != null && fromJson.length > 0) { existingOnes.addAll(Arrays.asList(fromJson)); } if(!existingOnes.contains(serverDescriptor)) { if(existingOnes.add(serverDescriptor)) { - SecurePreferencesFactory.getDefault().node(PLUGIN_ID).put(PREFERENCES_MMS_SERVERDATA, MMSJsonHelper.getPreparedGsonBuilder().create().toJson(existingOnes), true); + SecurePreferencesFactory.getDefault().node(PLUGIN_ID).put(PREFERENCES_MMS_SERVERDATA, MMSJsonHelper.getMMS3PreparedGsonBuilder().create().toJson(existingOnes), true); } } } catch (StorageException e) { @@ -82,14 +82,14 @@ public void addStoredMMSServerDescriptor(MMSServerDescriptor serverDescriptor) { public void removeStoredMMSServerDescriptor(MMSServerDescriptor serverDescriptor) { try(StringReader stringReader = new StringReader(getStoredServerDataString())) { - MMSServerDescriptor[] fromJson = MMSJsonHelper.getPreparedGsonBuilder().create().fromJson(stringReader, MMSServerDescriptor[].class); + MMSServerDescriptor[] fromJson = MMSJsonHelper.getMMS3PreparedGsonBuilder().create().fromJson(stringReader, MMSServerDescriptor[].class); Set existingOnes = new HashSet<>(); if(fromJson != null && fromJson.length > 0) { existingOnes.addAll(Arrays.asList(fromJson)); } Optional removable = existingOnes.stream().filter(s -> serverDescriptor.id.contentEquals(s.id)).findFirst(); if(removable.isPresent() && existingOnes.remove(removable.get())) { - SecurePreferencesFactory.getDefault().node(PLUGIN_ID).put(PREFERENCES_MMS_SERVERDATA, MMSJsonHelper.getPreparedGsonBuilder().create().toJson(existingOnes), true); + SecurePreferencesFactory.getDefault().node(PLUGIN_ID).put(PREFERENCES_MMS_SERVERDATA, MMSJsonHelper.getMMS3PreparedGsonBuilder().create().toJson(existingOnes), true); } } catch (StorageException e) { logHelper.error(e); @@ -99,10 +99,10 @@ public void removeStoredMMSServerDescriptor(MMSServerDescriptor serverDescriptor private String getStoredServerDataString() { String storedServerDataString = null; try { - storedServerDataString = SecurePreferencesFactory.getDefault().node(PLUGIN_ID).get(PREFERENCES_MMS_SERVERDATA, "[]"); + storedServerDataString = SecurePreferencesFactory.getDefault().node(PLUGIN_ID).get(PREFERENCES_MMS_SERVERDATA, "[]"); //$NON-NLS-1$ } catch (StorageException e1) {} if(storedServerDataString == null) { - storedServerDataString = "[]"; + storedServerDataString = "[]"; //$NON-NLS-1$ } return storedServerDataString; } diff --git a/plugins/com.thalesgroup.mde.openmbee.connector.mms.management.ui/src/com/thalesgroup/mde/openmbee/connector/mms/management/ui/data/MMSTreeParent.java b/plugins/com.thalesgroup.mde.openmbee.connector.mms.management.ui/src/com/thalesgroup/mde/openmbee/connector/mms/management/ui/data/MMSTreeParent.java index 183498a..3b377ff 100644 --- a/plugins/com.thalesgroup.mde.openmbee.connector.mms.management.ui/src/com/thalesgroup/mde/openmbee/connector/mms/management/ui/data/MMSTreeParent.java +++ b/plugins/com.thalesgroup.mde.openmbee.connector.mms.management.ui/src/com/thalesgroup/mde/openmbee/connector/mms/management/ui/data/MMSTreeParent.java @@ -35,7 +35,7 @@ public MMSTreeParent(MMSIdentifiableDescriptor mmsObject) { super(mmsObject); if(mmsObject instanceof MMSServerDescriptor) { MMSServerDescriptor server = (MMSServerDescriptor)mmsObject; - helper = new MMSServerHelper(server.url, server.autData); + helper = new MMSServerHelper(server.url, server.apiVersion, server.autData); } } @@ -85,9 +85,9 @@ public MMSTreeObject[] getChildren() { } else if(mmsObject instanceof MMSOrganizationDescriptor) { setChildren(wrapAll(helper.getProjects(mmsObject.id))); } else if(mmsObject instanceof MMSProjectDescriptor) { - setChildren(wrapAll(helper.getBranches(((MMSProjectDescriptor) mmsObject).org, mmsObject.id))); + setChildren(wrapAll(helper.getBranches(((MMSProjectDescriptor) mmsObject).orgId, mmsObject.id))); } else if(mmsObject instanceof MMSRefDescriptor) { - setChildren(wrapAll(helper.getCommits(((MMSProjectDescriptor) parent.mmsObject).org, parent.mmsObject.id, mmsObject.id))); + setChildren(wrapAll(helper.getCommits(((MMSProjectDescriptor) parent.mmsObject).orgId, parent.mmsObject.id, mmsObject.id))); } } if(children == null || children.size() == 0) hasChildren = false; diff --git a/plugins/com.thalesgroup.mde.openmbee.connector.mms.management.ui/src/com/thalesgroup/mde/openmbee/connector/mms/management/ui/utils/MMSTreeObjectViewLabelProvider.java b/plugins/com.thalesgroup.mde.openmbee.connector.mms.management.ui/src/com/thalesgroup/mde/openmbee/connector/mms/management/ui/utils/MMSTreeObjectViewLabelProvider.java index 078b35d..39a2a2a 100644 --- a/plugins/com.thalesgroup.mde.openmbee.connector.mms.management.ui/src/com/thalesgroup/mde/openmbee/connector/mms/management/ui/utils/MMSTreeObjectViewLabelProvider.java +++ b/plugins/com.thalesgroup.mde.openmbee.connector.mms.management.ui/src/com/thalesgroup/mde/openmbee/connector/mms/management/ui/utils/MMSTreeObjectViewLabelProvider.java @@ -29,6 +29,9 @@ import com.thalesgroup.mde.openmbee.connector.mms.management.ui.data.MMSTreeParent; public class MMSTreeObjectViewLabelProvider extends LabelProvider { + private static final String LBL_SERVER_DESCRIPTOR1 = "[%s] %s"; //$NON-NLS-1$ + private static final String LBL_SERVER_DESCRIPTOR2 = "[%s] %s [%s]"; //$NON-NLS-1$ + private static final String LBL_NAMED_DESCRIPTOR = "%s [%s]"; //$NON-NLS-1$ private static final String LBL_COMMIT_DESCRIPTOR = "%s [%s - %s]"; //$NON-NLS-1$ private IWorkbench workbench; @@ -46,8 +49,8 @@ public String getText(Object obj) { } else if(mmsObject instanceof MMSServerDescriptor) { MMSServerDescriptor mmsServer = (MMSServerDescriptor)mmsObject; return mmsServer.url.contentEquals(mmsServer.name) ? - mmsServer.name : - String.format(LBL_NAMED_DESCRIPTOR, mmsServer.name, mmsServer.url); + String.format(LBL_SERVER_DESCRIPTOR1, mmsServer.apiVersion, mmsServer.name) : + String.format(LBL_SERVER_DESCRIPTOR2, mmsServer.apiVersion, mmsServer.name, mmsServer.url); } else { return String.format(LBL_NAMED_DESCRIPTOR, ((MMSNamedDescriptor)mmsObject).name, mmsObject.id); } diff --git a/plugins/com.thalesgroup.mde.openmbee.connector.mms.management.ui/src/com/thalesgroup/mde/openmbee/connector/mms/management/ui/utils/MmsChildCreationWizard.java b/plugins/com.thalesgroup.mde.openmbee.connector.mms.management.ui/src/com/thalesgroup/mde/openmbee/connector/mms/management/ui/utils/MmsChildCreationWizard.java index c33b3cb..e919ddc 100644 --- a/plugins/com.thalesgroup.mde.openmbee.connector.mms.management.ui/src/com/thalesgroup/mde/openmbee/connector/mms/management/ui/utils/MmsChildCreationWizard.java +++ b/plugins/com.thalesgroup.mde.openmbee.connector.mms.management.ui/src/com/thalesgroup/mde/openmbee/connector/mms/management/ui/utils/MmsChildCreationWizard.java @@ -121,31 +121,33 @@ public void widgetSelected(SelectionEvent e) { boolean valid = false; MMSNamedDescriptor nd = null; switch(childType) { - case Organization: - valid = serverHelper.getOrgs().stream() - .noneMatch(o -> o.id.contentEquals(id.getText())); - if(valid) { - nd = new MMSOrganizationDescriptor(); + case Organization: { + valid = serverHelper.getOrgs().stream().noneMatch(o -> o.id.contentEquals(id.getText())); + if (valid) { + nd = new MMSOrganizationDescriptor(); + } + break; } - break; - case Project: - valid = serverHelper.getProjects().stream() - .noneMatch(p -> p.id.contentEquals(id.getText())); - if(valid) { - nd = new MMSProjectDescriptor(); + case Project: { + MMSIdentifiableDescriptor parent = MmsChildCreationWizard.this.parent; + valid = serverHelper.getProjects(parent.id).stream().noneMatch(p -> p.id.contentEquals(id.getText())); + if (valid) { + nd = new MMSProjectDescriptor(); + } + break; } - break; - case Ref: - MMSIdentifiableDescriptor parent = MmsChildCreationWizard.this.parent; - valid = serverHelper.getBranches((parent instanceof MMSProjectDescriptor) ? ((MMSProjectDescriptor) parent).org : null, parent.id).stream() - .noneMatch(b -> b.id.contentEquals(id.getText())); - if(valid) { - nd = new MMSRefDescriptor(); + case Ref: { + MMSIdentifiableDescriptor parent = MmsChildCreationWizard.this.parent; + valid = serverHelper.getBranches((parent instanceof MMSProjectDescriptor) ? ((MMSProjectDescriptor) parent).orgId : null, parent.id).stream() + .noneMatch(b -> b.id.contentEquals(id.getText())); + if (valid) { + nd = new MMSRefDescriptor(); + } + break; } - break; } - - if(valid) { + + if (valid) { nd.id = id.getText(); nd.name = name.getText().matches(VALIDATION_PATTERN_NAME) ? id.getText() : name.getText(); preparedChild.set(nd); diff --git a/plugins/com.thalesgroup.mde.openmbee.connector.mms.management.ui/src/com/thalesgroup/mde/openmbee/connector/mms/management/ui/utils/MmsServerConnectionPage.java b/plugins/com.thalesgroup.mde.openmbee.connector.mms.management.ui/src/com/thalesgroup/mde/openmbee/connector/mms/management/ui/utils/MmsServerConnectionPage.java index faf3693..0b755f6 100644 --- a/plugins/com.thalesgroup.mde.openmbee.connector.mms.management.ui/src/com/thalesgroup/mde/openmbee/connector/mms/management/ui/utils/MmsServerConnectionPage.java +++ b/plugins/com.thalesgroup.mde.openmbee.connector.mms.management.ui/src/com/thalesgroup/mde/openmbee/connector/mms/management/ui/utils/MmsServerConnectionPage.java @@ -36,6 +36,7 @@ public class MmsServerConnectionPage extends WizardPage { private Text serverName; private String defaultName = null; private String defaultUrl = null; + private String defaultAPIVersion = null; private String defaultUser = null; private String defaultPassword = null; @@ -67,6 +68,9 @@ public void createControl(Composite parent) { if(defaultUrl != null) { connection.setUrl(defaultUrl); } + if(defaultAPIVersion != null) { + connection.setAPIVersion(defaultAPIVersion); + } if(defaultUser != null) { connection.setUser(defaultUser); } @@ -88,6 +92,10 @@ public MMSServerDescriptor getConnectionData() { public String getUrl() { return connection.getUrl(); } + + public String getAPIVersion() { + return connection.getAPIVersion(); + } public String getUser() { return connection.getUser(); @@ -100,6 +108,10 @@ public String getPassword() { public void setDefaultUrl(String url) { defaultUrl = url; } + + public void setDefaultAPIVersion(String apiVersion) { + defaultAPIVersion = apiVersion; + } public void setDefaultUser(String user) { defaultUser = user; diff --git a/plugins/com.thalesgroup.mde.openmbee.connector.mms.management.ui/src/com/thalesgroup/mde/openmbee/connector/mms/management/ui/utils/MmsServerConnectionUpdateWizard.java b/plugins/com.thalesgroup.mde.openmbee.connector.mms.management.ui/src/com/thalesgroup/mde/openmbee/connector/mms/management/ui/utils/MmsServerConnectionUpdateWizard.java index 9c2b5e4..9117b05 100644 --- a/plugins/com.thalesgroup.mde.openmbee.connector.mms.management.ui/src/com/thalesgroup/mde/openmbee/connector/mms/management/ui/utils/MmsServerConnectionUpdateWizard.java +++ b/plugins/com.thalesgroup.mde.openmbee.connector.mms.management.ui/src/com/thalesgroup/mde/openmbee/connector/mms/management/ui/utils/MmsServerConnectionUpdateWizard.java @@ -37,6 +37,7 @@ public void addPages() { } catch (IllegalArgumentException e) {} connectionPage.setDefaultName(server.name); connectionPage.setDefaultUrl(server.url); + connectionPage.setDefaultAPIVersion(server.apiVersion); } @Override @@ -44,7 +45,9 @@ public boolean performFinish() { MMSServerDescriptor connectionData = connectionPage.getConnectionData(); boolean success = connectionData != null; if(success) { - connectionDataModified = !server.url.contentEquals(connectionData.url) || + connectionDataModified = !server.url.contentEquals(connectionData.url) || + server.apiVersion == null || + !server.apiVersion.contentEquals(connectionData.apiVersion) || !server.autData.contentEquals(connectionData.autData); success = connectionDataModified || !server.name.contentEquals(connectionData.name); if(success) { @@ -56,6 +59,7 @@ public boolean performFinish() { plugin.removeStoredMMSServerDescriptor(server); server.id = connectionData.id; server.url = connectionData.url; + server.apiVersion = connectionData.apiVersion; server.autData = connectionData.autData; server.name = connectionData.name; plugin.addStoredMMSServerDescriptor(server); diff --git a/plugins/com.thalesgroup.mde.openmbee.connector.mms.management.ui/src/com/thalesgroup/mde/openmbee/connector/mms/management/ui/views/MmsRepositoriesView.java b/plugins/com.thalesgroup.mde.openmbee.connector.mms.management.ui/src/com/thalesgroup/mde/openmbee/connector/mms/management/ui/views/MmsRepositoriesView.java index fa7cc55..2a2dfc2 100644 --- a/plugins/com.thalesgroup.mde.openmbee.connector.mms.management.ui/src/com/thalesgroup/mde/openmbee/connector/mms/management/ui/views/MmsRepositoriesView.java +++ b/plugins/com.thalesgroup.mde.openmbee.connector.mms.management.ui/src/com/thalesgroup/mde/openmbee/connector/mms/management/ui/views/MmsRepositoriesView.java @@ -69,7 +69,7 @@ public MmsRepositoriesView() { protected void retrieveViewerData() { MMSRepositoryViewRoot mmsRoot = new MMSRepositoryViewRoot(); - mmsRoot.id = "root"; + mmsRoot.id = "root"; //$NON-NLS-1$ viewerDataRoot = new MMSTreeParent(mmsRoot); MMSServerDescriptor[] storedMMSServerDescriptors = MmsServerManagementUiPlugin.getInstance().getStoredMMSServerDescriptors(); if(storedMMSServerDescriptors != null) { diff --git a/plugins/com.thalesgroup.mde.openmbee.connector.mms.management.ui/src/com/thalesgroup/mde/openmbee/connector/mms/management/ui/views/actions/SelectionBasedMmsCheckoutAction.java b/plugins/com.thalesgroup.mde.openmbee.connector.mms.management.ui/src/com/thalesgroup/mde/openmbee/connector/mms/management/ui/views/actions/SelectionBasedMmsCheckoutAction.java index 3064ec0..cbd686a 100644 --- a/plugins/com.thalesgroup.mde.openmbee.connector.mms.management.ui/src/com/thalesgroup/mde/openmbee/connector/mms/management/ui/views/actions/SelectionBasedMmsCheckoutAction.java +++ b/plugins/com.thalesgroup.mde.openmbee.connector.mms.management.ui/src/com/thalesgroup/mde/openmbee/connector/mms/management/ui/views/actions/SelectionBasedMmsCheckoutAction.java @@ -70,7 +70,7 @@ public void run() { dialog.run(true, true, new ImportRunnable( new AtomicReference(), new MmsProjectImportData( - new MmsConnectionData(server.url, server.autData, org.id), + new MmsConnectionData(server.url, server.apiVersion, server.autData, org.id), project.id, ref.id, commit == null ? null : commit.id), project.clientSideName, m -> { diff --git a/plugins/com.thalesgroup.mde.openmbee.connector.mms.sirius.ui/src/com/thalesgroup/mde/openmbee/connector/mms/sirius/ui/CapellaMmsExportWizard.java b/plugins/com.thalesgroup.mde.openmbee.connector.mms.sirius.ui/src/com/thalesgroup/mde/openmbee/connector/mms/sirius/ui/CapellaMmsExportWizard.java index 7d15135..6cf6e18 100644 --- a/plugins/com.thalesgroup.mde.openmbee.connector.mms.sirius.ui/src/com/thalesgroup/mde/openmbee/connector/mms/sirius/ui/CapellaMmsExportWizard.java +++ b/plugins/com.thalesgroup.mde.openmbee.connector.mms.sirius.ui/src/com/thalesgroup/mde/openmbee/connector/mms/sirius/ui/CapellaMmsExportWizard.java @@ -180,7 +180,7 @@ private ExecutionResult executeExport(IProject selectedProject, MmsProjectCommit if(connectionData != null && selectedProject != null) { try { - MMSServerHelper serverHelper = new MMSServerHelper(connectionData.serverUrl, connectionData.autData); + MMSServerHelper serverHelper = new MMSServerHelper(connectionData.serverUrl, connectionData.apiVersion, connectionData.autData); SiriusProjectConnector projectConnector = new SiriusProjectConnector(); monitor.beginTask("Export to MMS", 2+projectConnector.getNumberOfSubTaskOfToMms()); //$NON-NLS-1$ @@ -196,11 +196,10 @@ private ExecutionResult executeExport(IProject selectedProject, MmsProjectCommit connectionData.projectId, connectionData.projectServerName, selectedProject.getName()); - organizationId = project.org; + organizationId = project.orgId; projectId = project.id; projectFeaturePrefix = project.featurePrefix; - MMSRefDescriptor ref = serverHelper.getOrCreateBranch(project.org, project.id, - MMSServerHelper.MMS_REF__DEFAULT); + MMSRefDescriptor ref = serverHelper.getOrCreateBranch(project.orgId, project.id, MMSServerHelper.MMS_REF__DEFAULT); refId = ref.id; } else { // otherwise use the caught data @@ -211,7 +210,7 @@ private ExecutionResult executeExport(IProject selectedProject, MmsProjectCommit } monitor.worked(1); - // collect convertable resources + // collect convertible resources if(monitor.isCanceled()) { throw new InterruptedException(SiriusProjectConnector.MESSAGE_CANCELLATION_EXPORT); } @@ -224,7 +223,8 @@ private ExecutionResult executeExport(IProject selectedProject, MmsProjectCommit throw new InterruptedException(SiriusProjectConnector.MESSAGE_CANCELLATION_EXPORT); } if(siriusModelFiles.size()>1) { - success = projectConnector.toMms(connectionData.serverUrl, + success = projectConnector.toMms(connectionData.serverUrl, + connectionData.apiVersion, connectionData.autData, organizationId, projectId, diff --git a/plugins/com.thalesgroup.mde.openmbee.connector.mms.sirius.ui/src/com/thalesgroup/mde/openmbee/connector/mms/sirius/ui/ImportRunnable.java b/plugins/com.thalesgroup.mde.openmbee.connector.mms.sirius.ui/src/com/thalesgroup/mde/openmbee/connector/mms/sirius/ui/ImportRunnable.java index ae982c2..dd4b7f7 100644 --- a/plugins/com.thalesgroup.mde.openmbee.connector.mms.sirius.ui/src/com/thalesgroup/mde/openmbee/connector/mms/sirius/ui/ImportRunnable.java +++ b/plugins/com.thalesgroup.mde.openmbee.connector.mms.sirius.ui/src/com/thalesgroup/mde/openmbee/connector/mms/sirius/ui/ImportRunnable.java @@ -88,7 +88,8 @@ private ExecutionResult executeImport(MmsProjectImportData connectionData, Strin try { SiriusProjectConnector projectConnector = new SiriusProjectConnector(); monitor.beginTask("Import from MMS", projectConnector.getNumberOfSubTaskOfFromMms()); //$NON-NLS-1$ - success = projectConnector.fromMms(connectionData.serverUrl, + success = projectConnector.fromMms(connectionData.serverUrl, + connectionData.apiVersion, connectionData.autData, connectionData.projectId, connectionData.refId, diff --git a/plugins/com.thalesgroup.mde.openmbee.connector.mms.sirius.ui/src/com/thalesgroup/mde/openmbee/connector/mms/sirius/ui/data/MmsConnectionData.java b/plugins/com.thalesgroup.mde.openmbee.connector.mms.sirius.ui/src/com/thalesgroup/mde/openmbee/connector/mms/sirius/ui/data/MmsConnectionData.java index 06af04e..fa42dae 100644 --- a/plugins/com.thalesgroup.mde.openmbee.connector.mms.sirius.ui/src/com/thalesgroup/mde/openmbee/connector/mms/sirius/ui/data/MmsConnectionData.java +++ b/plugins/com.thalesgroup.mde.openmbee.connector.mms.sirius.ui/src/com/thalesgroup/mde/openmbee/connector/mms/sirius/ui/data/MmsConnectionData.java @@ -15,11 +15,13 @@ public class MmsConnectionData { public final String serverUrl; + public final String apiVersion; public final String autData; public final String orgId; - public MmsConnectionData(String serverUrl, String autData, String orgId) { + public MmsConnectionData(String serverUrl, String apiVersion, String autData, String orgId) { this.serverUrl = serverUrl; + this.apiVersion = apiVersion; this.autData = autData; this.orgId = orgId; } diff --git a/plugins/com.thalesgroup.mde.openmbee.connector.mms.sirius.ui/src/com/thalesgroup/mde/openmbee/connector/mms/sirius/ui/data/MmsProjectCommitData.java b/plugins/com.thalesgroup.mde.openmbee.connector.mms.sirius.ui/src/com/thalesgroup/mde/openmbee/connector/mms/sirius/ui/data/MmsProjectCommitData.java index 40fa39a..c1257fc 100644 --- a/plugins/com.thalesgroup.mde.openmbee.connector.mms.sirius.ui/src/com/thalesgroup/mde/openmbee/connector/mms/sirius/ui/data/MmsProjectCommitData.java +++ b/plugins/com.thalesgroup.mde.openmbee.connector.mms.sirius.ui/src/com/thalesgroup/mde/openmbee/connector/mms/sirius/ui/data/MmsProjectCommitData.java @@ -25,11 +25,11 @@ public class MmsProjectCommitData extends MmsConnectionData { public final boolean newProject; public MmsProjectCommitData(MmsConnectionData connectionData, String commitComment, String projectServerName, String projectId, boolean newProject) { - this(connectionData.serverUrl, connectionData.autData, connectionData.orgId, commitComment, newProject, projectServerName, projectId, null, null); + this(connectionData.serverUrl, connectionData.apiVersion, connectionData.autData, connectionData.orgId, commitComment, newProject, projectServerName, projectId, null, null); } - public MmsProjectCommitData(String serverUrl, String autData, String orgId, String commitComment, boolean newProject, String projectServerName, String projectId, String projectFeaturePrefix, String refId) { - super(serverUrl, autData, orgId); + public MmsProjectCommitData(String serverUrl, String apiVersion, String autData, String orgId, String commitComment, boolean newProject, String projectServerName, String projectId, String projectFeaturePrefix, String refId) { + super(serverUrl, apiVersion, autData, orgId); this.commitComment = commitComment; this.projectServerName = projectServerName; this.projectId = projectId; @@ -39,7 +39,8 @@ public MmsProjectCommitData(String serverUrl, String autData, String orgId, Stri } public MmsProjectCommitData(MmsConnectionData connectionData, String commitComment, boolean newProject, MMSProjectDescriptor project, MMSRefDescriptor ref) { - this(connectionData.serverUrl, + this(connectionData.serverUrl, + connectionData.apiVersion, connectionData.autData, connectionData.orgId, commitComment, diff --git a/plugins/com.thalesgroup.mde.openmbee.connector.mms.sirius.ui/src/com/thalesgroup/mde/openmbee/connector/mms/sirius/ui/data/MmsProjectConnectionData.java b/plugins/com.thalesgroup.mde.openmbee.connector.mms.sirius.ui/src/com/thalesgroup/mde/openmbee/connector/mms/sirius/ui/data/MmsProjectConnectionData.java index 35fc828..becde88 100644 --- a/plugins/com.thalesgroup.mde.openmbee.connector.mms.sirius.ui/src/com/thalesgroup/mde/openmbee/connector/mms/sirius/ui/data/MmsProjectConnectionData.java +++ b/plugins/com.thalesgroup.mde.openmbee.connector.mms.sirius.ui/src/com/thalesgroup/mde/openmbee/connector/mms/sirius/ui/data/MmsProjectConnectionData.java @@ -18,11 +18,11 @@ public class MmsProjectConnectionData extends MmsConnectionData { public final String refId; public MmsProjectConnectionData(MmsConnectionData connectionData, String projectId, String refId) { - this(connectionData.serverUrl, connectionData.autData, connectionData.orgId, projectId, refId); + this(connectionData.serverUrl, connectionData.apiVersion, connectionData.autData, connectionData.orgId, projectId, refId); } - public MmsProjectConnectionData(String serverUrl, String autData, String orgId, String projectId, String refId) { - super(serverUrl, autData, orgId); + public MmsProjectConnectionData(String serverUrl, String apiVersion, String autData, String orgId, String projectId, String refId) { + super(serverUrl, apiVersion, autData, orgId); this.projectId = projectId; this.refId = refId; } diff --git a/plugins/com.thalesgroup.mde.openmbee.connector.mms.sirius.ui/src/com/thalesgroup/mde/openmbee/connector/mms/sirius/ui/data/MmsProjectImportData.java b/plugins/com.thalesgroup.mde.openmbee.connector.mms.sirius.ui/src/com/thalesgroup/mde/openmbee/connector/mms/sirius/ui/data/MmsProjectImportData.java index df9633a..fb12934 100644 --- a/plugins/com.thalesgroup.mde.openmbee.connector.mms.sirius.ui/src/com/thalesgroup/mde/openmbee/connector/mms/sirius/ui/data/MmsProjectImportData.java +++ b/plugins/com.thalesgroup.mde.openmbee.connector.mms.sirius.ui/src/com/thalesgroup/mde/openmbee/connector/mms/sirius/ui/data/MmsProjectImportData.java @@ -17,7 +17,7 @@ public class MmsProjectImportData extends MmsProjectConnectionData { public final String commitId; public MmsProjectImportData(MmsConnectionData connectionData, String projectId, String refId, String commitId) { - super(connectionData.serverUrl, connectionData.autData, connectionData.orgId, projectId, refId); + super(connectionData.serverUrl, connectionData.apiVersion, connectionData.autData, connectionData.orgId, projectId, refId); this.commitId = commitId; } diff --git a/plugins/com.thalesgroup.mde.openmbee.connector.mms.sirius.ui/src/com/thalesgroup/mde/openmbee/connector/mms/sirius/ui/pages/ConnectMmsServerWizardPage.java b/plugins/com.thalesgroup.mde.openmbee.connector.mms.sirius.ui/src/com/thalesgroup/mde/openmbee/connector/mms/sirius/ui/pages/ConnectMmsServerWizardPage.java index c30bf85..a2e29de 100644 --- a/plugins/com.thalesgroup.mde.openmbee.connector.mms.sirius.ui/src/com/thalesgroup/mde/openmbee/connector/mms/sirius/ui/pages/ConnectMmsServerWizardPage.java +++ b/plugins/com.thalesgroup.mde.openmbee.connector.mms.sirius.ui/src/com/thalesgroup/mde/openmbee/connector/mms/sirius/ui/pages/ConnectMmsServerWizardPage.java @@ -109,7 +109,7 @@ protected void updatePageCompletness(String completnessKey, boolean completnessV } protected void loadOrganizationsIntoComboViewer() { - serverHelper = new MMSServerHelper(container.getUrl(), getConnectionData().autData); + serverHelper = new MMSServerHelper(container.getUrl(), container.getAPIVersion(), getConnectionData().autData); List orgs = serverHelper.getOrgs(); if(orgs != null && orgs.size()>0) { orgSelector.setInput(orgs); @@ -199,7 +199,7 @@ public MmsConnectionData getConnectionData() { String userpasswd = String.format(TEMPLATE_USERPASSWD, container.getUser(), container.getPassword()); String autData = String.format(TEMPLATE_BASICAUTDATA, Base64.getEncoder().encodeToString(userpasswd.getBytes())); String orgId = getSelectedDescriptorId(orgSelector); - return new MmsConnectionData(container.getUrl(), autData, orgId); + return new MmsConnectionData(container.getUrl(), container.getAPIVersion(), autData, orgId); } public String getUser() { diff --git a/plugins/com.thalesgroup.mde.openmbee.connector.mms.sirius.ui/src/com/thalesgroup/mde/openmbee/connector/mms/sirius/ui/pages/MmsProjectCommitWizardPage.java b/plugins/com.thalesgroup.mde.openmbee.connector.mms.sirius.ui/src/com/thalesgroup/mde/openmbee/connector/mms/sirius/ui/pages/MmsProjectCommitWizardPage.java index 804c1c1..c1cf6c3 100644 --- a/plugins/com.thalesgroup.mde.openmbee.connector.mms.sirius.ui/src/com/thalesgroup/mde/openmbee/connector/mms/sirius/ui/pages/MmsProjectCommitWizardPage.java +++ b/plugins/com.thalesgroup.mde.openmbee.connector.mms.sirius.ui/src/com/thalesgroup/mde/openmbee/connector/mms/sirius/ui/pages/MmsProjectCommitWizardPage.java @@ -104,7 +104,7 @@ public void widgetSelected(SelectionEvent e) { projectDescriptor.clientSideName = projectDescriptor.name; } List refs = - serverHelper.getBranches(projectDescriptor.org, projectDescriptor.id); + serverHelper.getBranches(projectDescriptor.orgId, projectDescriptor.id); refSelector.setInput(refs); refSelector.getCombo().setEnabled(true); } diff --git a/plugins/com.thalesgroup.mde.openmbee.connector.mms.sirius.ui/src/com/thalesgroup/mde/openmbee/connector/mms/sirius/ui/pages/MmsProjectVersionSelectionWizardPage.java b/plugins/com.thalesgroup.mde.openmbee.connector.mms.sirius.ui/src/com/thalesgroup/mde/openmbee/connector/mms/sirius/ui/pages/MmsProjectVersionSelectionWizardPage.java index 7d7e5e2..456429d 100644 --- a/plugins/com.thalesgroup.mde.openmbee.connector.mms.sirius.ui/src/com/thalesgroup/mde/openmbee/connector/mms/sirius/ui/pages/MmsProjectVersionSelectionWizardPage.java +++ b/plugins/com.thalesgroup.mde.openmbee.connector.mms.sirius.ui/src/com/thalesgroup/mde/openmbee/connector/mms/sirius/ui/pages/MmsProjectVersionSelectionWizardPage.java @@ -96,7 +96,7 @@ public void widgetSelected(SelectionEvent e) { projectDescriptor.clientSideName = projectDescriptor.name; } List refs = - serverHelper.getBranches(projectDescriptor.org, projectDescriptor.id); + serverHelper.getBranches(projectDescriptor.orgId, projectDescriptor.id); refSelector.setInput(refs); refSelector.getCombo().setEnabled(true); commitSelector.getCombo().setEnabled(false); @@ -127,7 +127,7 @@ public void widgetSelected(SelectionEvent e) { Object selectedRef = getSelectedElement(refSelector); if(selectedProject instanceof MMSProjectDescriptor && selectedRef instanceof MMSRefDescriptor) { List commits = serverHelper.getCommits( - ((MMSProjectDescriptor)selectedProject).org, + ((MMSProjectDescriptor)selectedProject).orgId, ((MMSProjectDescriptor)selectedProject).id, ((MMSRefDescriptor)selectedRef).id); commitSelector.setInput(commits); diff --git a/plugins/com.thalesgroup.mde.openmbee.connector.mms.sirius/src/com/thalesgroup/mde/openmbee/connector/mms/sirius/EmfMmsModelElementDescriptorConverter.java b/plugins/com.thalesgroup.mde.openmbee.connector.mms.sirius/src/com/thalesgroup/mde/openmbee/connector/mms/sirius/EmfMmsModelElementDescriptorConverter.java index 936dfdb..3107473 100644 --- a/plugins/com.thalesgroup.mde.openmbee.connector.mms.sirius/src/com/thalesgroup/mde/openmbee/connector/mms/sirius/EmfMmsModelElementDescriptorConverter.java +++ b/plugins/com.thalesgroup.mde.openmbee.connector.mms.sirius/src/com/thalesgroup/mde/openmbee/connector/mms/sirius/EmfMmsModelElementDescriptorConverter.java @@ -98,14 +98,14 @@ public Map fromMMS(List2) { - if(featureName.endsWith("Id")) { + if(featureName.endsWith("Id")) { //$NON-NLS-1$ esf = eClass.getEStructuralFeature(featureName.substring(0, featureName.length()-2)); - } else if(featureName.endsWith("Ids")) { + } else if(featureName.endsWith("Ids")) { //$NON-NLS-1$ esf = eClass.getEStructuralFeature(featureName.substring(0, featureName.length()-3)); } } if(esf == null) { - if(!featureName.startsWith("_")) MmsSiriusConnectorPlugin.getDefault().getLogger().warn(featureName); + if(!featureName.startsWith("_")) MmsSiriusConnectorPlugin.getDefault().getLogger().warn(featureName); //$NON-NLS-1$ } else if(esf.isChangeable() && !esf.isDerived() && !esf.isTransient() && !isOppositeOfContainmentReference(esf)) { if(esf.isMany()) { Object values = medAttribute.getValue(); @@ -378,7 +378,7 @@ public String getExternalId(EObject eobject, boolean calculateQualifiedNameIfNec if(id == null) { id = EcoreUtil.getID(eobject); String prefix = null; - String resourceId = ""; + String resourceId = ""; //$NON-NLS-1$ if(eResource == null) { resourceId = "NO_RESOURCE"+ID_SEPARATOR; //$NON-NLS-1$ } else { @@ -398,7 +398,7 @@ public String getExternalId(EObject eobject, boolean calculateQualifiedNameIfNec if ((id == null || id.length() == 0) && calculateQualifiedNameIfNecessary) { EAttribute idFeature = eobject.eClass().getEAllAttributes().stream() - .filter(eattr -> "name".contentEquals(eattr.getName().toLowerCase())) + .filter(eattr -> "name".contentEquals(eattr.getName().toLowerCase())) //$NON-NLS-1$ .findFirst().orElse(null); if(eobject.eContainer() != null) { id = String.format("%s%s%s", getExternalId(eobject.eContainer(), calculateQualifiedNameIfNecessary, meds), //$NON-NLS-1$ diff --git a/plugins/com.thalesgroup.mde.openmbee.connector.mms.sirius/src/com/thalesgroup/mde/openmbee/connector/mms/sirius/ProjectStructureConverter.java b/plugins/com.thalesgroup.mde.openmbee.connector.mms.sirius/src/com/thalesgroup/mde/openmbee/connector/mms/sirius/ProjectStructureConverter.java index 1df3509..319a923 100644 --- a/plugins/com.thalesgroup.mde.openmbee.connector.mms.sirius/src/com/thalesgroup/mde/openmbee/connector/mms/sirius/ProjectStructureConverter.java +++ b/plugins/com.thalesgroup.mde.openmbee.connector.mms.sirius/src/com/thalesgroup/mde/openmbee/connector/mms/sirius/ProjectStructureConverter.java @@ -49,6 +49,7 @@ import com.thalesgroup.mde.openmbee.connector.fsmodel.filesystem.FilesystemPackage; import com.thalesgroup.mde.openmbee.connector.mms.data.MMSConstants; import com.thalesgroup.mde.openmbee.connector.mms.data.MMSModelElementDescriptor; +import com.thalesgroup.mde.openmbee.connector.mms.data.MMSServerDescriptor; import com.thalesgroup.mde.openmbee.connector.mms.sirius.utils.ProjectAlreadyExistsException; import com.thalesgroup.mde.openmbee.connector.mms.sirius.utils.ProjectCreationException; import com.thalesgroup.mde.openmbee.connector.mms.utils.MMSServerHelper; @@ -160,7 +161,8 @@ public Map fromMMS(Collection toMMS(String baseUrl, String autData, String projectId, String branchId, String featurePrefix, Collection files) { + @SuppressWarnings("unchecked") + public Map toMMS(String baseUrl, String apiVersion, String autData, String projectId, String branchId, String featurePrefix, Collection files) { String fileNameFeatureId = featurePrefix+FILE_NAME; String filePathFeatureId = featurePrefix+FILE_PATH; String fileContentFeatureId = featurePrefix+FILE_CONTENT; @@ -168,7 +170,7 @@ public Map toMMS(String baseUrl, String au Stack convertibles = new Stack<>(); Map convertedResources = new HashMap<>(); Map convertedResourcesForIDs = new HashMap<>(); - MMSServerHelper mmsHelper = new MMSServerHelper(baseUrl, autData); + MMSServerHelper mmsHelper = new MMSServerHelper(baseUrl, apiVersion, autData); convertibles.addAll(files); while(!convertibles.empty()) { IResource current = convertibles.pop(); @@ -184,7 +186,7 @@ public Map toMMS(String baseUrl, String au IContainer container = current.getParent(); if(container != null && container.getType() != IResource.ROOT) { if(container.getType() == IResource.PROJECT) { - ownerId = projectId; + ownerId = MMSServerDescriptor.API_VERSION_4.contentEquals(apiVersion) ? "model" : projectId; //$NON-NLS-1$ // save the .project file if it exists IFile projectDescriptorFile = ((IProject) container).getFile(".project"); //$NON-NLS-1$ if(projectDescriptorFile.exists()) { @@ -231,12 +233,14 @@ public Map toMMS(String baseUrl, String au current.msiDescriptor.emfNsUri = fileSystemNsUri; if(!projectId.contentEquals(current.msiDescriptor.ownerId)) { MMSModelElementDescriptor owner = convertedResourcesForIDs.get(current.msiDescriptor.ownerId); - Object resourceIds = owner.msiDescriptor.attributes.get("resourceIds"); //$NON-NLS-1$ - if(resourceIds == null) { - resourceIds = new ArrayList(); - owner.msiDescriptor.attributes.put("resourceIds", resourceIds); //$NON-NLS-1$ + if (owner != null) { + Object resourceIds = owner.msiDescriptor.attributes.get("resourceIds"); //$NON-NLS-1$ + if(resourceIds == null) { + resourceIds = new ArrayList(); + owner.msiDescriptor.attributes.put("resourceIds", resourceIds); //$NON-NLS-1$ + } + ((ArrayList)resourceIds).add(current.id); } - ((ArrayList)resourceIds).add(current.id); } } return convertedResources; diff --git a/plugins/com.thalesgroup.mde.openmbee.connector.mms.sirius/src/com/thalesgroup/mde/openmbee/connector/mms/sirius/SiriusProjectConnector.java b/plugins/com.thalesgroup.mde.openmbee.connector.mms.sirius/src/com/thalesgroup/mde/openmbee/connector/mms/sirius/SiriusProjectConnector.java index 2c6d1b8..20534d4 100644 --- a/plugins/com.thalesgroup.mde.openmbee.connector.mms.sirius/src/com/thalesgroup/mde/openmbee/connector/mms/sirius/SiriusProjectConnector.java +++ b/plugins/com.thalesgroup.mde.openmbee.connector.mms.sirius/src/com/thalesgroup/mde/openmbee/connector/mms/sirius/SiriusProjectConnector.java @@ -41,6 +41,7 @@ import com.thalesgroup.mde.openmbee.connector.mms.data.MMSConstants; import com.thalesgroup.mde.openmbee.connector.mms.data.MMSModelElementDescriptor; import com.thalesgroup.mde.openmbee.connector.mms.data.MMSProjectDescriptor; +import com.thalesgroup.mde.openmbee.connector.mms.data.MMSServerDescriptor; import com.thalesgroup.mde.openmbee.connector.mms.sirius.utils.ProjectCreationException; import com.thalesgroup.mde.openmbee.connector.mms.utils.MMSServerHelper; @@ -55,27 +56,33 @@ public class SiriusProjectConnector { */ private static final String MESSAGE__PROJECT_CORRUPTION = "No elements can be found for the project '%s' at the branch '%s'. Maybe it has been corrupted on the server '%s'."; //$NON-NLS-1$ private static final IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot(); - private static final String FILTER_TEMPLATE__HOLDING_BIN = "holding_bin_%s"; //$NON-NLS-1$ - private static final String FILTER_TEMPLATE__VIEW_INSTANCES_BIN = "view_instances_bin_%s"; //$NON-NLS-1$ public static final String MESSAGE_CANCELLATION_EXPORT = "MMS export cancelled. Probably some elements have already been created on the server."; //$NON-NLS-1$ public static final String MESSAGE_CANCELLATION_IMPORT = "MMS import cancelled."; //$NON-NLS-1$ - - public boolean toMms(String baseUrl, String autData, String organizationId, String projectId, String branchId, Collection resources, String featurePrefix) throws InterruptedException { - return toMms(baseUrl, autData, organizationId, projectId, branchId, resources, "", featurePrefix); //$NON-NLS-1$ + + private static final String MMS3_FILTER_TEMPLATE__HOLDING_BIN = "holding_bin_%s"; //$NON-NLS-1$ + private static final String MMS3_FILTER_TEMPLATE__VIEW_INSTANCES_BIN = "view_instances_bin_%s"; //$NON-NLS-1$ + + private static final String MMS4_FILTER__MODEL = "model"; //$NON-NLS-1$ + private static final String MMS4_FILTER__MBEE = "__mbee__"; //$NON-NLS-1$ + private static final String MMS4_FILTER__HOLDING_BIN = "holding_bin"; //$NON-NLS-1$ + private static final String MMS4_FILTER__UNDEFINED = "undefined"; //$NON-NLS-1$ + + public boolean toMms(String baseUrl, String apiVersion, String autData, String organizationId, String projectId, String branchId, Collection resources, String featurePrefix) throws InterruptedException { + return toMms(baseUrl, apiVersion, autData, organizationId, projectId, branchId, resources, "", featurePrefix); //$NON-NLS-1$ } - public boolean toMms(String baseUrl, String autData, String organizationId, String projectId, String branchId, Collection resources, String commitComment, String featurePrefix) throws InterruptedException { - return toMms(baseUrl, autData, organizationId, projectId, branchId, resources, commitComment, featurePrefix, new NullProgressMonitor()); + public boolean toMms(String baseUrl, String apiVersion, String autData, String organizationId, String projectId, String branchId, Collection resources, String commitComment, String featurePrefix) throws InterruptedException { + return toMms(baseUrl, apiVersion, autData, organizationId, projectId, branchId, resources, commitComment, featurePrefix, new NullProgressMonitor()); } - public boolean toMms(String baseUrl, String autData, String organizationId, String projectId, String branchId, Collection resources, String commitComment, String featurePrefix, IProgressMonitor monitor) throws InterruptedException { + public boolean toMms(String baseUrl, String apiVersion, String autData, String organizationId, String projectId, String branchId, Collection resources, String commitComment, String featurePrefix, IProgressMonitor monitor) throws InterruptedException { try { // Convert structure startNewSubTaskIfNotCancelled(monitor, "Convert project structure", MESSAGE_CANCELLATION_EXPORT); //$NON-NLS-1$ ProjectStructureConverter structureConverter = new ProjectStructureConverter(); Map files = resources.stream().collect(Collectors.toMap(r -> r, r -> getFile(r))); Map convertedFiles = - structureConverter.toMMS(baseUrl, autData, projectId, branchId, featurePrefix, files.values()); + structureConverter.toMMS(baseUrl, apiVersion, autData, projectId, branchId, featurePrefix, files.values()); monitor.worked(1); // Convert model elements @@ -94,18 +101,20 @@ public boolean toMms(String baseUrl, String autData, String organizationId, Stri } } monitor.worked(1); - - + // Upload startNewSubTaskIfNotCancelled(monitor, "Upload model to MMS (cannot be cancelled)", MESSAGE_CANCELLATION_EXPORT); //$NON-NLS-1$ - MMSServerHelper serverHelper = new MMSServerHelper(baseUrl, autData); + MMSServerHelper serverHelper = new MMSServerHelper(baseUrl, apiVersion, autData); List structureWithModelElements = Stream.concat(convertedFiles.values().stream(), convertedModelElements.values().stream()) .collect(Collectors.toList()); Set idsOfStructureWithModelElements = structureWithModelElements.stream().map(med -> med.id).collect(Collectors.toSet()); - List filteredElements = Arrays.asList(projectId, - String.format(FILTER_TEMPLATE__HOLDING_BIN, projectId), - String.format(FILTER_TEMPLATE__VIEW_INSTANCES_BIN, projectId)); + List filteredElements = MMSServerDescriptor.API_VERSION_4.equals(apiVersion) ? + Arrays.asList(projectId, MMS4_FILTER__MODEL, MMS4_FILTER__MBEE, MMS4_FILTER__HOLDING_BIN, String.format(MMS4_FILTER__UNDEFINED)) : + Arrays.asList(projectId, + String.format(MMS3_FILTER_TEMPLATE__HOLDING_BIN, projectId), + String.format(MMS3_FILTER_TEMPLATE__VIEW_INSTANCES_BIN, projectId)); + // Calculate the removable elements List removables = serverHelper.getModelElements(organizationId, projectId, branchId).stream() .filter(med -> { @@ -116,7 +125,7 @@ public boolean toMms(String baseUrl, String autData, String organizationId, Stri // If something is not available in the current elements it needs to be removed return !idsOfStructureWithModelElements.contains(med.id); }).collect(Collectors.toList()); - if(removables.size() > 0) { + if (removables.size() > 0) { // Delete the locally removed elements from the server if(!serverHelper.removeModelElements(organizationId, projectId, branchId, String.format(MESSAGE__DELETE_COMMIT, commitComment), removables)) { throw new InterruptedException(MESSAGE__UNSUCCESSFUL_DELETE); @@ -125,7 +134,8 @@ public boolean toMms(String baseUrl, String autData, String organizationId, Stri monitor.worked(1); List createdOnServer = - serverHelper.createModelElements(projectId, + serverHelper.createModelElements(organizationId, + projectId, branchId, removables.size() > 0 ? String.format(MESSAGE__UPDATE_COMMIT, commitComment) : commitComment, structureWithModelElements); @@ -154,18 +164,18 @@ private IFile getFile(Resource res) { return wsRoot.getFile(new Path(res.getURI().toPlatformString(true))); } - public boolean fromMms(String baseUrl, String autData, String projectId, String branchId) throws InterruptedException { - return fromMms(baseUrl, autData, projectId, branchId, null, null, new NullProgressMonitor()); + public boolean fromMms(String baseUrl, String apiVersion, String autData, String projectId, String branchId) throws InterruptedException { + return fromMms(baseUrl, apiVersion, autData, projectId, branchId, null, null, new NullProgressMonitor()); } - public boolean fromMms(String baseUrl, String autData, String projectId, String branchId, String commitId, String projectName, IProgressMonitor monitor) throws InterruptedException { + public boolean fromMms(String baseUrl, String apiVersion, String autData, String projectId, String branchId, String commitId, String projectName, IProgressMonitor monitor) throws InterruptedException { boolean success = false; List elements = null; - MMSServerHelper serverHelper = new MMSServerHelper(baseUrl, autData); + MMSServerHelper serverHelper = new MMSServerHelper(baseUrl, apiVersion, autData); try { startNewSubTaskIfNotCancelled(monitor, "Download data from MMS", MESSAGE_CANCELLATION_IMPORT); //$NON-NLS-1$ - String holdingBinFilter = String.format(FILTER_TEMPLATE__HOLDING_BIN, projectId); - String viewInstancesBinFilter = String.format(FILTER_TEMPLATE__VIEW_INSTANCES_BIN, projectId); + String holdingBinFilter = String.format(MMS3_FILTER_TEMPLATE__HOLDING_BIN, projectId); + String viewInstancesBinFilter = String.format(MMS3_FILTER_TEMPLATE__VIEW_INSTANCES_BIN, projectId); elements = serverHelper.getModelElements(projectId, branchId, commitId); elements = elements.stream().filter(e -> !holdingBinFilter.contentEquals(e.id) && !viewInstancesBinFilter.contentEquals(e.id) ).collect(Collectors.toList()); monitor.worked(1); @@ -179,7 +189,7 @@ public boolean fromMms(String baseUrl, String autData, String projectId, String elements.remove(projectDescriptor); } else { try { - projectDescriptor = serverHelper.getModelElement(projectId, branchId, projectId, null).get(0); + projectDescriptor = serverHelper.getModelElement(projectId, branchId, projectId).get(0); } catch (IndexOutOfBoundsException e) { throw new InterruptedException("Project descriptor cannot be found on the server."); //$NON-NLS-1$ } diff --git a/plugins/com.thalesgroup.mde.openmbee.connector.mms.ui/src/com/thalesgroup/mde/openmbee/connector/mms/ui/MmsServerConnectionDataComposite.java b/plugins/com.thalesgroup.mde.openmbee.connector.mms.ui/src/com/thalesgroup/mde/openmbee/connector/mms/ui/MmsServerConnectionDataComposite.java index cbdd66e..bd42484 100644 --- a/plugins/com.thalesgroup.mde.openmbee.connector.mms.ui/src/com/thalesgroup/mde/openmbee/connector/mms/ui/MmsServerConnectionDataComposite.java +++ b/plugins/com.thalesgroup.mde.openmbee.connector.mms.ui/src/com/thalesgroup/mde/openmbee/connector/mms/ui/MmsServerConnectionDataComposite.java @@ -20,6 +20,8 @@ import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.fieldassist.ContentProposalAdapter; +import org.eclipse.jface.fieldassist.IContentProposal; +import org.eclipse.jface.fieldassist.IContentProposalListener; import org.eclipse.jface.fieldassist.TextContentAdapter; import org.eclipse.jface.wizard.WizardPage; import org.eclipse.swt.SWT; @@ -28,6 +30,7 @@ import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Label; @@ -45,36 +48,60 @@ public class MmsServerConnectionDataComposite extends Composite { private static final String TITLE__CONNECTION_ERROR = "Connection Error"; //$NON-NLS-1$ private static final String MSG__UNSUCCESSFUL_LOGIN = "Login to the server %s was not successful."; //$NON-NLS-1$ protected static final int LAYOUT_MINCOLUMNNUM = 3; - protected static final String LABEL_URL = "MMS server URL:"; //$NON-NLS-1$ + protected static final String LABEL_URL = "MMS Server URL:"; //$NON-NLS-1$ + protected static final String LABEL_API = "MMS API Version:"; //$NON-NLS-1$ protected static final String LABEL_USER = "Username:"; //$NON-NLS-1$ protected static final String LABEL_PASS = "Password:"; //$NON-NLS-1$ - + + private static final String[] API_VERSIONS = new String[] { MMSServerDescriptor.API_VERSION_3, MMSServerDescriptor.API_VERSION_4 }; + private UiHelper helper = UiHelper.getInstance(); private Text txtUrl; private Text txtUser; private Text txtPass; + private Combo cbApiVersion; private String serverUrl; private String username; private String password; + private String apiVersion; private MMSServerDescriptor serverConnectionData; public final int numberOfColumns; public MmsServerConnectionDataComposite(WizardPage containingPage, Composite parent, int style, int columnsInGrid, String lblConnectionTesterButton, List disablableControls, Consumer actionToExecuteAfterSuccessfulConnectionTest) { super(parent, style); + numberOfColumns = columnsInGrid < LAYOUT_MINCOLUMNNUM ? LAYOUT_MINCOLUMNNUM : columnsInGrid; GridLayout layout = new GridLayout(); this.setLayout(layout); layout.numColumns = numberOfColumns; - + txtUrl = helper.createTextRow(containingPage, this, LABEL_URL, numberOfColumns, disablableControls); txtUrl.setText(MmsUiPlugin.getDefault().getStoredMmsUrls()[0]); - new ContentProposalAdapter(txtUrl, new TextContentAdapter(), + ContentProposalAdapter urlProposalAdapter = new ContentProposalAdapter(txtUrl, new TextContentAdapter(), new VariableContentProposalProvider() { @Override protected Collection getPossibleValues() { return Arrays.asList(MmsUiPlugin.getDefault().getStoredMmsUrls()); } - }, null, null).setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE); + }, null, null); + urlProposalAdapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE); + urlProposalAdapter.addContentProposalListener(new IContentProposalListener() { + @Override + public void proposalAccepted(IContentProposal proposal) { + // FIXME retrieve api version from stored server data and update combo box + System.out.println(); + } + }); + + Label lbl = new Label(this, SWT.NONE); + lbl.setText(LABEL_API); + cbApiVersion = new Combo(this, SWT.READ_ONLY); + cbApiVersion.setItems(API_VERSIONS); + GridData gdFill = new GridData(SWT.FILL, SWT.CENTER, true, false); + gdFill.horizontalSpan = numberOfColumns - 1; + cbApiVersion.setLayoutData(gdFill); + cbApiVersion.select(1); + txtUser = helper.createTextRow(containingPage, this, LABEL_USER, numberOfColumns, disablableControls); txtUser.setText(MmsUiPlugin.getDefault().getStoredMmsUsers()[0]); new ContentProposalAdapter(txtUser, new TextContentAdapter(), @@ -84,23 +111,24 @@ protected Collection getPossibleValues() { return Arrays.asList(MmsUiPlugin.getDefault().getStoredMmsUsers()); } }, null, null).setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE); + txtPass = helper.createTextRow(containingPage, this, LABEL_PASS, numberOfColumns, SWT.PASSWORD, disablableControls); // Fill the space before the button Label lblFillBeforeButton = new Label(this, SWT.NONE); - GridData gdFill = new GridData(SWT.FILL, SWT.CENTER, true, false); + gdFill = new GridData(SWT.FILL, SWT.CENTER, true, false); gdFill.horizontalSpan = numberOfColumns - 1; lblFillBeforeButton.setLayoutData(gdFill); + Button btnTestConnection = new Button(this, SWT.PUSH); btnTestConnection.setText(lblConnectionTesterButton); btnTestConnection.addSelectionListener(new SelectionAdapter() { - @Override public void widgetSelected(SelectionEvent e) { try { boolean isLoginSuccessful = checkConnection(); if(isLoginSuccessful) { - serverConnectionData = new MMSServerDescriptor(serverUrl, MMSServerHelper.encodeBasicAuthData(username, password)); + serverConnectionData = new MMSServerDescriptor(serverUrl, apiVersion, MMSServerHelper.encodeBasicAuthData(username, password)); actionToExecuteAfterSuccessfulConnectionTest.accept(serverConnectionData); } else { throw new MMSConnectionException(String.format(MSG__UNSUCCESSFUL_LOGIN, serverUrl)); @@ -124,15 +152,20 @@ public void widgetSelected(SelectionEvent e) { protected boolean checkConnection() { serverUrl = txtUrl.getText(); + apiVersion = API_VERSIONS[cbApiVersion.getSelectionIndex()]; username = txtUser.getText(); password = txtPass.getText(); - String ticket = MMSServerHelper.login(serverUrl, username, password); + String ticket = MMSServerHelper.login(serverUrl, apiVersion, username, password); return ticket != null && !ticket.isEmpty(); } - + public String getUrl() { return serverUrl; } + + public String getAPIVersion() { + return apiVersion; + } public String getUser() { return username; @@ -146,6 +179,10 @@ public void setUrl(String url) { txtUrl.setText(url); } + public void setAPIVersion(String apiVersion) { + cbApiVersion.setText(apiVersion); + } + public void setUser(String user) { txtUser.setText(user); } diff --git a/plugins/com.thalesgroup.mde.openmbee.connector.mms/src/com/thalesgroup/mde/openmbee/connector/mms/data/MMS3JsonHelper.java b/plugins/com.thalesgroup.mde.openmbee.connector.mms/src/com/thalesgroup/mde/openmbee/connector/mms/data/MMS3JsonHelper.java new file mode 100644 index 0000000..21ecbb2 --- /dev/null +++ b/plugins/com.thalesgroup.mde.openmbee.connector.mms/src/com/thalesgroup/mde/openmbee/connector/mms/data/MMS3JsonHelper.java @@ -0,0 +1,121 @@ +/******************************************************************************* + * Copyright (c) 2020 Thales Global Services S.A.S. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Thales - initial API and implementation + *******************************************************************************/ +package com.thalesgroup.mde.openmbee.connector.mms.data; + +import java.util.ArrayList; +import java.util.List; + +import com.thalesgroup.mde.openmbee.connector.mms.utils.MMSServerHelper.MMSConnectionException; + +/** + * JSon helpers for MMS3 + */ +public class MMS3JsonHelper { + + private static final String INVALID_LOGIN = "Invalid login response:%s%s"; //$NON-NLS-1$ + + /** + * Retrieves a token from a given json data + * @param json the json data to be read + * @return a token + */ + public static String readTokenFromJson(String json) { + MMSRootDescriptor root = MMSJsonHelper.readRootFromJson(json); + if (root.data != null && root.data.ticket != null && root.data.ticket.length()>0) { + return root.data.ticket; + } else { + throw new MMSConnectionException(String.format(INVALID_LOGIN, System.lineSeparator(), json)); + } + } + + /** + * Retrieves a list of organizations from a given json data + * @param json the json data to be read + * @return a list of organizations + */ + public static List readOrganizationsFromJson(String json) { + List orgs = new ArrayList<>(); + + MMSRootDescriptor root = MMSJsonHelper.readRootFromJson(json); + for (MMSOrganizationDescriptor element : root.orgs) { + orgs.add(element); + } + + return orgs; + } + + /** + * Retrieves a list of projects from a given json data + * @param json the json data to be read + * @return a list of projects + */ + public static List readProjectsFromJson(String json) { + List projects = new ArrayList<>(); + + MMSRootDescriptor root = MMSJsonHelper.readRootFromJson(json); + for (MMSProjectDescriptor element : root.projects) { + projects.add(element); + } + + return projects; + } + + /** + * Retrieves a list of branches from a given json data + * @param json the json data to be read + * @return a list of branches + */ + public static List readBranchesFromJson(String json) { + List refs = new ArrayList<>(); + + MMSRootDescriptor root = MMSJsonHelper.readRootFromJson(json); + for (MMSRefDescriptor element : root.refs) { + refs.add(element); + } + + return refs; + } + + /** + * Retrieves a list of commits from a given json data + * @param json the json data to be read + * @return a list of commits + */ + public static List readCommitsFromJson(String json) { + List commits = new ArrayList<>(); + + MMSRootDescriptor root = MMSJsonHelper.readRootFromJson(json); + for (MMSCommitDescriptor element : root.commits) { + commits.add(element); + } + + return commits; + } + + /** + * Retrieves a list of elements from a given json data + * @param json the json data to be read + * @return a list of elements + */ + public static List readElementsFromJson(String json) { + List elements = new ArrayList<>(); + + MMSRootDescriptor root = MMSJsonHelper.readRootFromJson(json); + for (MMSModelElementDescriptor element : root.elements) { + elements.add(element); + } + + return elements; + } +} diff --git a/plugins/com.thalesgroup.mde.openmbee.connector.mms/src/com/thalesgroup/mde/openmbee/connector/mms/data/MMS4JsonHelper.java b/plugins/com.thalesgroup.mde.openmbee.connector.mms/src/com/thalesgroup/mde/openmbee/connector/mms/data/MMS4JsonHelper.java new file mode 100644 index 0000000..5037f60 --- /dev/null +++ b/plugins/com.thalesgroup.mde.openmbee.connector.mms/src/com/thalesgroup/mde/openmbee/connector/mms/data/MMS4JsonHelper.java @@ -0,0 +1,116 @@ +/******************************************************************************* + * Copyright (c) 2020 Thales Global Services S.A.S. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Thales - initial API and implementation + *******************************************************************************/ +package com.thalesgroup.mde.openmbee.connector.mms.data; + +import java.io.IOException; +import java.io.Reader; +import java.io.StringReader; +import java.util.Arrays; +import java.util.List; + +import com.google.gson.Gson; +import com.thalesgroup.mde.openmbee.connector.mms.utils.MMSServerHelper.MMSConnectionException; + +/** + * JSon helpers for MMS4 + */ +public class MMS4JsonHelper { + + private static final String INVALID_LOGIN = "Invalid login response:%s%s"; //$NON-NLS-1$ + private static final String INVALID_JSON_DATA = "Cannot read the given json:%s%s"; //$NON-NLS-1$ + + /** + * Retrieves a token from a given json data + * @param json the json data to be read + * @return a token + */ + public static String readTokenFromJson(String json) { + MMSRootDescriptor root = MMSJsonHelper.readRootFromJson(json); + if (root.token != null && root.token.length()>0) { + return root.token; + } else { + throw new MMSConnectionException(String.format(INVALID_LOGIN, System.lineSeparator(), json)); + } + } + + /** + * Retrieves a list of organizations from a given json data + * @param json the json data to be read + * @return a list of organizations + */ + public static List readOrganizationsFromJson(String json) { + try(Reader reader = new StringReader(json)) { + Gson gson = MMSJsonHelper.getMMS4PreparedGsonBuilder().create(); + return Arrays.asList(gson.fromJson(reader, MMSOrganizationDescriptor[].class)); + } catch (IOException e) { + throw new RuntimeException(String.format(INVALID_JSON_DATA, System.lineSeparator(), json), e); + } + } + + /** + * Retrieves a list of projects from a given json data + * @param json the json data to be read + * @return a list of projects + */ + public static List readProjectsFromJson(String json) { + try(Reader reader = new StringReader(json)) { + Gson gson = MMSJsonHelper.getMMS4PreparedGsonBuilder().create(); + return Arrays.asList(gson.fromJson(reader, MMSProjectDescriptor[].class)); + } catch (IOException e) { + throw new RuntimeException(String.format(INVALID_JSON_DATA, System.lineSeparator(), json), e); + } + } + + /** + * Retrieves a list of branches from a given json data + * @param json the json data to be read + * @return a list of branches + */ + public static List readBranchesFromJson(String json) { + try(Reader reader = new StringReader(json)) { + Gson gson = MMSJsonHelper.getMMS4PreparedGsonBuilder().create(); + return Arrays.asList(gson.fromJson(reader, MMSRefDescriptor[].class)); + } catch (IOException e) { + throw new RuntimeException(String.format(INVALID_JSON_DATA, System.lineSeparator(), json), e); + } + } + + /** + * Retrieves a list of commits from a given json data + * @param json the json data to be read + * @return a list of commits + */ + public static List readCommitsFromJson(String json) { + try(Reader reader = new StringReader(json)) { + Gson gson = MMSJsonHelper.getMMS4PreparedGsonBuilder().create(); + return Arrays.asList(gson.fromJson(reader, MMSCommitDescriptor[].class)); + } catch (IOException e) { + throw new RuntimeException(String.format(INVALID_JSON_DATA, System.lineSeparator(), json), e); + } + } + + /** + * Retrieves a list of elements from a given json data + * @param json the json data to be read + * @return a list of elements + */ + public static List readElementsFromJson(String json) { + try(Reader reader = new StringReader(json)) { + Gson gson = MMSJsonHelper.getMMS4PreparedGsonBuilder().create(); + return Arrays.asList(gson.fromJson(reader, MMSModelElementDescriptor[].class)); + } catch (IOException e) { + throw new RuntimeException(String.format(INVALID_JSON_DATA, System.lineSeparator(), json), e); + } + } +} diff --git a/plugins/com.thalesgroup.mde.openmbee.connector.mms/src/com/thalesgroup/mde/openmbee/connector/mms/data/MMSAPIHelper.java b/plugins/com.thalesgroup.mde.openmbee.connector.mms/src/com/thalesgroup/mde/openmbee/connector/mms/data/MMSAPIHelper.java new file mode 100644 index 0000000..16e71ec --- /dev/null +++ b/plugins/com.thalesgroup.mde.openmbee.connector.mms/src/com/thalesgroup/mde/openmbee/connector/mms/data/MMSAPIHelper.java @@ -0,0 +1,338 @@ +/******************************************************************************* + * Copyright (c) 2020 Thales Global Services S.A.S. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Thales - initial API and implementation + *******************************************************************************/ +package com.thalesgroup.mde.openmbee.connector.mms.data; + +import static com.thalesgroup.mde.openmbee.connector.mms.data.MMSJsonHelper.getMMS3PreparedGsonBuilder; +import static com.thalesgroup.mde.openmbee.connector.mms.data.MMSJsonHelper.getMMS4PreparedGsonBuilder; + +import java.util.List; +import java.util.stream.Collectors; + +import org.apache.http.client.fluent.Request; +import org.apache.http.entity.ContentType; + +import com.thalesgroup.mde.openmbee.connector.mms.utils.RestApiHelper; +import com.thalesgroup.mde.openmbee.connector.mms.utils.RestApiHelper.DeleteRequestWithBody; + +/** + * MMS3 & MMS4 API helpers + */ +public class MMSAPIHelper { + + private static final String URL_POSTFIX__ORGANIZATIONS = "orgs"; //$NON-NLS-1$ + private static final String URL_POSTFIX__ORGANIZATIONS_BY_ID = "orgs/%s"; //$NON-NLS-1$ + + private static final String URL_POSTFIX__MMS3__PROJECTS = "orgs/%s/projects"; //$NON-NLS-1$ + private static final String URL_POSTFIX__MMS3__PROJECTS_BY_ID = "projects/%s"; //$NON-NLS-1$ + private static final String URL_POSTFIX__MMS3__BRANCHES = "projects/%s/refs"; //$NON-NLS-1$ + private static final String URL_POSTFIX__MMS3__BRANCHES_BY_ID = "projects/%s/refs/%s"; //$NON-NLS-1$ + private static final String URL_POSTFIX__MMS3__COMMITS = "projects/%s/refs/%s/commits"; //$NON-NLS-1$ + private static final String URL_POSTFIX__MMS3__ELEMENTS = "projects/%s/refs/%s/elements"; //$NON-NLS-1$ + private static final String URL_POSTFIX__MMS3__ELEMENTS_BY_ID = "projects/%s/refs/%s/elements/%s"; //$NON-NLS-1$ + + private static final String URL_POSTFIX__MMS4__PROJECTS = "orgs/%s/projects"; //$NON-NLS-1$ + private static final String URL_POSTFIX__MMS4__PROJECTS_BY_ID = "orgs/%s/projects/%s"; //$NON-NLS-1$ + private static final String URL_POSTFIX__MMS4__BRANCHES = "orgs/%s/projects/%s/branches"; //$NON-NLS-1$ + private static final String URL_POSTFIX__MMS4__BRANCHES_BY_ID = "orgs/%s/projects/%s/branches/%s"; //$NON-NLS-1$ + private static final String URL_POSTFIX__MMS4__COMMITS = "orgs/%s/projects/%s/branches/%s/commits"; //$NON-NLS-1$ + private static final String URL_POSTFIX__MMS4__ELEMENTS = "orgs/%s/projects/%s/branches/%s/elements"; //$NON-NLS-1$ + private static final String URL_POSTFIX__MMS4__ELEMENTS_BY_ID = "orgs/%s/projects/%s/branches/%s/elements%s"; //$NON-NLS-1$ + + /** + * Retrieves all the organizations + * @param helper REST API helper + * @param apiVersion MMS API version + * @return the built HTTP request, or null if the API version is not handled + */ + public static Request getOrganizations(RestApiHelper helper, String apiVersion) { + if (MMSServerDescriptor.API_VERSION_3.equals(apiVersion)) { + return helper.prepareGet(URL_POSTFIX__ORGANIZATIONS); + } else if (MMSServerDescriptor.API_VERSION_4.equals(apiVersion)) { + return helper.prepareGet(URL_POSTFIX__ORGANIZATIONS); + } + return null; + } + + /** + * Creates an organization with the given data + * @param helper REST API helper + * @param apiVersion MMS API version + * @param organization organization related data + * @return the built HTTP request, or null if the API version is not handled + */ + public static Request postOrganizations(RestApiHelper helper, String apiVersion, MMSOrganizationDescriptor organization) { + if (MMSServerDescriptor.API_VERSION_3.equals(apiVersion)) { + MMSRootDescriptor root = new MMSRootDescriptor(); + root.orgs.add(organization); + String body = getMMS3PreparedGsonBuilder().create().toJson(root); + return helper.preparePost(URL_POSTFIX__ORGANIZATIONS).bodyString(body, ContentType.APPLICATION_JSON); + } else if (MMSServerDescriptor.API_VERSION_4.equals(apiVersion)) { + String body = getMMS3PreparedGsonBuilder().create().toJson(new MMSOrganizationDescriptor[] { organization }); + return helper.preparePost(URL_POSTFIX__ORGANIZATIONS).bodyString(body, ContentType.APPLICATION_JSON); + } + return null; + } + + /** + * Deletes an organization having a given identifier + * @param helper REST API helper + * @param apiVersion MMS API version + * @param organizationId organization identifier + * @return the built HTTP request, or null if the API version is not handled + */ + public static DeleteRequestWithBody deleteOrganizations(RestApiHelper helper, String apiVersion, String organizationId) { + if (MMSServerDescriptor.API_VERSION_3.equals(apiVersion)) { + return helper.prepareDelete(URL_POSTFIX__ORGANIZATIONS_BY_ID, organizationId); + } else if (MMSServerDescriptor.API_VERSION_4.equals(apiVersion)) { + return helper.prepareDelete(URL_POSTFIX__ORGANIZATIONS_BY_ID, organizationId); + } + return null; + } + + /** + * Retrieves all the projects related to a given organization + * @param helper REST API helper + * @param apiVersion MMS API version + * @param organizationId organization identifier + * @return the built HTTP request, or null if the API version is not handled + */ + public static Request getProjects(RestApiHelper helper, String apiVersion, String organizationId) { + if (MMSServerDescriptor.API_VERSION_3.equals(apiVersion)) { + return helper.prepareGet(URL_POSTFIX__MMS3__PROJECTS, organizationId); + } else if (MMSServerDescriptor.API_VERSION_4.equals(apiVersion)) { + return helper.prepareGet(URL_POSTFIX__MMS4__PROJECTS, organizationId); + } + return null; + } + + /** + * Creates a project with the given data, related to a given organization + * @param helper REST API helper + * @param apiVersion MMS API version + * @param organizationId organization identifier + * @param project project related data + * @return the built HTTP request, or null if the API version is not handled + */ + public static Request postProjects(RestApiHelper helper, String apiVersion, String organizationId, MMSProjectDescriptor project) { + if (MMSServerDescriptor.API_VERSION_3.equals(apiVersion)) { + MMSRootDescriptor root = new MMSRootDescriptor(); + root.projects.add(project); + String body = getMMS3PreparedGsonBuilder().create().toJson(root); + return helper.preparePost(URL_POSTFIX__MMS3__PROJECTS, organizationId).bodyString(body, ContentType.APPLICATION_JSON); + } else if (MMSServerDescriptor.API_VERSION_4.equals(apiVersion)) { + String body = getMMS4PreparedGsonBuilder().create().toJson(new MMSProjectDescriptor[] { project }); + return helper.preparePost(URL_POSTFIX__MMS4__PROJECTS, organizationId).bodyString(body, ContentType.APPLICATION_JSON); + } + return null; + } + + /** + * Deletes a project having a given identifier, related to a given organization + * @param helper REST API helper + * @param apiVersion MMS API version + * @param organizationId organization identifier + * @param projectId project identifier + * @return the built HTTP request, or null if the API version is not handled + */ + public static DeleteRequestWithBody deleteProjects(RestApiHelper helper, String apiVersion, String organizationId, String projectId) { + if (MMSServerDescriptor.API_VERSION_3.equals(apiVersion)) { + return helper.prepareDelete(URL_POSTFIX__MMS3__PROJECTS_BY_ID, projectId); + } else if (MMSServerDescriptor.API_VERSION_4.equals(apiVersion)) { + return helper.prepareDelete(URL_POSTFIX__MMS4__PROJECTS_BY_ID, organizationId, projectId); + } + return null; + } + + /** + * Retrieves all the branches related to a given project, within a given organization + * @param helper REST API helper + * @param apiVersion MMS API version + * @param organizationId organization identifier + * @param projectId project identifier + * @return the built HTTP request, or null if the API version is not handled + */ + public static Request getBranches(RestApiHelper helper, String apiVersion, String organizationId, String projectId) { + if (MMSServerDescriptor.API_VERSION_3.equals(apiVersion)) { + return helper.prepareGet(URL_POSTFIX__MMS3__BRANCHES, projectId); + } else if (MMSServerDescriptor.API_VERSION_4.equals(apiVersion)) { + return helper.prepareGet(URL_POSTFIX__MMS4__BRANCHES, organizationId, projectId); + } + return null; + } + + /** + * Retrieves the branch having a given identifier, related to a given project, within a given organization + * @param helper REST API helper + * @param apiVersion MMS API version + * @param organizationId organization identifier + * @param projectId project identifier + * @param branchId branch identifier + * @return the built HTTP request, or null if the API version is not handled + */ + public static Request getBranch(RestApiHelper helper, String apiVersion, String organizationId, String projectId, String branchId) { + if (MMSServerDescriptor.API_VERSION_3.equals(apiVersion)) { + return helper.prepareGet(URL_POSTFIX__MMS3__BRANCHES_BY_ID, projectId, branchId); + } else if (MMSServerDescriptor.API_VERSION_4.equals(apiVersion)) { + return helper.prepareGet(URL_POSTFIX__MMS4__BRANCHES_BY_ID, organizationId, projectId, branchId); + } + return null; + } + + /** + * Creates a branch with the given data, related to a given project, within a given organization + * @param helper REST API helper + * @param apiVersion MMS API version + * @param organizationId organization identifier + * @param projectId project identifier + * @param branch branch related data + * @return the built HTTP request, or null if the API version is not handled + */ + public static Request postBranches(RestApiHelper helper, String apiVersion, String organizationId, String projectId, MMSRefDescriptor branch) { + if (MMSServerDescriptor.API_VERSION_3.equals(apiVersion)) { + MMSRootDescriptor root = new MMSRootDescriptor(); + root.refs.add(branch); + String body = getMMS3PreparedGsonBuilder().create().toJson(root); + return helper.preparePost(URL_POSTFIX__MMS3__BRANCHES, projectId).bodyString(body, ContentType.APPLICATION_JSON); + } else if (MMSServerDescriptor.API_VERSION_4.equals(apiVersion)) { + String body = getMMS3PreparedGsonBuilder().create().toJson(new MMSRefDescriptor[] { branch }); + return helper.preparePost(URL_POSTFIX__MMS4__BRANCHES, projectId).bodyString(body, ContentType.APPLICATION_JSON); + } + return null; + } + + /** + * Deletes a branch having a given identifier, related to a given project, within a given organization + * @param helper REST API helper + * @param apiVersion MMS API version + * @param organizationId organization identifier + * @param projectId project identifier + * @param branchId branch identifier + * @return the built HTTP request, or null if the API version is not handled + */ + public static DeleteRequestWithBody deleteBranches(RestApiHelper helper, String apiVersion, String organizationId, String projectId, String branchId) { + if (MMSServerDescriptor.API_VERSION_3.equals(apiVersion)) { + return helper.prepareDelete(URL_POSTFIX__MMS3__BRANCHES_BY_ID, projectId, branchId); + } else if (MMSServerDescriptor.API_VERSION_4.equals(apiVersion)) { + return helper.prepareDelete(URL_POSTFIX__MMS4__BRANCHES_BY_ID, organizationId, projectId, branchId); + } + return null; + } + + /** + * Retrieves all the commits related to a given branch, within a given project and a given organization + * @param helper REST API helper + * @param apiVersion MMS API version + * @param organizationId organization identifier + * @param projectId project identifier + * @param branchId branch identifier + * @return the built HTTP request, or null if the API version is not handled + */ + public static Request getCommits(RestApiHelper helper, String apiVersion, String organizationId, String projectId, String branchId) { + if (MMSServerDescriptor.API_VERSION_3.equals(apiVersion)) { + return helper.prepareGet(URL_POSTFIX__MMS3__COMMITS, projectId, branchId); + } else if (MMSServerDescriptor.API_VERSION_4.equals(apiVersion)) { + return helper.prepareGet(URL_POSTFIX__MMS4__COMMITS, organizationId, projectId, branchId); + } + return null; + } + + /** + * Retrieves all the elements related to a given branch, within a given project and a given organization + * @param helper REST API helper + * @param apiVersion MMS API version + * @param organizationId organization identifier + * @param projectId project identifier + * @param branchId branch identifier + * @return the built HTTP request, or null if the API version is not handled + */ + public static Request getElements(RestApiHelper helper, String apiVersion, String organizationId, String projectId, String branchId) { + if (MMSServerDescriptor.API_VERSION_3.equals(apiVersion)) { + return helper.prepareGet(URL_POSTFIX__MMS3__ELEMENTS, projectId, branchId); + } else if (MMSServerDescriptor.API_VERSION_4.equals(apiVersion)) { + return helper.prepareGet(URL_POSTFIX__MMS4__ELEMENTS, organizationId, projectId, branchId); + } + return null; + } + + /** + * Retrieves the element having a given identifier, related to a given branch (and an optional commit), within a given project and a given organization + * @param helper REST API helper + * @param apiVersion MMS API version + * @param organizationId organization identifier + * @param projectId project identifier + * @param branchId branch identifier + * @param elementId element identifier + * @param commitId commit identifier (optional, can be null) + * @return the built HTTP request, or null if the API version is not handled + */ + public static Request getElement(RestApiHelper helper, String apiVersion, String organizationId, String projectId, String branchId, String elementId) { + if (MMSServerDescriptor.API_VERSION_3.equals(apiVersion)) { + return helper.prepareGet(URL_POSTFIX__MMS3__ELEMENTS_BY_ID, projectId, branchId, elementId); + } else if (MMSServerDescriptor.API_VERSION_4.equals(apiVersion)) { + return helper.prepareGet(URL_POSTFIX__MMS4__ELEMENTS_BY_ID, organizationId, projectId, branchId, elementId); + } + return null; + } + + /** + * Creates a set of elements with the given data, related to a given branch, within a given project and a given organization + * @param helper REST API helper + * @param apiVersion MMS API version + * @param organizationId organization identifier + * @param projectId project identifier + * @param branchId branch identifier + * @param commitComment the commit description + * @param modelElements elements related data + * @return the built HTTP request, or null if the API version is not handled + */ + public static Request postElements(RestApiHelper helper, String apiVersion, String organizationId, String projectId, String branchId, String commitComment, List modelElements) { + if (MMSServerDescriptor.API_VERSION_3.equals(apiVersion)) { + MMSRootDescriptor root = new MMSRootDescriptor(); + root.elements = modelElements; + root.comment = commitComment; + String body = getMMS3PreparedGsonBuilder().create().toJson(root); + return helper.preparePost(URL_POSTFIX__MMS3__ELEMENTS, projectId, branchId).bodyString(body, ContentType.APPLICATION_JSON); + } else if (MMSServerDescriptor.API_VERSION_4.equals(apiVersion)) { + String body = getMMS4PreparedGsonBuilder().create().toJson(modelElements.toArray()); + return helper.preparePost(URL_POSTFIX__MMS4__ELEMENTS, organizationId, projectId, branchId).bodyString(body, ContentType.APPLICATION_JSON); + } + return null; + } + + /** + * Deletes a set of elements having the given identifiers, related to a given branch, within a given project and a given organization + * @param helper REST API helper + * @param apiVersion MMS API version + * @param organizationId organization identifier + * @param projectId project identifier + * @param branchId branch identifier + * @param commitComment the commit description + * @param modelElements elements related data + * @return the built HTTP request, or null if the API version is not handled + */ + public static DeleteRequestWithBody deleteElements(RestApiHelper helper, String apiVersion, String organizationId, String projectId, String branchId, String commitComment, List modelElements) { + if (MMSServerDescriptor.API_VERSION_3.equals(apiVersion)) { + MMSRootDescriptor root = new MMSRootDescriptor(); + root.elements = modelElements; + root.comment = commitComment; + String body = getMMS3PreparedGsonBuilder().create().toJson(root); + return helper.prepareDelete(URL_POSTFIX__MMS3__ELEMENTS, projectId, branchId).bodyString(body, ContentType.APPLICATION_JSON); + } else if (MMSServerDescriptor.API_VERSION_4.equals(apiVersion)) { + List ids = modelElements.stream().map(elt -> elt.id).collect(Collectors.toList()); + String body = getMMS4PreparedGsonBuilder().create().toJson(ids.toArray()); + return helper.prepareDelete(URL_POSTFIX__MMS4__ELEMENTS, organizationId, projectId, branchId).bodyString(body, ContentType.APPLICATION_JSON); + } + return null; + } +} diff --git a/plugins/com.thalesgroup.mde.openmbee.connector.mms/src/com/thalesgroup/mde/openmbee/connector/mms/data/MMSJsonHelper.java b/plugins/com.thalesgroup.mde.openmbee.connector.mms/src/com/thalesgroup/mde/openmbee/connector/mms/data/MMSJsonHelper.java index b17c86b..35c75b9 100644 --- a/plugins/com.thalesgroup.mde.openmbee.connector.mms/src/com/thalesgroup/mde/openmbee/connector/mms/data/MMSJsonHelper.java +++ b/plugins/com.thalesgroup.mde.openmbee.connector.mms/src/com/thalesgroup/mde/openmbee/connector/mms/data/MMSJsonHelper.java @@ -17,9 +17,8 @@ import java.io.Reader; import java.io.StringReader; import java.lang.reflect.Type; -import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.List; import com.google.gson.Gson; @@ -28,145 +27,85 @@ import com.google.gson.JsonElement; import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializer; -import com.google.gson.JsonSyntaxException; public class MMSJsonHelper { - public static List readOrganizationsFromJson(String json) { - List orgs = new ArrayList<>(); - try { - MMSRootDescriptor root = readRootFromJson(json); - for (MMSOrganizationDescriptor element : root.orgs) { - orgs.add(element); - } - } catch (JsonSyntaxException ex) { - // MMS4 data structure - MMSOrganizationDescriptor[] orgsArray = readOrganizationsFromJsonArray(json); - return Arrays.asList(orgsArray); + public static String readTokenFromJson(String apiVersion, String json) { + if (MMSServerDescriptor.API_VERSION_3.equals(apiVersion)) { + return MMS3JsonHelper.readTokenFromJson(json); + } else if (MMSServerDescriptor.API_VERSION_4.equals(apiVersion)) { + return MMS4JsonHelper.readTokenFromJson(json); } - return orgs; + return ""; //$NON-NLS-1$ } - public static List readProjectsFromJson(String json) { - List projects = new ArrayList<>(); - try { - MMSRootDescriptor root = readRootFromJson(json); - for (MMSProjectDescriptor element : root.projects) { - projects.add(element); - } - } catch (JsonSyntaxException ex) { - // MMS4 data structure - MMSProjectDescriptor[] projectsArray = readProjectsFromJsonArray(json); - return Arrays.asList(projectsArray); + public static List readOrganizationsFromJson(String apiVersion, String json) { + if (MMSServerDescriptor.API_VERSION_3.equals(apiVersion)) { + return MMS3JsonHelper.readOrganizationsFromJson(json); + } else if (MMSServerDescriptor.API_VERSION_4.equals(apiVersion)) { + return MMS4JsonHelper.readOrganizationsFromJson(json); } - return projects; + return Collections.emptyList(); } - public static List readBranchesFromJson(String json) { - List refs = new ArrayList<>(); - try { - MMSRootDescriptor root = readRootFromJson(json); - for (MMSRefDescriptor element : root.refs) { - refs.add(element); - } - } catch (JsonSyntaxException ex) { - // MMS4 data structure - MMSRefDescriptor[] refsArray = readBranchesFromJsonArray(json); - return Arrays.asList(refsArray); + public static List readProjectsFromJson(String apiVersion, String json) { + if (MMSServerDescriptor.API_VERSION_3.equals(apiVersion)) { + return MMS3JsonHelper.readProjectsFromJson(json); + } else if (MMSServerDescriptor.API_VERSION_4.equals(apiVersion)) { + return MMS4JsonHelper.readProjectsFromJson(json); } - return refs; + return Collections.emptyList(); } - public static List readCommitsFromJson(String json) { - List commits = new ArrayList<>(); - try { - MMSRootDescriptor root = readRootFromJson(json); - for (MMSCommitDescriptor element : root.commits) { - commits.add(element); - } - } catch (JsonSyntaxException ex) { - // MMS4 data structure - MMSCommitDescriptor[] commitsArray = readCommitsFromJsonArray(json); - return Arrays.asList(commitsArray); + public static List readBranchesFromJson(String apiVersion, String json) { + if (MMSServerDescriptor.API_VERSION_3.equals(apiVersion)) { + return MMS3JsonHelper.readBranchesFromJson(json); + } else if (MMSServerDescriptor.API_VERSION_4.equals(apiVersion)) { + return MMS4JsonHelper.readBranchesFromJson(json); } - return commits; + return Collections.emptyList(); } - public static List readElementsFromJson(String json) { - List elements = new ArrayList<>(); - try { - MMSRootDescriptor root = readRootFromJson(json); - for (MMSModelElementDescriptor element : root.elements) { - elements.add(element); - } - } catch (JsonSyntaxException ex) { - // MMS4 data structure - MMSModelElementDescriptor[] elementsArray = readElementsFromJsonArray(json); - return Arrays.asList(elementsArray); - } - return elements; - } - - public static MMSRootDescriptor readRootFromJson(String json) { - try(Reader reader = new StringReader(json)) { - Gson gson = getPreparedGsonBuilder().create(); - return gson.fromJson(reader, MMSRootDescriptor.class); - } catch (IOException e) { - throw new RuntimeException(String.format("Cannot read the given json:%s%s", System.lineSeparator(), json), e); //$NON-NLS-1$ + public static List readCommitsFromJson(String apiVersion, String json) { + if (MMSServerDescriptor.API_VERSION_3.equals(apiVersion)) { + return MMS3JsonHelper.readCommitsFromJson(json); + } else if (MMSServerDescriptor.API_VERSION_4.equals(apiVersion)) { + return MMS4JsonHelper.readCommitsFromJson(json); } + return Collections.emptyList(); } - public static MMSOrganizationDescriptor[] readOrganizationsFromJsonArray(String json) { - try(Reader reader = new StringReader(json)) { - Gson gson = getPreparedGsonBuilder().create(); - return gson.fromJson(reader, MMSOrganizationDescriptor[].class); - } catch (IOException e) { - throw new RuntimeException(String.format("Cannot read the given json:%s%s", System.lineSeparator(), json), e); //$NON-NLS-1$ + public static List readElementsFromJson(String apiVersion, String json) { + if (MMSServerDescriptor.API_VERSION_3.equals(apiVersion)) { + return MMS3JsonHelper.readElementsFromJson(json); + } else if (MMSServerDescriptor.API_VERSION_4.equals(apiVersion)) { + return MMS4JsonHelper.readElementsFromJson(json); } + return Collections.emptyList(); } - public static MMSProjectDescriptor[] readProjectsFromJsonArray(String json) { - try(Reader reader = new StringReader(json)) { - Gson gson = getPreparedGsonBuilder().create(); - return gson.fromJson(reader, MMSProjectDescriptor[].class); - } catch (IOException e) { - throw new RuntimeException(String.format("Cannot read the given json:%s%s", System.lineSeparator(), json), e); //$NON-NLS-1$ - } - } - - public static MMSRefDescriptor[] readBranchesFromJsonArray(String json) { - try(Reader reader = new StringReader(json)) { - Gson gson = getPreparedGsonBuilder().create(); - return gson.fromJson(reader, MMSRefDescriptor[].class); - } catch (IOException e) { - throw new RuntimeException(String.format("Cannot read the given json:%s%s", System.lineSeparator(), json), e); //$NON-NLS-1$ - } - } - - public static MMSCommitDescriptor[] readCommitsFromJsonArray(String json) { + public static MMSRootDescriptor readRootFromJson(String json) { try(Reader reader = new StringReader(json)) { - Gson gson = getPreparedGsonBuilder().create(); - return gson.fromJson(reader, MMSCommitDescriptor[].class); + Gson gson = getMMS3PreparedGsonBuilder().create(); + return gson.fromJson(reader, MMSRootDescriptor.class); } catch (IOException e) { throw new RuntimeException(String.format("Cannot read the given json:%s%s", System.lineSeparator(), json), e); //$NON-NLS-1$ } } - public static MMSModelElementDescriptor[] readElementsFromJsonArray(String json) { - try(Reader reader = new StringReader(json)) { - Gson gson = getPreparedGsonBuilder().create(); - return gson.fromJson(reader, MMSModelElementDescriptor[].class); - } catch (IOException e) { - throw new RuntimeException(String.format("Cannot read the given json:%s%s", System.lineSeparator(), json), e); //$NON-NLS-1$ - } + public static GsonBuilder getMMS3PreparedGsonBuilder() { + return new GsonBuilder().registerTypeHierarchyAdapter(Collection.class, new SkipEmptyCollectionsSerializer()) + .registerTypeAdapter(MMSModelElementDescriptor.class, new MMSModelElementDescriptor.JsonMMS3TypeAdapter()) + .registerTypeAdapter(MMSProjectDescriptor.class, new MMSProjectDescriptor.JsonMMS3TypeAdapter()); } - public static GsonBuilder getPreparedGsonBuilder() { + public static GsonBuilder getMMS4PreparedGsonBuilder() { return new GsonBuilder().registerTypeHierarchyAdapter(Collection.class, new SkipEmptyCollectionsSerializer()) - .registerTypeAdapter(MMSModelElementDescriptor.class, new MMSModelElementDescriptor.JsonTypeAdapter()); + .registerTypeAdapter(MMSModelElementDescriptor.class, new MMSModelElementDescriptor.JsonMMS4TypeAdapter()) + .registerTypeAdapter(MMSProjectDescriptor.class, new MMSProjectDescriptor.JsonMMS4TypeAdapter()); } - public static class SkipEmptyCollectionsSerializer implements JsonSerializer> { + private static class SkipEmptyCollectionsSerializer implements JsonSerializer> { @Override public JsonElement serialize(Collection src, Type typeOfSrc, JsonSerializationContext context) { diff --git a/plugins/com.thalesgroup.mde.openmbee.connector.mms/src/com/thalesgroup/mde/openmbee/connector/mms/data/MMSModelElementDescriptor.java b/plugins/com.thalesgroup.mde.openmbee.connector.mms/src/com/thalesgroup/mde/openmbee/connector/mms/data/MMSModelElementDescriptor.java index b39d0eb..0e3f2d3 100644 --- a/plugins/com.thalesgroup.mde.openmbee.connector.mms/src/com/thalesgroup/mde/openmbee/connector/mms/data/MMSModelElementDescriptor.java +++ b/plugins/com.thalesgroup.mde.openmbee.connector.mms/src/com/thalesgroup/mde/openmbee/connector/mms/data/MMSModelElementDescriptor.java @@ -42,7 +42,7 @@ public class MMSModelElementDescriptor extends MMSIdentifiableDescriptor { @Override public String toString() { return String.format("MMSModelElement:\r\n\t%s\r\n\t%s", //$NON-NLS-1$ - String.join("\r\n\t", Arrays.stream(MMSModelElementDescriptor.class.getFields()).map(f -> { + String.join("\r\n\t", Arrays.stream(MMSModelElementDescriptor.class.getFields()).map(f -> { //$NON-NLS-1$ try { return String.format("%s: %s", f.getName(), f.get(this)); //$NON-NLS-1$ } catch (IllegalArgumentException | IllegalAccessException e) {} @@ -187,8 +187,8 @@ protected Object decodeObject(JsonObject jo) { } } - - public static class JsonTypeAdapter implements JsonDeserializer, JsonSerializer { + + public static class JsonMMS3TypeAdapter implements JsonDeserializer, JsonSerializer { private static final Gson gson = new GsonBuilder() .registerTypeAdapter(MMSMSInfoDescriptor.class, new MMSMSInfoDescriptor.ComplexTypeInfoJsonTypeAdapter()) @@ -217,4 +217,32 @@ public JsonElement serialize(MMSModelElementDescriptor desc, Type type, JsonSeri return serialized; } } + + public static class JsonMMS4TypeAdapter implements JsonDeserializer, JsonSerializer { + + private static final Gson gson = new GsonBuilder() + .registerTypeAdapter(MMSMSInfoDescriptor.class, new MMSMSInfoDescriptor.ComplexTypeInfoJsonTypeAdapter()) + .create(); + + @Override + public MMSModelElementDescriptor deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { + return gson.fromJson(json, MMSModelElementDescriptor.class); + } + + @Override + public JsonElement serialize(MMSModelElementDescriptor desc, Type type, JsonSerializationContext context) { + JsonObject serialized = gson.toJsonTree(desc.vcsiDescriptor, MMSVCSInfoDescriptior.class).getAsJsonObject(); + + serialized.remove("_inRefIds"); //$NON-NLS-1$ + serialized.addProperty("id", desc.msiDescriptor.id); //$NON-NLS-1$ + String name = (String) desc.msiDescriptor.attributes.get("EMF_FEATURE__name"); //$NON-NLS-1$ + serialized.addProperty("name", name != null ? name : ""); //$NON-NLS-1$ //$NON-NLS-2$ + serialized.addProperty("type", desc.msiDescriptor.type); //$NON-NLS-1$ + JsonObject msinfo = gson.toJsonTree(desc.msiDescriptor, MMSMSInfoDescriptor.class).getAsJsonObject(); + serialized.add("custom", msinfo); //$NON-NLS-1$ + serialized.addProperty("parent", desc.msiDescriptor.ownerId); //$NON-NLS-1$ + + return serialized; + } + } } diff --git a/plugins/com.thalesgroup.mde.openmbee.connector.mms/src/com/thalesgroup/mde/openmbee/connector/mms/data/MMSProjectDescriptor.java b/plugins/com.thalesgroup.mde.openmbee.connector.mms/src/com/thalesgroup/mde/openmbee/connector/mms/data/MMSProjectDescriptor.java index af08cd1..4868809 100644 --- a/plugins/com.thalesgroup.mde.openmbee.connector.mms/src/com/thalesgroup/mde/openmbee/connector/mms/data/MMSProjectDescriptor.java +++ b/plugins/com.thalesgroup.mde.openmbee.connector.mms/src/com/thalesgroup/mde/openmbee/connector/mms/data/MMSProjectDescriptor.java @@ -13,9 +13,20 @@ *******************************************************************************/ package com.thalesgroup.mde.openmbee.connector.mms.data; +import java.lang.reflect.Type; import java.util.ArrayList; import java.util.List; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; + public class MMSProjectDescriptor extends MMSNamedDescriptor { public static final String FEATURE_PREFIX__EMF = "EMF_FEATURE__"; //$NON-NLS-1$ public static final String FEATURE_PREFIX = "featurePrefix"; //$NON-NLS-1$ @@ -25,21 +36,63 @@ public class MMSProjectDescriptor extends MMSNamedDescriptor { public String _refId; public String _elasticId; public Boolean _editable; - public String type = MMSConstants.MMS_TYPE_PROJECT; public String _created; public String _modified; public String _projectId; public String categoryId; public String _creator; - public String twcId; public String _modifier; public String _uri; public String _qualifiedName; public String _qualifiedId; - public String orgId; // MMS3.x - public String org; // MMS4 - public String visibility; // MMS4 + public String orgId; public String featurePrefix; public String clientSideName; public List _inRefIds = new ArrayList<>(); + + public static class JsonMMS3TypeAdapter implements JsonDeserializer, JsonSerializer { + + private static final Gson gson = new GsonBuilder().create(); + + @Override + public MMSProjectDescriptor deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { + return gson.fromJson(json, MMSProjectDescriptor.class); + } + + @Override + public JsonElement serialize(MMSProjectDescriptor desc, Type type, JsonSerializationContext context) { + JsonObject serialized = gson.toJsonTree(desc, MMSProjectDescriptor.class).getAsJsonObject(); + serialized.addProperty("type", MMSConstants.MMS_TYPE_PROJECT); //$NON-NLS-1$ + return serialized; + } + } + + public static class JsonMMS4TypeAdapter implements JsonDeserializer, JsonSerializer { + + private static final Gson gson = new GsonBuilder().create(); + + @Override + public MMSProjectDescriptor deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { + MMSProjectDescriptor desc = gson.fromJson(json, MMSProjectDescriptor.class); + desc.orgId = ((JsonObject) json).get("org").getAsString(); //$NON-NLS-1$ + desc.clientSideName = ((JsonObject) json).get("custom").getAsJsonObject().get("clientSideName").getAsString(); //$NON-NLS-1$ //$NON-NLS-2$ + desc.featurePrefix = ((JsonObject) json).get("custom").getAsJsonObject().get("featurePrefix").getAsString(); //$NON-NLS-1$ //$NON-NLS-2$ + return desc; + } + + @Override + public JsonElement serialize(MMSProjectDescriptor desc, Type type, JsonSerializationContext context) { + JsonObject serialized = gson.toJsonTree(desc, MMSProjectDescriptor.class).getAsJsonObject(); + serialized.remove("orgId"); //$NON-NLS-1$ + serialized.remove("clientSideName"); //$NON-NLS-1$ + serialized.remove("featurePrefix"); //$NON-NLS-1$ + serialized.remove("_inRefIds"); //$NON-NLS-1$ + serialized.addProperty("visibility", MMSProjectDescriptor.PRIVATE_VISIBILITY); //$NON-NLS-1$ + JsonObject custom = new JsonObject(); + custom.addProperty("clientSideName", desc.clientSideName); //$NON-NLS-1$ + custom.addProperty("featurePrefix", desc.featurePrefix); //$NON-NLS-1$ + serialized.add("custom", custom); //$NON-NLS-1$ + return serialized; + } + } } diff --git a/plugins/com.thalesgroup.mde.openmbee.connector.mms/src/com/thalesgroup/mde/openmbee/connector/mms/data/MMSRefDescriptor.java b/plugins/com.thalesgroup.mde.openmbee.connector.mms/src/com/thalesgroup/mde/openmbee/connector/mms/data/MMSRefDescriptor.java index 2bfd485..0b081b8 100644 --- a/plugins/com.thalesgroup.mde.openmbee.connector.mms/src/com/thalesgroup/mde/openmbee/connector/mms/data/MMSRefDescriptor.java +++ b/plugins/com.thalesgroup.mde.openmbee.connector.mms/src/com/thalesgroup/mde/openmbee/connector/mms/data/MMSRefDescriptor.java @@ -18,8 +18,7 @@ public class MMSRefDescriptor extends MMSNamedDescriptor { public String parentCommitId; public String parentRefId; public String status; - public String twcId; - public String type; + public String type; public static final String TYPE__BRANCH = "Branch"; //$NON-NLS-1$ diff --git a/plugins/com.thalesgroup.mde.openmbee.connector.mms/src/com/thalesgroup/mde/openmbee/connector/mms/data/MMSServerDescriptor.java b/plugins/com.thalesgroup.mde.openmbee.connector.mms/src/com/thalesgroup/mde/openmbee/connector/mms/data/MMSServerDescriptor.java index 29023aa..b6fd955 100644 --- a/plugins/com.thalesgroup.mde.openmbee.connector.mms/src/com/thalesgroup/mde/openmbee/connector/mms/data/MMSServerDescriptor.java +++ b/plugins/com.thalesgroup.mde.openmbee.connector.mms/src/com/thalesgroup/mde/openmbee/connector/mms/data/MMSServerDescriptor.java @@ -14,19 +14,24 @@ package com.thalesgroup.mde.openmbee.connector.mms.data; public class MMSServerDescriptor extends MMSNamedDescriptor { - - public MMSServerDescriptor(String url, String authData) { - this(url, url, authData); + + public static final String API_VERSION_3 = "MMS 3.x"; //$NON-NLS-1$ + public static final String API_VERSION_4 = "MMS 4"; //$NON-NLS-1$ + + public MMSServerDescriptor(String url, String version, String authData) { + this(url, url, version, authData); } - public MMSServerDescriptor(String name, String url, String autData) { + public MMSServerDescriptor(String name, String url, String version, String autData) { this.id = url+autData; this.url = url; this.name = name; + this.apiVersion = version; this.autData = autData; } public String url; + public String apiVersion; public String autData; @Override diff --git a/plugins/com.thalesgroup.mde.openmbee.connector.mms/src/com/thalesgroup/mde/openmbee/connector/mms/utils/MMSServerHelper.java b/plugins/com.thalesgroup.mde.openmbee.connector.mms/src/com/thalesgroup/mde/openmbee/connector/mms/utils/MMSServerHelper.java index 58df83f..f41206b 100644 --- a/plugins/com.thalesgroup.mde.openmbee.connector.mms/src/com/thalesgroup/mde/openmbee/connector/mms/utils/MMSServerHelper.java +++ b/plugins/com.thalesgroup.mde.openmbee.connector.mms/src/com/thalesgroup/mde/openmbee/connector/mms/utils/MMSServerHelper.java @@ -13,13 +13,11 @@ *******************************************************************************/ package com.thalesgroup.mde.openmbee.connector.mms.utils; -import static com.thalesgroup.mde.openmbee.connector.mms.data.MMSJsonHelper.getPreparedGsonBuilder; import static com.thalesgroup.mde.openmbee.connector.mms.data.MMSJsonHelper.readBranchesFromJson; import static com.thalesgroup.mde.openmbee.connector.mms.data.MMSJsonHelper.readCommitsFromJson; import static com.thalesgroup.mde.openmbee.connector.mms.data.MMSJsonHelper.readElementsFromJson; import static com.thalesgroup.mde.openmbee.connector.mms.data.MMSJsonHelper.readOrganizationsFromJson; import static com.thalesgroup.mde.openmbee.connector.mms.data.MMSJsonHelper.readProjectsFromJson; -import static com.thalesgroup.mde.openmbee.connector.mms.data.MMSJsonHelper.readRootFromJson; import java.io.IOException; import java.util.Base64; @@ -38,39 +36,33 @@ import org.apache.http.entity.ContentType; import com.thalesgroup.mde.openmbee.connector.mms.MmsConnectorPlugin; +import com.thalesgroup.mde.openmbee.connector.mms.data.MMSAPIHelper; import com.thalesgroup.mde.openmbee.connector.mms.data.MMSCommitDescriptor; +import com.thalesgroup.mde.openmbee.connector.mms.data.MMSJsonHelper; import com.thalesgroup.mde.openmbee.connector.mms.data.MMSModelElementDescriptor; import com.thalesgroup.mde.openmbee.connector.mms.data.MMSOrganizationDescriptor; import com.thalesgroup.mde.openmbee.connector.mms.data.MMSProjectDescriptor; import com.thalesgroup.mde.openmbee.connector.mms.data.MMSRefDescriptor; -import com.thalesgroup.mde.openmbee.connector.mms.data.MMSRootDescriptor; +import com.thalesgroup.mde.openmbee.connector.mms.data.MMSServerDescriptor; import com.thalesgroup.mde.openmbee.connector.mms.utils.RestApiHelper.DeleteRequestWithBody; public class MMSServerHelper { private static final String MSG__INVALID_BASIC_AUTH_DATA = "The given string isn't a valid basic authentication data: %s"; //$NON-NLS-1$ private static final String PREFIX__BASIC_AUTH_DATA = "Basic "; //$NON-NLS-1$ - private static final String ESCAPING_PATTERN = "[^a-zA-Z0-9\\-_]"; //$NON-NLS-1$ - - public static final String URL_POSTFIX__PROJECTS = "projects"; //$NON-NLS-1$ - public static final String URL_POSTFIX__PROJECTS_OF_ORGANIZATION = "orgs/%s/projects"; //$NON-NLS-1$ - public static final String URL_POSTFIX__ORGANIZATIONS = "orgs"; //$NON-NLS-1$ - public static final String MMS_REF__DEFAULT = "master"; //$NON-NLS-1$ - private static final int MAX_RETRY_NUMBER = 5; + public static final String MMS_REF__DEFAULT = "master"; //$NON-NLS-1$ + private String baseUrl; + private String apiVersion; private RestApiHelper restHelper; - public MMSServerHelper(String baseUrl, String autData) { + public MMSServerHelper(String baseUrl, String apiVersion, String autData) { this.baseUrl = baseUrl; - restHelper = new RestApiHelper(baseUrl, null, autData, isMMS4API()); - } - - public boolean isMMS4API() { - // MMS4 services API - // FIXME an explicit information shall replace this hazardous URL interpretation - return this.baseUrl.contains("alfresco") ? false : true; //$NON-NLS-1$ + this.apiVersion = apiVersion; + this.restHelper = new RestApiHelper(baseUrl, null, autData, + MMSServerDescriptor.API_VERSION_4.equals(apiVersion) ? "api/" : ""); //$NON-NLS-1$ //$NON-NLS-2$ } public void setAutData(String autData) { @@ -78,11 +70,10 @@ public void setAutData(String autData) { } public String login(String username, String password) throws MMSConnectionException { - return login(baseUrl, username, password); + return login(baseUrl, apiVersion, username, password); } - public static String login(String url, String username, String password) throws MMSConnectionException { - String loginTicketJson; + public static String login(String url, String apiVersion, String username, String password) throws MMSConnectionException { try { if(!url.endsWith("api/login")) { //$NON-NLS-1$ if(!url.endsWith("/")) { //$NON-NLS-1$ @@ -95,18 +86,11 @@ public static String login(String url, String username, String password) throws String.format("{\"username\": \"%s\", \"password\": \"%s\"}", //$NON-NLS-1$ username, password), ContentType.APPLICATION_JSON); - loginTicketJson = tryToExecuteAndGetContentAsString(request); + String loginTicketJson = tryToExecuteAndGetContentAsString(request); + return MMSJsonHelper.readTokenFromJson(apiVersion, loginTicketJson); } catch (IOException e) { throw new MMSConnectionException("Unable to send login request to "+url, e); //$NON-NLS-1$ } - MMSRootDescriptor root = readRootFromJson(loginTicketJson); - if (root.data != null && root.data.ticket != null && root.data.ticket.length()>0) { - return root.data.ticket; // MMS 3.x - } else if (root.token != null && root.token.length()>0) { - return root.token; // MMS 4 - } else { - throw new MMSConnectionException("Invalid login response:\r\n"+loginTicketJson); //$NON-NLS-1$ - } } /** @@ -130,12 +114,11 @@ public static String[] decodeBasicAuthData(String authData) throws IllegalArgume } return userPasswordPair; } + public static String encodeBasicAuthData(String username, String password) { return PREFIX__BASIC_AUTH_DATA+Base64.getEncoder().encodeToString((username+":"+password).getBytes()); //$NON-NLS-1$ } - - - + /********************************************************************************************* ******************************* Organization handler features ******************************* *********************************************************************************************/ @@ -147,9 +130,9 @@ public static String encodeBasicAuthData(String username, String password) { */ public List getOrgs() throws MMSConnectionException { try { - Request request = restHelper.prepareGet(URL_POSTFIX__ORGANIZATIONS); - String orgsJson = tryToExecuteAndGetContentAsString(request); - return readOrganizationsFromJson(orgsJson); + Request request = MMSAPIHelper.getOrganizations(restHelper, apiVersion); + String json = tryToExecuteAndGetContentAsString(request); + return readOrganizationsFromJson(apiVersion, json); } catch (IOException e) { throw new MMSConnectionException("Cannot query organizations from "+baseUrl, e); //$NON-NLS-1$ } @@ -173,18 +156,13 @@ public MMSOrganizationDescriptor createOrg(String orgId) throws MMSConnectionExc * @return the descriptor of the newly created project */ public MMSOrganizationDescriptor createOrg(String orgId, String orgName) throws MMSConnectionException { - MMSOrganizationDescriptor org = new MMSOrganizationDescriptor(); - org.id = orgId; - org.name = orgName; - MMSRootDescriptor root = new MMSRootDescriptor(); - root.orgs.add(org); - - String json = getPreparedGsonBuilder().create().toJson(root); try { - Request request = restHelper.preparePost(URL_POSTFIX__ORGANIZATIONS) - .bodyString(json, ContentType.APPLICATION_JSON); + MMSOrganizationDescriptor org = new MMSOrganizationDescriptor(); + org.id = orgId; + org.name = orgName; + Request request = MMSAPIHelper.postOrganizations(restHelper, apiVersion, org); String response = tryToExecuteAndGetContentAsString(request); - List createdOrg = readOrganizationsFromJson(response); + List createdOrg = readOrganizationsFromJson(apiVersion, response); return createdOrg.get(0); } catch (IOException e) { throw new MMSConnectionException("Cannot create org with the id "+orgId, e); //$NON-NLS-1$ @@ -192,129 +170,96 @@ public MMSOrganizationDescriptor createOrg(String orgId, String orgName) throws } /** - * Tries to wuery the organization for the specified id and if it doesn't exist + * Tries to query the organization for the specified id and if it doesn't exist * creates it. If project creation is necessary the id is also used as name. * * @param orgId * @return the project for the specified id */ public MMSOrganizationDescriptor getOrCreateOrg(String orgId) throws MMSConnectionException { - MMSOrganizationDescriptor org; List orgList = getOrgs(); Optional organizationWithSpecifiedId = orgList.stream().filter(o -> orgId.contentEquals(o.id)).findFirst(); - org = organizationWithSpecifiedId.orElseGet(() -> createOrg(orgId, orgId)); - return org; + return organizationWithSpecifiedId.orElseGet(() -> createOrg(orgId, orgId)); } /** - * Removes the specified organisation (and every projects from it). + * Removes the specified organization (and every projects from it). * - * @param orgId the id of the removable organisation - * @return the response of the organisation deletion call + * @param orgId the id of the removable organization + * @return the response of the organization deletion call */ public boolean removeOrg(MMSOrganizationDescriptor orgId) throws MMSConnectionException { return removeOrg(orgId.id); } /** - * Removes the specified organisation (and every projects from it). + * Removes the specified organization (and every projects from it). * - * @param orgId the id of the removable organisation - * @return the status of the organisation deletion call (200 if everything is OK) + * @param orgId the id of the removable organization + * @return the status of the organization deletion call (200 if everything is OK) */ public boolean removeOrg(String orgId) throws MMSConnectionException { try { - Request request = restHelper.prepareGet(URL_POSTFIX__PROJECTS_OF_ORGANIZATION, orgId); + Request request = MMSAPIHelper.getProjects(restHelper, apiVersion, orgId); String containedProjectsJson = tryToExecuteAndGetContentAsString(request); - MMSRootDescriptor root = readRootFromJson(containedProjectsJson); - root.projects.forEach(p -> { if(!removeProject(p)) MmsConnectorPlugin.getDefault().getLogger().error("Project cannot be deleted: "+p.id);}); //$NON-NLS-1$ - int statusCode = restHelper.prepareDelete("orgs/%s", orgId).execute().returnResponse().getStatusLine().getStatusCode(); //$NON-NLS-1$ + List projects = readProjectsFromJson(apiVersion, containedProjectsJson); + projects.forEach(p -> { if(!removeProject(p)) MmsConnectorPlugin.getDefault().getLogger().error("Project cannot be deleted: "+p.id);}); //$NON-NLS-1$ + int statusCode = MMSAPIHelper.deleteOrganizations(restHelper, apiVersion, orgId).execute().returnResponse().getStatusLine().getStatusCode(); return 200 == statusCode; } catch (IOException e) { throw new MMSConnectionException("Cannot remove organisation "+orgId, e); //$NON-NLS-1$ } } - - - + /********************************************************************************************* ********************************* Project handler features ********************************* *********************************************************************************************/ - + /** * Queries projects of the specified organization from the server. * - * @param orgId the id of the organization - * @return the list of projects - */ - public List getProjects(String orgId) throws MMSConnectionException { - try { - Request request = restHelper.prepareGet(URL_POSTFIX__PROJECTS_OF_ORGANIZATION, orgId); - String projectsJson = tryToExecuteAndGetContentAsString(request); - return readProjectsFromJson(projectsJson); - } catch (IOException e) { - throw new MMSConnectionException( - String.format("Cannot query projects of '%s' organization from %s", orgId, baseUrl), e); //$NON-NLS-1$ - } - } - - /** - * Queries projects of the the server. - * + * @param organizationId the id of the organization * @return the list of projects */ - public List getProjects() throws MMSConnectionException { + public List getProjects(String organizationId) throws MMSConnectionException { try { - Request request = restHelper.prepareGet(URL_POSTFIX__PROJECTS); - String projectsJson = tryToExecuteAndGetContentAsString(request); - return readProjectsFromJson(projectsJson); + Request request = MMSAPIHelper.getProjects(restHelper, apiVersion, organizationId); + String json = tryToExecuteAndGetContentAsString(request); + return readProjectsFromJson(apiVersion, json); } catch (IOException e) { - throw new MMSConnectionException( - String.format("Cannot query projects from %s", baseUrl), e); //$NON-NLS-1$ + throw new MMSConnectionException(String.format("Cannot query projects of '%s' organization from %s", organizationId, baseUrl), e); //$NON-NLS-1$ } } - + public MMSProjectDescriptor createProject(String orgId, String projectId) throws MMSConnectionException { return createProject(orgId, projectId, projectId); } - + public MMSProjectDescriptor createProject(String orgId, String projectId, String projectName) throws MMSConnectionException { return createProject(orgId, projectId, projectName, projectName); } - + /** * @param projectId if its null then a unique id will be generated based on the given name and organization * @return the project descriptor (its id may differs from the given one because escaped characters are used for creation) * @throws MMSConnectionException */ public MMSProjectDescriptor createProject(String orgId, String projectId, String projectServerName, String projectEclipseName) throws MMSConnectionException { - MMSProjectDescriptor project = new MMSProjectDescriptor(); - if (!isMMS4API()) { - project.featurePrefix = MMSProjectDescriptor.FEATURE_PREFIX__EMF; + try { + MMSProjectDescriptor project = new MMSProjectDescriptor(); project.clientSideName = projectEclipseName; + project.featurePrefix = MMSProjectDescriptor.FEATURE_PREFIX__EMF; + project.name = projectServerName; project.orgId = orgId; - } else { - project.type = null; - project.visibility = MMSProjectDescriptor.PRIVATE_VISIBILITY; // MMS 4 - } - project.name = projectServerName; - if(projectId == null || projectId.isEmpty()) { - project.id = generateUniqueProjectId(orgId, projectServerName); - } else { - project.id = escape(projectId); - } - MMSRootDescriptor root = new MMSRootDescriptor(); - root.projects.add(project); - - String json = isMMS4API() ? - getPreparedGsonBuilder().create().toJson(new MMSProjectDescriptor[] { project }) - : getPreparedGsonBuilder().create().toJson(root); - try { - Request request = restHelper.preparePost(URL_POSTFIX__PROJECTS_OF_ORGANIZATION, orgId) - .bodyString(json, ContentType.APPLICATION_JSON); + if (projectId == null || projectId.isEmpty()) { + project.id = generateUniqueProjectId(orgId, projectServerName); + } else { + project.id = escape(projectId); + } + Request request = MMSAPIHelper.postProjects(restHelper, apiVersion, orgId, project); String resp = tryToExecuteAndGetContentAsString(request); - List respRoot = readProjectsFromJson(resp); + List respRoot = readProjectsFromJson(apiVersion, resp); return respRoot.get(0); } catch (IOException e) { throw new MMSConnectionException(String.format("Cannot create project in the '%s' organization with the id '%s'", orgId, projectId), e); //$NON-NLS-1$ @@ -322,12 +267,12 @@ public MMSProjectDescriptor createProject(String orgId, String projectId, String } public String generateUniqueProjectId(String orgId, String projectName) { - if (isMMS4API()) { + if (MMSServerDescriptor.API_VERSION_4.equals(apiVersion)) { return UUID.randomUUID().toString(); } String projectIdBase = generateBaseProjectId(orgId, projectName); - Set projectIdsOnServer = getProjects().stream().map(p -> p.id.toLowerCase()).collect(Collectors.toSet()); + Set projectIdsOnServer = getProjects(orgId).stream().map(p -> p.id.toLowerCase()).collect(Collectors.toSet()); boolean idCollision = projectIdsOnServer.contains(projectIdBase.toLowerCase()); long i = -1; while(idCollision) { @@ -347,92 +292,67 @@ public static String escape(String projectId) { } public MMSProjectDescriptor getOrCreateProject(String orgId, String id) throws MMSConnectionException { - MMSProjectDescriptor project; - project = getProjects(orgId).stream() - .filter(p -> id.equalsIgnoreCase(p.id)) - .findFirst().orElseGet(() -> createProject(orgId, id, id)); - return project; + return getProjects(orgId).stream().filter(p -> id.equalsIgnoreCase(p.id)).findFirst().orElseGet(() -> createProject(orgId, id, id)); } public boolean removeProject(MMSProjectDescriptor p) { try { - int statusCode = restHelper.prepareDelete("projects/%s", p.id).execute().returnResponse().getStatusLine().getStatusCode(); //$NON-NLS-1$ + int statusCode = MMSAPIHelper.deleteProjects(restHelper, apiVersion, p.orgId, p.id).execute().returnResponse().getStatusLine().getStatusCode(); return 200 == statusCode; } catch (IOException e) { e.printStackTrace(); } return false; } - - - + /********************************************************************************************* ********************************** Branch handler features ********************************** *********************************************************************************************/ - public List getBranches(String organizationId, String projectId) throws MMSConnectionException { try { - Request request; - if (isMMS4API()) { - request = restHelper.prepareGet("orgs/%s/projects/%s/branches", organizationId, projectId); //$NON-NLS-1$ - } else { - request = restHelper.prepareGet("projects/%s/refs", projectId); //$NON-NLS-1$ - } - String projectsJson = tryToExecuteAndGetContentAsString(request); - return readBranchesFromJson(projectsJson); + Request request = MMSAPIHelper.getBranches(restHelper, apiVersion, organizationId, projectId); + String json = tryToExecuteAndGetContentAsString(request); + return readBranchesFromJson(apiVersion, json); } catch (IOException e) { - throw new MMSConnectionException( - String.format("Cannot query branches of '%s' project from %s", projectId, baseUrl), e); //$NON-NLS-1$ + throw new MMSConnectionException(String.format("Cannot query branches of '%s' project from %s", projectId, baseUrl), e); //$NON-NLS-1$ } } - + public MMSRefDescriptor getBranch(String organizationId, String projectId, String branchId) throws MMSConnectionException { try { - Request request; - if (isMMS4API()) { - request = restHelper.prepareGet("orgs/%s/projects/%s/branches/%s", organizationId, projectId, branchId); //$NON-NLS-1$ - } else { - request = restHelper.prepareGet("projects/%s/refs/%s", projectId, branchId); //$NON-NLS-1$ - } - String projectsJson = tryToExecuteAndGetContentAsString(request); - return readBranchesFromJson(projectsJson).get(0); + Request request = MMSAPIHelper.getBranch(restHelper, apiVersion, organizationId, projectId, branchId); + String json = tryToExecuteAndGetContentAsString(request); + return readBranchesFromJson(apiVersion, json).get(0); } catch (IOException e) { - throw new MMSConnectionException( - String.format("Cannot query branches of '%s' project from %s", projectId, baseUrl), e); //$NON-NLS-1$ + throw new MMSConnectionException(String.format("Cannot query branches of '%s' project from %s", projectId, baseUrl), e); //$NON-NLS-1$ } } - + public MMSRefDescriptor createBranch(MMSProjectDescriptor owner, String branchId) throws MMSConnectionException { - return createBranch(owner.id, branchId, branchId, MMS_REF__DEFAULT); + return createBranch(owner.orgId, owner.id, branchId, branchId, MMS_REF__DEFAULT); } - - public MMSRefDescriptor createBranch(String projectId, String branchId) throws MMSConnectionException { - return createBranch(projectId, branchId, branchId, MMS_REF__DEFAULT); + + public MMSRefDescriptor createBranch(String organizationId, String projectId, String branchId) throws MMSConnectionException { + return createBranch(organizationId, projectId, branchId, branchId, MMS_REF__DEFAULT); } - - public MMSRefDescriptor createBranch(String projectId, String branchId, String branchName) throws MMSConnectionException { - return createBranch(projectId, branchId, branchName, MMS_REF__DEFAULT); + + public MMSRefDescriptor createBranch(String organizationId, String projectId, String branchId, String branchName) throws MMSConnectionException { + return createBranch(organizationId, projectId, branchId, branchName, MMS_REF__DEFAULT); } - - public MMSRefDescriptor createBranch(String projectId, String branchId, String branchName, String parentRefId) throws MMSConnectionException { - MMSRefDescriptor branch = new MMSRefDescriptor(); - branch.id = branchId; - branch.name = branchName; - branch.type = MMSRefDescriptor.TYPE__BRANCH; - branch.parentRefId = parentRefId; - MMSRootDescriptor root = new MMSRootDescriptor(); - root.refs.add(branch); - - String json = getPreparedGsonBuilder().create().toJson(root); + + public MMSRefDescriptor createBranch(String organizationId, String projectId, String branchId, String branchName, String parentRefId) throws MMSConnectionException { try { - Request request = restHelper.preparePost("projects/%s/refs", projectId) //$NON-NLS-1$ - .bodyString(json, ContentType.APPLICATION_JSON); + MMSRefDescriptor branch = new MMSRefDescriptor(); + branch.id = branchId; + branch.name = branchName; + branch.type = MMSRefDescriptor.TYPE__BRANCH; + branch.parentRefId = parentRefId; + Request request = MMSAPIHelper.postBranches(restHelper, apiVersion, organizationId, projectId, branch); String resp = tryToExecuteAndGetContentAsString(request); - MMSRootDescriptor respRoot = readRootFromJson(resp); - return (respRoot.refs != null && respRoot.refs.size() > 0) ? respRoot.refs.get(0) : null; + List refs = readBranchesFromJson(apiVersion, resp); + return (refs != null && refs.size() > 0) ? refs.get(0) : null; } catch (IOException e) { - throw new MMSConnectionException( - String.format("Cannot create branch '%s' for the project '%s'", branchId, projectId), e); //$NON-NLS-1$ + throw new MMSConnectionException(String.format("Cannot create branch '%s' for the project '%s'", branchId, projectId), e); //$NON-NLS-1$ } } @@ -446,82 +366,47 @@ public MMSRefDescriptor getOrCreateBranch(String organizationId, String projectI public List getCommits(String organizationId, String projectId, String branchId) throws MMSConnectionException { try { - Request request; - if (isMMS4API()) { - request = restHelper.prepareGet("orgs/%s/projects/%s/branches/%s/commits", organizationId, projectId, branchId); //$NON-NLS-1$ - } else { - request = restHelper.prepareGet("projects/%s/refs/%s/commits", projectId, branchId); //$NON-NLS-1$ - } - String commitsJson = tryToExecuteAndGetContentAsString(request); - return readCommitsFromJson(commitsJson); + Request request = MMSAPIHelper.getCommits(restHelper, apiVersion, organizationId, projectId, branchId); + String json = tryToExecuteAndGetContentAsString(request); + return readCommitsFromJson(apiVersion, json); } catch (IOException e) { - throw new MMSConnectionException( - String.format("Cannot query commits from the '%s' barnch of '%s' project from %s", branchId, projectId, baseUrl), e); //$NON-NLS-1$ + throw new MMSConnectionException(String.format("Cannot query commits from the '%s' barnch of '%s' project from %s", branchId, projectId, baseUrl), e); //$NON-NLS-1$ } } - public boolean removeBranch(MMSRefDescriptor p) { + public boolean removeBranch(MMSRefDescriptor ref) { try { - int statusCode = restHelper.prepareDelete("projects/%s/%s", p._projectId, p.id).execute().returnResponse().getStatusLine().getStatusCode(); //$NON-NLS-1$ + int statusCode = MMSAPIHelper.deleteBranches(restHelper, apiVersion, null, ref._projectId, ref.id).execute().returnResponse().getStatusLine().getStatusCode(); return 200 == statusCode; } catch (IOException e) { e.printStackTrace(); } return false; } - - - + /********************************************************************************************* ****************************** Model element handler features ****************************** *********************************************************************************************/ - - public List getModelElement(String projectId, String branchId, String elementId, String commitId) throws MMSConnectionException { + public List getModelElement(String projectId, String branchId, String elementId) throws MMSConnectionException { try { - Request preparedGet; - if(commitId == null) { - preparedGet = restHelper.prepareGet("projects/%s/refs/%s/elements/%s", projectId, branchId, elementId); //$NON-NLS-1$ - } else { - preparedGet = restHelper.prepareGet("projects/%s/refs/%s/elements/%s?commitId=%s", projectId, branchId, elementId, commitId); //$NON-NLS-1$ - } - String projectsJson = tryToExecuteAndGetContentAsString(preparedGet); - return readElementsFromJson(projectsJson); + Request request = MMSAPIHelper.getElement(restHelper, apiVersion, null, projectId, branchId, elementId); + String json = tryToExecuteAndGetContentAsString(request); + return readElementsFromJson(apiVersion, json); } catch (IOException e) { - throw new MMSConnectionException( - String.format("Cannot query branches of '%s' project from %s", projectId, baseUrl), e); //$NON-NLS-1$ + throw new MMSConnectionException(String.format("Cannot query branches of '%s' project from %s", projectId, baseUrl), e); //$NON-NLS-1$ } } - + public List getModelElements(String organizationId, String projectId, String branchId) throws MMSConnectionException { try { - Request request; - if (isMMS4API()) { - request = restHelper.prepareGet("orgs/%s/projects/%s/branches/%s/elements", organizationId, projectId, branchId); //$NON-NLS-1$ - } else { - request = restHelper.prepareGet("projects/%s/refs/%s/elements", projectId, branchId); //$NON-NLS-1$ - } - String projectsJson = tryToExecuteAndGetContentAsString(request); - return readElementsFromJson(projectsJson); + Request request = MMSAPIHelper.getElements(restHelper, apiVersion, organizationId, projectId, branchId); + String json = tryToExecuteAndGetContentAsString(request); + return readElementsFromJson(apiVersion, json); } catch (IOException e) { - throw new MMSConnectionException( - String.format("Cannot query branches of '%s' project from %s", projectId, baseUrl), e); //$NON-NLS-1$ + throw new MMSConnectionException(String.format("Cannot query branches of '%s' project from %s", projectId, baseUrl), e); //$NON-NLS-1$ } } - - public List getModelElements(String organizationId, String projectId, String branchId, String commitId) throws MMSConnectionException { - if(commitId==null) { - return getModelElements(organizationId, projectId, branchId); - } - try { - Request request = restHelper.prepareGet("projects/%s/refs/%s/elements?commitId=%s", projectId, branchId, commitId); //$NON-NLS-1$ - String projectsJson = tryToExecuteAndGetContentAsString(request); - return readElementsFromJson(projectsJson); - } catch (IOException e) { - throw new MMSConnectionException( - String.format("Cannot query branches of '%s' project from %s", projectId, baseUrl), e); //$NON-NLS-1$ - } - } - + public MMSModelElementDescriptor prepareModelElement(String projectId, String branchId, String id, String nsUri, String type, String ownerId, Map modelingAttributes) { @@ -538,57 +423,34 @@ public MMSModelElementDescriptor prepareModelElement(String projectId, String br return med; } - public List createModelElements(String projectId, String branchId, List meds) + public List createModelElements(String organizationId, String projectId, String branchId, List meds) throws MMSConnectionException { - return createModelElements(projectId, branchId, "", meds); //$NON-NLS-1$ + return createModelElements(organizationId, projectId, branchId, "", meds); //$NON-NLS-1$ } - - public List createModelElements(String projectId, String branchId, String commitComment, List meds) - throws MMSConnectionException { - MMSRootDescriptor root = new MMSRootDescriptor(); - root.elements = meds; - root.comment = commitComment; - - String json = getPreparedGsonBuilder().create().toJson(root); + + public List createModelElements(String organizationId, String projectId, String branchId, String commitComment, List modelElements) throws MMSConnectionException { try { - Request request = restHelper.preparePost("projects/%s/refs/%s/elements", projectId, branchId) //$NON-NLS-1$ - .bodyString(json, ContentType.APPLICATION_JSON); - String resp = tryToExecuteAndGetContentAsString(request); - MMSRootDescriptor returnedRoot = readRootFromJson(resp); - return returnedRoot.elements; + Request request = MMSAPIHelper.postElements(restHelper, apiVersion, organizationId, projectId, branchId, commitComment, modelElements); + String json = tryToExecuteAndGetContentAsString(request); + return readElementsFromJson(apiVersion, json); } catch (IOException e) { throw new MMSConnectionException( String.format("Element creation failed at the branch '%s' of project '%s' on the server '%s'", branchId, projectId, baseUrl), e); //$NON-NLS-1$ } } - public boolean removeModelElements(String organizationId, String projectId, String branchId, String commitComment, List meds) - throws MMSConnectionException { - MMSRootDescriptor root = new MMSRootDescriptor(); - root.elements = meds; - root.comment = commitComment; - + public boolean removeModelElements(String organizationId, String projectId, String branchId, String commitComment, List modelElements) throws MMSConnectionException { try { - DeleteRequestWithBody request; - if (isMMS4API()) { - String json = getPreparedGsonBuilder().create().toJson(meds.toArray()); - request = restHelper.prepareDelete("orgs/%s/projects/%s/branches/%s/elements", organizationId, projectId, branchId) //$NON-NLS-1$ - .bodyString(json, ContentType.APPLICATION_JSON); - } else { - String json = getPreparedGsonBuilder().create().toJson(root); - request = restHelper.prepareDelete("projects/%s/refs/%s/elements", projectId, branchId) //$NON-NLS-1$ - .bodyString(json, ContentType.APPLICATION_JSON); - } - - String resp = tryToExecuteAndGetContentAsString(request); - List returnedElements = readElementsFromJson(resp); - return returnedElements.size() == meds.size(); + DeleteRequestWithBody request = MMSAPIHelper.deleteElements(restHelper, apiVersion, organizationId, projectId, branchId, commitComment, modelElements); + String json = tryToExecuteAndGetContentAsString(request); + List returnedElements = readElementsFromJson(apiVersion, json); + return returnedElements.size() == modelElements.size(); } catch (IOException e) { throw new MMSConnectionException( String.format("Element creation failed at the branch '%s' of project '%s' on the server '%s'", branchId, projectId, baseUrl), e); //$NON-NLS-1$ } } - + private static String tryToExecuteAndGetContentAsString(Request req) throws ClientProtocolException, IOException { String response = null; int retryNumber = 0; diff --git a/plugins/com.thalesgroup.mde.openmbee.connector.mms/src/com/thalesgroup/mde/openmbee/connector/mms/utils/RestApiHelper.java b/plugins/com.thalesgroup.mde.openmbee.connector.mms/src/com/thalesgroup/mde/openmbee/connector/mms/utils/RestApiHelper.java index baf4b41..d810e54 100644 --- a/plugins/com.thalesgroup.mde.openmbee.connector.mms/src/com/thalesgroup/mde/openmbee/connector/mms/utils/RestApiHelper.java +++ b/plugins/com.thalesgroup.mde.openmbee.connector.mms/src/com/thalesgroup/mde/openmbee/connector/mms/utils/RestApiHelper.java @@ -38,12 +38,11 @@ public class RestApiHelper { private String autData; private String apiPrefix; - public RestApiHelper(String baseUrl, String ticket, String autData, boolean isMMS4API) { + public RestApiHelper(String baseUrl, String ticket, String autData, String apiPrefix) { this.baseUrl = baseUrl; //this.ticket = ticket; this.autData = autData; - // MMS4 services API - this.apiPrefix = isMMS4API ? "api/" : ""; //$NON-NLS-1$ //$NON-NLS-2$ + this.apiPrefix = apiPrefix; } /**