Search in sources :

Example 6 with EntityId

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

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

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

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

Example 10 with EntityId

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

the class EdmmTypeProperties method getDefaultConfiguration.

public static void getDefaultConfiguration(EdmmType edmmType, EntityGraph entityGraph) {
    EntityId e;
    switch(edmmType) {
        case COMPUTE:
            EntityId computeId = EntityGraph.COMPONENT_TYPES.extend(EdmmType.COMPUTE.getValue());
            entityGraph.addEntity(new MappingEntity(computeId, entityGraph));
            entityGraph.addEntity(new ScalarEntity(BASE, computeId.extend(DefaultKeys.EXTENDS), entityGraph));
            break;
        case DATABASE:
            EntityId databaseId = EntityGraph.COMPONENT_TYPES.extend(EdmmType.DATABASE.getValue());
            entityGraph.addEntity(new MappingEntity(databaseId, entityGraph));
            entityGraph.addEntity(new ScalarEntity(BASE, databaseId.extend(DefaultKeys.EXTENDS), entityGraph));
            break;
        case DBMS:
            EntityId dbmsId = EntityGraph.COMPONENT_TYPES.extend(EdmmType.DBMS.getValue());
            entityGraph.addEntity(new MappingEntity(dbmsId, entityGraph));
            entityGraph.addEntity(new ScalarEntity(EdmmType.SOFTWARE_COMPONENT.getValue(), dbmsId.extend(DefaultKeys.EXTENDS), entityGraph));
            getDefaultConfiguration(EdmmType.SOFTWARE_COMPONENT, entityGraph);
            break;
        case MYSQL_DATABASE:
            EntityId mySqlDatabaseId = EntityGraph.COMPONENT_TYPES.extend(EdmmType.MYSQL_DATABASE.getValue());
            entityGraph.addEntity(new MappingEntity(mySqlDatabaseId, entityGraph));
            entityGraph.addEntity(new ScalarEntity(EdmmType.DATABASE.getValue(), mySqlDatabaseId.extend(DefaultKeys.EXTENDS), entityGraph));
            getDefaultConfiguration(EdmmType.DATABASE, entityGraph);
            break;
        case MYSQL_DBMS:
            EntityId mySqlDbmsId = EntityGraph.COMPONENT_TYPES.extend(EdmmType.MYSQL_DBMS.getValue());
            entityGraph.addEntity(new MappingEntity(mySqlDbmsId, entityGraph));
            entityGraph.addEntity(new ScalarEntity(EdmmType.DBMS.getValue(), mySqlDbmsId.extend(DefaultKeys.EXTENDS), entityGraph));
            getDefaultConfiguration(EdmmType.DBMS, entityGraph);
            break;
        case SOFTWARE_COMPONENT:
            EntityId softwareComponent = EntityGraph.COMPONENT_TYPES.extend(EdmmType.SOFTWARE_COMPONENT.getValue());
            entityGraph.addEntity(new MappingEntity(softwareComponent, entityGraph));
            entityGraph.addEntity(new ScalarEntity(BASE, softwareComponent.extend(DefaultKeys.EXTENDS), entityGraph));
            break;
        case TOMCAT:
            EntityId tomcatId = EntityGraph.COMPONENT_TYPES.extend(EdmmType.TOMCAT.getValue());
            entityGraph.addEntity(new MappingEntity(tomcatId, entityGraph));
            entityGraph.addEntity(new ScalarEntity(EdmmType.WEB_SERVER.getValue(), tomcatId.extend(DefaultKeys.EXTENDS), entityGraph));
            getDefaultConfiguration(EdmmType.WEB_SERVER, entityGraph);
            break;
        case WEB_APPLICATION:
            EntityId webApplication = EntityGraph.COMPONENT_TYPES.extend(EdmmType.WEB_APPLICATION.getValue());
            entityGraph.addEntity(new MappingEntity(webApplication, entityGraph));
            entityGraph.addEntity(new ScalarEntity(BASE, webApplication.extend(DefaultKeys.EXTENDS), entityGraph));
            break;
        case WEB_SERVER:
            EntityId webServerId = EntityGraph.COMPONENT_TYPES.extend(EdmmType.WEB_SERVER.getValue());
            entityGraph.addEntity(new MappingEntity(webServerId, entityGraph));
            entityGraph.addEntity(new ScalarEntity(EdmmType.SOFTWARE_COMPONENT.getValue(), webServerId.extend(DefaultKeys.EXTENDS), entityGraph));
            getDefaultConfiguration(EdmmType.SOFTWARE_COMPONENT, entityGraph);
            break;
        case GO:
            EntityId goId = EntityGraph.COMPONENT_TYPES.extend(EdmmType.GO.getValue());
            entityGraph.addEntity(new MappingEntity(goId, entityGraph));
            entityGraph.addEntity(new ScalarEntity(EdmmType.WEB_SERVER.getValue(), goId.extend(DefaultKeys.EXTENDS), entityGraph));
            getDefaultConfiguration(EdmmType.WEB_SERVER, entityGraph);
            break;
        case CONNECTS_TO:
            EntityId connectsToId = EntityGraph.RELATION_TYPES.extend(EdmmType.CONNECTS_TO.getValue());
            entityGraph.addEntity(new MappingEntity(connectsToId, entityGraph));
            entityGraph.addEntity(new ScalarEntity(EdmmType.DEPENDS_ON.getValue(), connectsToId.extend(DefaultKeys.EXTENDS), entityGraph));
            getDefaultConfiguration(EdmmType.DEPENDS_ON, entityGraph);
            break;
        case DEPENDS_ON:
            EntityId dependsOnId = EntityGraph.RELATION_TYPES.extend(EdmmType.DEPENDS_ON.getValue());
            entityGraph.addEntity(new MappingEntity(dependsOnId, entityGraph));
            entityGraph.addEntity(new ScalarEntity(null, dependsOnId.extend(DefaultKeys.EXTENDS), entityGraph));
            break;
        case HOSTED_ON:
            EntityId hostedOnId = EntityGraph.RELATION_TYPES.extend(EdmmType.HOSTED_ON.getValue());
            entityGraph.addEntity(new MappingEntity(hostedOnId, entityGraph));
            entityGraph.addEntity(new ScalarEntity(EdmmType.DEPENDS_ON.getValue(), hostedOnId.extend(DefaultKeys.EXTENDS), entityGraph));
            getDefaultConfiguration(EdmmType.DEPENDS_ON, entityGraph);
            break;
        case PLATFORM:
            e = EntityGraph.COMPONENT_TYPES.extend(EdmmType.PLATFORM.getValue());
            entityGraph.addEntity(new MappingEntity(e, entityGraph));
            entityGraph.addEntity(new ScalarEntity(BASE, e.extend(DefaultKeys.EXTENDS), entityGraph));
            break;
        case PAAS:
            e = EntityGraph.COMPONENT_TYPES.extend(EdmmType.PAAS.getValue());
            entityGraph.addEntity(new MappingEntity(e, entityGraph));
            entityGraph.addEntity(new ScalarEntity(EdmmType.PLATFORM.getValue(), e.extend(DefaultKeys.EXTENDS), entityGraph));
            getDefaultConfiguration(EdmmType.PLATFORM, entityGraph);
            break;
        case DBAAS:
            e = EntityGraph.COMPONENT_TYPES.extend(EdmmType.DBAAS.getValue());
            entityGraph.addEntity(new MappingEntity(e, entityGraph));
            entityGraph.addEntity(new ScalarEntity(EdmmType.PLATFORM.getValue(), e.extend(DefaultKeys.EXTENDS), entityGraph));
            getDefaultConfiguration(EdmmType.PLATFORM, entityGraph);
            break;
        case SAAS:
            e = EntityGraph.COMPONENT_TYPES.extend(EdmmType.SAAS.getValue());
            entityGraph.addEntity(new MappingEntity(e, entityGraph));
            entityGraph.addEntity(new ScalarEntity(EdmmType.PLATFORM.getValue(), e.extend(DefaultKeys.EXTENDS), entityGraph));
            getDefaultConfiguration(EdmmType.PLATFORM, entityGraph);
            break;
        case AWS_BEANSTALK:
            e = EntityGraph.COMPONENT_TYPES.extend(EdmmType.AWS_BEANSTALK.getValue());
            entityGraph.addEntity(new MappingEntity(e, entityGraph));
            entityGraph.addEntity(new ScalarEntity(EdmmType.PAAS.getValue(), e.extend(DefaultKeys.EXTENDS), entityGraph));
            getDefaultConfiguration(EdmmType.PAAS, entityGraph);
            break;
        case AWS_AURORA:
            e = EntityGraph.COMPONENT_TYPES.extend(EdmmType.AWS_AURORA.getValue());
            entityGraph.addEntity(new MappingEntity(e, entityGraph));
            entityGraph.addEntity(new ScalarEntity(EdmmType.DBAAS.getValue(), e.extend(DefaultKeys.EXTENDS), entityGraph));
            getDefaultConfiguration(EdmmType.DBAAS, entityGraph);
            break;
        case AUTH0:
            e = EntityGraph.COMPONENT_TYPES.extend(EdmmType.AUTH0.getValue());
            entityGraph.addEntity(new MappingEntity(e, entityGraph));
            entityGraph.addEntity(new ScalarEntity(EdmmType.SAAS.getValue(), e.extend(DefaultKeys.EXTENDS), entityGraph));
            getDefaultConfiguration(EdmmType.SAAS, entityGraph);
            break;
        case MOM:
            EntityId momId = EntityGraph.COMPONENT_TYPES.extend(EdmmType.MOM.getValue());
            entityGraph.addEntity(new MappingEntity(momId, entityGraph));
            entityGraph.addEntity(new ScalarEntity(EdmmType.SOFTWARE_COMPONENT.getValue(), momId.extend(DefaultKeys.EXTENDS), entityGraph));
            getDefaultConfiguration(EdmmType.SOFTWARE_COMPONENT, entityGraph);
            break;
        case RABBITMQ:
            EntityId rabbitMqId = EntityGraph.COMPONENT_TYPES.extend(EdmmType.RABBITMQ.getValue());
            entityGraph.addEntity(new MappingEntity(rabbitMqId, entityGraph));
            entityGraph.addEntity(new ScalarEntity(EdmmType.MOM.getValue(), rabbitMqId.extend(DefaultKeys.EXTENDS), entityGraph));
            getDefaultConfiguration(EdmmType.MOM, entityGraph);
            break;
        case MONGODB:
            EntityId mongoId = EntityGraph.COMPONENT_TYPES.extend(EdmmType.MONGODB.getValue());
            entityGraph.addEntity(new MappingEntity(mongoId, entityGraph));
            entityGraph.addEntity(new ScalarEntity(EdmmType.DBMS.getValue(), mongoId.extend(DefaultKeys.EXTENDS), entityGraph));
            getDefaultConfiguration(EdmmType.DBMS, entityGraph);
            break;
        case MONGODB_SCHEMA:
            EntityId mongoSchemaId = EntityGraph.COMPONENT_TYPES.extend(EdmmType.MONGODB_SCHEMA.getValue());
            entityGraph.addEntity(new MappingEntity(mongoSchemaId, entityGraph));
            entityGraph.addEntity(new ScalarEntity(EdmmType.DATABASE.getValue(), mongoSchemaId.extend(DefaultKeys.EXTENDS), entityGraph));
            getDefaultConfiguration(EdmmType.DATABASE, entityGraph);
            break;
    }
}
Also used : EntityId(io.github.edmm.core.parser.EntityId) ScalarEntity(io.github.edmm.core.parser.ScalarEntity) 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