Search in sources :

Example 6 with MappingEntity

use of io.github.edmm.core.parser.MappingEntity 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;
}
Also used : EntityId(io.github.edmm.core.parser.EntityId) Entity(io.github.edmm.core.parser.Entity) ScalarEntity(io.github.edmm.core.parser.ScalarEntity) SequenceEntity(io.github.edmm.core.parser.SequenceEntity) MappingEntity(io.github.edmm.core.parser.MappingEntity) TRelationshipType(org.eclipse.winery.model.tosca.TRelationshipType) QName(javax.xml.namespace.QName) TEntityType(org.eclipse.winery.model.tosca.TEntityType) ScalarEntity(io.github.edmm.core.parser.ScalarEntity) MappingEntity(io.github.edmm.core.parser.MappingEntity) TNodeType(org.eclipse.winery.model.tosca.TNodeType)

Example 7 with MappingEntity

use of io.github.edmm.core.parser.MappingEntity 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));
        }
    }
}
Also used : EntityId(io.github.edmm.core.parser.EntityId) SequenceEntity(io.github.edmm.core.parser.SequenceEntity) QName(javax.xml.namespace.QName) ScalarEntity(io.github.edmm.core.parser.ScalarEntity) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) MappingEntity(io.github.edmm.core.parser.MappingEntity)

Example 8 with MappingEntity

use of io.github.edmm.core.parser.MappingEntity in project winery by eclipse.

the class EdmmConverter method transform.

public EntityGraph transform(TServiceTemplate serviceTemplate) {
    EntityGraph entityGraph = new EntityGraph();
    setMetadata(entityGraph);
    List<TNodeTemplate> nodeTemplates = serviceTemplate.getTopologyTemplate().getNodeTemplates();
    List<TRelationshipTemplate> relationshipTemplates = serviceTemplate.getTopologyTemplate().getRelationshipTemplates();
    if (!nodeTemplates.isEmpty()) {
        entityGraph.addEntity(new MappingEntity(EntityGraph.COMPONENTS, entityGraph));
    }
    nodeTemplates.forEach(nodeTemplate -> createNode(nodeTemplate, entityGraph));
    relationshipTemplates.forEach(relationship -> createRelation(relationship, entityGraph));
    List<OTParticipant> participants = serviceTemplate.getTopologyTemplate().getParticipants();
    if (participants != null && !participants.isEmpty()) {
        entityGraph.addEntity(new MappingEntity(EntityGraph.PARTICIPANTS, entityGraph));
        participants.forEach(participant -> createParticipant(participant, nodeTemplates, entityGraph));
    }
    createTechnologyMapping(nodeTemplates, entityGraph);
    return entityGraph;
}
Also used : EntityGraph(io.github.edmm.core.parser.EntityGraph) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) MappingEntity(io.github.edmm.core.parser.MappingEntity) OTParticipant(org.eclipse.winery.model.tosca.extensions.OTParticipant)

Example 9 with MappingEntity

use of io.github.edmm.core.parser.MappingEntity 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));
        }
    });
}
Also used : EntityId(io.github.edmm.core.parser.EntityId) SequenceEntity(io.github.edmm.core.parser.SequenceEntity) ScalarEntity(io.github.edmm.core.parser.ScalarEntity) MappingEntity(io.github.edmm.core.parser.MappingEntity)

Example 10 with MappingEntity

use of io.github.edmm.core.parser.MappingEntity 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));
}
Also used : EntityId(io.github.edmm.core.parser.EntityId) ScalarEntity(io.github.edmm.core.parser.ScalarEntity) MappingEntity(io.github.edmm.core.parser.MappingEntity)

Aggregations

MappingEntity (io.github.edmm.core.parser.MappingEntity)11 EntityId (io.github.edmm.core.parser.EntityId)9 ScalarEntity (io.github.edmm.core.parser.ScalarEntity)9 SequenceEntity (io.github.edmm.core.parser.SequenceEntity)4 QName (javax.xml.namespace.QName)3 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)3 Entity (io.github.edmm.core.parser.Entity)2 EntityGraph (io.github.edmm.core.parser.EntityGraph)2 TNodeType (org.eclipse.winery.model.tosca.TNodeType)2 StringWriter (java.io.StringWriter)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Optional (java.util.Optional)1 Stream (java.util.stream.Stream)1 EdmmDependantTest (org.eclipse.winery.edmm.EdmmDependantTest)1 TEntityType (org.eclipse.winery.model.tosca.TEntityType)1 TInterface (org.eclipse.winery.model.tosca.TInterface)1