Search in sources :

Example 6 with TInterface

use of org.eclipse.winery.model.tosca.TInterface 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 7 with TInterface

use of org.eclipse.winery.model.tosca.TInterface in project winery by eclipse.

the class ServiceTemplateResource method generatePlaceholdersWithCapability.

@POST
@Path("placeholder/generator")
@Consumes({ MediaType.APPLICATION_XML, MediaType.TEXT_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.TEXT_XML, MediaType.APPLICATION_JSON })
public Response generatePlaceholdersWithCapability() {
    Splitting splitting = new Splitting();
    TTopologyTemplate topologyTemplate = this.getServiceTemplate().getTopologyTemplate();
    if (topologyTemplate == null) {
        return Response.notModified().build();
    }
    try {
        // get all open requirements and the respective node templates with open requirements
        Map<TRequirement, TNodeTemplate> requirementsAndItsNodeTemplates = splitting.getOpenRequirementsAndItsNodeTemplate(topologyTemplate);
        IRepository repo = RepositoryFactory.getRepository();
        // iterate over all open requirements
        for (Map.Entry<TRequirement, TNodeTemplate> entry : requirementsAndItsNodeTemplates.entrySet()) {
            List<PropertyDefinitionKV> propertyDefinitionKVList = new ArrayList<>();
            LinkedHashMap<String, String> placeholderNodeTemplateProperties = new LinkedHashMap<>();
            // current node template with open requirements
            TNodeTemplate nodeTemplateWithOpenReq = entry.getValue();
            // get type of node template with open requirements
            NodeTypeId id = new NodeTypeId(nodeTemplateWithOpenReq.getType());
            TNodeType sourceNodeType = repo.getElement(id);
            List<TInterface> sourceNodeTypeInterfaces = sourceNodeType.getInterfaces();
            if (sourceNodeTypeInterfaces != null) {
                for (TInterface tInterface : sourceNodeTypeInterfaces) {
                    // TODO: make this more safe
                    for (TOperation tOperation : tInterface.getOperations()) {
                        List<TParameter> inputParameters = tOperation.getInputParameters();
                        if (inputParameters != null) {
                            for (TParameter inputParameter : inputParameters) {
                                generateInputParameters(propertyDefinitionKVList, placeholderNodeTemplateProperties, sourceNodeType, inputParameter);
                            }
                        }
                    }
                }
            }
            List<TRelationshipTemplate> incomingRelationshipTemplates = ModelUtilities.getIncomingRelationshipTemplates(topologyTemplate, nodeTemplateWithOpenReq);
            List<TParameter> inputParameters = splitting.getInputParamListofIncomingRelationshipTemplates(topologyTemplate, incomingRelationshipTemplates);
            for (TParameter inputParameter : inputParameters) {
                String prefixTARGET = "TARGET_";
                String prefixSOURCE = "SOURCE_";
                String inputParamName = inputParameter.getName();
                if (inputParamName.contains(prefixTARGET)) {
                    inputParamName = inputParamName.replaceAll(prefixTARGET, "");
                }
                if (inputParamName.contains(prefixSOURCE)) {
                    inputParamName = inputParamName.replaceAll(prefixSOURCE, "");
                }
                inputParameter.setName(inputParamName);
                generateInputParameters(propertyDefinitionKVList, placeholderNodeTemplateProperties, sourceNodeType, inputParameter);
            }
            // get required capability type of open requirement
            QName capabilityType = splitting.getRequiredCapabilityTypeQNameOfRequirement(entry.getKey());
            // create new placeholder node type
            TNodeType placeholderNodeType = splitting.createPlaceholderNodeType(nodeTemplateWithOpenReq.getName());
            QName placeholderQName = new QName(placeholderNodeType.getTargetNamespace(), placeholderNodeType.getName());
            WinerysPropertiesDefinition winerysPropertiesDefinition = sourceNodeType.getWinerysPropertiesDefinition();
            // add properties definition
            placeholderNodeType.setProperties(null);
            if (winerysPropertiesDefinition != null) {
                winerysPropertiesDefinition.setPropertyDefinitions(propertyDefinitionKVList);
                placeholderNodeType.setProperties(winerysPropertiesDefinition);
                String namespace = placeholderNodeType.getWinerysPropertiesDefinition().getNamespace();
                NamespaceManager namespaceManager = RepositoryFactory.getRepository().getNamespaceManager();
                if (!namespaceManager.hasPermanentProperties(namespace)) {
                    namespaceManager.addPermanentNamespace(namespace);
                }
            }
            NodeTypeId placeholderId = new NodeTypeId(placeholderQName);
            // check if placeholder node type exists
            if (repo.exists(placeholderId)) {
                // delete and create new
                RestUtils.delete(placeholderId);
            }
            repo.setElement(placeholderId, placeholderNodeType);
            // create placeholder node template
            TNodeTemplate placeholderNodeTemplate = splitting.createPlaceholderNodeTemplate(topologyTemplate, nodeTemplateWithOpenReq.getName(), placeholderQName);
            // create capability of placeholder node template
            TCapability capa = splitting.createPlaceholderCapability(topologyTemplate, capabilityType);
            ModelUtilities.setPropertiesKV(placeholderNodeTemplate, placeholderNodeTemplateProperties);
            if (placeholderNodeTemplate.getCapabilities() == null) {
                placeholderNodeTemplate.setCapabilities(new ArrayList<>());
            }
            placeholderNodeTemplate.getCapabilities().add(capa);
            for (Map.Entry<QName, String> targetLocation : nodeTemplateWithOpenReq.getOtherAttributes().entrySet()) {
                placeholderNodeTemplate.getOtherAttributes().put(targetLocation.getKey(), targetLocation.getValue());
            }
            // add placeholder to node template and connect with source node template with open requirements
            topologyTemplate.addNodeTemplate(placeholderNodeTemplate);
            ModelUtilities.createRelationshipTemplateAndAddToTopology(nodeTemplateWithOpenReq, placeholderNodeTemplate, ToscaBaseTypes.hostedOnRelationshipType, topologyTemplate);
        }
        LOGGER.debug("PERSISTING");
        RestUtils.persist(this);
        LOGGER.debug("PERSISTED");
        String responseId = this.getServiceTemplate().getId();
        return Response.ok().entity(responseId).build();
    } catch (Exception e) {
        LOGGER.error("Could not fetch requirements and capabilities", e);
        return Response.status(Status.BAD_REQUEST).entity(e.getMessage()).build();
    }
}
Also used : NamespaceManager(org.eclipse.winery.repository.backend.NamespaceManager) PropertyDefinitionKV(org.eclipse.winery.model.tosca.extensions.kvproperties.PropertyDefinitionKV) TInterface(org.eclipse.winery.model.tosca.TInterface) ArrayList(java.util.ArrayList) WinerysPropertiesDefinition(org.eclipse.winery.model.tosca.extensions.kvproperties.WinerysPropertiesDefinition) LinkedHashMap(java.util.LinkedHashMap) TRequirement(org.eclipse.winery.model.tosca.TRequirement) TOperation(org.eclipse.winery.model.tosca.TOperation) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) QName(javax.xml.namespace.QName) TCapability(org.eclipse.winery.model.tosca.TCapability) SplittingException(org.eclipse.winery.repository.splitting.SplittingException) JAXBException(javax.xml.bind.JAXBException) IOException(java.io.IOException) TNodeType(org.eclipse.winery.model.tosca.TNodeType) Splitting(org.eclipse.winery.repository.splitting.Splitting) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) IRepository(org.eclipse.winery.repository.backend.IRepository) TParameter(org.eclipse.winery.model.tosca.TParameter) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 8 with TInterface

