16
16
import com .nomagic .uml2 .ext .magicdraw .compositestructures .mdinternalstructures .Connector ;
17
17
import com .nomagic .uml2 .ext .magicdraw .mdprofiles .Stereotype ;
18
18
import com .nomagic .uml2 .ext .magicdraw .metadata .UMLPackage ;
19
+ import com .nomagic .magicdraw .hyperlinks .ElementHyperlink ;
19
20
import org .openmbee .mdk .SysMLExtensions ;
20
21
import org .openmbee .mdk .api .function .TriFunction ;
21
22
import org .openmbee .mdk .api .incubating .MDKConstants ;
22
23
import org .openmbee .mdk .api .incubating .convert .Converters ;
23
24
import org .openmbee .mdk .api .stream .MDKCollectors ;
24
25
import org .openmbee .mdk .json .JacksonUtils ;
26
+ import org .openmbee .mdk .util .MDUtils ;
25
27
import org .openmbee .mdk .util .Utils ;
26
28
import org .eclipse .emf .ecore .EDataType ;
27
29
import org .eclipse .emf .ecore .EObject ;
36
38
import java .util .*;
37
39
import java .util .function .BiFunction ;
38
40
import java .util .stream .Collectors ;
39
-
41
+ import java . io . Reader ;
40
42
41
43
public class EMFExporter implements BiFunction <Element , Project , ObjectNode > {
42
44
@ Override
@@ -96,45 +98,14 @@ private static ObjectNode convert(Element element, Project project, boolean nest
96
98
return objectNode ;
97
99
}
98
100
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" )
99
107
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 );
138
109
}
139
110
140
111
private static void dumpUMLPackageLiterals () {
@@ -158,7 +129,7 @@ private static void dumpUMLPackageLiterals() {
158
129
private enum Processor {
159
130
/*APPLIED_STEREOTYPE(
160
131
(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());
162
133
objectNode.set(MDKConstants.APPLIED_STEREOTYPE_IDS_KEY, applied);
163
134
return objectNode;
164
135
},
@@ -189,6 +160,10 @@ private enum Processor {
189
160
),
190
161
DOCUMENTATION_PRE (
191
162
(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);
192
167
objectNode .put (MDKConstants .DOCUMENTATION_KEY , (String ) Utils .getElementAttribute (element , Utils .AvailableAttribute .Documentation ));
193
168
return objectNode ;
194
169
},
@@ -238,17 +213,16 @@ private enum Processor {
238
213
element .getOwner () != null && Converters .getElementToIdConverter ().apply (element .getOwner ()).endsWith (MDKConstants .SYNC_SYSML_ID_SUFFIX ) ? null : objectNode ,
239
214
Type .PRE
240
215
),
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
+ // ),
252
226
TYPE (
253
227
(element , project , objectNode ) -> {
254
228
if (!objectNode .has (MDKConstants .TYPE_KEY )) {
@@ -328,7 +302,7 @@ private enum Processor {
328
302
if (docEl != null ) {
329
303
ArrayNode ownedCommentIds = ((ArrayNode ) objectNode .get (MDKConstants .OWNED_COMMENT_IDS_KEY ));
330
304
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 )))
332
306
ownedCommentIds .remove (i );
333
307
}
334
308
if (ownedCommentIds .size () == 0 ) {
@@ -390,7 +364,7 @@ else if (o instanceof BigDecimal) {
390
364
}
391
365
n .set ("value" , node );
392
366
if (o instanceof Element ) {
393
- node = TextNode .valueOf (getEID ((Element )o ));
367
+ node = TextNode .valueOf (MDUtils . getEID ((Element )o ));
394
368
n .set ("elementId" , node );
395
369
n .remove ("value" );
396
370
}
@@ -449,7 +423,7 @@ else if (object instanceof ValueSpecification) {
449
423
//return fillValueSpecification((ValueSpecification) object);
450
424
}
451
425
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 );
453
427
}
454
428
else if (object instanceof String ) {
455
429
return TextNode .valueOf ((String ) object );
@@ -522,7 +496,7 @@ private enum EStructuralFeatureOverride {
522
496
/*if (element instanceof ValueSpecification && !(element instanceof TimeExpression)) {
523
497
return objectNode;
524
498
}*/
525
- objectNode .put (MDKConstants .ID_KEY , getEID (element ));
499
+ objectNode .put (MDKConstants .ID_KEY , MDUtils . getEID (element ));
526
500
return objectNode ;
527
501
}
528
502
),
@@ -535,7 +509,7 @@ private enum EStructuralFeatureOverride {
535
509
}*/
536
510
//UNCHECKED_E_STRUCTURAL_FEATURE_FUNCTION.apply(element, project, UMLPackage.Literals.ELEMENT__OWNER, objectNode);
537
511
// 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 ));
539
513
return objectNode ;
540
514
}
541
515
),
0 commit comments