Skip to content

Commit

Permalink
Merge pull request #224 from Open-MBEE/release/5.0.1
Browse files Browse the repository at this point in the history
Release/5.0.1
  • Loading branch information
ivan-gomes authored Mar 15, 2022
2 parents 910d26b + 6ad1d65 commit 979ee6d
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 132 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Cameo MDK is a plugin for [Cameo Systems Modeler](https://www.nomagic.com/produc
* [Cameo Systems Modeler (CSM)](https://www.nomagic.com/products/cameo-systems-modeler) or another No Magic environment bundle that includes the [SysML plugin](https://www.nomagic.com/product-addons/magicdraw-addons/sysml-plugin)
* The latest Cameo MDK is compatible with **19.0 SP3** and **19.0 SP4**. Compatibility for previous versions of Cameo MDK can be found in the [compatibility matrices](https://github.com/Open-MBEE/open-mbee.github.io/wiki/Compatibilities).
* [Model Management System (MMS)](https://www.openmbee.org/projects.html#mms)
* The latest Cameo MDK is compatible with MMS **4.x**. Compatibility for previous version of Cameo MDK can be found in the [compatibility matrices](https://github.com/Open-MBEE/open-mbee.github.io/wiki/Compatibilities).
* The Cameo MDK (5.0+) is compatible with MMS **4.x**. Compatibility for previous version of Cameo MDK can be found in the [compatibility matrices](https://github.com/Open-MBEE/open-mbee.github.io/wiki/Compatibilities).

## Installation

Expand Down Expand Up @@ -45,7 +45,7 @@ Cameo MDK is a Java project that uses the [Gradle](https://gradle.org/) build to


## Custom Build Profiles
Starting with version 5.0+ you will be able to define custom build profiles (in `./buildProfiles`) which will house
Starting with version 4.5.1+ you will be able to define custom build profiles (in `./buildProfiles`) which will house
the classpath and other variables previously managed by setting `-buildAccess=internal`. These profiles will allow
customization based on your build process and for your particular version of Cameo.

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=5.0.0
version=5.0.1
group=org.openmbee.mdk.magic
descriptorFile=MDR_Plugin_Model_Development_Kit_91110_descriptor.xml
magicdDrawGroupName=gov.nasa.jpl.cae.magicdraw.mdk
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/gov/nasa/jpl/mbee/mdk/MDKConfigurator.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,6 @@ private void addElementActions(ActionsManager manager, Element e, List<Element>
if (manager.getActionFor(ValidateElementRecursivelyAction.DEFAULT_ID) == null) {
models.addAction(new ValidateElementRecursivelyAction(es, "Validate Models"));
}
if (manager.getActionFor(ValidateElementDepthAction.DEFAULT_ID) == null) {
models.addAction(new ValidateElementDepthAction(es, "Validate Models (specified depth)"));
}
if (manager.getActionFor(ValidateElementAction.DEFAULT_ID) == null) {
models.addAction(new ValidateElementAction(es, "Validate Element"));
}
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/gov/nasa/jpl/mbee/mdk/json/JacksonUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ public static ObjectMapper getObjectMapper() {

public static JsonFactory getJsonFactory() {
if (JSON_FACTORY_INSTANCE == null) {
JSON_FACTORY_INSTANCE = new JsonFactory();
JSON_FACTORY_INSTANCE.setCodec(JacksonUtils.getObjectMapper());
JSON_FACTORY_INSTANCE = new TempFileJsonFactory(getObjectMapper());
}
return JSON_FACTORY_INSTANCE;
}
Expand Down
52 changes: 52 additions & 0 deletions src/main/java/gov/nasa/jpl/mbee/mdk/json/TempFileJsonFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package gov.nasa.jpl.mbee.mdk.json;

import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.util.JsonParserDelegate;
import com.fasterxml.jackson.databind.MappingJsonFactory;
import com.fasterxml.jackson.databind.ObjectMapper;
import gov.nasa.jpl.mbee.mdk.json.JacksonUtils;
import gov.nasa.jpl.mbee.mdk.options.MDKOptionsGroup;

import java.io.File;
import java.io.IOException;
import java.util.Objects;

class TempFileJsonFactory extends MappingJsonFactory {

public TempFileJsonFactory() {
super();
}

public TempFileJsonFactory(ObjectMapper mapper) {
super(mapper);
}

public TempFileJsonFactory(JsonFactory src, ObjectMapper mapper) {
super(src, mapper);
}

@Override
public JsonParser createParser(File file) throws IOException {
return new TempFileJsonParser(super.createParser(file), file);
}

private static class TempFileJsonParser extends JsonParserDelegate {

private final File file;

public TempFileJsonParser(JsonParser d, File file) {
super(d);
this.file = file;
}

@Override
public void close() throws IOException {
if (file != null && (MDKOptionsGroup.getMDKOptions().isLogJson() || !file.delete())) {
file.deleteOnExit();
}
super.close();
}
}

}
17 changes: 6 additions & 11 deletions src/main/java/gov/nasa/jpl/mbee/mdk/mms/MMSUtils.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package gov.nasa.jpl.mbee.mdk.mms;

import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.nomagic.ci.persistence.IProject;
import com.nomagic.magicdraw.core.Application;
import com.nomagic.magicdraw.core.Project;
import com.nomagic.magicdraw.core.ProjectUtilities;
Expand All @@ -24,10 +21,13 @@
import gov.nasa.jpl.mbee.mdk.mms.actions.MMSLogoutAction;
import gov.nasa.jpl.mbee.mdk.mms.endpoints.*;
import gov.nasa.jpl.mbee.mdk.options.MDKOptionsGroup;
import gov.nasa.jpl.mbee.mdk.util.*;
import gov.nasa.jpl.mbee.mdk.util.MDUtils;
import gov.nasa.jpl.mbee.mdk.util.TaskRunner;
import gov.nasa.jpl.mbee.mdk.util.Utils;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.*;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.entity.ContentType;
import org.apache.http.impl.client.CloseableHttpClient;
Expand Down Expand Up @@ -110,7 +110,7 @@ public static boolean validateJwtToken(Project project, ProgressStatus progressS
IOException, URISyntaxException, GeneralSecurityException {
// build request
HttpRequestBase request = prepareEndpointBuilderBasicGet(MMSValidateJwtToken.builder(), project).build();

// do request
ObjectNode responseJson = JacksonUtils.getObjectMapper().createObjectNode();
sendMMSRequest(project, request, progressStatus, responseJson);
Expand Down Expand Up @@ -336,11 +336,6 @@ private static String generateMmsOutput(InputStream inputStream, final File resp
System.out.println("[INFO] Response Body: " + responseFile.getPath());
Application.getInstance().getGUILog().log("[INFO] Response Body: " + responseFile.getPath());
}
else {
if(!responseFile.delete()) { // if we cannot immediately delete we'll get it later
responseFile.deleteOnExit();
}
}
}
return "";
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,11 @@ public void run(ProgressStatus progressStatus) {
progressStatus.setCurrent(0);

List<Pair<Element, ObjectNode>> clientElements = new ArrayList<>(rootElements.size());
Set<String> clientIdsVisited = new HashSet<>(rootElements.size());
Collection<File> responseFiles = new ArrayList<>(3);
for (Element element : rootElements) {
collectClientElementsRecursively(project, element, depth, clientElements);
int loopDepth = depth;
collectClientElementsRecursively(project, element, loopDepth, clientElements, clientIdsVisited);
try {
File searchFile = searchForServerElements(project, element, progressStatus);
if(searchFile != null) {
Expand Down Expand Up @@ -127,21 +129,28 @@ private File searchForServerElements(Project project, Element element, ProgressS
return MMSUtils.sendMMSRequest(project, searchRequest, progressStatus);
}

private static void collectClientElementsRecursively(Project project, Element element, int depth, List<Pair<Element, ObjectNode>> elements) {
private static void collectClientElementsRecursively(Project project, Element element, int loopDepth, List<Pair<Element, ObjectNode>> elements, Set<String> visitedElementIds) {
ObjectNode jsonObject = Converters.getElementToJsonConverter().apply(element, project);
if (jsonObject == null) {
return;
}
String id = Converters.getElementToIdConverter().apply(element);
if (visitedElementIds.contains(id)) {
return;
}
elements.add(new Pair<>(element, jsonObject));
if (depth-- != 0) {
visitedElementIds.add(id);

if (loopDepth-- != 0) {
for (Element elementChild : element.getOwnedElement()) {
collectClientElementsRecursively(project, elementChild, depth, elements);
collectClientElementsRecursively(project, elementChild, loopDepth, elements, visitedElementIds);
}
}
if (element.equals(project.getPrimaryModel())) {
visitedElementIds.add(Converters.getIProjectToIdConverter().apply(project.getPrimaryProject()));
List<Package> attachedModels = project.getModels();
attachedModels.remove(project.getPrimaryModel());
attachedModels.forEach(attachedModel -> collectClientElementsRecursively(project, attachedModel, 0, elements));
attachedModels.forEach(attachedModel -> collectClientElementsRecursively(project, attachedModel, 0, elements, visitedElementIds));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,34 +245,38 @@ private void determineChangesUsingCommitResponse(File responseFile, Set<String>
Set<ObjectNode> commitObjects = parsedResponseObjects.get(MDKConstants.COMMITS_NODE);

if(commitObjects != null && !commitObjects.isEmpty()) {
int size = 0;
String commitSyncDirection = "";
Map<String, Integer> commitSizes = new HashMap<>();
for(ObjectNode jsonObject : commitObjects) {
if(jsonObject.isArray() && jsonObject.size() > 0) {
for(int i = 0; i < jsonObject.size(); i++) {
JsonNode currentNode = jsonObject.get(i);
JsonNode sourceField = currentNode.get(MDKConstants.SOURCE_FIELD);
boolean isSyncingCommit = sourceField != null && sourceField.isTextual() && MDKConstants.MAGICDRAW_SOURCE_VALUE.equalsIgnoreCase(sourceField.asText());
if(isSyncingCommit) {
commitSyncDirection = "Removed";
} else {
commitSyncDirection = "Added";
}

size = validateJsonElementArray(currentNode, isSyncingCommit, lockedElementIds, size);
}
} else { // what do we throw here? and should we?
throw new IllegalStateException();
validateJsonElementArray(jsonObject, lockedElementIds, commitSizes);
}

if (MDUtils.isDeveloperMode()) {
Application.getInstance().getGUILog().log("[INFO] " + project.getName() + " - " + commitSyncDirection + " " + NumberFormat.getInstance().format(size) + " MMS element change" + (size != 1 ? "s" : "") + " for commit " + commitId + ".");
if (commitSizes.isEmpty()) {
Application.getInstance().getGUILog().log("[INFO] No objects found in commit.");
return;
}else {
for (Map.Entry<String, Integer> size : commitSizes.entrySet()) {
Application.getInstance().getGUILog().log("[INFO] " + project.getName() + " - " + size.getKey() + " " + NumberFormat.getInstance().format(size.getValue()) + " MMS element change" + (size.getValue() != 1 ? "s" : "") + " for commit " + commitId + ".");
}
}
}
}
}
}

private int validateJsonElementArray(JsonNode arrayNode, boolean isSyncingCommit, Set<String> lockedElementIds, int size) {
private void validateJsonElementArray(JsonNode arrayNode, Set<String> lockedElementIds, Map<String, Integer> sizes) {
JsonNode sourceField = arrayNode.get(MDKConstants.SOURCE_FIELD);
String commitSyncDirection = "";
int size = 0;
boolean isSyncingCommit = sourceField != null && sourceField.isTextual() && MDKConstants.MAGICDRAW_SOURCE_VALUE.equalsIgnoreCase(sourceField.asText());
if(isSyncingCommit) {
commitSyncDirection = "Removed";
} else {
commitSyncDirection = "Added";
}
if (sizes.containsKey(commitSyncDirection)) {
size = sizes.get(commitSyncDirection);
}
for (Map.Entry<String, Changelog.ChangeType> entry : CHANGE_MAPPING.entrySet()) {
JsonNode changesJsonArray = arrayNode.get(entry.getKey());
if (changesJsonArray == null || !changesJsonArray.isArray()) {
Expand Down Expand Up @@ -315,8 +319,7 @@ private int validateJsonElementArray(JsonNode arrayNode, boolean isSyncingCommit
size++;
}
}

return size;
sizes.put(commitSyncDirection, size);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package gov.nasa.jpl.mbee.mdk.mms.validation;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.nomagic.actions.ActionsCategory;
Expand Down Expand Up @@ -151,6 +149,7 @@ private void processServerElements(Map<String, Pair<Element, ObjectNode>> client
// solves edge case where first model validation incorrectly removes bins from project
removeServerObjectNodeUsingIdPrefix(elementObjects, MDKConstants.HOLDING_BIN_ID_PREFIX);
}
//Remove View Instances Bin
removeServerObjectNodeUsingIdPrefix(elementObjects, MDKConstants.VIEW_INSTANCES_BIN_PREFIX);

for(ObjectNode jsonObject : elementObjects) {
Expand Down

0 comments on commit 979ee6d

Please sign in to comment.