Search in sources :

Example 1 with EntityId

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

the class EdmmConverter method createNode.

private void createNode(TNodeTemplate nodeTemplate, EntityGraph entityGraph) {
    // create the component inside the topology.
    EntityId componentNodeId = EntityGraph.COMPONENTS.extend(nodeTemplate.getId());
    entityGraph.addEntity(new MappingEntity(componentNodeId, entityGraph));
    // add the type to the model
    EntityId nodeTypeEntityId = this.createType(nodeTypes.get(nodeTemplate.getType()), EntityGraph.COMPONENT_TYPES, entityGraph);
    entityGraph.addEntity(new ScalarEntity(nodeTypeEntityId.getName(), componentNodeId.extend(DefaultKeys.TYPE), entityGraph));
    createProperties(nodeTemplate, componentNodeId, entityGraph);
    createArtifact(nodeTemplate, componentNodeId, entityGraph);
    createOperations(nodeTypes.get(nodeTemplate.getType()), componentNodeId, entityGraph);
}
Also used : EntityId(io.github.edmm.core.parser.EntityId) ScalarEntity(io.github.edmm.core.parser.ScalarEntity) MappingEntity(io.github.edmm.core.parser.MappingEntity)

Example 2 with EntityId

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

the class EdmmConverter method createPropertiesDefinition.

private void createPropertiesDefinition(TEntityType toscaType, EntityId typeEntityId, EntityGraph entityGraph) {
    if (Objects.nonNull(toscaType.getWinerysPropertiesDefinition())) {
        EntityId propertiesEntityId = typeEntityId.extend(DefaultKeys.PROPERTIES);
        entityGraph.addEntity(new MappingEntity(propertiesEntityId, entityGraph));
        toscaType.getWinerysPropertiesDefinition().getPropertyDefinitions().forEach(propertyDef -> {
            EntityId propertyEntityId = propertiesEntityId.extend(propertyDef.getKey());
            entityGraph.addEntity(new MappingEntity(propertyEntityId, entityGraph));
            String normalizedType = propertyDef.getType().replace("xsd:", "");
            EntityId propertyTypeEntityId = propertyEntityId.extend(DefaultKeys.TYPE);
            entityGraph.addEntity(new ScalarEntity(normalizedType, propertyTypeEntityId, entityGraph));
        });
    }
}
Also used : EntityId(io.github.edmm.core.parser.EntityId) ScalarEntity(io.github.edmm.core.parser.ScalarEntity) MappingEntity(io.github.edmm.core.parser.MappingEntity)

Example 3 with EntityId

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

the class EdmmConverter method createArtifact.

private void createArtifact(TNodeTemplate nodeTemplate, EntityId componentNodeId, EntityGraph entityGraph) {
    if (nodeTemplate.getDeploymentArtifacts() != null && nodeTemplate.getDeploymentArtifacts().size() > 0) {
        EntityId artifactsEntityId = componentNodeId.extend(DefaultKeys.ARTIFACTS);
        entityGraph.addEntity(new SequenceEntity(artifactsEntityId, entityGraph));
        for (TDeploymentArtifact artifact : nodeTemplate.getDeploymentArtifacts()) {
            String path = null;
            TArtifactTemplate artifactTemplate = artifactTemplates.get(artifact.getArtifactRef());
            if (artifactTemplate != null && artifactTemplate.getArtifactReferences().size() > 0) {
                path = artifactTemplate.getArtifactReferences().get(0).getReference();
            }
            EntityId artifactEntityId = artifactsEntityId.extend(artifact.getArtifactType().getLocalPart().toLowerCase());
            createPathReferenceEntity(entityGraph, path, artifactEntityId);
        }
    }
}
Also used : EntityId(io.github.edmm.core.parser.EntityId) SequenceEntity(io.github.edmm.core.parser.SequenceEntity) TArtifactTemplate(org.eclipse.winery.model.tosca.TArtifactTemplate) TDeploymentArtifact(org.eclipse.winery.model.tosca.TDeploymentArtifact)

Example 4 with EntityId

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

