Skip to content

Commit

Permalink
Fixes for multi participant support (winery#693)
Browse files Browse the repository at this point in the history
Signed-off-by: Karoline Saatkamp <[email protected]>
Co-authored-by: Lukas Harzenetter <[email protected]>
  • Loading branch information
saatkamp and lharzenetter authored Jan 11, 2023
1 parent aa931b2 commit 0e8f698
Show file tree
Hide file tree
Showing 94 changed files with 3,524 additions and 15,457 deletions.
22 changes: 11 additions & 11 deletions .idea/runConfigurations/TOSCA_Mangement_UI.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions .idea/runConfigurations/Topologymodeler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions .idea/runConfigurations/Winery.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*/
public class UiConfigurationObject extends AbstractConfigurationObject {

public static String apiUrlKey = "repositoryApiUrl";
private static final String apiUrlKey = "repositoryApiUrl";

private static final Logger logger = LoggerFactory.getLogger(UiConfigurationObject.class);

Expand Down Expand Up @@ -71,7 +71,20 @@ public Map<String, String> getEndpoints() {
return endpoints;
}

public Map<String, String> getDarus() { return darus; }
public Map<String, String> getDarus() {
return darus;
}

public String getApiEndpoint() {
String apiEndpoint = this.endpoints.get(apiUrlKey);

if (apiEndpoint == null) {
// set to default
apiEndpoint = "http://localhost:8080/winery";
}

return apiEndpoint;
}

public Map<String, String> getGit() {
return git;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,4 @@ public void testIsFeatureEnabled() {
assertFalse(result.getFeatures().get("test2"));
assertNull(result.getFeatures().get("test3"));
}

@AfterAll
static void reset() {
Environment.getInstance().copyDefaultConfigFile();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public EntityGraph transform(TServiceTemplate serviceTemplate) {

List<OTParticipant> participants = serviceTemplate.getTopologyTemplate().getParticipants();
if (participants != null && !participants.isEmpty()) {
entityGraph.addEntity(new ScalarEntity(ModelUtilities.getOwnerParticipantOfServiceTemplate(serviceTemplate), EntityGraph.OWNER, entityGraph));
entityGraph.addEntity(new MappingEntity(EntityGraph.PARTICIPANTS, entityGraph));
participants.forEach(participant -> createParticipant(participant, nodeTemplates, entityGraph));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import { ModalVariant, ModalVariantAndState } from './entities-modal/modal-model
import { align, LiveModelingStates, PropertyDefinitionType, toggleModalType } from '../models/enums';
import { ImportTopologyModalData } from '../models/importTopologyModalData';
import { ImportTopologyService } from '../services/import-topology.service';
import { SplitMatchTopologyService } from '../services/split-match-topology.service';
import { SplitMatchTopologyService } from '../sidebars/splitting-matching/split-match-topology.service';
import { PlaceComponentsService } from '../services/placement.service';
import { DifferenceStates, VersionUtils } from '../models/ToscaDiff';
import { ErrorHandlerService } from '../services/error-handler.service';
Expand Down Expand Up @@ -1125,8 +1125,6 @@ export class CanvasComponent implements OnInit, OnDestroy, OnChanges, AfterViewI
);
}
);
} else if (this.topologyRendererState.buttonsState.matchTopologyButton) {
this.splitMatchService.matchTopology(this.backendService, this.ngRedux, this.topologyRendererActions, this.errorHandler);
} else if (this.topologyRendererState.buttonsState.substituteTopologyButton) {
this.ngRedux.dispatch(this.topologyRendererActions.substituteTopology());
this.backendService.substituteTopology();
Expand Down Expand Up @@ -1286,33 +1284,10 @@ export class CanvasComponent implements OnInit, OnDestroy, OnChanges, AfterViewI
paintRelationship(newRelationship: TRelationshipTemplate) {
const allJsPlumbRelationships = this.newJsPlumbInstance.getAllConnections();
if (!allJsPlumbRelationships.some((rel) => rel.id === newRelationship.id)) {
let labelString = (!newRelationship.state ? '' : newRelationship.state + '<br>')
// why not use name -> save the type's id into the name (without management version)
+ newRelationship.name;

if (labelString.startsWith(this.backendService.configuration.relationshipPrefix)) {
// Workaround to support old topology templates with the real name
labelString = newRelationship.type.substring(newRelationship.type.indexOf('}') + 1);
}

const labelString = this.generateRelationshipLabel(newRelationship);
let relationSource = newRelationship.sourceElement.ref;
let relationTarget = newRelationship.targetElement.ref;

if (newRelationship.policies) {
const list: TPolicy[] = newRelationship.policies;
labelString += '<br>';
for (const value of list) {
const visual = this.entityTypes.policyTypeVisuals.find(
policyTypeVisual => policyTypeVisual.typeId === value.policyType
);

if (visual && visual.imageUrl) {
labelString += '<img style="display: block; margin-left: auto; margin-right: auto; margin-top: 5px;' +
' max-width: 40px; max-height: 40px;" src="' + visual.imageUrl + '" alt="Policy icon" />';
}
}
}

// check if source reference is not a node template
{
if (!this.allNodesIds.includes(relationSource)) {
Expand All @@ -1339,40 +1314,8 @@ export class CanvasComponent implements OnInit, OnDestroy, OnChanges, AfterViewI
}
}

const border = !newRelationship.state
? '#fafafa' : VersionUtils.getElementColorByDiffState(newRelationship.state);
const me = this;
const conn = this.newJsPlumbInstance.connect({
source: relationSource,
target: relationTarget,
overlays: [['Arrow', { width: 15, length: 15, location: 1, id: 'arrow', direction: 1 }],
['Label', {
label: labelString,
id: labelString,
events: {
click: () => {
setTimeout(() => me.onClickJsPlumbConnection(conn), 1);
}
},
labelStyle: {
font: '11px Roboto, sans-serif',
color: '#212121',
fill: '#efefef',
borderStyle: border,
borderWidth: 1,
padding: '3px'
}
}]
],
});
const conn = this.createNewJsPlumbConnection(relationSource, relationTarget, newRelationship);
this.handleRelSideBar(conn, newRelationship);

if (newRelationship.state) {
setTimeout(() => {
conn.addType(newRelationship.state.toString().toLowerCase());
this.revalidateContainer();
}, 1);
}
}
}

Expand Down Expand Up @@ -1527,6 +1470,7 @@ export class CanvasComponent implements OnInit, OnDestroy, OnChanges, AfterViewI
this.ngRedux.dispatch(this.actions.sendPaletteOpened(false));
this.hideSidebar();
this.clearSelectedNodes();
this.unmarkConnections();
this.nodeComponentChildren.forEach((node) => node.makeSelectionVisible = false);
this.gridTemplate.pageX = $event.pageX;
this.gridTemplate.pageY = $event.pageY;
Expand Down Expand Up @@ -1596,6 +1540,7 @@ export class CanvasComponent implements OnInit, OnDestroy, OnChanges, AfterViewI
this.ngRedux.dispatch(this.actions.sendPaletteOpened(false));
}
}
this.ngRedux.dispatch(this.topologyRendererActions.setSelectedNodes(this.selectedNodes.map(node => node.id)));
}

