Skip to content

Commit

Permalink
Session handling fix in buildRelationship. addDependentElements requi…
Browse files Browse the repository at this point in the history
…red 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().
  • Loading branch information
Trent A Severson authored and Trent A Severson committed Dec 5, 2023
1 parent 455fa7e commit ca4a239
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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;
}

Expand Down
49 changes: 28 additions & 21 deletions src/main/java/org/aero/mtip/XML/Import/ImportXmlSysml.java
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public static Element buildDiagram(Project project, HashMap<String, XMLItem> par

public static Element buildRelationship(Project project, HashMap<String, XMLItem> 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;
}

Expand All @@ -240,44 +240,50 @@ public static Element buildRelationship(Project project, HashMap<String, XMLItem
Element owner = GetImportedOwner(modelElement, parsedXML);
Element client = GetImportedClient(modelElement, parsedXML);
if(client == null) {
ImportLog.log("Client null for relationship " + modelElement.getName() + " " + modelElement.getEAID());
ImportLog.log(String.format("Client null for relationship %s. Import id %s", modelElement.getName(), modelElement.getEAID()));
}
Element supplier = GetImportedSupplier(modelElement, parsedXML);
if(supplier == null) {
ImportLog.log("Supplier null for relationship " + modelElement.getName() + " " + modelElement.getEAID());
ImportLog.log(String.format("Supplier null for relationship %s. Import id %s", modelElement.getName(), modelElement.getEAID()));
}

//Create relationship in Cameo
if (!SessionManager.getInstance().isSessionCreated(project)) {
SessionManager.getInstance().createSession(project, "Creating Relationship of type " + modelElement.getType() + ".");
SessionManager.getInstance().createSession(project, String.format("Creating CommonRelationship of type %s.",modelElement.getType()));
}
CommonRelationship relationship = crf.createElement(modelElement.getType(), modelElement.getAttribute("name"), modelElement.getEAID());

SessionManager.getInstance().closeSession(project);

relationship.createDependentElements(project, parsedXML, modelElement);
Element newElement = relationship.createElement(project, owner, client, supplier, modelElement);

if(newElement != null) {
if(newElement.getOwner() == null) {
newElement.dispose();
ImportLog.log("Owner failed to be set including any default owners. Relationship not created.");
return null;
}
if (!SessionManager.getInstance().isSessionCreated(project)) {
SessionManager.getInstance().createSession(project, String.format("Creating Relationship of type %s.", modelElement.getType()));
}

Element newElement = relationship.createElement(project, owner, client, supplier, modelElement);

SessionManager.getInstance().closeSession(project);

if(newElement != null) {
TrackRelationshipIds(modelElement, newElement, supplier, client);
ImportLog.log("Created relationship of type: " + modelElement.getType() + " and id: " + modelElement.getEAID() + " with parent " + modelElement.getParent() + ".");
SessionManager.getInstance().closeSession(project);
return newElement;
if (newElement == null) {
ImportLog.log(String.format("Relationship not created. Type: %s ID: %s with parent %s.", modelElement.getType(), modelElement.getEAID(), modelElement.getParent()));
return null;
}
ImportLog.log("Relationship not created. Type: " + modelElement.getType() + " ID: " + modelElement.getEAID() + " with parent " + modelElement.getParent() + ".");
SessionManager.getInstance().closeSession(project);
return null;

if(newElement.getOwner() == null) {
newElement.dispose();
ImportLog.log("Owner failed to be set including any default owners. Relationship not created.");
return null;
}

TrackRelationshipIds(modelElement, newElement, supplier, client);
ImportLog.log(String.format("Created relationship of type: %s and id: %s with parent %s.", modelElement.getType(), modelElement.getEAID(), modelElement.getParent()));
return newElement;
}

public static Element buildElement(Project project, HashMap<String, XMLItem> 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;
}

Expand All @@ -297,6 +303,7 @@ public static Element buildElement(Project project, HashMap<String, XMLItem> 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);
Expand All @@ -306,14 +313,14 @@ public static Element buildElement(Project project, HashMap<String, XMLItem> 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.");
return null;
}

ImportLog.log("Created element " + modelElement.getAttribute("name") + " of type: " + modelElement.getType() + " with no initial owner.");

return newElement;
}

Expand Down

0 comments on commit ca4a239

Please sign in to comment.