use of io.github.edmm.core.parser.ScalarEntity in project winery by eclipse.
the class EdmmConverter method createType.
private EntityId createType(TEntityType toscaType, EntityId parentEntityId, EntityGraph entityGraph) {
if (!entityGraph.getEntity(parentEntityId).isPresent()) {
entityGraph.addEntity(new MappingEntity(parentEntityId, entityGraph));
}
EntityId typeEntityId = parentEntityId.extend(this.normalizeQName(toscaType.getQName()));
EdmmType edmmType = oneToOneMappings.get(toscaType.getQName());
if (edmmType != null) {
typeEntityId = parentEntityId.extend(edmmType.getValue());
entityGraph.addEntity(new MappingEntity(typeEntityId, entityGraph));
EdmmTypeProperties.getDefaultConfiguration(edmmType, entityGraph);
this.createPropertiesDefinition(toscaType, typeEntityId, entityGraph);
if (Objects.nonNull(toscaType.getDerivedFrom())) {
QName inheritsFrom = toscaType.getDerivedFrom().getType();
TEntityType parent = toscaType instanceof TNodeType ? nodeTypes.get(inheritsFrom) : relationshipTypes.get(inheritsFrom);
createType(parent, parentEntityId, entityGraph);
}
} else {
Optional<Entity> entity = entityGraph.getEntity(typeEntityId);
if (!entity.isPresent()) {
entityGraph.addEntity(new MappingEntity(typeEntityId, entityGraph));
if (Objects.nonNull(toscaType.getDerivedFrom())) {
QName inheritsFrom = toscaType.getDerivedFrom().getType();
TEntityType parent = toscaType instanceof TNodeType ? nodeTypes.get(inheritsFrom) : relationshipTypes.get(inheritsFrom);
EntityId baseTypeEntityId = createType(parent, parentEntityId, entityGraph);
entityGraph.addEntity(new ScalarEntity(baseTypeEntityId.getName(), typeEntityId.extend(DefaultKeys.EXTENDS), entityGraph));
} else {
String parentElement = "base";
edmmType = edmmTypeMappings.get(toscaType.getQName());
if (edmmType != null) {
parentElement = edmmType.getValue();
EdmmTypeProperties.getDefaultConfiguration(edmmType, entityGraph);
} else if (toscaType instanceof TRelationshipType) {
parentElement = EdmmType.DEPENDS_ON.getValue();
EdmmTypeProperties.getDefaultConfiguration(EdmmType.DEPENDS_ON, entityGraph);
}
entityGraph.addEntity(new ScalarEntity(parentElement, typeEntityId.extend(DefaultKeys.EXTENDS), entityGraph));
}
this.createPropertiesDefinition(toscaType, typeEntityId, entityGraph);
}
}
return typeEntityId;
}
use of io.github.edmm.core.parser.ScalarEntity in project winery by eclipse.
the class EdmmConverter method createParticipant.
private void createParticipant(OTParticipant participant, List<TNodeTemplate> nodeTemplates, EntityGraph entityGraph) {
EntityId participantEntity = EntityGraph.PARTICIPANTS.extend(participant.getName());
entityGraph.addEntity(new MappingEntity(participantEntity, entityGraph));
EntityId endpointEntityId = participantEntity.extend(DefaultKeys.ENDPOINT);
entityGraph.addEntity(new ScalarEntity(participant.getUrl(), endpointEntityId, entityGraph));
EntityId componentsEntityId = participantEntity.extend(DefaultKeys.COMPONENTS);
entityGraph.addEntity(new SequenceEntity(componentsEntityId, entityGraph));
for (TNodeTemplate nodeTemplate : nodeTemplates) {
Map<QName, String> attributes = nodeTemplate.getOtherAttributes();
String name = attributes.get(new QName(TOSCA_WINERY_EXTENSIONS_NAMESPACE, "participant"));
if (participant.getName().equals(name)) {
EntityId valueEntity = componentsEntityId.extend(nodeTemplate.getId());
entityGraph.addEntity(new ScalarEntity(nodeTemplate.getId(), valueEntity, entityGraph));
}
}
}
use of io.github.edmm.core.parser.ScalarEntity in project winery by eclipse.
the class EdmmConverter method createPathReferenceEntity.
private void createPathReferenceEntity(EntityGraph entityGraph, String givenPath, EntityId entityId) {
String path = givenPath;
if (givenPath != null) {
try {
path = URLDecoder.decode(this.useAbsolutePaths ? Environments.getInstance().getRepositoryConfig().getRepositoryRoot() + "/" + givenPath : givenPath, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
entityGraph.addEntity(new ScalarEntity(path, entityId, entityGraph));
}
use of io.github.edmm.core.parser.ScalarEntity in project winery by eclipse.
the class EdmmConverter method createRelation.
private void createRelation(TRelationshipTemplate relationship, EntityGraph entityGraph) {
EntityId sourceComponentEntityId = EntityGraph.COMPONENTS.extend(relationship.getSourceElement().getRef().getId());
// the entity will always be in the graph since we first transform the NodeTemplates
entityGraph.getEntity(sourceComponentEntityId).ifPresent(entity -> {
EntityId relationTypeEntityId = createType(relationshipTypes.get(relationship.getType()), EntityGraph.RELATION_TYPES, entityGraph);
EntityId relationsCollectionEntityId = sourceComponentEntityId.extend(DefaultKeys.RELATIONS);
if (!entityGraph.getEntity(relationsCollectionEntityId).isPresent()) {
entityGraph.addEntity(new SequenceEntity(relationsCollectionEntityId, entityGraph));
}
EntityId relationEntityId = relationsCollectionEntityId.extend(relationTypeEntityId.getName());
if (Objects.nonNull(relationship.getProperties()) && Objects.nonNull(ModelUtilities.getPropertiesKV(relationship))) {
entityGraph.addEntity(new MappingEntity(relationEntityId, entityGraph));
createProperties(relationship, relationEntityId, entityGraph);
} else {
String targetComponent = relationship.getTargetElement().getRef().getId();
entityGraph.addEntity(new ScalarEntity(targetComponent, relationEntityId, entityGraph));
}
});
}
use of io.github.edmm.core.parser.ScalarEntity in project winery by eclipse.
the class EdmmConverter method createProperties.
private void createProperties(TEntityTemplate toscaTemplate, EntityId componentNodeId, EntityGraph entityGraph) {
EntityId propertiesEntityId = componentNodeId.extend(DefaultKeys.PROPERTIES);
entityGraph.addEntity(new MappingEntity(propertiesEntityId, entityGraph));
if (Objects.nonNull(toscaTemplate.getProperties()) && Objects.nonNull(ModelUtilities.getPropertiesKV(toscaTemplate))) {
ModelUtilities.getPropertiesKV(toscaTemplate).forEach((key, value) -> {
EntityId propertyEntityId = propertiesEntityId.extend(key);
entityGraph.addEntity(new ScalarEntity(value, propertyEntityId, entityGraph));
});
}
// add name as property
String name = toscaTemplate.getName();
if (name == null) {
name = toscaTemplate.getId();
}
EntityId propertyEntityId = propertiesEntityId.extend("name");
entityGraph.addEntity(new ScalarEntity(name, propertyEntityId, entityGraph));
}
Aggregations