From d8f7cae245adc01978ca6d9499a8bc98d31186ca Mon Sep 17 00:00:00 2001 From: Enquier Date: Tue, 28 May 2024 10:35:29 -0600 Subject: [PATCH 1/6] add enriched svg capability back to MDK --- .../mdk/api/incubating/MDKConstants.java | 2 +- .../api/incubating/convert/Converters.java | 3 +- .../org/openmbee/mdk/docgen/DocGenUtils.java | 2 +- .../org/openmbee/mdk/emf/EMFExporter.java | 86 ++++------- .../org/openmbee/mdk/emf/EMFImporter.java | 2 +- .../java/org/openmbee/mdk/util/MDUtils.java | 133 +++++++++++++++--- 6 files changed, 147 insertions(+), 81 deletions(-) diff --git a/src/main/java/org/openmbee/mdk/api/incubating/MDKConstants.java b/src/main/java/org/openmbee/mdk/api/incubating/MDKConstants.java index 9e6d07081..178246626 100644 --- a/src/main/java/org/openmbee/mdk/api/incubating/MDKConstants.java +++ b/src/main/java/org/openmbee/mdk/api/incubating/MDKConstants.java @@ -51,7 +51,7 @@ public class MDKConstants { REF_CREATED_STATUS = "created", ORG_KEY = "org", ORG_ID_KEY = ORG_KEY + ID_KEY_SUFFIX, - TWC_ID_KEY = "twc" + ID_KEY_SUFFIX, + TWC_ID_KEY = DERIVED_KEY_PREFIX + "twc" + ID_KEY_SUFFIX, TWC_VERSION_KEY = "twcVersion", ARTIFACTS_KEY = "_artifacts", CHECKSUM_KEY = "checksum", diff --git a/src/main/java/org/openmbee/mdk/api/incubating/convert/Converters.java b/src/main/java/org/openmbee/mdk/api/incubating/convert/Converters.java index 981c55031..9ba8bc17b 100644 --- a/src/main/java/org/openmbee/mdk/api/incubating/convert/Converters.java +++ b/src/main/java/org/openmbee/mdk/api/incubating/convert/Converters.java @@ -9,6 +9,7 @@ import org.openmbee.mdk.api.incubating.MDKConstants; import org.openmbee.mdk.emf.EMFExporter; import org.openmbee.mdk.emf.EMFImporter; +import org.openmbee.mdk.util.MDUtils; import org.apache.commons.lang3.math.NumberUtils; import java.util.function.BiFunction; @@ -40,7 +41,7 @@ public static JsonToElementFunction getJsonToElementConverter() { public static Function getElementToIdConverter() { if (ELEMENT_TO_ID_CONVERTER == null) { - ELEMENT_TO_ID_CONVERTER = EMFExporter::getEID; + ELEMENT_TO_ID_CONVERTER = MDUtils::getEID; } return ELEMENT_TO_ID_CONVERTER; } diff --git a/src/main/java/org/openmbee/mdk/docgen/DocGenUtils.java b/src/main/java/org/openmbee/mdk/docgen/DocGenUtils.java index 68e810066..41002da0f 100644 --- a/src/main/java/org/openmbee/mdk/docgen/DocGenUtils.java +++ b/src/main/java/org/openmbee/mdk/docgen/DocGenUtils.java @@ -12,7 +12,7 @@ import org.openmbee.mdk.docgen.docbook.DocumentElement; import org.openmbee.mdk.docgen.view.ViewElement; import org.openmbee.mdk.util.MDUtils; -import org.apache.commons.lang3.StringEscapeUtils; +import org.apache.commons.text.StringEscapeUtils; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.select.Elements; diff --git a/src/main/java/org/openmbee/mdk/emf/EMFExporter.java b/src/main/java/org/openmbee/mdk/emf/EMFExporter.java index 1956f7558..0b59794eb 100644 --- a/src/main/java/org/openmbee/mdk/emf/EMFExporter.java +++ b/src/main/java/org/openmbee/mdk/emf/EMFExporter.java @@ -16,12 +16,14 @@ import com.nomagic.uml2.ext.magicdraw.compositestructures.mdinternalstructures.Connector; import com.nomagic.uml2.ext.magicdraw.mdprofiles.Stereotype; import com.nomagic.uml2.ext.magicdraw.metadata.UMLPackage; +import com.nomagic.magicdraw.hyperlinks.ElementHyperlink; import org.openmbee.mdk.SysMLExtensions; import org.openmbee.mdk.api.function.TriFunction; import org.openmbee.mdk.api.incubating.MDKConstants; import org.openmbee.mdk.api.incubating.convert.Converters; import org.openmbee.mdk.api.stream.MDKCollectors; import org.openmbee.mdk.json.JacksonUtils; +import org.openmbee.mdk.util.MDUtils; import org.openmbee.mdk.util.Utils; import org.eclipse.emf.ecore.EDataType; import org.eclipse.emf.ecore.EObject; @@ -36,7 +38,7 @@ import java.util.*; import java.util.function.BiFunction; import java.util.stream.Collectors; - +import java.io.Reader; public class EMFExporter implements BiFunction { @Override @@ -96,45 +98,14 @@ private static ObjectNode convert(Element element, Project project, boolean nest return objectNode; } + /* + * @deprecated + * As of MDK 6.1.1 this function has been moved to make it more widely available to other processes. This link is subject to remvoal in a future version. Please refactor accordingly + * @see org.openmbee.mdk.util.MDUtils#getEID() + */ + @Deprecated(since="6.1.1") public static String getEID(EObject eObject) { - if (eObject == null) { - return null; - } - if (!(eObject instanceof Element)) { - return EcoreUtil.getID(eObject); - } - Element element = (Element) eObject; - Project project = Project.getProject(element); - - // custom handling of primary model id - if (element instanceof Model && element == project.getPrimaryModel()) { - return Converters.getIProjectToIdConverter().apply(project.getPrimaryProject()) + MDKConstants.PRIMARY_MODEL_ID_SUFFIX; - } - - // local projects don't properly maintain the ids of some elements. this id spoofing mitigates that for us, but can mess up the MMS delta counts in some cases (annoying, but ultimately harmless) - // NOTE - this spoofing is replicated in LocalSyncTransactionListener in order to properly add / remove elements in the unsynched queue. any updates here should be replicated there as well. - // there's no more instance spec that's a result of stereotyping, so instance spec should just have their normal id - /*if (eObject instanceof TimeExpression && ((TimeExpression) eObject).get_timeEventOfWhen() != null) { - return getEID(((TimeExpression) eObject).get_timeEventOfWhen()) + MDKConstants.TIME_EXPRESSION_ID_SUFFIX; - }*/ - if (element instanceof ValueSpecification && ((ValueSpecification) element).getOwningSlot() != null) { - ValueSpecification slotValue = (ValueSpecification) element; - return getEID(slotValue.getOwningSlot()) + MDKConstants.SLOT_VALUE_ID_SEPARATOR + slotValue.getOwningSlot().getValue().indexOf(slotValue) + "-" + slotValue.eClass().getName().toLowerCase(); - } - if (element instanceof TaggedValue) { - TaggedValue slot = (TaggedValue) element; - if (slot.getTaggedValueOwner() != null && slot.getTagDefinition() != null) { - // add _asi to owner in constructed id to maintain continuity with 19.x slots - return getEID(slot.getOwner()) + MDKConstants.APPLIED_STEREOTYPE_INSTANCE_ID_SUFFIX + MDKConstants.SLOT_ID_SEPARATOR + getEID(slot.getTagDefinition()); - } - } - if (element instanceof Slot) { - Slot slot = (Slot) element; - if (slot.getOwningInstance() != null && ((Slot) element).getDefiningFeature() != null) { - return getEID(slot.getOwningInstance()) + MDKConstants.SLOT_ID_SEPARATOR + getEID(slot.getDefiningFeature()); - } - } - return element.getLocalID(); + return MDUtils.getEID(eObject); } private static void dumpUMLPackageLiterals() { @@ -158,7 +129,7 @@ private static void dumpUMLPackageLiterals() { private enum Processor { /*APPLIED_STEREOTYPE( (element, project, objectNode) -> { - ArrayNode applied = StereotypesHelper.getStereotypes(element).stream().map(stereotype -> TextNode.valueOf(getEID(stereotype))).collect(MDKCollectors.toArrayNode()); + ArrayNode applied = StereotypesHelper.getStereotypes(element).stream().map(stereotype -> TextNode.valueOf(MDUtils.getEID(stereotype))).collect(MDKCollectors.toArrayNode()); objectNode.set(MDKConstants.APPLIED_STEREOTYPE_IDS_KEY, applied); return objectNode; }, @@ -189,6 +160,10 @@ private enum Processor { ), DOCUMENTATION_PRE( (element, project, objectNode) -> { + //Todo: FIgure out how to read this stuff and parse the { - if (project.isRemote()) { - objectNode.put(MDKConstants.TWC_ID_KEY, element.getID()); - } - return objectNode; - } - ), - */ + //TWC_ID is disabled indefinitely, due to our inability to update the ID and associated issues + // TWC_ID( + // (element, project, objectNode) -> { + // if (project.isRemote() && element.getID() != element.getLocalID()) { + // objectNode.put(MDKConstants.TWC_ID_KEY, element.getID()); + // } + // return objectNode; + // }, + // Type.PRE + // ), TYPE( (element, project, objectNode) -> { if (!objectNode.has(MDKConstants.TYPE_KEY)) { @@ -328,7 +302,7 @@ private enum Processor { if (docEl != null) { ArrayNode ownedCommentIds = ((ArrayNode) objectNode.get(MDKConstants.OWNED_COMMENT_IDS_KEY)); for (int i = 0; i < ownedCommentIds.size(); i++) { - if (ownedCommentIds.get(i).asText().equals(getEID(docEl))) + if (ownedCommentIds.get(i).asText().equals(MDUtils.getEID(docEl))) ownedCommentIds.remove(i); } if (ownedCommentIds.size() == 0) { @@ -390,7 +364,7 @@ else if (o instanceof BigDecimal) { } n.set("value", node); if (o instanceof Element) { - node = TextNode.valueOf(getEID((Element)o)); + node = TextNode.valueOf(MDUtils.getEID((Element)o)); n.set("elementId", node); n.remove("value"); } @@ -449,7 +423,7 @@ else if (object instanceof ValueSpecification) { //return fillValueSpecification((ValueSpecification) object); } else if (eStructuralFeature instanceof EReference && object instanceof EObject) { - return EMFExporter.DEFAULT_SERIALIZATION_FUNCTION.apply(getEID(((EObject) object)), project, eStructuralFeature); + return EMFExporter.DEFAULT_SERIALIZATION_FUNCTION.apply(MDUtils.getEID(((EObject) object)), project, eStructuralFeature); } else if (object instanceof String) { return TextNode.valueOf((String) object); @@ -522,7 +496,7 @@ private enum EStructuralFeatureOverride { /*if (element instanceof ValueSpecification && !(element instanceof TimeExpression)) { return objectNode; }*/ - objectNode.put(MDKConstants.ID_KEY, getEID(element)); + objectNode.put(MDKConstants.ID_KEY, MDUtils.getEID(element)); return objectNode; } ), @@ -535,7 +509,7 @@ private enum EStructuralFeatureOverride { }*/ //UNCHECKED_E_STRUCTURAL_FEATURE_FUNCTION.apply(element, project, UMLPackage.Literals.ELEMENT__OWNER, objectNode); // safest way to prevent circular references, like with ValueSpecifications - objectNode.put(MDKConstants.OWNER_ID_KEY, element instanceof Model && project.getModels().stream().anyMatch(model -> element == model) ? Converters.getIProjectToIdConverter().apply(project.getPrimaryProject()) : getEID(owner)); + objectNode.put(MDKConstants.OWNER_ID_KEY, element instanceof Model && project.getModels().stream().anyMatch(model -> element == model) ? Converters.getIProjectToIdConverter().apply(project.getPrimaryProject()) : MDUtils.getEID(owner)); return objectNode; } ), diff --git a/src/main/java/org/openmbee/mdk/emf/EMFImporter.java b/src/main/java/org/openmbee/mdk/emf/EMFImporter.java index 8e3abeb5f..dda18e111 100644 --- a/src/main/java/org/openmbee/mdk/emf/EMFImporter.java +++ b/src/main/java/org/openmbee/mdk/emf/EMFImporter.java @@ -108,7 +108,7 @@ public static class PreProcessor { 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.get(MDKConstants.OWNED_COMMENT_IDS_KEY).size() == 0) { objectNode.remove(MDKConstants.OWNED_COMMENT_IDS_KEY); } } diff --git a/src/main/java/org/openmbee/mdk/util/MDUtils.java b/src/main/java/org/openmbee/mdk/util/MDUtils.java index f815d2e08..896561f10 100644 --- a/src/main/java/org/openmbee/mdk/util/MDUtils.java +++ b/src/main/java/org/openmbee/mdk/util/MDUtils.java @@ -1,21 +1,37 @@ package org.openmbee.mdk.util; +import com.nomagic.log.LoggerBridge; import com.nomagic.magicdraw.core.Application; import com.nomagic.magicdraw.core.Project; import com.nomagic.magicdraw.core.ProjectUtilities; import com.nomagic.magicdraw.esi.EsiUtils; +import com.nomagic.magicdraw.export.image.EnrichedSVGExporter; import com.nomagic.magicdraw.export.image.ImageExporter; import com.nomagic.magicdraw.ui.browser.BrowserTabTree; import com.nomagic.magicdraw.ui.browser.Node; import com.nomagic.magicdraw.uml.BaseElement; +import com.nomagic.magicdraw.uml.symbols.AbstractDiagramPresentationElement; +import com.nomagic.magicdraw.uml.symbols.DiagramPaintContext; import com.nomagic.magicdraw.uml.symbols.DiagramPresentationElement; import com.nomagic.magicdraw.uml.symbols.PresentationElement; +import com.nomagic.uml2.ext.magicdraw.auxiliaryconstructs.mdmodels.Model; import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Element; +import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Slot; +import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.TaggedValue; +import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.ValueSpecification; +import com.nomagic.utils.CameoUtilities; +import com.nomagic.utils.FileHelper; + +import org.openmbee.mdk.api.incubating.MDKConstants; +import org.openmbee.mdk.api.incubating.convert.Converters; import org.openmbee.mdk.docgen.DocGenUtils; import org.apache.batik.anim.dom.SAXSVGDocumentFactory; import org.apache.batik.util.XMLResourceDescriptor; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.util.EcoreUtil; import org.w3c.dom.Document; +import javax.annotation.CheckForNull; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; @@ -23,7 +39,11 @@ import javax.xml.transform.stream.StreamResult; import java.awt.event.ActionEvent; import java.io.*; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import static com.nomagic.magicdraw.uml.DiagramTypeConstants.*; @@ -196,32 +216,22 @@ public static long getRemoteVersion(Project project) { public static void exportSVG(File svgFile, DiagramPresentationElement diagramPresentationElement) throws IOException, TransformerException { String originalSvgEnrichedExportPropertyValue = System.getProperty(SVG_ENRICHED_EXPORT_PROPERTY_NAME); - try { - boolean svgEnrichedExportPropertyValue = originalSvgEnrichedExportPropertyValue != null - && Boolean.getBoolean(originalSvgEnrichedExportPropertyValue) - && !diagramPresentationElement.getDiagramType().getRootType().equals(DEPENDENCY_MATRIX); + // boolean svgEnrichedExportPropertyValue = originalSvgEnrichedExportPropertyValue != null + // && Boolean.getBoolean(originalSvgEnrichedExportPropertyValue) + // && !diagramPresentationElement.getDiagramType().getRootType().equals(DEPENDENCY_MATRIX); + boolean svgEnrichedExportPropertyValue = true; System.setProperty(SVG_ENRICHED_EXPORT_PROPERTY_NAME, Boolean.toString(svgEnrichedExportPropertyValue)); ImageExporter.export(diagramPresentationElement, ImageExporter.SVG, svgFile, false, DocGenUtils.DOCGEN_DIAGRAM_DPI, DocGenUtils.DOCGEN_DIAGRAM_SCALE_PERCENT); + StringBuilder svgString = new StringBuilder(readFileToString(svgFile, StandardCharsets.UTF_8)); + if (isEnriched(svgString)) { - if (svgEnrichedExportPropertyValue) { - try (InputStream svgInputStream = new FileInputStream(svgFile); Writer svgWriter = new FileWriter(svgFile)) { - String parser = XMLResourceDescriptor.getXMLParserClassName(); - SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser); - Document svg = f.createDocument(null, svgInputStream); - XMLUtil.asList(svg.getElementsByTagName("g")).stream() - .filter(g -> g instanceof org.w3c.dom.Element) - .map(g -> (org.w3c.dom.Element) g) - .filter(g -> Objects.equals(g.getAttribute("class"), "element")) - .forEach(g -> g.setAttribute("stroke-width", "0px")); - DOMSource source = new DOMSource(svg); - StreamResult result = new StreamResult(svgWriter); - - TransformerFactory transformerFactory = TransformerFactory.newInstance(); - Transformer transformer = transformerFactory.newTransformer(); - transformer.transform(source, result); - } + Pattern p = Pattern.compile("id=\"([a-z0-9\\-]+)\""); + Matcher m = p.matcher(svgString); + m.replaceAll(match -> getEID(Converters.getIdToElementConverter().apply(match.group(1), diagramPresentationElement.getProject()))); + appendStyle(svgString); + EnrichedSVGExporter.rewriteFile(svgFile, svgString, StandardCharsets.UTF_8); } } finally { if (originalSvgEnrichedExportPropertyValue != null) { @@ -233,4 +243,85 @@ public static void exportSVG(File svgFile, DiagramPresentationElement diagramPre } } + public static String readFileToString(File file, @CheckForNull Charset charset) { + ByteArrayOutputStream st = new ByteArrayOutputStream(); + + try { + copy(new FileInputStream(file), st); + } catch (IOException e) { + Application.getInstance().getGUILog().log("[ERROR] " + e.getMessage()); + e.printStackTrace(); + } + + return charset != null ? st.toString(charset) : st.toString(); + } + + private static void copy(InputStream input, OutputStream output) throws IOException { + byte[] buffer = new byte[512]; + int count = 0; + + while(count != -1) { + count = input.read(buffer); + if (count > 0) { + output.write(buffer, 0, count); + } + } + + input.close(); + output.close(); + } + + private static void appendStyle(StringBuilder svgString) { + int var1 = svgString.indexOf(""); + return styleComment > 0; + } + + public static String getEID(EObject eObject) { + if (eObject == null) { + return null; + } + if (!(eObject instanceof Element)) { + return EcoreUtil.getID(eObject); + } + Element element = (Element) eObject; + Project project = Project.getProject(element); + + // custom handling of primary model id + if (element instanceof Model && element == project.getPrimaryModel()) { + return Converters.getIProjectToIdConverter().apply(project.getPrimaryProject()) + MDKConstants.PRIMARY_MODEL_ID_SUFFIX; + } + + // local projects don't properly maintain the ids of some elements. this id spoofing mitigates that for us, but can mess up the MMS delta counts in some cases (annoying, but ultimately harmless) + // NOTE - this spoofing is replicated in LocalSyncTransactionListener in order to properly add / remove elements in the unsynched queue. any updates here should be replicated there as well. + // there's no more instance spec that's a result of stereotyping, so instance spec should just have their normal id + /*if (eObject instanceof TimeExpression && ((TimeExpression) eObject).get_timeEventOfWhen() != null) { + return getEID(((TimeExpression) eObject).get_timeEventOfWhen()) + MDKConstants.TIME_EXPRESSION_ID_SUFFIX; + }*/ + if (element instanceof ValueSpecification && ((ValueSpecification) element).getOwningSlot() != null) { + ValueSpecification slotValue = (ValueSpecification) element; + return getEID(slotValue.getOwningSlot()) + MDKConstants.SLOT_VALUE_ID_SEPARATOR + slotValue.getOwningSlot().getValue().indexOf(slotValue) + "-" + slotValue.eClass().getName().toLowerCase(); + } + if (element instanceof TaggedValue) { + TaggedValue slot = (TaggedValue) element; + if (slot.getTaggedValueOwner() != null && slot.getTagDefinition() != null) { + // add _asi to owner in constructed id to maintain continuity with 19.x slots + return getEID(slot.getOwner()) + MDKConstants.APPLIED_STEREOTYPE_INSTANCE_ID_SUFFIX + MDKConstants.SLOT_ID_SEPARATOR + getEID(slot.getTagDefinition()); + } + } + if (element instanceof Slot) { + Slot slot = (Slot) element; + if (slot.getOwningInstance() != null && ((Slot) element).getDefiningFeature() != null) { + return getEID(slot.getOwningInstance()) + MDKConstants.SLOT_ID_SEPARATOR + getEID(slot.getDefiningFeature()); + } + } + return element.getLocalID(); + } } From 60ca27dacbf6847146fcabc8b788bce4f5127a98 Mon Sep 17 00:00:00 2001 From: Enquier Date: Tue, 28 May 2024 10:35:29 -0600 Subject: [PATCH 2/6] replace twcId inside svg --- .../java/org/openmbee/mdk/util/MDUtils.java | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/openmbee/mdk/util/MDUtils.java b/src/main/java/org/openmbee/mdk/util/MDUtils.java index 896561f10..7c61a2542 100644 --- a/src/main/java/org/openmbee/mdk/util/MDUtils.java +++ b/src/main/java/org/openmbee/mdk/util/MDUtils.java @@ -224,14 +224,18 @@ public static void exportSVG(File svgFile, DiagramPresentationElement diagramPre System.setProperty(SVG_ENRICHED_EXPORT_PROPERTY_NAME, Boolean.toString(svgEnrichedExportPropertyValue)); ImageExporter.export(diagramPresentationElement, ImageExporter.SVG, svgFile, false, DocGenUtils.DOCGEN_DIAGRAM_DPI, DocGenUtils.DOCGEN_DIAGRAM_SCALE_PERCENT); - StringBuilder svgString = new StringBuilder(readFileToString(svgFile, StandardCharsets.UTF_8)); + String svgString = readFileToString(svgFile, StandardCharsets.UTF_8); if (isEnriched(svgString)) { - - Pattern p = Pattern.compile("id=\"([a-z0-9\\-]+)\""); + Project project = diagramPresentationElement.getProject(); + Pattern p = Pattern.compile("id=\"([a-z0-9-]+)\""); Matcher m = p.matcher(svgString); - m.replaceAll(match -> getEID(Converters.getIdToElementConverter().apply(match.group(1), diagramPresentationElement.getProject()))); - appendStyle(svgString); - EnrichedSVGExporter.rewriteFile(svgFile, svgString, StandardCharsets.UTF_8); + svgString = m.replaceAll(match -> { + String replace = "id=\"" + fixId(match.group(1), project) + "\""; + return replace; + }); + StringBuilder sb = new StringBuilder(svgString); + appendStyle(sb); + EnrichedSVGExporter.rewriteFile(svgFile, sb, StandardCharsets.UTF_8); } } finally { if (originalSvgEnrichedExportPropertyValue != null) { @@ -243,6 +247,16 @@ public static void exportSVG(File svgFile, DiagramPresentationElement diagramPre } } + private static String fixId (String id, Project project) { + try { + UUID.fromString(id); + id = getEID(Converters.getIdToElementConverter().apply(id, project)); + } catch(IllegalArgumentException e) { + //Do Nothing + } + return id; + } + public static String readFileToString(File file, @CheckForNull Charset charset) { ByteArrayOutputStream st = new ByteArrayOutputStream(); @@ -279,7 +293,7 @@ private static void appendStyle(StringBuilder svgString) { } - public static boolean isEnriched(StringBuilder svgString) { + public static boolean isEnriched(String svgString) { int styleComment = svgString.indexOf(""); return styleComment > 0; } From 90a24201f11087be1f330382cc0a949757f76550 Mon Sep 17 00:00:00 2001 From: Enquier Date: Tue, 28 May 2024 10:35:29 -0600 Subject: [PATCH 3/6] minor tweaks for 2021x compatibility --- build.gradle | 1 + src/main/java/org/openmbee/mdk/util/MDUtils.java | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index f51e7ca67..687838d03 100644 --- a/build.gradle +++ b/build.gradle @@ -179,6 +179,7 @@ dependencies { // Apache Commons-IO implementation group: 'org.apache.commons', name: 'commons-io', version: '1.3.2' + implementation group: 'org.apache.commons', name: 'commons-text', version: '1.1' //implementation group: 'commons-io', name: 'commons-io', version: '2.4' // Apache HTTP diff --git a/src/main/java/org/openmbee/mdk/util/MDUtils.java b/src/main/java/org/openmbee/mdk/util/MDUtils.java index 7c61a2542..eaa6fcd75 100644 --- a/src/main/java/org/openmbee/mdk/util/MDUtils.java +++ b/src/main/java/org/openmbee/mdk/util/MDUtils.java @@ -10,7 +10,6 @@ import com.nomagic.magicdraw.ui.browser.BrowserTabTree; import com.nomagic.magicdraw.ui.browser.Node; import com.nomagic.magicdraw.uml.BaseElement; -import com.nomagic.magicdraw.uml.symbols.AbstractDiagramPresentationElement; import com.nomagic.magicdraw.uml.symbols.DiagramPaintContext; import com.nomagic.magicdraw.uml.symbols.DiagramPresentationElement; import com.nomagic.magicdraw.uml.symbols.PresentationElement; From 9f8b5cdc31aae16d8da899f76c43f9283b1cb115 Mon Sep 17 00:00:00 2001 From: Enquier Date: Tue, 28 May 2024 10:35:29 -0600 Subject: [PATCH 4/6] continue to improve runner documentation and performance --- build.gradle | 4 ++ gradle.properties | 2 +- .../org/openmbee/mdk/emf/EMFExporter.java | 13 +++- .../mms/actions/ValidateBranchesAction.java | 4 +- .../mdk/mms/sync/delta/DeltaSyncRunner.java | 70 ++++++++++++------- .../mdk/mms/sync/manual/ManualSyncRunner.java | 7 +- .../mdk/mms/validation/BranchValidator.java | 16 +++-- .../mdk/mms/validation/ProjectValidator.java | 24 +++++-- .../java/org/openmbee/mdk/util/MDUtils.java | 13 ---- 9 files changed, 93 insertions(+), 60 deletions(-) diff --git a/build.gradle b/build.gradle index 687838d03..48791cac8 100644 --- a/build.gradle +++ b/build.gradle @@ -191,6 +191,10 @@ dependencies { implementation group: 'com.beust', name: 'jcommander', version: '1.72' + // jsoup HTML parser library @ https://jsoup.org/ + implementation group: 'org.jsoup', name: 'jsoup', version: '1.17.2' + + // Test Dependencies //testImplementation 'junit:junit:4.11' testImplementation group: 'org.gradle', name: 'gradle-core', version: '6.1.1' diff --git a/gradle.properties b/gradle.properties index 8ab140a8d..11290532f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -version=6.1.0 +version=6.1.1 group=org.openmbee.mdk.magic descriptorFile=MDR_Plugin_Model_Development_Kit_91110_descriptor.xml magicdDrawGroupName=org.openmbee.mdk diff --git a/src/main/java/org/openmbee/mdk/emf/EMFExporter.java b/src/main/java/org/openmbee/mdk/emf/EMFExporter.java index 0b59794eb..95fa73359 100644 --- a/src/main/java/org/openmbee/mdk/emf/EMFExporter.java +++ b/src/main/java/org/openmbee/mdk/emf/EMFExporter.java @@ -25,11 +25,15 @@ import org.openmbee.mdk.json.JacksonUtils; import org.openmbee.mdk.util.MDUtils; import org.openmbee.mdk.util.Utils; +import org.w3c.dom.html.HTMLDocument; import org.eclipse.emf.ecore.EDataType; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EReference; import org.eclipse.emf.ecore.EStructuralFeature; import org.eclipse.emf.ecore.util.EcoreUtil; +import org.jsoup.Jsoup; +import org.jsoup.nodes.Document; +import org.jsoup.select.Elements; import java.lang.reflect.Field; import java.lang.reflect.Modifier; @@ -39,6 +43,7 @@ import java.util.function.BiFunction; import java.util.stream.Collectors; import java.io.Reader; +import java.io.StringReader; public class EMFExporter implements BiFunction { @Override @@ -161,7 +166,13 @@ private enum Processor { DOCUMENTATION_PRE( (element, project, objectNode) -> { //Todo: FIgure out how to read this stuff and parse the persistedLocalChangelog = new Changelog<>(); Collection persistedLocalSyncElements = SyncElements.getAllByType(project, SyncElement.Type.LOCAL); for (SyncElement syncElement : persistedLocalSyncElements) { @@ -154,8 +168,10 @@ else if (value instanceof Element) { localUpdated = localChangelog.get(Changelog.ChangeType.UPDATED), localDeleted = localChangelog.get(Changelog.ChangeType.DELETED); + progressStatus.increase(); // BUILD COMPLETE MMS CHANGELOG - + progressStatus.setDescription("Coordinated Sync: Building Server Changelog"); + progressStatus.cancelIfCanceled(); Changelog persistedMmsChangelog = new Changelog<>(); Collection persistedMmsSyncElements = SyncElements.getAllByType(project, SyncElement.Type.MMS); for (SyncElement syncElement : persistedMmsSyncElements) { @@ -177,9 +193,9 @@ else if (value instanceof Element) { Map mmsJsons = new HashMap<>(elementIdsToGet.size()); // Get latest json for element added/changed from MMS - + progressStatus.increase(); if (!elementIdsToGet.isEmpty()) { - progressStatus.setDescription("Getting " + elementIdsToGet.size() + " added/changed element" + (elementIdsToGet.size() != 1 ? "s" : "") + " from MMS"); + progressStatus.setDescription("Coordinated Sync: Getting " + elementIdsToGet.size() + " added/changed element" + (elementIdsToGet.size() != 1 ? "s" : "") + " from MMS"); File responseFile; ObjectNode response; try { @@ -220,8 +236,8 @@ else if (value instanceof Element) { } // NEW CONFLICT DETECTION - - progressStatus.setDescription("Detecting conflicts"); + progressStatus.increase(); + progressStatus.setDescription("Coordinated Sync: Detecting conflicts"); Map, Changelog.Change>> conflictedChanges = new LinkedHashMap<>(), unconflictedChanges = new LinkedHashMap<>(); localChangelog.findConflicts(mmsChangelog, (change, change2) -> change != null && change2 != null, conflictedChanges, unconflictedChanges); @@ -305,13 +321,13 @@ else if (shouldUpdate && mmsChange != null) { } // POINT OF NO RETURN - + progressStatus.increase(); // COMMIT UNCONFLICTED CREATIONS AND UPDATES TO MMS String projectId = Converters.getIProjectToIdConverter().apply(project.getPrimaryProject()); String refId = MDUtils.getBranchId(project); boolean shouldLogNoLocalChanges = shouldCommit; if (shouldCommit && !localElementsToPost.isEmpty()) { - progressStatus.setDescription("Committing creations and updates to MMS"); + progressStatus.setDescription("Coordinated Sync: Committing creations and updates to MMS"); LinkedList postElements = new LinkedList<>(); for (Element element : localElementsToPost.values()) { ObjectNode elementObjectNode = Converters.getElementToJsonConverter().apply(element, project); @@ -345,12 +361,12 @@ else if (shouldUpdate && mmsChange != null) { shouldLogNoLocalChanges = false; } } - + progressStatus.increase(); // COMMIT UNCONFLICTED DELETIONS TO MMS // NEEDS TO BE AFTER LOCAL; EX: MOVE ELEMENT OUT ON MMS, DELETE OWNER LOCALLY, WHAT HAPPENS? if (shouldCommit && shouldCommitDeletes && !deleteElements.isEmpty()) { - progressStatus.setDescription("Committing deletions to MMS"); + progressStatus.setDescription("Coordinated Sync: Committing deletions to MMS"); try { File file = MMSUtils.createEntityFile(this.getClass(), ContentType.APPLICATION_JSON, deleteElements, MMSUtils.JsonBlobType.ELEMENT_ID); HttpRequestBase elementsDeleteRequest = MMSUtils.prepareEndpointBuilderBasicJsonDeleteRequest(MMSElementsEndpoint.builder(), project, file) @@ -373,7 +389,7 @@ else if (shouldUpdate && mmsChange != null) { } // OUTPUT RESULT OF LOCAL CHANGES - + progressStatus.increase(); if (shouldLogNoLocalChanges) { Application.getInstance().getGUILog().log("[INFO] No local changes to commit to MMS."); } @@ -381,7 +397,7 @@ else if (shouldUpdate && mmsChange != null) { // ADD CREATED ELEMENTS LOCALLY FROM MMS // CHANGE UPDATED ELEMENTS LOCALLY FROM MMS // REMOVE DELETED ELEMENTS LOCALLY FROM MMS - + progressStatus.increase(); if (shouldUpdate) { listener.setDisabled(true); @@ -401,8 +417,8 @@ else if (shouldUpdate && mmsChange != null) { } // HANDLE CONFLICTS - - progressStatus.setDescription("Finishing up"); + progressStatus.increase(); + progressStatus.setDescription("Coordinated Sync: Finishing up"); Set localConflictedElements = new HashSet<>(); Set mmsConflictedElements = new HashSet<>(); @@ -422,7 +438,7 @@ else if (shouldUpdate && mmsChange != null) { } ElementValidator elementValidator = new ElementValidator("CSync Conflict Validation", ElementValidator.buildElementPairs(localConflictedElements, project), mmsConflictedElements, project); - elementValidator.run(progressStatus); + ProgressStatusRunner.runWithProgressStatus(elementValidator, "Element Validation", true, 0); if (!elementValidator.getInvalidElements().isEmpty()) { Application.getInstance().getGUILog().log("[INFO] There are potential conflicts in " + elementValidator.getInvalidElements().size() + " element" + (elementValidator.getInvalidElements().size() != 1 ? "s" : "") + " between MMS and local changes. Please resolve them and re-sync."); vss.add(elementValidator.getValidationSuite()); @@ -447,7 +463,7 @@ else if (shouldUpdate && mmsChange != null) { } // CLEAR IN-MEMORY AND PERSIST UNPROCESSED & FAILURES - + progressStatus.increase(); listener.setDisabled(true); Project project = Application.getInstance().getProject(); if (!SessionManager.getInstance().isSessionCreated(project)) { @@ -502,7 +518,7 @@ else if (shouldUpdate && mmsChange != null) { SessionManager.getInstance().closeSession(project); listener.setDisabled(false); - + progressStatus.increase(); // SUCCESS failure = false; } diff --git a/src/main/java/org/openmbee/mdk/mms/sync/manual/ManualSyncRunner.java b/src/main/java/org/openmbee/mdk/mms/sync/manual/ManualSyncRunner.java index 3dd32ebce..66132186d 100644 --- a/src/main/java/org/openmbee/mdk/mms/sync/manual/ManualSyncRunner.java +++ b/src/main/java/org/openmbee/mdk/mms/sync/manual/ManualSyncRunner.java @@ -53,7 +53,8 @@ public void run(ProgressStatus progressStatus) { progressStatus.setIndeterminate(true); ProjectValidator pv = new ProjectValidator(project); - pv.validate(); + + pv.run(progressStatus); if (pv.hasErrors()) { Application.getInstance().getGUILog().log("[ERROR] Project validation could not be completed. Manual validation aborted."); return; @@ -64,8 +65,8 @@ public void run(ProgressStatus progressStatus) { } if (project.isRemote()) { - BranchValidator bv = new BranchValidator(project); - bv.validate(null, false); + BranchValidator bv = new BranchValidator(project, false); + bv.run(null); if (bv.hasErrors()) { Application.getInstance().getGUILog().log("[ERROR] Branch validation could not be completed. Manual validation aborted."); return; diff --git a/src/main/java/org/openmbee/mdk/mms/validation/BranchValidator.java b/src/main/java/org/openmbee/mdk/mms/validation/BranchValidator.java index e59d84562..172625fcd 100644 --- a/src/main/java/org/openmbee/mdk/mms/validation/BranchValidator.java +++ b/src/main/java/org/openmbee/mdk/mms/validation/BranchValidator.java @@ -13,6 +13,8 @@ import com.nomagic.magicdraw.core.project.ProjectDescriptorsFactory; import com.nomagic.magicdraw.esi.EsiUtils; import com.nomagic.task.ProgressStatus; +import com.nomagic.task.RunnableWithProgress; + import org.openmbee.mdk.actions.ClipboardAction; import org.openmbee.mdk.api.incubating.MDKConstants; import org.openmbee.mdk.api.incubating.convert.Converters; @@ -39,9 +41,10 @@ import java.text.NumberFormat; import java.util.*; -public class BranchValidator { +public class BranchValidator implements RunnableWithProgress { private final Project project; + private boolean allBranches; private boolean errors; private ValidationSuite validationSuite = new ValidationSuite("structure"); // private ValidationRule twcMissingBranchValidationRule = new ValidationRule("Missing in Client", "Branch shall exist in TWC if it exists in MMS.", ViolationSeverity.WARNING); @@ -49,15 +52,16 @@ public class BranchValidator { private ValidationRule branchEquivalenceValidationRule = new ValidationRule("Branch Equivalence", "Branch shall be represented in MagicDraw and MMS equivalently.", ViolationSeverity.ERROR); private ValidationRule mmsBuildingBranchValidationRule = new ValidationRule("Building on Server", "Branch shall be completely built on MMS before it is used.", ViolationSeverity.WARNING); - public BranchValidator(Project project) { + public BranchValidator(Project project, boolean allBranches) { this.project = project; + this.allBranches = allBranches; // validationSuite.addValidationRule(twcMissingBranchValidationRule); validationSuite.addValidationRule(mmsMissingBranchValidationRule); validationSuite.addValidationRule(branchEquivalenceValidationRule); validationSuite.addValidationRule(mmsBuildingBranchValidationRule); } - public void validate(ProgressStatus progressStatus, boolean allBranches) { + public void run(ProgressStatus progressStatus) { if (project == null) { return; } @@ -82,7 +86,7 @@ public void validate(ProgressStatus progressStatus, boolean allBranches) { } Collection targetBranches = null; - if (allBranches) { + if (this.allBranches) { try { ProjectDescriptor projectDescriptor = ProjectDescriptorsFactory.createAnyRemoteProjectDescriptor(project); targetBranches = EsiUtils.getBranches(projectDescriptor); @@ -107,7 +111,7 @@ public void validate(ProgressStatus progressStatus, boolean allBranches) { String entryKey; if ((value = branchJson.get(MDKConstants.ID_KEY)) != null && value.isTextual()) { entryKey = value.asText(); - if (allBranches || entryKey.equals(currentBranch)) { + if (this.allBranches || entryKey.equals(currentBranch)) { clientBranches.put(entryKey, new Pair<>(branch, branchJson)); } } @@ -135,7 +139,7 @@ public void validate(ProgressStatus progressStatus, boolean allBranches) { String entryKey; if ((value = refObjectNode.get(MDKConstants.ID_KEY)) != null && value.isTextual()) { entryKey = value.asText(); - if (allBranches || entryKey.equals(currentBranch)) { + if (this.allBranches || entryKey.equals(currentBranch)) { serverBranches.put(entryKey, refObjectNode); } } diff --git a/src/main/java/org/openmbee/mdk/mms/validation/ProjectValidator.java b/src/main/java/org/openmbee/mdk/mms/validation/ProjectValidator.java index 951059a1b..979522b77 100644 --- a/src/main/java/org/openmbee/mdk/mms/validation/ProjectValidator.java +++ b/src/main/java/org/openmbee/mdk/mms/validation/ProjectValidator.java @@ -9,7 +9,8 @@ import com.nomagic.magicdraw.core.ProjectUtilities; import com.nomagic.magicdraw.esi.EsiUtils; import com.nomagic.magicdraw.esi.EsiUtils.EsiBranchInfo; - +import com.nomagic.task.ProgressStatus; +import com.nomagic.task.RunnableWithProgress; import com.nomagic.magicdraw.teamwork2.ITeamworkService; import com.nomagic.magicdraw.teamwork2.TeamworkService; import org.openmbee.mdk.api.incubating.MDKConstants; @@ -25,7 +26,8 @@ import org.openmbee.mdk.validation.ViolationSeverity; import org.apache.http.client.methods.HttpRequestBase; import org.apache.http.entity.ContentType; -import org.openmbee.mdk.mms.endpoints.MMSProjectsEndpoint; +import org.openmbee.mdk.mms.endpoints.MMSProjectEndpoint; +import org.openmbee.mdk.mms.endpoints.MMSEndpointBuilderConstants; import javax.swing.JOptionPane; import java.io.File; @@ -56,7 +58,7 @@ */ -public class ProjectValidator { +public class ProjectValidator implements RunnableWithProgress { private final Project project; private boolean errors; @@ -102,7 +104,8 @@ public void updateTWCServiceToProject(JsonNode projectJson) { MMSUtils.JsonBlobType.PROJECT); // generate project post request HttpRequestBase request = MMSUtils - .prepareEndpointBuilderBasicJsonPostRequest(MMSProjectsEndpoint.builder(), project, sendData) + .prepareEndpointBuilderBasicJsonPostRequest(MMSProjectEndpoint.builder(), project, sendData) + .addParam(MMSEndpointBuilderConstants.URI_PROJECT_SUFFIX, Converters.getIProjectToIdConverter().apply(project.getPrimaryProject())) .build(); // do project post request MMSUtils.sendMMSRequest(project, request); @@ -130,13 +133,20 @@ public void checkIfTWCServiceChanged(JsonNode projectJson) { } } - public void validate() { + @Override + public void run(ProgressStatus progressStatus) { ObjectNode response; try { - HttpRequestBase projectsRequest = MMSUtils.prepareEndpointBuilderBasicGet(MMSProjectsEndpoint.builder(), project).build(); - File responseFile = MMSUtils.sendMMSRequest(project, projectsRequest); + HttpRequestBase projectRequest = MMSUtils.prepareEndpointBuilderBasicGet(MMSProjectEndpoint.builder(), project) + .addParam(MMSEndpointBuilderConstants.URI_PROJECT_SUFFIX, Converters.getIProjectToIdConverter().apply(project.getPrimaryProject())) + .build(); + if (progressStatus != null) { + progressStatus.setDescription("Retrieving Project(s)"); + progressStatus.setIndeterminate(true); + } + File responseFile = MMSUtils.sendMMSRequest(project, projectRequest); try (JsonParser jsonParser = JacksonUtils.getJsonFactory().createParser(responseFile)) { response = JacksonUtils.parseJsonObject(jsonParser); } diff --git a/src/main/java/org/openmbee/mdk/util/MDUtils.java b/src/main/java/org/openmbee/mdk/util/MDUtils.java index eaa6fcd75..d4d4a159b 100644 --- a/src/main/java/org/openmbee/mdk/util/MDUtils.java +++ b/src/main/java/org/openmbee/mdk/util/MDUtils.java @@ -1,6 +1,5 @@ package org.openmbee.mdk.util; -import com.nomagic.log.LoggerBridge; import com.nomagic.magicdraw.core.Application; import com.nomagic.magicdraw.core.Project; import com.nomagic.magicdraw.core.ProjectUtilities; @@ -10,7 +9,6 @@ import com.nomagic.magicdraw.ui.browser.BrowserTabTree; import com.nomagic.magicdraw.ui.browser.Node; import com.nomagic.magicdraw.uml.BaseElement; -import com.nomagic.magicdraw.uml.symbols.DiagramPaintContext; import com.nomagic.magicdraw.uml.symbols.DiagramPresentationElement; import com.nomagic.magicdraw.uml.symbols.PresentationElement; import com.nomagic.uml2.ext.magicdraw.auxiliaryconstructs.mdmodels.Model; @@ -18,24 +16,15 @@ import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Slot; import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.TaggedValue; import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.ValueSpecification; -import com.nomagic.utils.CameoUtilities; -import com.nomagic.utils.FileHelper; import org.openmbee.mdk.api.incubating.MDKConstants; import org.openmbee.mdk.api.incubating.convert.Converters; import org.openmbee.mdk.docgen.DocGenUtils; -import org.apache.batik.anim.dom.SAXSVGDocumentFactory; -import org.apache.batik.util.XMLResourceDescriptor; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.util.EcoreUtil; -import org.w3c.dom.Document; import javax.annotation.CheckForNull; -import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; import java.awt.event.ActionEvent; import java.io.*; import java.nio.charset.Charset; @@ -44,8 +33,6 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import static com.nomagic.magicdraw.uml.DiagramTypeConstants.*; - /** * A collection of utility functions for accessing the MagicDraw (MD) * application. From 136eccd3bf6f3a7b6e52cde23078dbafca7e8aa5 Mon Sep 17 00:00:00 2001 From: Enquier Date: Tue, 28 May 2024 11:39:11 -0600 Subject: [PATCH 5/6] fix javafx --- build.gradle | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 48791cac8..3f54927b1 100644 --- a/build.gradle +++ b/build.gradle @@ -229,10 +229,13 @@ dependencies { distribution group: 'org.openjfx', name: 'javafx-fxml', version: '11.0.2', classifier: 'win' distribution group: 'org.openjfx', name: 'javafx-controls', version: '11.0.2', classifier: 'win' distribution group: 'org.openjfx', name: 'javafx-swing', version: '11.0.2', classifier: 'win' + distribution group: 'org.openjfx', name: 'javafx-graphics', version: '11.0.2', classifier: 'win' + distribution group: 'org.openjfx', name: 'javafx-base', version: '11.0.2', classifier: 'win' distribution group: 'org.openjfx', name: 'javafx-fxml', version: '11.0.2', classifier: 'mac' distribution group: 'org.openjfx', name: 'javafx-controls', version: '11.0.2', classifier: 'mac' distribution group: 'org.openjfx', name: 'javafx-swing', version: '11.0.2', classifier: 'mac' - + distribution group: 'org.openjfx', name: 'javafx-graphics', version: '11.0.2', classifier: 'mac' + distribution group: 'org.openjfx', name: 'javafx-base', version: '11.0.2', classifier: 'mac' // This ensures classpath load order to match the MagicDraw provided order and then includes extras needed for non-OpenAPI stuff. // This was necessary because of the Application class stubbing that was done in the chromium libraries. From 83dc174d804235bfdb2a100b483392b8d4bed672 Mon Sep 17 00:00:00 2001 From: Enquier Date: Wed, 29 May 2024 11:53:35 -0600 Subject: [PATCH 6/6] fix branch validation/twcIds --- .../java/org/openmbee/mdk/api/incubating/MDKConstants.java | 3 ++- .../org/openmbee/mdk/mms/validation/BranchValidator.java | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/openmbee/mdk/api/incubating/MDKConstants.java b/src/main/java/org/openmbee/mdk/api/incubating/MDKConstants.java index 178246626..9ede7bd57 100644 --- a/src/main/java/org/openmbee/mdk/api/incubating/MDKConstants.java +++ b/src/main/java/org/openmbee/mdk/api/incubating/MDKConstants.java @@ -51,7 +51,7 @@ public class MDKConstants { REF_CREATED_STATUS = "created", ORG_KEY = "org", ORG_ID_KEY = ORG_KEY + ID_KEY_SUFFIX, - TWC_ID_KEY = DERIVED_KEY_PREFIX + "twc" + ID_KEY_SUFFIX, + TWC_ID_KEY = "twc" + ID_KEY_SUFFIX, TWC_VERSION_KEY = "twcVersion", ARTIFACTS_KEY = "_artifacts", CHECKSUM_KEY = "checksum", @@ -74,6 +74,7 @@ public class MDKConstants { MESSAGES_NODE = "messages", REJECTED_NODE = "rejected", SOURCE_FIELD = "source", + ARCHIVED_FIELD = "_archived", DELETED_FIELD = "deleted", MAGICDRAW_SOURCE_VALUE = "magicdraw", ELEMENT_TYPE_VALUE = "Element", diff --git a/src/main/java/org/openmbee/mdk/mms/validation/BranchValidator.java b/src/main/java/org/openmbee/mdk/mms/validation/BranchValidator.java index 172625fcd..0ee4f0fd0 100644 --- a/src/main/java/org/openmbee/mdk/mms/validation/BranchValidator.java +++ b/src/main/java/org/openmbee/mdk/mms/validation/BranchValidator.java @@ -190,7 +190,11 @@ else if (serverBranch == null) { serverBranch.remove(MDKConstants.STATUS_KEY); serverBranch.remove(MDKConstants.PARENT_COMMIT_ID); - clientBranch.getValue().put(MDKConstants.DELETED_FIELD, false); + clientBranch.getValue().put(MDKConstants.ARCHIVED_FIELD, false); + if (serverBranch.get(MDKConstants.DELETED_FIELD) != null) { + serverBranch.set(MDKConstants.ARCHIVED_FIELD, serverBranch.get(MDKConstants.DELETED_FIELD)); + serverBranch.remove(MDKConstants.DELETED_FIELD); + } JsonNode diff = JsonPatchFunction.getInstance().apply(clientBranch.getValue(), serverBranch); if (diff != null && diff.isArray() && diff.size() > 0) { ValidationRuleViolation v = new ValidationRuleViolation(project.getPrimaryModel(), "[BRANCH NOT EQUIVALENT] The Teamwork Cloud branch \"" + clientBranch.getKey().getName() + "\" is not equivalent to the corresponding MMS branch.");