diff --git a/pom.xml b/pom.xml index 0551771b..36db0af0 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ it.unibz.inf.ontouml ontouml-vp-plugin - 0.5.1 + 0.5.2 OntoUML 2 Plugin for Visual Paradigm diff --git a/src/main/java/it/unibz/inf/ontouml/vp/OntoUMLPlugin.java b/src/main/java/it/unibz/inf/ontouml/vp/OntoUMLPlugin.java index b3facc9e..1efc52fb 100644 --- a/src/main/java/it/unibz/inf/ontouml/vp/OntoUMLPlugin.java +++ b/src/main/java/it/unibz/inf/ontouml/vp/OntoUMLPlugin.java @@ -16,7 +16,7 @@ */ public class OntoUMLPlugin implements VPPlugin { - public static final String PLUGIN_VERSION_RELEASE = "0.5.1"; + public static final String PLUGIN_VERSION_RELEASE = "0.5.2"; public static final String PLUGIN_ID = "it.unibz.inf.ontouml.vp"; public static final String PLUGIN_NAME = "OntoUML Plugin"; public static final String PLUGIN_REPO = "https://github.com/OntoUML/ontouml-vp-plugin/"; diff --git a/src/main/java/it/unibz/inf/ontouml/vp/controllers/SmartModellingController.java b/src/main/java/it/unibz/inf/ontouml/vp/controllers/SmartModellingController.java index f3d610ab..83de4fba 100644 --- a/src/main/java/it/unibz/inf/ontouml/vp/controllers/SmartModellingController.java +++ b/src/main/java/it/unibz/inf/ontouml/vp/controllers/SmartModellingController.java @@ -10,15 +10,16 @@ public class SmartModellingController { public static void setAggregationKind(IModelElement element) { - IAssociation association = (IAssociation) element; - IAssociationEnd compositionFromEnd = (IAssociationEnd) association.getFromEnd(); - IAssociationEnd compositionToEnd = (IAssociationEnd) association.getToEnd(); + final IAssociation association = (IAssociation) element; + final IAssociationEnd toEnd = (IAssociationEnd) association.getToEnd(); + final IAssociationEnd fromEnd = (IAssociationEnd) association.getFromEnd(); + final String toAgg = toEnd.getAggregationKind().toLowerCase(); - if (compositionToEnd.getAggregationKind().equals(IAssociationEnd.AGGREGATION_KIND_NONE)) { - compositionToEnd.setAggregationKind(IAssociationEnd.AGGREGATION_KIND_COMPOSITED); + if (IAssociationEnd.AGGREGATION_KIND_NONE.toLowerCase().equals(toAgg)) { + toEnd.setAggregationKind(IAssociationEnd.AGGREGATION_KIND_COMPOSITED); } - compositionFromEnd.setAggregationKind(IAssociationEnd.AGGREGATION_KIND_NONE); + fromEnd.setAggregationKind(IAssociationEnd.AGGREGATION_KIND_NONE); } public static void removeAggregationKind(IModelElement element) { diff --git a/src/main/java/it/unibz/inf/ontouml/vp/model/GufoExportOptions.java b/src/main/java/it/unibz/inf/ontouml/vp/model/GufoExportOptions.java index 0bc5eda2..a5e54ca1 100644 --- a/src/main/java/it/unibz/inf/ontouml/vp/model/GufoExportOptions.java +++ b/src/main/java/it/unibz/inf/ontouml/vp/model/GufoExportOptions.java @@ -7,7 +7,7 @@ public class GufoExportOptions { - private String baseIRI; + private String baseIri; private String format; private String uriFormatBy; private boolean createInverses; @@ -20,7 +20,7 @@ public class GufoExportOptions { public GufoExportOptions() {} public GufoExportOptions(ProjectConfigurations projectConfigurations) { - baseIRI = projectConfigurations.getExportGUFOIRI(); + baseIri = projectConfigurations.getExportGUFOIRI(); format = projectConfigurations.getExportGUFOFormat(); uriFormatBy = projectConfigurations.getExportGUFOURIFormat(); createInverses = projectConfigurations.getExportGUFOInverseBox(); @@ -38,12 +38,12 @@ public GufoExportOptions(ProjectConfigurations projectConfigurations) { } } - public String getBaseIRI() { - return baseIRI; + public String getBaseIri() { + return baseIri; } - public void setBaseIRI(String baseIRI) { - this.baseIRI = baseIRI; + public void setBaseIri(String baseIri) { + this.baseIri = baseIri; } public String getFormat() { diff --git a/src/main/java/it/unibz/inf/ontouml/vp/model/ontouml2vp/IAssociationClassLoader.java b/src/main/java/it/unibz/inf/ontouml/vp/model/ontouml2vp/IAssociationClassLoader.java new file mode 100644 index 00000000..ececd92c --- /dev/null +++ b/src/main/java/it/unibz/inf/ontouml/vp/model/ontouml2vp/IAssociationClassLoader.java @@ -0,0 +1,78 @@ +package it.unibz.inf.ontouml.vp.model.ontouml2vp; + +import static it.unibz.inf.ontouml.vp.model.ontouml2vp.LoaderUtils.loadName; +import static it.unibz.inf.ontouml.vp.model.ontouml2vp.LoaderUtils.logElementCreation; + +import com.vp.plugin.ApplicationManager; +import com.vp.plugin.model.IAssociationClass; +import com.vp.plugin.model.IModelElement; +import com.vp.plugin.model.IProject; +import com.vp.plugin.model.factory.IModelElementFactory; +import it.unibz.inf.ontouml.vp.model.ontouml.model.Classifier; +import it.unibz.inf.ontouml.vp.model.ontouml.model.Relation; +import it.unibz.inf.ontouml.vp.utils.StereotypesManager; + +public class IAssociationClassLoader { + + static IProject vpProject = ApplicationManager.instance().getProjectManager().getProject(); + + public static IAssociationClass importElement(Relation fromRelation) { + logElementCreation(fromRelation); + + IAssociationClass toRelation = getOrCreateAssociation(fromRelation); + fromRelation.setId(toRelation.getId()); + + loadName(fromRelation, toRelation); + + loadSource(fromRelation, toRelation); + loadTarget(fromRelation, toRelation); + + // Unable to process "isDerived" for IAssociationClass + // Unable to process "isAbstract" for IAssociationClass + // Unable to process "property ends" fully for IAssociationClass + + fromRelation + .getStereotype() + .ifPresent( + stereotype -> { + if (!"derivation".equals(stereotype)) { + StereotypesManager.applyStereotype(toRelation, stereotype); + } + }); + + ITaggedValueLoader.loadTaggedValues(fromRelation, toRelation); + + return toRelation; + } + + private static void loadSource(Relation fromRelation, IAssociationClass toRelation) { + Classifier fromSource = fromRelation.getSource(); + IModelElement toSource = vpProject.getModelElementById(fromSource.getId()); + + if (toSource != null) { + toRelation.setFrom(toSource); + } + } + + private static void loadTarget(Relation fromRelation, IAssociationClass toRelation) { + Classifier fromTarget = fromRelation.getTarget(); + IModelElement toTarget = vpProject.getModelElementById(fromTarget.getId()); + + if (toTarget != null) { + toRelation.setTo(toTarget); + } + } + + private static IAssociationClass getOrCreateAssociation(Relation fromRelation) { + IModelElement toRelation = vpProject.getModelElementById(fromRelation.getId()); + + if (toRelation instanceof IAssociationClass) { + System.out.println("Relation " + fromRelation.getId() + " exists! Let's update it!"); + } else { + System.out.println("Relation " + fromRelation.getId() + " not found! Let's create it"); + toRelation = IModelElementFactory.instance().createAssociationClass(); + } + + return (IAssociationClass) toRelation; + } +} diff --git a/src/main/java/it/unibz/inf/ontouml/vp/model/ontouml2vp/IAssociationClassUIModelLoader.java b/src/main/java/it/unibz/inf/ontouml/vp/model/ontouml2vp/IAssociationClassUIModelLoader.java new file mode 100644 index 00000000..15feea6e --- /dev/null +++ b/src/main/java/it/unibz/inf/ontouml/vp/model/ontouml2vp/IAssociationClassUIModelLoader.java @@ -0,0 +1,39 @@ +package it.unibz.inf.ontouml.vp.model.ontouml2vp; + +import static it.unibz.inf.ontouml.vp.model.ontouml2vp.LoaderUtils.getIDiagramElement; +import static it.unibz.inf.ontouml.vp.model.ontouml2vp.LoaderUtils.getIModelElement; + +import com.vp.plugin.ApplicationManager; +import com.vp.plugin.DiagramManager; +import com.vp.plugin.diagram.IClassDiagramUIModel; +import com.vp.plugin.diagram.IDiagramElement; +import com.vp.plugin.model.IAssociationClass; +import com.vp.plugin.model.IModelElement; +import it.unibz.inf.ontouml.vp.model.ontouml.view.RelationView; +import java.awt.Point; + +public class IAssociationClassUIModelLoader { + + static DiagramManager diagramManager = ApplicationManager.instance().getDiagramManager(); + + public static void load(IClassDiagramUIModel toDiagram, RelationView fromView) { + IModelElement toModelElement = getIModelElement(fromView); + + if (!(toModelElement instanceof IAssociationClass)) { + System.out.println( + LoaderUtils.getIncompatibleMessage(fromView, toModelElement, IAssociationClass.class)); + return; + } + + IDiagramElement toSource = getIDiagramElement(toDiagram, fromView.getSource()); + IDiagramElement toTarget = getIDiagramElement(toDiagram, fromView.getTarget()); + + Point[] toPoints = IConnectorUIModelLoader.loadPoints(fromView); + + IDiagramElement toView = + diagramManager.createConnector(toDiagram, toModelElement, toSource, toTarget, toPoints); + + fromView.setId(toView.getId()); + toView.resetCaption(); + } +} diff --git a/src/main/java/it/unibz/inf/ontouml/vp/model/ontouml2vp/IAssociationUIModelLoader.java b/src/main/java/it/unibz/inf/ontouml/vp/model/ontouml2vp/IAssociationUIModelLoader.java index 0e55d0b5..2cde8e44 100644 --- a/src/main/java/it/unibz/inf/ontouml/vp/model/ontouml2vp/IAssociationUIModelLoader.java +++ b/src/main/java/it/unibz/inf/ontouml/vp/model/ontouml2vp/IAssociationUIModelLoader.java @@ -7,9 +7,7 @@ import com.vp.plugin.DiagramManager; import com.vp.plugin.diagram.IClassDiagramUIModel; import com.vp.plugin.diagram.IDiagramElement; -import com.vp.plugin.diagram.connector.IAssociationUIModel; import com.vp.plugin.model.IAssociation; -import com.vp.plugin.model.IAssociationClass; import com.vp.plugin.model.IModelElement; import it.unibz.inf.ontouml.vp.model.ontouml.view.RelationView; import java.awt.*; @@ -21,8 +19,8 @@ public class IAssociationUIModelLoader { public static void load(IClassDiagramUIModel toDiagram, RelationView fromView) { IModelElement toModelElement = getIModelElement(fromView); - if (!(toModelElement instanceof IAssociation) - && !(toModelElement instanceof IAssociationClass)) { + if (!(toModelElement instanceof IAssociation)) { + // && !(toModelElement instanceof IAssociationClass)) { System.out.println( LoaderUtils.getIncompatibleMessage(fromView, toModelElement, IAssociation.class)); return; @@ -33,9 +31,8 @@ public static void load(IClassDiagramUIModel toDiagram, RelationView fromView) { Point[] toPoints = IConnectorUIModelLoader.loadPoints(fromView); - IAssociationUIModel toView = - (IAssociationUIModel) - diagramManager.createConnector(toDiagram, toModelElement, toSource, toTarget, toPoints); + IDiagramElement toView = + diagramManager.createConnector(toDiagram, toModelElement, toSource, toTarget, toPoints); fromView.setId(toView.getId()); toView.resetCaption(); diff --git a/src/main/java/it/unibz/inf/ontouml/vp/model/ontouml2vp/IClassDiagramLoader.java b/src/main/java/it/unibz/inf/ontouml/vp/model/ontouml2vp/IClassDiagramLoader.java index 658e580d..94bed933 100644 --- a/src/main/java/it/unibz/inf/ontouml/vp/model/ontouml2vp/IClassDiagramLoader.java +++ b/src/main/java/it/unibz/inf/ontouml/vp/model/ontouml2vp/IClassDiagramLoader.java @@ -39,6 +39,18 @@ public static void load(Diagram fromDiagram, boolean shouldOverride, boolean sho .filter(view -> !view.getModelElement().holdsBetweenClasses()) .forEach(fromRelationView -> IAssociationUIModelLoader.load(toDiagram, fromRelationView)); + fromDiagram.getAllRelationViews().stream() + .filter(view -> view.getModelElement() != null) + .filter(view -> view.getModelElement().holdsBetweenClassAndRelation()) + .forEach( + fromRelationView -> IAssociationClassUIModelLoader.load(toDiagram, fromRelationView)); + + fromDiagram.getAllRelationViews().stream() + .filter(view -> view.getModelElement() != null) + .filter(view -> !view.getModelElement().holdsBetweenClassAndRelation()) + .forEach( + fromRelationView -> IAssociationClassUIModelLoader.load(toDiagram, fromRelationView)); + fromDiagram .getAllGeneralizationViews() .forEach(fromGenView -> IGeneralizationUIModelLoader.load(toDiagram, fromGenView)); diff --git a/src/main/java/it/unibz/inf/ontouml/vp/model/ontouml2vp/IProjectLoader.java b/src/main/java/it/unibz/inf/ontouml/vp/model/ontouml2vp/IProjectLoader.java index 194d8091..8009b6a2 100644 --- a/src/main/java/it/unibz/inf/ontouml/vp/model/ontouml2vp/IProjectLoader.java +++ b/src/main/java/it/unibz/inf/ontouml/vp/model/ontouml2vp/IProjectLoader.java @@ -65,6 +65,9 @@ public static void importModel(Project fromProject) { .forEach(rel -> IAssociationLoader.importElement(rel)); // transform relations between classes and relations + fromProject.getAllRelations().stream() + .filter(rel -> rel.holdsBetweenClassAndRelation()) + .forEach(rel -> IAssociationClassLoader.importElement(rel)); // transform generalization fromProject.getAllGeneralizations().forEach(gen -> IGeneralizationLoader.importElement(gen)); diff --git a/src/main/java/it/unibz/inf/ontouml/vp/model/uml/Association.java b/src/main/java/it/unibz/inf/ontouml/vp/model/uml/Association.java index 7e099de5..e896c800 100644 --- a/src/main/java/it/unibz/inf/ontouml/vp/model/uml/Association.java +++ b/src/main/java/it/unibz/inf/ontouml/vp/model/uml/Association.java @@ -295,10 +295,11 @@ public static void setNavigability(IAssociation association) { final IAssociationEnd sourceEnd = getSourceEnd(association); final IAssociationEnd targetEnd = getTargetEnd(association); + final String targetAgg = targetEnd.getAggregationKind().toLowerCase(); sourceEnd.setNavigable(IAssociationEnd.NAVIGABLE_NAV_UNSPECIFIED); - if (IAssociationEnd.AGGREGATION_KIND_NONE.equals(targetEnd.getAggregationKind())) { + if (IAssociationEnd.AGGREGATION_KIND_NONE.toLowerCase().equals(targetAgg)) { targetEnd.setNavigable(IAssociationEnd.NAVIGABLE_NAV_NAVIGABLE); } else { targetEnd.setNavigable(IAssociationEnd.NAVIGABLE_NAV_UNSPECIFIED); @@ -336,22 +337,19 @@ public static void setDefaultAggregationKind(IAssociation association, boolean f targetEnd.setAggregationKind(aggregationKind); } else { // By not forcing override we keep user-defined aggregation (e.g., "shared") - final String currentAggregationKind = targetEnd.getAggregationKind(); - - if (IAssociationEnd.AGGREGATION_KIND_NONE.equals(currentAggregationKind)) { + // The 16.3 release changes the aggregation kind's string and we must keep backwards + // compatibility + final String targetCurrentAggregation = + targetEnd.getAggregationKind() != null + ? targetEnd.getAggregationKind().toLowerCase() + : "none"; + + if (IAssociationEnd.AGGREGATION_KIND_NONE.toLowerCase().equals(targetCurrentAggregation)) { targetEnd.setAggregationKind(aggregationKind); } } } - public static void setAggregationKind(IAssociation association, String aggregationKind) { - final IAssociationEnd sourceEnd = getSourceEnd(association); - final IAssociationEnd targetEnd = getTargetEnd(association); - - sourceEnd.setAggregationKind(IAssociationEnd.AGGREGATION_KIND_NONE); - targetEnd.setAggregationKind(aggregationKind); - } - public static void setDefaultMultiplicity(IAssociation association, boolean forceOverride) { final IClass source = getSource(association); final IClass target = getTarget(association); diff --git a/src/main/java/it/unibz/inf/ontouml/vp/model/uml/Property.java b/src/main/java/it/unibz/inf/ontouml/vp/model/uml/Property.java index c71494ba..8929c552 100644 --- a/src/main/java/it/unibz/inf/ontouml/vp/model/uml/Property.java +++ b/src/main/java/it/unibz/inf/ontouml/vp/model/uml/Property.java @@ -3,7 +3,12 @@ import com.google.gson.JsonObject; import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; -import com.vp.plugin.model.*; +import com.vp.plugin.model.IAssociationClass; +import com.vp.plugin.model.IAssociationEnd; +import com.vp.plugin.model.IAttribute; +import com.vp.plugin.model.IClass; +import com.vp.plugin.model.IModelElement; +import com.vp.plugin.model.IMultiplicity; import com.vp.plugin.model.factory.IModelElementFactory; import java.util.ArrayList; import java.util.Iterator; @@ -382,13 +387,13 @@ public String getAggregationKind() { public void setAggregationKind(int aggregation) { switch (aggregation) { case 0: - this.aggregationKind = "NONE"; + this.aggregationKind = IAssociationEnd.AGGREGATION_KIND_NONE; break; case 1: - this.aggregationKind = "SHARED"; + this.aggregationKind = IAssociationEnd.AGGREGATION_KIND_SHARED; break; case 2: - this.aggregationKind = "COMPOSITE"; + this.aggregationKind = IAssociationEnd.AGGREGATION_KIND_COMPOSITED; break; default: } @@ -401,14 +406,14 @@ public void setAggregationKind(String aggregationKind) { } switch (aggregationKind.toUpperCase()) { - case "NONE": - this.aggregationKind = "NONE"; + case IAssociationEnd.AGGREGATION_KIND_NONE: + this.aggregationKind = IAssociationEnd.AGGREGATION_KIND_NONE; return; - case "COMPOSITED": - this.aggregationKind = "COMPOSITE"; + case IAssociationEnd.AGGREGATION_KIND_SHARED: + this.aggregationKind = IAssociationEnd.AGGREGATION_KIND_SHARED; return; - case "SHARED": - this.aggregationKind = "SHARED"; + case IAssociationEnd.AGGREGATION_KIND_COMPOSITED: + this.aggregationKind = IAssociationEnd.AGGREGATION_KIND_COMPOSITED; return; default: this.aggregationKind = null; diff --git a/src/main/java/it/unibz/inf/ontouml/vp/model/vp2ontouml/IModelElementTransformer.java b/src/main/java/it/unibz/inf/ontouml/vp/model/vp2ontouml/IModelElementTransformer.java index b6900376..0b799788 100644 --- a/src/main/java/it/unibz/inf/ontouml/vp/model/vp2ontouml/IModelElementTransformer.java +++ b/src/main/java/it/unibz/inf/ontouml/vp/model/vp2ontouml/IModelElementTransformer.java @@ -13,6 +13,6 @@ public static void transform(IModelElement source, Element target) { target.addName(name); String description = source.getDescription(); - target.addDescription(description.isEmpty() ? null : description); + target.addDescription(description != null && description.isEmpty() ? null : description); } } diff --git a/src/main/java/it/unibz/inf/ontouml/vp/model/vp2ontouml/IPropertyAdapter.java b/src/main/java/it/unibz/inf/ontouml/vp/model/vp2ontouml/IPropertyAdapter.java index 07747221..45e98e13 100644 --- a/src/main/java/it/unibz/inf/ontouml/vp/model/vp2ontouml/IPropertyAdapter.java +++ b/src/main/java/it/unibz/inf/ontouml/vp/model/vp2ontouml/IPropertyAdapter.java @@ -4,6 +4,7 @@ import com.vp.plugin.model.IAttribute; import com.vp.plugin.model.IModelElement; import com.vp.plugin.model.IMultiplicity; +import it.unibz.inf.ontouml.vp.model.ontouml.model.AggregationKind; import java.util.Iterator; public class IPropertyAdapter implements IAdapter { @@ -75,11 +76,11 @@ public String getAggregationKind() { int value = attribute.getAggregation(); switch (value) { case 0: - return "NONE"; + return AggregationKind.NONE.getName(); case 1: - return "SHARED"; + return AggregationKind.SHARED.getName(); case 2: - return "COMPOSITE"; + return AggregationKind.COMPOSITE.getName(); } } diff --git a/src/main/java/it/unibz/inf/ontouml/vp/model/vp2ontouml/IStereotypeTransformer.java b/src/main/java/it/unibz/inf/ontouml/vp/model/vp2ontouml/IStereotypeTransformer.java index d3b13e36..dcb3cf45 100644 --- a/src/main/java/it/unibz/inf/ontouml/vp/model/vp2ontouml/IStereotypeTransformer.java +++ b/src/main/java/it/unibz/inf/ontouml/vp/model/vp2ontouml/IStereotypeTransformer.java @@ -9,13 +9,14 @@ public static void transform(IModelElement source, Decoratable target) { String stereotype = null; if (source instanceof IClass - || source instanceof IAssociationClass || source instanceof IAssociation || source instanceof IAttribute || source instanceof IAssociationEnd) stereotype = getFirstStereotype(source); if (source instanceof IDataType) stereotype = "datatype"; + if (source instanceof IAssociationClass) stereotype = "derivation"; + // if (source instanceof IClass) { // stereotype = getFirstStereotype((IClass) source); // } else if (source instanceof IAssociationClass) {