Skip to content

Commit

Permalink
#1 MMS4 Support
Browse files Browse the repository at this point in the history
  • Loading branch information
j-barata committed Feb 24, 2020
1 parent cb84641 commit eb74e20
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ private ExecutionResult executeImport(MmsProjectImportData connectionData, Strin
monitor.beginTask("Import from MMS", projectConnector.getNumberOfSubTaskOfFromMms()); //$NON-NLS-1$
success = projectConnector.fromMms(connectionData.serverUrl,
connectionData.apiVersion,
connectionData.autData,
connectionData.autData,
connectionData.orgId,
connectionData.projectId,
connectionData.refId,
connectionData.commitId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,19 +164,19 @@ private IFile getFile(Resource res) {
return wsRoot.getFile(new Path(res.getURI().toPlatformString(true)));
}

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 apiVersion, String autData, String organizationId, String projectId, String branchId) throws InterruptedException {
return fromMms(baseUrl, apiVersion, autData, organizationId, projectId, branchId, null, null, new NullProgressMonitor());
}

public boolean fromMms(String baseUrl, String apiVersion, String autData, String projectId, String branchId, String commitId, String projectName, IProgressMonitor monitor) throws InterruptedException {
public boolean fromMms(String baseUrl, String apiVersion, String autData, String organizationId, String projectId, String branchId, String commitId, String projectName, IProgressMonitor monitor) throws InterruptedException {
boolean success = false;
List<MMSModelElementDescriptor> elements = null;
MMSServerHelper serverHelper = new MMSServerHelper(baseUrl, apiVersion, autData);
try {
startNewSubTaskIfNotCancelled(monitor, "Download data from MMS", MESSAGE_CANCELLATION_IMPORT); //$NON-NLS-1$
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 = serverHelper.getModelElements(organizationId, projectId, branchId, commitId);
elements = elements.stream().filter(e -> !holdingBinFilter.contentEquals(e.id) && !viewInstancesBinFilter.contentEquals(e.id) ).collect(Collectors.toList());
monitor.worked(1);
} catch (MMSServerHelper.MMSConnectionException e) {
Expand All @@ -189,7 +189,7 @@ public boolean fromMms(String baseUrl, String apiVersion, String autData, String
elements.remove(projectDescriptor);
} else {
try {
projectDescriptor = serverHelper.getModelElement(projectId, branchId, projectId).get(0);
projectDescriptor = serverHelper.getModelElement(organizationId, projectId, branchId, projectId).get(0);
} catch (IndexOutOfBoundsException e) {
throw new InterruptedException("Project descriptor cannot be found on the server."); //$NON-NLS-1$
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class MMSAPIHelper {
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_COMMIT_ID = "projects/%s/refs/%s/elements?commitId=%s"; //$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$
Expand Down Expand Up @@ -265,6 +266,25 @@ public static Request getElements(RestApiHelper helper, String apiVersion, Strin
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
* @param commitId commit 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, String commitId) {
if (MMSServerDescriptor.API_VERSION_3.equals(apiVersion)) {
return helper.prepareGet(URL_POSTFIX__MMS3__ELEMENTS_BY_COMMIT_ID, projectId, branchId, commitId);
} else if (MMSServerDescriptor.API_VERSION_4.equals(apiVersion)) {
// FIXME not implemented yet
}
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,9 @@ public boolean removeBranch(MMSRefDescriptor ref) {
/*********************************************************************************************
****************************** Model element handler features ******************************
*********************************************************************************************/
public List<MMSModelElementDescriptor> getModelElement(String projectId, String branchId, String elementId) throws MMSConnectionException {
public List<MMSModelElementDescriptor> getModelElement(String organizationId, String projectId, String branchId, String elementId) throws MMSConnectionException {
try {
Request request = MMSAPIHelper.getElement(restHelper, apiVersion, null, projectId, branchId, elementId);
Request request = MMSAPIHelper.getElement(restHelper, apiVersion, organizationId, projectId, branchId, elementId);
String json = tryToExecuteAndGetContentAsString(request);
return readElementsFromJson(apiVersion, json);
} catch (IOException e) {
Expand All @@ -407,6 +407,19 @@ public List<MMSModelElementDescriptor> getModelElements(String organizationId, S
}
}

public List<MMSModelElementDescriptor> getModelElements(String organizationId, String projectId, String branchId, String commitId) throws MMSConnectionException {
if(commitId==null) {
return getModelElements(organizationId, projectId, branchId);
}
try {
Request request = MMSAPIHelper.getElements(restHelper, apiVersion, organizationId, projectId, branchId, commitId);
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$
}
}

public MMSModelElementDescriptor prepareModelElement(String projectId, String branchId,
String id, String nsUri, String type,
String ownerId, Map<String, Object> modelingAttributes) {
Expand Down

0 comments on commit eb74e20

Please sign in to comment.