the class EdmmConverter method createOperations.

private void createOperations(TEntityType type, EntityId nodeTypeEntityId, EntityGraph entityGraph) {
    if (type instanceof TNodeType && Objects.nonNull(((TNodeType) type).getInterfaces())) {
        List<TInterface> interfaces = ((TNodeType) type).getInterfaces();
        interfaces.forEach(anInterface -> {
            anInterface.getOperations().forEach(operation -> {
                EntityId operationsEntityId = nodeTypeEntityId.extend(DefaultKeys.OPERATIONS);
                entityGraph.addEntity(new MappingEntity(operationsEntityId, entityGraph));
                TNodeTypeImplementation implementation = nodeTypeImplementations.values().stream().filter(impl -> impl.getNodeType().equals(type.getQName())).findFirst().orElse(null);
                String path = getImplementationForOperation(implementation, anInterface.getName(), operation.getName());
                EntityId operationId = operationsEntityId.extend(operation.getName());
                createPathReferenceEntity(entityGraph, path, operationId);
            });
        });
    }
}
Also used : EntityId(io.github.edmm.core.parser.EntityId) TInterface(org.eclipse.winery.model.tosca.TInterface) TNodeTypeImplementation(org.eclipse.winery.model.tosca.TNodeTypeImplementation) MappingEntity(io.github.edmm.core.parser.MappingEntity) TNodeType(org.eclipse.winery.model.tosca.TNodeType)

Example 5 with EntityId

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

the class EdmmConverter method createTechnologyMapping.

private void createTechnologyMapping(List<TNodeTemplate> nodeTemplates, EntityGraph entityGraph) {
    Map<String, List<TNodeTemplate>> deploymentTechnologyMapping = new HashMap<>();
    for (TNodeTemplate nodeTemplate : nodeTemplates) {
        Map<QName, String> attributes = nodeTemplate.getOtherAttributes();
        String key = attributes.get(new QName(TOSCA_WINERY_EXTENSIONS_NAMESPACE, "deployment-technology"));
        if (key != null) {
            deploymentTechnologyMapping.computeIfAbsent(key, k -> new ArrayList<>());
            deploymentTechnologyMapping.get(key).add(nodeTemplate);
        }
    }
    if (!deploymentTechnologyMapping.isEmpty()) {
        entityGraph.addEntity(new MappingEntity(EntityGraph.ORCHESTRATION_TECHNOLOGY, entityGraph));
        deploymentTechnologyMapping.forEach((key, nodes) -> {
            EntityId entity = EntityGraph.ORCHESTRATION_TECHNOLOGY.extend(key);
            entityGraph.addEntity(new SequenceEntity(entity, entityGraph));
            for (TNodeTemplate nodeTemplate : nodes) {
                EntityId valueEntity = entity.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) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) ScalarEntity(io.github.edmm.core.parser.ScalarEntity) ArrayList(java.util.ArrayList) List(java.util.List) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) MappingEntity(io.github.edmm.core.parser.MappingEntity)

Aggregations

EntityId (io.github.edmm.core.parser.EntityId)10 MappingEntity (io.github.edmm.core.parser.MappingEntity)9 ScalarEntity (io.github.edmm.core.parser.ScalarEntity)8 SequenceEntity (io.github.edmm.core.parser.SequenceEntity)5 QName (javax.xml.namespace.QName)3 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)2 TNodeType (org.eclipse.winery.model.tosca.TNodeType)2 Entity (io.github.edmm.core.parser.Entity)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 TArtifactTemplate (org.eclipse.winery.model.tosca.TArtifactTemplate)1 TDeploymentArtifact (org.eclipse.winery.model.tosca.TDeploymentArtifact)1 TEntityType (org.eclipse.winery.model.tosca.TEntityType)1 TInterface (org.eclipse.winery.model.tosca.TInterface)1 TNodeTypeImplementation (org.eclipse.winery.model.tosca.TNodeTypeImplementation)1 TRelationshipType (org.eclipse.winery.model.tosca.TRelationshipType)1