Skip to content

Commit

Permalink
[Label Expressions] Source and Target of connections get model object…
Browse files Browse the repository at this point in the history
…s not view objects
  • Loading branch information
Phillipus committed Oct 10, 2023
1 parent ee3e1fe commit 482cdf9
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
*/
package com.archimatetool.editor.ui.textrender;

import com.archimatetool.model.IArchimateConcept;
import com.archimatetool.model.IArchimateModelObject;
import com.archimatetool.model.IArchimateRelationship;
import com.archimatetool.model.IConnectable;
import com.archimatetool.model.IDiagramModel;
import com.archimatetool.model.IDiagramModelArchimateComponent;
Expand All @@ -30,11 +32,11 @@ public abstract class AbstractTextRenderer implements ITextRenderer {
* @return object itself or the underlying object
*/
protected IArchimateModelObject getActualObject(IArchimateModelObject object) {
if(object instanceof IDiagramModelArchimateComponent) {
return ((IDiagramModelArchimateComponent)object).getArchimateConcept();
if(object instanceof IDiagramModelArchimateComponent dmo) {
return dmo.getArchimateConcept();
}
if(object instanceof IDiagramModelReference) {
return ((IDiagramModelReference)object).getReferencedModel();
if(object instanceof IDiagramModelReference dmr) {
return dmr.getReferencedModel();
}
return object;
}
Expand All @@ -61,18 +63,18 @@ protected IArchimateModelObject getObjectFromPrefix(IArchimateModelObject object
}

// View - object is an IDiagramModelComponent so return IDiagramModel
if(viewPrefix.equals(prefix) && object instanceof IDiagramModelComponent) {
return ((IDiagramModelComponent)object).getDiagramModel();
if(viewPrefix.equals(prefix) && object instanceof IDiagramModelComponent dmc) {
return dmc.getDiagramModel();
}

// Model Folder
if(modelFolderPrefix.equals(prefix) && actualObject.eContainer() instanceof IFolder) { // Has a folder parent
return (IFolder)actualObject.eContainer();
if(modelFolderPrefix.equals(prefix) && actualObject.eContainer() instanceof IFolder folder) { // Has a folder parent
return folder;
}

// View Folder
if(viewFolderPrefix.equals(prefix) && object instanceof IDiagramModelComponent) {
IDiagramModel dm = ((IDiagramModelComponent)object).getDiagramModel();
if(viewFolderPrefix.equals(prefix) && object instanceof IDiagramModelComponent dmc) {
IDiagramModel dm = dmc.getDiagramModel();
return dm != null ? (IArchimateModelObject)dm.eContainer() : null; // folder parent of IDiagramModel
}

Expand All @@ -83,38 +85,56 @@ protected IArchimateModelObject getObjectFromPrefix(IArchimateModelObject object
}

// Source of Connection
if(sourcePrefix.equals(prefix) && object instanceof IDiagramModelConnection) {
return getActualObject(((IDiagramModelConnection)object).getSource());
if(sourcePrefix.equals(prefix) && object instanceof IDiagramModelConnection dmc) {
return getActualObject(dmc.getSource());
}

// Target of Connection
if(targetPrefix.equals(prefix) && object instanceof IDiagramModelConnection) {
return getActualObject(((IDiagramModelConnection)object).getTarget());
if(targetPrefix.equals(prefix) && object instanceof IDiagramModelConnection dmc) {
return getActualObject(dmc.getTarget());
}

// Linked Source object from a connection
if(prefix.endsWith(":source") && object instanceof IConnectable) {
// Linked Source object from a connection/relation
if(prefix.endsWith(":source") && object instanceof IConnectable connectable) {
prefix = prefix.replace(":source", "");

// Has at least one target connection that matches...
for(IDiagramModelConnection connection : ((IConnectable)object).getTargetConnections()) {
IArchimateModelObject actualConnection = getActualObject(connection);
// Has at least one source connection that matches...
for(IDiagramModelConnection connection : connectable.getTargetConnections()) {
IArchimateModelObject actualConnection = getActualObject(connection); // Could be "connection" or a relationship type
if(actualConnection.eClass().getName().toLowerCase().contains(prefix)) {
return getActualObject(connection.getSource());
}
}

// No connection, so has at least one source model relation that matches...
if(actualObject instanceof IArchimateConcept concept) {
for(IArchimateRelationship relationship : concept.getTargetRelationships()) {
if(relationship.eClass().getName().toLowerCase().contains(prefix)) {
return relationship.getSource();
}
}
}
}
// Linked Target object from a connection
else if(prefix.endsWith(":target") && object instanceof IConnectable) {
// Linked Target object from a connection/relation
else if(prefix.endsWith(":target") && object instanceof IConnectable connectable) {
prefix = prefix.replace(":target", "");

// Has at least one target connection that matches...
for(IDiagramModelConnection connection : ((IConnectable)object).getSourceConnections()) {
IArchimateModelObject actualConnection = getActualObject(connection);
for(IDiagramModelConnection connection : connectable.getSourceConnections()) {
IArchimateModelObject actualConnection = getActualObject(connection); // Could be "connection" or a relationship type
if(actualConnection.eClass().getName().toLowerCase().contains(prefix)) {
return getActualObject(connection.getTarget());
}
}

// No connection, so has at least one target model relation that matches...
if(actualObject instanceof IArchimateConcept concept) {
for(IArchimateRelationship relationship : concept.getSourceRelationships()) {
if(relationship.eClass().getName().toLowerCase().contains(prefix)) {
return relationship.getTarget();
}
}
}
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@

import static org.junit.Assert.assertEquals;

import org.junit.Before;
import org.junit.Test;

import com.archimatetool.model.IArchimateFactory;
import com.archimatetool.model.IArchimateModelObject;
import com.archimatetool.model.IConnectable;
import com.archimatetool.model.IDiagramModelArchimateConnection;
import com.archimatetool.model.IDiagramModelArchimateObject;
import com.archimatetool.model.IDiagramModelGroup;
Expand All @@ -28,8 +30,14 @@ public class DocumentationRendererTests extends AbstractTextRendererTests {

private DocumentationRenderer renderer = new DocumentationRenderer();

private IDiagramModelArchimateObject dmo = TextRendererTests.createDiagramModelObject();
private IDiagramModelArchimateConnection dmc = TextRendererTests.createDiagramModelConnection();
private IDiagramModelArchimateObject dmo;
private IDiagramModelArchimateConnection dmc;

@Before
public void beforeEachTest() {
dmo = TextRendererTests.createDiagramModelObject();
dmc = TextRendererTests.createDiagramModelConnection();
}

@Override
protected DocumentationRenderer getRenderer() {
Expand Down Expand Up @@ -109,10 +117,32 @@ public void render_ConnectedSourceDocumentation() {
assertEquals("Source Documentation", result);
}

@Test
public void render_ConnectedSourceDocumentation_No_DiagramModelComponent() {
IConnectable target = dmc.getTarget();

// remove dmc
dmc.disconnect();

String result = renderer.render(target, "$assignment:source{documentation}");
assertEquals("Source Documentation", result);
}

@Test
public void render_ConnectedTargetDocumentation() {
String result = renderer.render(dmc.getSource(), "$assignment:target{documentation}");
assertEquals("Target Documentation", result);
}

@Test
public void render_ConnectedTargetDocumentation_No_DiagramModelComponent() {
IConnectable source = dmc.getSource();

// remove dmc
dmc.disconnect();

String result = renderer.render(source, "$assignment:target{documentation}");
assertEquals("Target Documentation", result);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@

import static org.junit.Assert.assertEquals;

import org.junit.Before;
import org.junit.Test;

import com.archimatetool.model.IArchimateFactory;
import com.archimatetool.model.IArchimateModelObject;
import com.archimatetool.model.IConnectable;
import com.archimatetool.model.IDiagramModelArchimateConnection;
import com.archimatetool.model.IDiagramModelArchimateObject;
import com.archimatetool.model.IDiagramModelGroup;
Expand All @@ -28,8 +30,14 @@ public class NameRendererTests extends AbstractTextRendererTests {

private NameRenderer renderer = new NameRenderer();

private IDiagramModelArchimateObject dmo = TextRendererTests.createDiagramModelObject();
private IDiagramModelArchimateConnection dmc = TextRendererTests.createDiagramModelConnection();
private IDiagramModelArchimateObject dmo;
private IDiagramModelArchimateConnection dmc;

@Before
public void beforeEachTest() {
dmo = TextRendererTests.createDiagramModelObject();
dmc = TextRendererTests.createDiagramModelConnection();
}

@Override
protected NameRenderer getRenderer() {
Expand Down Expand Up @@ -103,10 +111,32 @@ public void render_ConnectedSourceName() {
assertEquals("Source Concept", result);
}

@Test
public void render_ConnectedSourceName_No_DiagramModelComponent() {
IConnectable target = dmc.getTarget();

// remove dmc
dmc.disconnect();

String result = renderer.render(target, "$assignment:source{name}");
assertEquals("Source Concept", result);
}

@Test
public void render_ConnectedTargetName() {
String result = renderer.render(dmc.getSource(), "$assignment:target{name}");
assertEquals("Target Concept", result);
}

@Test
public void render_ConnectedTargetName_No_DiagramModelComponent() {
IConnectable source = dmc.getSource();

// remove dmc
dmc.disconnect();

String result = renderer.render(source, "$assignment:target{name}");
assertEquals("Target Concept", result);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@

import static org.junit.Assert.assertEquals;

import org.junit.Before;
import org.junit.Test;

import com.archimatetool.model.IArchimateDiagramModel;
import com.archimatetool.model.IArchimateFactory;
import com.archimatetool.model.IConnectable;
import com.archimatetool.model.IDiagramModelArchimateConnection;
import com.archimatetool.model.IDiagramModelArchimateObject;
import com.archimatetool.model.IDiagramModelReference;
Expand All @@ -27,8 +29,14 @@ public class TypeRendererTests extends AbstractTextRendererTests {

private TypeRenderer renderer = new TypeRenderer();

private IDiagramModelArchimateObject dmo = TextRendererTests.createDiagramModelObject();
private IDiagramModelArchimateConnection dmc = TextRendererTests.createDiagramModelConnection();
private IDiagramModelArchimateObject dmo;
private IDiagramModelArchimateConnection dmc;

@Before
public void beforeEachTest() {
dmo = TextRendererTests.createDiagramModelObject();
dmc = TextRendererTests.createDiagramModelConnection();
}

@Override
protected TypeRenderer getRenderer() {
Expand Down Expand Up @@ -93,17 +101,39 @@ public void render_ParentType() {
}

@Test
public void render_ConnectedSourceName() {
public void render_ConnectedSourceType() {
String result = renderer.render(dmc.getTarget(), "$assignment:source{type}");
assertEquals("Business Actor", result);
}

@Test
public void render_ConnectedTargetName() {
public void render_ConnectedSourceType_No_DiagramModelComponent() {
IConnectable target = dmc.getTarget();

// remove dmc
dmc.disconnect();

String result = renderer.render(target, "$assignment:source{type}");
assertEquals("Business Actor", result);
}

@Test
public void render_ConnectedTargetType() {
String result = renderer.render(dmc.getSource(), "$assignment:target{type}");
assertEquals("Business Role", result);
}

@Test
public void render_ConnectedTargetType_No_DiagramModelComponent() {
IConnectable source = dmc.getSource();

// remove dmc
dmc.disconnect();

String result = renderer.render(source, "$assignment:target{type}");
assertEquals("Business Role", result);
}

@Test
public void render_ModelFolderName() {
String result = renderer.render(dmo, "$mfolder{type}");
Expand Down

0 comments on commit 482cdf9

Please sign in to comment.