use of org.eclipse.winery.model.tosca.TInterface in project winery by eclipse.

the class Splitting method getInputParamListofIncomingRelationshipTemplates.

public List<TParameter> getInputParamListofIncomingRelationshipTemplates(TTopologyTemplate topologyTemplate, List<TRelationshipTemplate> listOfIncomingRelationshipTemplates) {
    List<TParameter> listOfInputs = new ArrayList<>();
    IRepository repo = RepositoryFactory.getRepository();
    for (TRelationshipTemplate incomingRelationshipTemplate : listOfIncomingRelationshipTemplates) {
        TNodeTemplate incomingNodetemplate = ModelUtilities.getSourceNodeTemplateOfRelationshipTemplate(topologyTemplate, incomingRelationshipTemplate);
        NodeTypeId incomingNodeTypeId = new NodeTypeId(incomingNodetemplate.getType());
        TNodeType incomingNodeType = repo.getElement(incomingNodeTypeId);
        List<TInterface> incomingNodeTypeInterfaces = incomingNodeType.getInterfaces();
        RelationshipTypeId incomingRelationshipTypeId = new RelationshipTypeId(incomingRelationshipTemplate.getType());
        if (!incomingNodeTypeInterfaces.isEmpty()) {
            TInterface relevantInterface = null;
            List<TInterface> connectionInterfaces = incomingNodeTypeInterfaces.stream().filter(tInterface -> tInterface.getIdFromIdOrNameField().contains("connection")).collect(Collectors.toList());
            if (connectionInterfaces.size() > 1) {
                TNodeTemplate targetNodeTemplate = ModelUtilities.getTargetNodeTemplateOfRelationshipTemplate(topologyTemplate, incomingRelationshipTemplate);
                for (TInterface tInterface : connectionInterfaces) {
                    int separator = tInterface.getIdFromIdOrNameField().lastIndexOf("/");
                    String prefixRelation = tInterface.getIdFromIdOrNameField().substring(separator + 1);
                    if (targetNodeTemplate.getName() != null && targetNodeTemplate.getName().toLowerCase().contains(prefixRelation.toLowerCase())) {
                        relevantInterface = tInterface;
                    }
                }
            } else {
                relevantInterface = connectionInterfaces.get(0);
            }
            if (relevantInterface != null) {
                for (TOperation tOperation : relevantInterface.getOperations()) {
                    List<TParameter> inputParameters = tOperation.getInputParameters();
                    if (inputParameters != null) {
                        listOfInputs.addAll(inputParameters);
                    }
                }
            }
        }
    }
    return listOfInputs;
}
Also used : SortedSet(java.util.SortedSet) RequirementTypeId(org.eclipse.winery.model.ids.definitions.RequirementTypeId) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) ArrayList(java.util.ArrayList) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) TParameter(org.eclipse.winery.model.tosca.TParameter) TCapabilityType(org.eclipse.winery.model.tosca.TCapabilityType) VersionSupport(org.eclipse.winery.model.version.VersionSupport) BackendUtils(org.eclipse.winery.repository.backend.BackendUtils) Map(java.util.Map) TRequirement(org.eclipse.winery.model.tosca.TRequirement) Util(org.eclipse.winery.repository.common.Util) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) ListUtils.listIsNotNullOrEmpty(org.eclipse.winery.common.ListUtils.listIsNotNullOrEmpty) Set(java.util.Set) IOException(java.io.IOException) TNodeType(org.eclipse.winery.model.tosca.TNodeType) Collectors(java.util.stream.Collectors) TInterface(org.eclipse.winery.model.tosca.TInterface) RelationshipTypeId(org.eclipse.winery.model.ids.definitions.RelationshipTypeId) RepositoryFactory(org.eclipse.winery.repository.backend.RepositoryFactory) CapabilityTypeId(org.eclipse.winery.model.ids.definitions.CapabilityTypeId) Objects(java.util.Objects) List(java.util.List) DASpecification(org.eclipse.winery.repository.driverspecificationandinjection.DASpecification) TCapability(org.eclipse.winery.model.tosca.TCapability) IRepository(org.eclipse.winery.repository.backend.IRepository) TRelationshipType(org.eclipse.winery.model.tosca.TRelationshipType) Optional(java.util.Optional) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) TOperation(org.eclipse.winery.model.tosca.TOperation) ModelUtilities(org.eclipse.winery.model.tosca.utils.ModelUtilities) DriverInjection(org.eclipse.winery.repository.driverspecificationandinjection.DriverInjection) QName(javax.xml.namespace.QName) TRequirementType(org.eclipse.winery.model.tosca.TRequirementType) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) RelationshipTypeId(org.eclipse.winery.model.ids.definitions.RelationshipTypeId) TInterface(org.eclipse.winery.model.tosca.TInterface) ArrayList(java.util.ArrayList) TNodeType(org.eclipse.winery.model.tosca.TNodeType) TOperation(org.eclipse.winery.model.tosca.TOperation) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) TParameter(org.eclipse.winery.model.tosca.TParameter) IRepository(org.eclipse.winery.repository.backend.IRepository) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate)

