Skip to content

Commit

Permalink
Merge pull request #250 from Open-MBEE/develop
Browse files Browse the repository at this point in the history
5.1.1 release
  • Loading branch information
dlamoris authored Dec 5, 2022
2 parents 393f584 + bea310b commit 3828361
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 39 deletions.
17 changes: 17 additions & 0 deletions .github/stale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Number of days of inactivity before an issue becomes stale
daysUntilStale: 60
# Number of days of inactivity before a stale issue is closed
daysUntilClose: 7
# Issues with these labels will never be considered stale
exemptLabels:
- pinned
- security
# Label to use when marking an issue as stale
staleLabel: stale
# Comment to post when marking an issue as stale. Set to `false` to disable
markComment: >
This issue has been automatically marked as stale because it has not had
recent activity. It will be closed if no further activity occurs. Thank you
for your contributions.
# Comment to post when closing a stale issue. Set to `false` to disable
closeComment: true
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=5.1.0
version=5.1.1
group=org.openmbee.mdk.magic
descriptorFile=MDR_Plugin_Model_Development_Kit_91110_descriptor.xml
magicdDrawGroupName=gov.nasa.jpl.cae.magicdraw.mdk
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/gov/nasa/jpl/mbee/mdk/MDKPluginHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void init() {

private void configureEnvironmentOptions() {
EnvironmentOptions mdkOptions = Application.getInstance().getEnvironmentOptions();
mdkOptions.addGroup(new MDKEnvironmentOptionsGroup());
mdkOptions.addGroup(MDKEnvironmentOptionsGroup.getInstance());
}


Expand Down
5 changes: 5 additions & 0 deletions src/main/java/gov/nasa/jpl/mbee/mdk/emf/EMFImporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ public static class PreProcessor {
JsonNode jsonNode = objectNode.get(MDKConstants.DOCUMENTATION_KEY);
if (jsonNode != null && jsonNode.isTextual()) {
ModelHelper.setComment(element, jsonNode.asText());
//prevent ownedCommentIds empty array from wiping out documentation later
if (objectNode.get(MDKConstants.OWNED_COMMENT_IDS_KEY) != null
&& objectNode.get(MDKConstants.OWNED_COMMENT_IDS_KEY).isEmpty()) {
objectNode.remove(MDKConstants.OWNED_COMMENT_IDS_KEY);
}
}
return element;
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/gov/nasa/jpl/mbee/mdk/json/JacksonUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ public static ObjectNode parseJsonString(String string) throws IOException {
return parseJsonObject(parser);
}

public static Map<String, Set<ObjectNode>> parseResponseIntoObjects(File responseFile, String expectedKey) throws IOException {
public static Map<String, List<ObjectNode>> parseResponseIntoObjects(File responseFile, String expectedKey) throws IOException {
JsonToken current;
Map<String, Set<ObjectNode>> parsedResponseObjects = new HashMap<>();
Map<String, List<ObjectNode>> parsedResponseObjects = new HashMap<>();
try(JsonParser jsonParser = JacksonUtils.getJsonFactory().createParser(responseFile)) {
current = (jsonParser.getCurrentToken() == null ? jsonParser.nextToken() : jsonParser.getCurrentToken());
if (current != JsonToken.START_OBJECT) {
Expand Down Expand Up @@ -155,8 +155,8 @@ public static Map<String, Set<ObjectNode>> parseResponseIntoObjects(File respons
return parsedResponseObjects;
}

private static Set<ObjectNode> parseExpectedArray(JsonParser jsonParser, JsonToken current) throws IOException {
Set<ObjectNode> parsedObjects = new HashSet<>();
private static List<ObjectNode> parseExpectedArray(JsonParser jsonParser, JsonToken current) throws IOException {
List<ObjectNode> parsedObjects = new ArrayList<>();
if (current != null) { // assumes the calling method has begun initial parsing stages
current = jsonParser.nextToken();
if(current.equals(JsonToken.START_ARRAY)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ public void run(ProgressStatus progressStatus) {
}

private ObjectNode findParentBranch(File responseFile, String parentBranchId) throws IOException {
Map<String, Set<ObjectNode>> parsedResponseObjects = JacksonUtils.parseResponseIntoObjects(responseFile, MDKConstants.REFS_NODE);
Set<ObjectNode> refObjects = parsedResponseObjects.get(MDKConstants.REFS_NODE);
Map<String, List<ObjectNode>> parsedResponseObjects = JacksonUtils.parseResponseIntoObjects(responseFile, MDKConstants.REFS_NODE);
List<ObjectNode> refObjects = parsedResponseObjects.get(MDKConstants.REFS_NODE);

if(refObjects != null && !refObjects.isEmpty()) {
for(ObjectNode refObjectNode : refObjects) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ public void actionPerformed(@CheckForNull ActionEvent actionEvent) {
List<ObjectNode> elementsToUpdate = new ArrayList<>(1);
List<String> elementsToDelete = new ArrayList<>(1);
if (elementObjectNode != null) {
if (serverObjectNode != null && serverObjectNode.get(MDKConstants.CONTENTS_KEY) != null && !serverObjectNode.get(MDKConstants.CONTENTS_KEY).isEmpty()) {
elementObjectNode.set(MDKConstants.CONTENTS_KEY, serverObjectNode.get(MDKConstants.CONTENTS_KEY));
}
elementsToUpdate.add(elementObjectNode);
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void run(ProgressStatus progressStatus) {
int loopDepth = depth;
collectClientElementsRecursively(project, element, loopDepth, clientElements, clientIdsVisited);
try {
File searchFile = searchForServerElements(project, element, progressStatus);
File searchFile = searchForServerElements(project, element, loopDepth, progressStatus);
if(searchFile != null) {
responseFiles.add(searchFile);
}
Expand All @@ -113,18 +113,27 @@ public void run(ProgressStatus progressStatus) {
elementValidator.run(progressStatus);
}

private File searchForServerElements(Project project, Element element, ProgressStatus progressStatus)
private File searchForServerElements(Project project, Element element, int depth, ProgressStatus progressStatus)
throws ServerException, IOException, URISyntaxException, GeneralSecurityException {
Collection<String> nodeIds = new HashSet<>(); // this is a collection because the createEntityFile method expects it
if(element.equals(project.getPrimaryModel())) {
nodeIds.add(Converters.getIProjectToIdConverter().apply(project.getPrimaryProject())); // adding the root node because we'll recurse to get the entire tree from it
} else {
nodeIds.add(element.getLocalID());
}
File sendData = MMSUtils.createEntityFile(this.getClass(), ContentType.APPLICATION_JSON, nodeIds, MMSUtils.JsonBlobType.SEARCH);
HttpRequestBase searchRequest = MMSUtils.prepareEndpointBuilderBasicJsonPostRequest(MMSSearchEndpoint.builder(), project, sendData)
.addParam(MMSEndpointBuilderConstants.URI_PROJECT_SUFFIX, Converters.getIProjectToIdConverter().apply(project.getPrimaryProject()))
.addParam(MMSEndpointBuilderConstants.URI_REF_SUFFIX, MDUtils.getBranchId(project)).build();
File sendData;
HttpRequestBase searchRequest;
if (depth == 0) {
sendData = MMSUtils.createEntityFile(this.getClass(), ContentType.APPLICATION_JSON, nodeIds, MMSUtils.JsonBlobType.ELEMENT_ID);
searchRequest = MMSUtils.prepareEndpointBuilderBasicJsonPutRequest(MMSElementsEndpoint.builder(), project, sendData)
.addParam(MMSEndpointBuilderConstants.URI_PROJECT_SUFFIX, Converters.getIProjectToIdConverter().apply(project.getPrimaryProject()))
.addParam(MMSEndpointBuilderConstants.URI_REF_SUFFIX, MDUtils.getBranchId(project)).build();
} else {
sendData = MMSUtils.createEntityFile(this.getClass(), ContentType.APPLICATION_JSON, nodeIds, MMSUtils.JsonBlobType.SEARCH);
searchRequest = MMSUtils.prepareEndpointBuilderBasicJsonPostRequest(MMSSearchEndpoint.builder(), project, sendData)
.addParam(MMSEndpointBuilderConstants.URI_PROJECT_SUFFIX, Converters.getIProjectToIdConverter().apply(project.getPrimaryProject()))
.addParam(MMSEndpointBuilderConstants.URI_REF_SUFFIX, MDUtils.getBranchId(project)).build();
}
// use endpoint to make request
return MMSUtils.sendMMSRequest(project, searchRequest, progressStatus);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,16 @@ public void projectOpened(Project project) {
return;
}
projectClosed(project);
// no need to poll mms when it'll just do the whole thing at commit
/*
getProjectMapping(project).setScheduledFuture(TaskRunner.scheduleWithProgressStatus(progressStatus -> {
try {
getProjectMapping(project).update();
} catch (URISyntaxException | IOException | ServerException | GeneralSecurityException e) {
e.printStackTrace();
}
}, "MMS Fetch", false, TaskRunner.ThreadExecutionStrategy.POOLED, false, (r, ses) -> ses.scheduleAtFixedRate(r, 0, 1, TimeUnit.MINUTES)));
}, "MMS Fetch", false, TaskRunner.ThreadExecutionStrategy.POOLED, false, (r, ses) -> ses.scheduleAtFixedRate(r, 0, 60, TimeUnit.MINUTES)));
*/
if (MDKProjectOptions.getMbeeEnabled(project)) {
MMSLoginAction.loginAction(project);
}
Expand Down Expand Up @@ -177,9 +180,8 @@ public synchronized boolean update() throws URISyntaxException, IOException, Ser
return false;
}
Deque<String> commitIdDeque = new ArrayDeque<>();
int exponent = 0;

obtainAndParseCommits(commitIdDeque, exponent, project);
obtainAndParseCommits(commitIdDeque, project);

if (commitIdDeque.isEmpty()) {
return true;
Expand All @@ -202,25 +204,20 @@ public synchronized boolean update() throws URISyntaxException, IOException, Ser
return true;
}

private void obtainAndParseCommits(Deque<String> commitIdDeque, int exponent, Project project)
private void obtainAndParseCommits(Deque<String> commitIdDeque, Project project)
throws URISyntaxException, IOException, ServerException, GeneralSecurityException {
int limit = 1;
int size = 0;

while(size < limit) { // setup so condition is true at least once, previously this was a do while loop
commitIdDeque.clear();
limit = (int) Math.pow(10, exponent++);

// look at commits until it gets to lastSyncedCommitId
commitIdDeque.clear();
HashMap<String, String> uriBuilderParams = new HashMap<>();
uriBuilderParams.put("limit", Integer.toString(limit));
//uriBuilderParams.put("limit", Integer.toString(limit));
HttpRequestBase commitsRequest = MMSUtils.prepareEndpointBuilderBasicGet(MMSCommitsEndpoint.builder(), project)
.addParam(MMSEndpointBuilderConstants.URI_PROJECT_SUFFIX, Converters.getIProjectToIdConverter().apply(project.getPrimaryProject()))
.addParam(MMSEndpointBuilderConstants.URI_REF_SUFFIX, MDUtils.getBranchId(project))
.addParam(MMSEndpointBuilderConstants.URI_BUILDER_PARAMETERS, uriBuilderParams).build();
File responseFile = MMSUtils.sendMMSRequest(project, commitsRequest);

Map<String, Set<ObjectNode>> parsedResponseObjects = JacksonUtils.parseResponseIntoObjects(responseFile, MDKConstants.COMMITS_NODE);
Set<ObjectNode> elementObjects = parsedResponseObjects.get(MDKConstants.COMMITS_NODE);
Map<String, List<ObjectNode>> parsedResponseObjects = JacksonUtils.parseResponseIntoObjects(responseFile, MDKConstants.COMMITS_NODE);
List<ObjectNode> elementObjects = parsedResponseObjects.get(MDKConstants.COMMITS_NODE);
if(elementObjects != null && !elementObjects.isEmpty()) {
for(ObjectNode jsonObject : elementObjects) {
JsonNode idValue = jsonObject.get(MDKConstants.ID_KEY);
Expand All @@ -234,21 +231,19 @@ private void obtainAndParseCommits(Deque<String> commitIdDeque, int exponent, Pr
}
commitIdDeque.addFirst(id);
}
size++;
}
}
}
}

private void determineChangesUsingCommitResponse(File responseFile, Set<String> lockedElementIds, String commitId) throws IOException {
// turns out the response still uses commits as the field of interest in terms of parsing
Map<String, Set<ObjectNode>> parsedResponseObjects = JacksonUtils.parseResponseIntoObjects(responseFile, MDKConstants.COMMITS_NODE);
Set<ObjectNode> commitObjects = parsedResponseObjects.get(MDKConstants.COMMITS_NODE);
Map<String, List<ObjectNode>> parsedResponseObjects = JacksonUtils.parseResponseIntoObjects(responseFile, MDKConstants.COMMITS_NODE);
List<ObjectNode> commitObjects = parsedResponseObjects.get(MDKConstants.COMMITS_NODE);

if(commitObjects != null && !commitObjects.isEmpty()) {
Map<String, Integer> commitSizes = new HashMap<>();
for(ObjectNode jsonObject : commitObjects) {
if(jsonObject.isArray() && jsonObject.size() > 0) {
if(jsonObject.isObject() && jsonObject.size() > 0) {
validateJsonElementArray(jsonObject, lockedElementIds, commitSizes);
}
if (MDUtils.isDeveloperMode()) {
Expand All @@ -265,8 +260,8 @@ private void determineChangesUsingCommitResponse(File responseFile, Set<String>
}
}

private void validateJsonElementArray(JsonNode arrayNode, Set<String> lockedElementIds, Map<String, Integer> sizes) {
JsonNode sourceField = arrayNode.get(MDKConstants.SOURCE_FIELD);
private void validateJsonElementArray(JsonNode objectNode, Set<String> lockedElementIds, Map<String, Integer> sizes) {
JsonNode sourceField = objectNode.get(MDKConstants.SOURCE_FIELD);
String commitSyncDirection = "";
int size = 0;
boolean isSyncingCommit = sourceField != null && sourceField.isTextual() && MDKConstants.MAGICDRAW_SOURCE_VALUE.equalsIgnoreCase(sourceField.asText());
Expand All @@ -279,7 +274,7 @@ private void validateJsonElementArray(JsonNode arrayNode, Set<String> lockedElem
size = sizes.get(commitSyncDirection);
}
for (Map.Entry<String, Changelog.ChangeType> entry : CHANGE_MAPPING.entrySet()) {
JsonNode changesJsonArray = arrayNode.get(entry.getKey());
JsonNode changesJsonArray = objectNode.get(entry.getKey());
if (changesJsonArray == null || !changesJsonArray.isArray()) {
throw new IllegalStateException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,10 @@ public void run(ProgressStatus progressStatus) {
private void processServerElements(Map<String, Pair<Element, ObjectNode>> clientElementMap, Map<String, ObjectNode> serverElementMap) throws IOException {
// process the parsers against the lists, adding processed keys to processed sets in case of multiple returns
for (File responseFile : serverElementFiles) {
Map<String, Set<ObjectNode>> parsedResponseObjects = JacksonUtils.parseResponseIntoObjects(responseFile, MDKConstants.ELEMENTS_NODE);
Set<ObjectNode> elementObjects = parsedResponseObjects.get(MDKConstants.ELEMENTS_NODE);
if(elementObjects != null && !elementObjects.isEmpty()) {
Map<String, List<ObjectNode>> parsedResponseObjects = JacksonUtils.parseResponseIntoObjects(responseFile, MDKConstants.ELEMENTS_NODE);
List<ObjectNode> elementObjectsList = parsedResponseObjects.get(MDKConstants.ELEMENTS_NODE);
if(elementObjectsList != null && !elementObjectsList.isEmpty()) {
Set<ObjectNode> elementObjects = new HashSet<>(elementObjectsList);
if(serverObjectsOnlyHasBins(elementObjects)) {
// solves edge case where first model validation incorrectly removes bins from project
removeServerObjectNodeUsingIdPrefix(elementObjects, MDKConstants.HOLDING_BIN_ID_PREFIX);
Expand Down

0 comments on commit 3828361

Please sign in to comment.