Search in sources :

Example 1 with ScalarEntity

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

the class EdmmConverterTest method transformProperties.

@Test
void transformProperties() {
    // region *** build the TopologyTemplate ***
    TTopologyTemplate.Builder topology = new TTopologyTemplate.Builder();
    topology.addNodeTemplate(nodeTemplates.get("test_node_3"));
    // endregion
    TServiceTemplate serviceTemplate = new TServiceTemplate();
    serviceTemplate.setTopologyTemplate(topology.build());
    EdmmConverter edmmConverter = new EdmmConverter(nodeTypes, relationshipTypes, nodeTypeImplementations, relationshipTypeImplementations, artifactTemplates, edmmTypeExtendsMapping, edmm1to1Mapping);
    EntityGraph transform = edmmConverter.transform(serviceTemplate);
    assertNotNull(transform);
    assertTrue(transform.vertexSet().stream().anyMatch(entity -> entity instanceof MappingEntity && entity.getName().equals("properties")));
    Stream.of("os_family", "public_key", "ssh_port").forEach(key -> {
        assertTrue(transform.vertexSet().stream().anyMatch(entity -> entity instanceof MappingEntity && entity.getName().equals(key) && entity.getParent().isPresent() && entity.getParent().get().getName().equals("properties") && entity.getChildren().size() == 1));
    });
    Stream.of("os_family", "public_key", "ssh_port").forEach(key -> {
        assertTrue(transform.vertexSet().stream().anyMatch(entity -> entity instanceof ScalarEntity && entity.getName().equals(key) && !((ScalarEntity) entity).getValue().isEmpty() && entity.getParent().isPresent() && entity.getParent().get().getName().equals("properties")));
    });
}
Also used : EntityGraph(io.github.edmm.core.parser.EntityGraph) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) StringWriter(java.io.StringWriter) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) Test(org.junit.jupiter.api.Test) EdmmDependantTest(org.eclipse.winery.edmm.EdmmDependantTest) Entity(io.github.edmm.core.parser.Entity) MappingEntity(io.github.edmm.core.parser.MappingEntity) Stream(java.util.stream.Stream) EntityGraph(io.github.edmm.core.parser.EntityGraph) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) ScalarEntity(io.github.edmm.core.parser.ScalarEntity) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) UnsupportedEncodingException(java.io.UnsupportedEncodingException) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) ScalarEntity(io.github.edmm.core.parser.ScalarEntity) MappingEntity(io.github.edmm.core.parser.MappingEntity) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) Test(org.junit.jupiter.api.Test) EdmmDependantTest(org.eclipse.winery.edmm.EdmmDependantTest)

Example 2 with ScalarEntity

use of io.github.edmm.core.parser.ScalarEntity 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 3 with ScalarEntity

use of io.github.edmm.core.parser.ScalarEntity 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 4 with ScalarEntity

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

the class EdmmConverter method setMetadata.

private void setMetadata(EntityGraph entityGraph) {
    entityGraph.addEntity(new ScalarEntity("edm_1_0", EntityGraph.VERSION, entityGraph));
    entityGraph.addEntity(new ScalarEntity("12345", EntityGraph.MULTI_ID, entityGraph));
}
Also used : ScalarEntity(io.github.edmm.core.parser.ScalarEntity)

Example 5 with ScalarEntity

use of io.github.edmm.core.parser.ScalarEntity 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

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