Example 9 with TInterface

use of org.eclipse.winery.model.tosca.TInterface in project winery by eclipse.

the class GenericArtifactsResource method findInterface.

private Optional<TInterface> findInterface(EntityTypeId id, String interfaceName) {
    TInterface i;
    List<TInterface> interfaces = new ArrayList<>();
    IRepository repository = RepositoryFactory.getRepository();
    if (this.res instanceof NodeTypeImplementationResource || this.res instanceof NodeTypeImplementationsResource) {
        TNodeType nodeType = repository.getElement((NodeTypeId) id);
        if (nodeType.getInterfaces() != null) {
            interfaces.addAll(nodeType.getInterfaces());
        }
    } else if (this.res instanceof RelationshipTypeImplementationResource || this.res instanceof RelationshipTypeImplementationsResource) {
        TRelationshipType relationshipType = repository.getElement((RelationshipTypeId) id);
        if (relationshipType.getSourceInterfaces() != null) {
            interfaces.addAll(relationshipType.getSourceInterfaces());
        }
        if (relationshipType.getTargetInterfaces() != null) {
            interfaces.addAll(relationshipType.getTargetInterfaces());
        }
        if (relationshipType.getInterfaces() != null) {
            interfaces.addAll(relationshipType.getInterfaces());
        }
    }
    Iterator<TInterface> it = interfaces.iterator();
    do {
        i = it.next();
        if (i.getName().equals(interfaceName)) {
            return Optional.of(i);
        }
    } while (it.hasNext());
    return Optional.empty();
}
Also used : TRelationshipType(org.eclipse.winery.model.tosca.TRelationshipType) RelationshipTypeImplementationsResource(org.eclipse.winery.repository.rest.resources.entitytypeimplementations.relationshiptypeimplementations.RelationshipTypeImplementationsResource) RelationshipTypeId(org.eclipse.winery.model.ids.definitions.RelationshipTypeId) TInterface(org.eclipse.winery.model.tosca.TInterface) INodeTemplateResourceOrNodeTypeImplementationResourceOrRelationshipTypeImplementationResource(org.eclipse.winery.repository.rest.resources._support.INodeTemplateResourceOrNodeTypeImplementationResourceOrRelationshipTypeImplementationResource) RelationshipTypeImplementationResource(org.eclipse.winery.repository.rest.resources.entitytypeimplementations.relationshiptypeimplementations.RelationshipTypeImplementationResource) NodeTypeImplementationsResource(org.eclipse.winery.repository.rest.resources.entitytypeimplementations.nodetypeimplementations.NodeTypeImplementationsResource) ArrayList(java.util.ArrayList) NodeTypeImplementationResource(org.eclipse.winery.repository.rest.resources.entitytypeimplementations.nodetypeimplementations.NodeTypeImplementationResource) IRepository(org.eclipse.winery.repository.backend.IRepository) TNodeType(org.eclipse.winery.model.tosca.TNodeType)

