Skip to content

Commit 50f44ca

Browse files
authored
Merge pull request #280 from Open-MBEE/feature/enrichedSvg
Feature/enriched svg
2 parents 566d9f0 + 6d4efa7 commit 50f44ca

File tree

6 files changed

+161
-81
lines changed

6 files changed

+161
-81
lines changed

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ dependencies {
179179

180180
// Apache Commons-IO
181181
implementation group: 'org.apache.commons', name: 'commons-io', version: '1.3.2'
182+
implementation group: 'org.apache.commons', name: 'commons-text', version: '1.12.0'
182183
//implementation group: 'commons-io', name: 'commons-io', version: '2.4'
183184

184185
// Apache HTTP

src/main/java/org/openmbee/mdk/api/incubating/convert/Converters.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.openmbee.mdk.api.incubating.MDKConstants;
1010
import org.openmbee.mdk.emf.EMFExporter;
1111
import org.openmbee.mdk.emf.EMFImporter;
12+
import org.openmbee.mdk.util.MDUtils;
1213
import org.apache.commons.lang3.math.NumberUtils;
1314

1415
import java.util.function.BiFunction;
@@ -40,7 +41,7 @@ public static JsonToElementFunction getJsonToElementConverter() {
4041

4142
public static Function<Element, String> getElementToIdConverter() {
4243
if (ELEMENT_TO_ID_CONVERTER == null) {
43-
ELEMENT_TO_ID_CONVERTER = EMFExporter::getEID;
44+
ELEMENT_TO_ID_CONVERTER = MDUtils::getEID;
4445
}
4546
return ELEMENT_TO_ID_CONVERTER;
4647
}

src/main/java/org/openmbee/mdk/docgen/DocGenUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import org.openmbee.mdk.docgen.docbook.DocumentElement;
1313
import org.openmbee.mdk.docgen.view.ViewElement;
1414
import org.openmbee.mdk.util.MDUtils;
15-
import org.apache.commons.lang3.StringEscapeUtils;
15+
import org.apache.commons.text.StringEscapeUtils;
1616
import org.jsoup.Jsoup;
1717
import org.jsoup.nodes.Document;
1818
import org.jsoup.select.Elements;

src/main/java/org/openmbee/mdk/emf/EMFExporter.java

Lines changed: 30 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@
1616
import com.nomagic.uml2.ext.magicdraw.compositestructures.mdinternalstructures.Connector;
1717
import com.nomagic.uml2.ext.magicdraw.mdprofiles.Stereotype;
1818
import com.nomagic.uml2.ext.magicdraw.metadata.UMLPackage;
19+
import com.nomagic.magicdraw.hyperlinks.ElementHyperlink;
1920
import org.openmbee.mdk.SysMLExtensions;
2021
import org.openmbee.mdk.api.function.TriFunction;
2122
import org.openmbee.mdk.api.incubating.MDKConstants;
2223
import org.openmbee.mdk.api.incubating.convert.Converters;
2324
import org.openmbee.mdk.api.stream.MDKCollectors;
2425
import org.openmbee.mdk.json.JacksonUtils;
26+
import org.openmbee.mdk.util.MDUtils;
2527
import org.openmbee.mdk.util.Utils;
2628
import org.eclipse.emf.ecore.EDataType;
2729
import org.eclipse.emf.ecore.EObject;
@@ -36,7 +38,7 @@
3638
import java.util.*;
3739
import java.util.function.BiFunction;
3840
import java.util.stream.Collectors;
39-
41+
import java.io.Reader;
4042

4143
public class EMFExporter implements BiFunction<Element, Project, ObjectNode> {
4244
@Override
@@ -96,45 +98,14 @@ private static ObjectNode convert(Element element, Project project, boolean nest
9698
return objectNode;
9799
}
98100

101+
/*
102+
* @deprecated
103+
* 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
104+
* @see org.openmbee.mdk.util.MDUtils#getEID()
105+
*/
106+
@Deprecated(since="6.1.1")
99107
public static String getEID(EObject eObject) {
100-
if (eObject == null) {
101-
return null;
102-
}
103-
if (!(eObject instanceof Element)) {
104-
return EcoreUtil.getID(eObject);
105-
}
106-
Element element = (Element) eObject;
107-
Project project = Project.getProject(element);
108-
109-
// custom handling of primary model id
110-
if (element instanceof Model && element == project.getPrimaryModel()) {
111-
return Converters.getIProjectToIdConverter().apply(project.getPrimaryProject()) + MDKConstants.PRIMARY_MODEL_ID_SUFFIX;
112-
}
113-
114-
// 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)
115-
// 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.
116-
// there's no more instance spec that's a result of stereotyping, so instance spec should just have their normal id
117-
/*if (eObject instanceof TimeExpression && ((TimeExpression) eObject).get_timeEventOfWhen() != null) {
118-
return getEID(((TimeExpression) eObject).get_timeEventOfWhen()) + MDKConstants.TIME_EXPRESSION_ID_SUFFIX;
119-
}*/
120-
if (element instanceof ValueSpecification && ((ValueSpecification) element).getOwningSlot() != null) {
121-
ValueSpecification slotValue = (ValueSpecification) element;
122-
return getEID(slotValue.getOwningSlot()) + MDKConstants.SLOT_VALUE_ID_SEPARATOR + slotValue.getOwningSlot().getValue().indexOf(slotValue) + "-" + slotValue.eClass().getName().toLowerCase();
123-
}
124-
if (element instanceof TaggedValue) {
125-
TaggedValue slot = (TaggedValue) element;
126-
if (slot.getTaggedValueOwner() != null && slot.getTagDefinition() != null) {
127-
// add _asi to owner in constructed id to maintain continuity with 19.x slots
128-
return getEID(slot.getOwner()) + MDKConstants.APPLIED_STEREOTYPE_INSTANCE_ID_SUFFIX + MDKConstants.SLOT_ID_SEPARATOR + getEID(slot.getTagDefinition());
129-
}
130-
}
131-
if (element instanceof Slot) {
132-
Slot slot = (Slot) element;
133-
if (slot.getOwningInstance() != null && ((Slot) element).getDefiningFeature() != null) {
134-
return getEID(slot.getOwningInstance()) + MDKConstants.SLOT_ID_SEPARATOR + getEID(slot.getDefiningFeature());
135-
}
136-
}
137-
return element.getLocalID();
108+
return MDUtils.getEID(eObject);
138109
}
139110

140111
private static void dumpUMLPackageLiterals() {
@@ -158,7 +129,7 @@ private static void dumpUMLPackageLiterals() {
158129
private enum Processor {
159130
/*APPLIED_STEREOTYPE(
160131
(element, project, objectNode) -> {
161-
ArrayNode applied = StereotypesHelper.getStereotypes(element).stream().map(stereotype -> TextNode.valueOf(getEID(stereotype))).collect(MDKCollectors.toArrayNode());
132+
ArrayNode applied = StereotypesHelper.getStereotypes(element).stream().map(stereotype -> TextNode.valueOf(MDUtils.getEID(stereotype))).collect(MDKCollectors.toArrayNode());
162133
objectNode.set(MDKConstants.APPLIED_STEREOTYPE_IDS_KEY, applied);
163134
return objectNode;
164135
},
@@ -189,6 +160,10 @@ private enum Processor {
189160
),
190161
DOCUMENTATION_PRE(
191162
(element, project, objectNode) -> {
163+
//Todo: FIgure out how to read this stuff and parse the <a tags from MD
164+
// String doc_text = (String) Utils.getElementAttribute(element, Utils.AvailableAttribute.Documentation);
165+
// Reader reader = new StringReader(doc_text);
166+
// HTMLDocument html = new HTMLDocument(doc_text);
192167
objectNode.put(MDKConstants.DOCUMENTATION_KEY, (String) Utils.getElementAttribute(element, Utils.AvailableAttribute.Documentation));
193168
return objectNode;
194169
},
@@ -238,17 +213,16 @@ private enum Processor {
238213
element.getOwner() != null && Converters.getElementToIdConverter().apply(element.getOwner()).endsWith(MDKConstants.SYNC_SYSML_ID_SUFFIX) ? null : objectNode,
239214
Type.PRE
240215
),
241-
/*
242-
TWC_ID is disabled indefinitely, due to our inability to update the ID and associated issues
243-
TWC_ID(
244-
(element, project, objectNode) -> {
245-
if (project.isRemote()) {
246-
objectNode.put(MDKConstants.TWC_ID_KEY, element.getID());
247-
}
248-
return objectNode;
249-
}
250-
),
251-
*/
216+
//TWC_ID is disabled indefinitely, due to our inability to update the ID and associated issues
217+
// TWC_ID(
218+
// (element, project, objectNode) -> {
219+
// if (project.isRemote() && element.getID() != element.getLocalID()) {
220+
// objectNode.put(MDKConstants.TWC_ID_KEY, element.getID());
221+
// }
222+
// return objectNode;
223+
// },
224+
// Type.PRE
225+
// ),
252226
TYPE(
253227
(element, project, objectNode) -> {
254228
if (!objectNode.has(MDKConstants.TYPE_KEY)) {
@@ -328,7 +302,7 @@ private enum Processor {
328302
if (docEl != null) {
329303
ArrayNode ownedCommentIds = ((ArrayNode) objectNode.get(MDKConstants.OWNED_COMMENT_IDS_KEY));
330304
for (int i = 0; i < ownedCommentIds.size(); i++) {
331-
if (ownedCommentIds.get(i).asText().equals(getEID(docEl)))
305+
if (ownedCommentIds.get(i).asText().equals(MDUtils.getEID(docEl)))
332306
ownedCommentIds.remove(i);
333307
}
334308
if (ownedCommentIds.size() == 0) {
@@ -390,7 +364,7 @@ else if (o instanceof BigDecimal) {
390364
}
391365
n.set("value", node);
392366
if (o instanceof Element) {
393-
node = TextNode.valueOf(getEID((Element)o));
367+
node = TextNode.valueOf(MDUtils.getEID((Element)o));
394368
n.set("elementId", node);
395369
n.remove("value");
396370
}
@@ -449,7 +423,7 @@ else if (object instanceof ValueSpecification) {
449423
//return fillValueSpecification((ValueSpecification) object);
450424
}
451425
else if (eStructuralFeature instanceof EReference && object instanceof EObject) {
452-
return EMFExporter.DEFAULT_SERIALIZATION_FUNCTION.apply(getEID(((EObject) object)), project, eStructuralFeature);
426+
return EMFExporter.DEFAULT_SERIALIZATION_FUNCTION.apply(MDUtils.getEID(((EObject) object)), project, eStructuralFeature);
453427
}
454428
else if (object instanceof String) {
455429
return TextNode.valueOf((String) object);
@@ -522,7 +496,7 @@ private enum EStructuralFeatureOverride {
522496
/*if (element instanceof ValueSpecification && !(element instanceof TimeExpression)) {
523497
return objectNode;
524498
}*/
525-
objectNode.put(MDKConstants.ID_KEY, getEID(element));
499+
objectNode.put(MDKConstants.ID_KEY, MDUtils.getEID(element));
526500
return objectNode;
527501
}
528502
),
@@ -535,7 +509,7 @@ private enum EStructuralFeatureOverride {
535509
}*/
536510
//UNCHECKED_E_STRUCTURAL_FEATURE_FUNCTION.apply(element, project, UMLPackage.Literals.ELEMENT__OWNER, objectNode);
537511
// safest way to prevent circular references, like with ValueSpecifications
538-
objectNode.put(MDKConstants.OWNER_ID_KEY, element instanceof Model && project.getModels().stream().anyMatch(model -> element == model) ? Converters.getIProjectToIdConverter().apply(project.getPrimaryProject()) : getEID(owner));
512+
objectNode.put(MDKConstants.OWNER_ID_KEY, element instanceof Model && project.getModels().stream().anyMatch(model -> element == model) ? Converters.getIProjectToIdConverter().apply(project.getPrimaryProject()) : MDUtils.getEID(owner));
539513
return objectNode;
540514
}
541515
),

src/main/java/org/openmbee/mdk/emf/EMFImporter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public static class PreProcessor {
108108
ModelHelper.setComment(element, jsonNode.asText());
109109
//prevent ownedCommentIds empty array from wiping out documentation later
110110
if (objectNode.get(MDKConstants.OWNED_COMMENT_IDS_KEY) != null
111-
&& objectNode.get(MDKConstants.OWNED_COMMENT_IDS_KEY).isEmpty()) {
111+
&& objectNode.get(MDKConstants.OWNED_COMMENT_IDS_KEY).size() == 0) {
112112
objectNode.remove(MDKConstants.OWNED_COMMENT_IDS_KEY);
113113
}
114114
}

0 commit comments

Comments
 (0)