Search in sources :

Example 6 with ScalarEntity

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;
}
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 ScalarEntity

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));
        }
    }
}
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 ScalarEntity

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));
}
Also used : ScalarEntity(io.github.edmm.core.parser.ScalarEntity) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 9 with ScalarEntity

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));
        }
    });
}
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 ScalarEntity

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

Aggregations

ScalarEntity (io.github.edmm.core.parser.ScalarEntity)14 MappingEntity (io.github.edmm.core.parser.MappingEntity)12 EntityId (io.github.edmm.core.parser.EntityId)8 Entity (io.github.edmm.core.parser.Entity)5 EntityGraph (io.github.edmm.core.parser.EntityGraph)4 SequenceEntity (io.github.edmm.core.parser.SequenceEntity)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 EdmmDependantTest (org.eclipse.winery.edmm.EdmmDependantTest)4 TServiceTemplate (org.eclipse.winery.model.tosca.TServiceTemplate)4 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)4 Test (org.junit.jupiter.api.Test)4 StringWriter (java.io.StringWriter)3 Arrays (java.util.Arrays)3 Optional (java.util.Optional)3 Stream (java.util.stream.Stream)3 QName (javax.xml.namespace.QName)3 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)3 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)3 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)3 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)2