Example 10 with TInterface

use of org.eclipse.winery.model.tosca.TInterface in project winery by eclipse.

the class GeneratorTest method testInOut.

@Test
public void testInOut() throws Exception {
    TInterface tinterface = new TInterface();
    tinterface.setName("http://www.example.org/interfaces/lifecycle");
    TOperation op1 = new TOperation();
    op1.setName("Op1InOut");
    tinterface.getOperation().add(op1);
    TOperation.InputParameters op1InputParameters = new TOperation.InputParameters();
    TParameter op1ip1 = new TParameter();
    op1ip1.setName("op1ip1");
    op1ip1.setType("xs:string");
    op1InputParameters.getInputParameter().add(op1ip1);
    TParameter op1ip2 = new TParameter();
    op1ip2.setName("op1ip2");
    op1ip2.setType("xs:string");
    op1InputParameters.getInputParameter().add(op1ip2);
    op1.setInputParameters(op1InputParameters);
    TOperation.OutputParameters op1OutputParameters = new TOperation.OutputParameters();
    TParameter op1op1 = new TParameter();
    op1op1.setName("op1op1");
    op1op1.setType("xs:string");
    op1OutputParameters.getOutputParameter().add(op1op1);
    TParameter op1op2 = new TParameter();
    op1op2.setName("op1op2");
    op1op1.setType("xs:string");
    op1OutputParameters.getOutputParameter().add(op1op2);
    op1.setOutputParameters(op1OutputParameters);
    TNodeType nodeType = new TNodeType();
    nodeType.setName("test");
    nodeType.setTargetNamespace("http://asd.com");
    Generator gen = new Generator(tinterface, "org.opentosca.ia", new URL("http://asd.com"), "testname", WORKING_DIR.toFile());
    Path generateProject = gen.generateProject();
    System.out.println(generateProject);
}
Also used : Path(java.nio.file.Path) TInterface(org.eclipse.winery.model.tosca.TInterface) TOperation(org.eclipse.winery.model.tosca.TOperation) TParameter(org.eclipse.winery.model.tosca.TParameter) URL(java.net.URL) TNodeType(org.eclipse.winery.model.tosca.TNodeType) Test(org.junit.Test)

Aggregations

TInterface (org.eclipse.winery.model.tosca.TInterface)15 TNodeType (org.eclipse.winery.model.tosca.TNodeType)10 TOperation (org.eclipse.winery.model.tosca.TOperation)10 URL (java.net.URL)6 ArrayList (java.util.ArrayList)6 QName (javax.xml.namespace.QName)5 TParameter (org.eclipse.winery.model.tosca.TParameter)5 IRepository (org.eclipse.winery.repository.backend.IRepository)5 IOException (java.io.IOException)4 Path (java.nio.file.Path)4 TRelationshipType (org.eclipse.winery.model.tosca.TRelationshipType)4 LinkedHashMap (java.util.LinkedHashMap)3 NodeTypeId (org.eclipse.winery.model.ids.definitions.NodeTypeId)3 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)3 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)3 PropertyDefinitionKV (org.eclipse.winery.model.tosca.extensions.kvproperties.PropertyDefinitionKV)3 WinerysPropertiesDefinition (org.eclipse.winery.model.tosca.extensions.kvproperties.WinerysPropertiesDefinition)3 Test (org.junit.Test)3 Map (java.util.Map)2 Produces (javax.ws.rs.Produces)2