From d0018cacd7d81fccf73cb410135e6eab05e9b26c Mon Sep 17 00:00:00 2001 From: Doris Lam Date: Wed, 25 Jan 2023 09:59:17 -0800 Subject: [PATCH 1/3] ignore ownedRuleIds on views --- .../mbee/mdk/api/incubating/MDKConstants.java | 3 ++- .../gov/nasa/jpl/mbee/mdk/emf/EMFExporter.java | 11 +++++++++++ .../gov/nasa/jpl/mbee/mdk/emf/EMFImporter.java | 17 ++++++++++++++++- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/api/incubating/MDKConstants.java b/src/main/java/gov/nasa/jpl/mbee/mdk/api/incubating/MDKConstants.java index 08b7b25b8..854f9b144 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/api/incubating/MDKConstants.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/api/incubating/MDKConstants.java @@ -70,7 +70,8 @@ public class MDKConstants { SOURCE_FIELD = "source", DELETED_FIELD = "deleted", MAGICDRAW_SOURCE_VALUE = "magicdraw", - ELEMENT_TYPE_VALUE = "Element"; + ELEMENT_TYPE_VALUE = "Element", + OWNED_RULE_IDS = "ownedRuleIds"; @Deprecated public static final String diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/emf/EMFExporter.java b/src/main/java/gov/nasa/jpl/mbee/mdk/emf/EMFExporter.java index 6e484e038..115a6d697 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/emf/EMFExporter.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/emf/EMFExporter.java @@ -287,6 +287,17 @@ private enum Processor { }, Type.PRE ), + VIEW_POST( + (element, project, objectNode) -> { + Stereotype viewStereotype = Utils.getViewStereotype(project); + if (viewStereotype == null || !StereotypesHelper.hasStereotypeOrDerived(element, viewStereotype)) { + return objectNode; + } + objectNode.remove(MDKConstants.OWNED_RULE_IDS); + return objectNode; + }, + Type.POST + ), MOUNT_POST( (element, project, objectNode) -> { if (!objectNode.get(MDKConstants.TYPE_KEY).asText().equals("Mount")) { diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/emf/EMFImporter.java b/src/main/java/gov/nasa/jpl/mbee/mdk/emf/EMFImporter.java index 3720eb58f..e1afbd7a9 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/emf/EMFImporter.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/emf/EMFImporter.java @@ -8,6 +8,7 @@ import com.nomagic.magicdraw.openapi.uml.ModelElementsManager; import com.nomagic.magicdraw.openapi.uml.ReadOnlyElementException; import com.nomagic.uml2.ext.jmi.helpers.ModelHelper; +import com.nomagic.uml2.ext.jmi.helpers.StereotypesHelper; import com.nomagic.uml2.ext.jmi.reflect.AbstractRepository; import com.nomagic.uml2.ext.magicdraw.auxiliaryconstructs.mdmodels.Model; import com.nomagic.uml2.ext.magicdraw.auxiliaryconstructs.mdtemplates.ParameterableElement; @@ -24,6 +25,7 @@ import gov.nasa.jpl.mbee.mdk.json.ImportException; import gov.nasa.jpl.mbee.mdk.json.ReferenceException; import gov.nasa.jpl.mbee.mdk.util.Changelog; +import gov.nasa.jpl.mbee.mdk.util.Utils; import org.eclipse.emf.common.util.BasicEList; import org.eclipse.emf.common.util.UniqueEList; import org.eclipse.emf.ecore.*; @@ -84,7 +86,7 @@ private synchronized Changelog.Change convert(ObjectNode objectNode, Pr protected List getPreProcessors() { if (preProcessors == null) { - preProcessors = Arrays.asList(PreProcessor.CREATE, PreProcessor.EDITABLE, PreProcessor.DOCUMENTATION, PreProcessor.SYSML_ID_VALIDATION); + preProcessors = Arrays.asList(PreProcessor.CREATE, PreProcessor.EDITABLE, PreProcessor.DOCUMENTATION, PreProcessor.SYSML_ID_VALIDATION, PreProcessor.VIEW_OWNED_RULE_ID); } return preProcessors; } @@ -123,6 +125,19 @@ public static class PreProcessor { } return element; } + ), + VIEW_OWNED_RULE_ID = new PreProcessor( + (objectNode, project, strict, element) -> { + JsonNode jsonNode = objectNode.get(MDKConstants.OWNED_RULE_IDS); + if (jsonNode == null || !jsonNode.isArray()) { + return element; + } + // if element is a view, remove ownedRuleIds + if (StereotypesHelper.hasStereotypeOrDerived(element, Utils.getViewStereotype(project))) { + objectNode.remove(MDKConstants.OWNED_RULE_IDS); + } + return element; + } ); static PreProcessor getCreatePreProcessor(BiFunction idToElementConverter) { From ce1460ad1833288cf51513d0d2dc79d8157ae225 Mon Sep 17 00:00:00 2001 From: Doris Lam Date: Wed, 25 Jan 2023 12:26:01 -0800 Subject: [PATCH 2/3] set to empty array instead of removing it on export --- src/main/java/gov/nasa/jpl/mbee/mdk/emf/EMFExporter.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/gov/nasa/jpl/mbee/mdk/emf/EMFExporter.java b/src/main/java/gov/nasa/jpl/mbee/mdk/emf/EMFExporter.java index 115a6d697..c9801796d 100644 --- a/src/main/java/gov/nasa/jpl/mbee/mdk/emf/EMFExporter.java +++ b/src/main/java/gov/nasa/jpl/mbee/mdk/emf/EMFExporter.java @@ -290,10 +290,12 @@ private enum Processor { VIEW_POST( (element, project, objectNode) -> { Stereotype viewStereotype = Utils.getViewStereotype(project); - if (viewStereotype == null || !StereotypesHelper.hasStereotypeOrDerived(element, viewStereotype)) { + JsonNode node = objectNode.get(MDKConstants.OWNED_RULE_IDS); + if (viewStereotype == null || !StereotypesHelper.hasStereotypeOrDerived(element, viewStereotype) || + node == null || !node.isArray() || node.size() == 0) { return objectNode; } - objectNode.remove(MDKConstants.OWNED_RULE_IDS); + ((ArrayNode)node).removeAll(); return objectNode; }, Type.POST From 02fbbc44b50157ea2d6e75d62c03a259c75b9d59 Mon Sep 17 00:00:00 2001 From: dlamoris Date: Wed, 25 Jan 2023 12:40:48 -0800 Subject: [PATCH 3/3] update version --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index a66c834a5..7710ce00b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -version=5.1.2 +version=5.1.3 group=org.openmbee.mdk.magic descriptorFile=MDR_Plugin_Model_Development_Kit_91110_descriptor.xml magicdDrawGroupName=gov.nasa.jpl.cae.magicdraw.mdk