From ca4a239c3401a517f7bf60dcc7c9e28fb22d12aa Mon Sep 17 00:00:00 2001 From: Trent A Severson Date: Mon, 4 Dec 2023 16:46:29 -0800 Subject: [PATCH] Session handling fix in buildRelationship. addDependentElements required between commonElementsFactory.createElement() and commonRelationship.createElement(). Each of these must be contained within their own session within the buildRelationship function. Changed log statements to String.format for readability. Removed session handling within OpaqueExpression.createElement(). --- .../Profile/OpaqueExpression.java | 4 -- .../aero/mtip/XML/Import/ImportXmlSysml.java | 49 +++++++++++-------- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/src/main/java/org/aero/mtip/ModelElements/Profile/OpaqueExpression.java b/src/main/java/org/aero/mtip/ModelElements/Profile/OpaqueExpression.java index 1679daf..0aea1f7 100644 --- a/src/main/java/org/aero/mtip/ModelElements/Profile/OpaqueExpression.java +++ b/src/main/java/org/aero/mtip/ModelElements/Profile/OpaqueExpression.java @@ -61,9 +61,6 @@ public Element createElement(Project project, Element owner, XMLItem xmlElement) */ public Element createElement(Project project, Element owner, String body, String language) { ElementsFactory f = project.getElementsFactory(); - if (!SessionManager.getInstance().isSessionCreated(project)) { - SessionManager.getInstance().createSession(project, "Create Opaque Expression Element"); - } com.nomagic.uml2.ext.magicdraw.classes.mdkernel.OpaqueExpression oe = f.createOpaqueExpressionInstance(); ((NamedElement)oe).setName(name); @@ -73,7 +70,6 @@ public Element createElement(Project project, Element owner, String body, String oe.getLanguage().clear(); oe.getLanguage().add(language); - SessionManager.getInstance().closeSession(project); return oe; } diff --git a/src/main/java/org/aero/mtip/XML/Import/ImportXmlSysml.java b/src/main/java/org/aero/mtip/XML/Import/ImportXmlSysml.java index 348f02f..0415519 100644 --- a/src/main/java/org/aero/mtip/XML/Import/ImportXmlSysml.java +++ b/src/main/java/org/aero/mtip/XML/Import/ImportXmlSysml.java @@ -229,7 +229,7 @@ public static Element buildDiagram(Project project, HashMap par public static Element buildRelationship(Project project, HashMap parsedXML, XMLItem modelElement, String id) { if(!IsRelationshipSupported(modelElement)) { - ImportLog.log(modelElement.getType() + " type not supported. "+ modelElement.getEAID()); + ImportLog.log(String.format("%s type not supported. Import id %s", modelElement.getType(), modelElement.getEAID())); return null; } @@ -240,44 +240,50 @@ public static Element buildRelationship(Project project, HashMap parsedXML, XMLItem modelElement, String id) { if(!IsElementSupported(modelElement)) { - ImportLog.log(modelElement.getType() + " type not supported. "+ modelElement.getEAID()); + ImportLog.log(String.format("%s type not supported. Import id %s", modelElement.getType(), modelElement.getEAID())); return null; } @@ -297,6 +303,7 @@ public static Element buildElement(Project project, HashMap par if (!SessionManager.getInstance().isSessionCreated(project)) { SessionManager.getInstance().createSession(project, "Create " + modelElement.getType() + " with dependent Elements"); } + Element newElement = element.createElement(project, owner, modelElement); // addStereotypeTaggedValues and addDependentElements will call and end their own sessions. End session here. SessionManager.getInstance().closeSession(project); @@ -306,6 +313,7 @@ public static Element buildElement(Project project, HashMap par addStereotypes(newElement, modelElement); element.addStereotypeTaggedValues(modelElement); element.addDependentElements(parsedXML, modelElement); + if(newElement.getOwner() == null) { newElement.dispose(); ImportLog.log("Owner failed to be set including any default owners. Element with id " + modelElement.getEAID() + " not created."); @@ -313,7 +321,6 @@ public static Element buildElement(Project project, HashMap par } ImportLog.log("Created element " + modelElement.getAttribute("name") + " of type: " + modelElement.getType() + " with no initial owner."); - return newElement; }