/**
Expand Down Expand Up @@ -2577,71 +2522,63 @@ export class CanvasComponent implements OnInit, OnDestroy, OnChanges, AfterViewI
const relationshipTemplate = currentRelationships.find((el) => el.id === rel.id);
if (relationshipTemplate) {
if (rel.policies !== relationshipTemplate.policies) {
const oldCon = this.newJsPlumbInstance.getAllConnections().find((jSPlumbConnection) => jSPlumbConnection.id === relationshipTemplate.id);
const allConnections = this.newJsPlumbInstance.getAllConnections();
let conn = allConnections.find((jSPlumbConnection) => jSPlumbConnection.id === relationshipTemplate.id);
if (relationshipTemplate.policies) {
let labelString = (!relationshipTemplate.state ? '' : relationshipTemplate.state + '<br>')
+ relationshipTemplate.name;
if (labelString.startsWith(this.backendService.configuration.relationshipPrefix)) {
// Workaround to support old topology templates with the real name
labelString = relationshipTemplate.type.substring(relationshipTemplate.type.indexOf('}') + 1);
}
const list: TPolicy[] = relationshipTemplate.policies.policy;
labelString += '<br>';
for (const value of list) {
const visual = this.entityTypes.policyTypeVisuals.find(
policyTypeVisual => policyTypeVisual.typeId === value.policyType
);
if (visual && visual.imageUrl) {
labelString += '<img style="display: block; margin-left: auto; margin-right: auto; margin-top: 5px;' +
' max-width: 40px; max-height: 40px;" src="' + visual.imageUrl + '" alt="Icon" />';
}
}
const relationshipType = this.entityTypes.relationshipTypes.filter((rT) => rT.qName === relationshipTemplate.type)[0];

if (oldCon) {
const border = !relationshipTemplate.state
? '#fafafa' : VersionUtils.getElementColorByDiffState(relationshipTemplate.state);
const me = this;
if (conn) {
// create new JsPlumb instance with updated attributes
const newCon = this.newJsPlumbInstance.connect({
source: oldCon.source,
target: oldCon.target,
paintStyle: {
stroke: relationshipType.color,
strokeWidth: 2
},
hoverPaintStyle: { stroke: relationshipType.color, strokeWidth: 5 },
overlays: [['Arrow', { width: 15, length: 15, location: 1, id: 'arrow', direction: 1 }],
['Label', {
label: labelString,
id: 'label',
events: {
click: function () {
setTimeout(() => me.onClickJsPlumbConnection(newCon), 1);
}
},
labelStyle: {
font: '11px Roboto, sans-serif',
color: '#212121',
fill: '#efefef',
borderStyle: border,
borderWidth: 1,
padding: '3px'
}
}]
],
});
// and delete the old one
this.newJsPlumbInstance.deleteConnection(oldCon);
const source = conn.source;
const target = conn.target;
this.newJsPlumbInstance.deleteConnection(conn);

conn = this.createNewJsPlumbConnection(source, target, relationshipTemplate);
this.handleRelSideBar(conn, relationshipTemplate);
}
}
this.allRelationshipTemplates[this.allRelationshipTemplates.indexOf(rel)] = relationshipTemplate;
this.onClickJsPlumbConnection(oldCon);
this.onClickJsPlumbConnection(conn);
this.revalidateContainer();

return true;
}
}
});
this.revalidateContainer();
}

private createNewJsPlumbConnection(source, target, relationshipTemplate: TRelationshipTemplate) {
const border = !relationshipTemplate.state
? '#fafafa' : VersionUtils.getElementColorByDiffState(relationshipTemplate.state);
const labelString = this.generateRelationshipLabel(relationshipTemplate);
const conn = this.newJsPlumbInstance.connect({
source: source,
target: target,
overlays: [['Arrow', { width: 15, length: 15, location: 1, id: 'arrow', direction: 1 }],
['Label', {
label: labelString,
id: relationshipTemplate.id + '_jsPlumbId',
labelStyle: {
font: '11px Roboto, sans-serif',
color: '#212121',
fill: '#efefef',
borderStyle: border,
borderWidth: 1,
padding: '3px'
}
}]
],
});

if (relationshipTemplate.state) {
setTimeout(() => {
conn.addType(relationshipTemplate.state.toString().toLowerCase());
this.revalidateContainer();
}, 1);
}

return conn;
}

private typeToHref(typeQName: QName, refType: string): string {
Expand Down Expand Up @@ -2698,4 +2635,31 @@ export class CanvasComponent implements OnInit, OnDestroy, OnChanges, AfterViewI
this.capabilitiesModal.hide();
}

private generateRelationshipLabel(newRelationship: TRelationshipTemplate) {
let labelString = (!newRelationship.state ? '' : newRelationship.state + '<br>')
// why not use name -> save the type's id into the name (without management version)
+ newRelationship.name;

if (labelString.startsWith(this.backendService.configuration.relationshipPrefix)) {
// Workaround to support old topology templates with the real name
labelString = newRelationship.type.substring(newRelationship.type.indexOf('}') + 1);
}

if (newRelationship.policies) {
const list: TPolicy[] = newRelationship.policies;
labelString += '<br>';
for (const value of list) {
const visual = this.entityTypes.policyTypeVisuals.find(
policyTypeVisual => policyTypeVisual.typeId === value.policyType
);

if (visual && visual.imageUrl) {
labelString += '<img style="display: block; margin-left: auto; margin-right: auto; margin-top: 5px;' +
' max-width: 40px; max-height: 40px;" src="' + visual.imageUrl + '" alt="Policy icon" />';
}
}
}
return labelString;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,9 @@ export abstract class TopologyTemplateUtil {
if (!this.objectsEquals(currentRelationshipTemplate.properties, lastSavedRelationshipTemplate.properties)) {
return true;
}
if (!this.objectsEquals(currentRelationshipTemplate.policies, lastSavedRelationshipTemplate.policies)) {
if ((!currentRelationshipTemplate.policies && lastSavedRelationshipTemplate.policies)
|| (currentRelationshipTemplate.policies && !lastSavedRelationshipTemplate.policies)
|| !this.objectsEquals(currentRelationshipTemplate.policies, lastSavedRelationshipTemplate.policies)) {
return true;
}
return false;
Expand Down
Loading

0 comments on commit 0e8f698

Please sign in to comment.