Search in sources :

Example 1 with PolicyTemplateId

use of org.eclipse.winery.common.ids.definitions.PolicyTemplateId in project winery by eclipse.

the class BackendUtils method createWrapperDefinitionsAndInitialEmptyElement.

public static Definitions createWrapperDefinitionsAndInitialEmptyElement(IRepository repository, DefinitionsChildId id) {
    final Definitions definitions = createWrapperDefinitions(id);
    HasIdInIdOrNameField element;
    if (id instanceof RelationshipTypeImplementationId) {
        element = new TRelationshipTypeImplementation();
    } else if (id instanceof NodeTypeImplementationId) {
        element = new TNodeTypeImplementation();
    } else if (id instanceof RequirementTypeId) {
        element = new TRequirementType();
    } else if (id instanceof NodeTypeId) {
        element = new TNodeType();
    } else if (id instanceof RelationshipTypeId) {
        element = new TRelationshipType();
    } else if (id instanceof CapabilityTypeId) {
        element = new TCapabilityType();
    } else if (id instanceof ArtifactTypeId) {
        element = new TArtifactType();
    } else if (id instanceof PolicyTypeId) {
        element = new TPolicyType();
    } else if (id instanceof PolicyTemplateId) {
        element = new TPolicyTemplate();
    } else if (id instanceof ServiceTemplateId) {
        element = new TServiceTemplate();
    } else if (id instanceof ArtifactTemplateId) {
        element = new TArtifactTemplate();
    } else if (id instanceof XSDImportId) {
        // TImport has no id; thus directly generating it without setting an id
        TImport tImport = new TImport();
        definitions.setElement(tImport);
        return definitions;
    } else {
        throw new IllegalStateException("Unhandled id branch. Could happen for XSDImportId");
    }
    copyIdToFields(element, id);
    definitions.setElement((TExtensibleElements) element);
    return definitions;
}
Also used : ArtifactTypeId(org.eclipse.winery.common.ids.definitions.ArtifactTypeId) TArtifactTemplate(org.eclipse.winery.model.tosca.TArtifactTemplate) TImport(org.eclipse.winery.model.tosca.TImport) TCapabilityType(org.eclipse.winery.model.tosca.TCapabilityType) TRequirementType(org.eclipse.winery.model.tosca.TRequirementType) TNodeTypeImplementation(org.eclipse.winery.model.tosca.TNodeTypeImplementation) HasIdInIdOrNameField(org.eclipse.winery.model.tosca.HasIdInIdOrNameField) TArtifactType(org.eclipse.winery.model.tosca.TArtifactType) TPolicyType(org.eclipse.winery.model.tosca.TPolicyType) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) NodeTypeImplementationId(org.eclipse.winery.common.ids.definitions.NodeTypeImplementationId) XSDImportId(org.eclipse.winery.common.ids.definitions.imports.XSDImportId) RelationshipTypeId(org.eclipse.winery.common.ids.definitions.RelationshipTypeId) CapabilityTypeId(org.eclipse.winery.common.ids.definitions.CapabilityTypeId) TDefinitions(org.eclipse.winery.model.tosca.TDefinitions) Definitions(org.eclipse.winery.model.tosca.Definitions) RelationshipTypeImplementationId(org.eclipse.winery.common.ids.definitions.RelationshipTypeImplementationId) ServiceTemplateId(org.eclipse.winery.common.ids.definitions.ServiceTemplateId) ArtifactTemplateId(org.eclipse.winery.common.ids.definitions.ArtifactTemplateId) TNodeType(org.eclipse.winery.model.tosca.TNodeType) TRelationshipType(org.eclipse.winery.model.tosca.TRelationshipType) TPolicyTemplate(org.eclipse.winery.model.tosca.TPolicyTemplate) PolicyTypeId(org.eclipse.winery.common.ids.definitions.PolicyTypeId) TRelationshipTypeImplementation(org.eclipse.winery.model.tosca.TRelationshipTypeImplementation) RequirementTypeId(org.eclipse.winery.common.ids.definitions.RequirementTypeId) PolicyTemplateId(org.eclipse.winery.common.ids.definitions.PolicyTemplateId) NodeTypeId(org.eclipse.winery.common.ids.definitions.NodeTypeId)

Example 2 with PolicyTemplateId

use of org.eclipse.winery.common.ids.definitions.PolicyTemplateId in project winery by eclipse.

the class BackendUtilsTestWithGitBackedRepository method initializePropertiesDoesNothingInTheCaseOfXmlElemenetPropperties.

@Test
public void initializePropertiesDoesNothingInTheCaseOfXmlElemenetPropperties() throws Exception {
    this.setRevisionTo("origin/plain");
    PolicyTemplateId policyTemplateId = new PolicyTemplateId("http://www.example.org", "policytemplate", false);
    // create prepared policy template
    final IRepository repository = RepositoryFactory.getRepository();
    final Definitions definitions = BackendUtils.createWrapperDefinitionsAndInitialEmptyElement(repository, policyTemplateId);
    final TPolicyTemplate policyTemplate = (TPolicyTemplate) definitions.getElement();
    QName policyTypeQName = new QName("http://plain.winery.opentosca.org/policytypes", "PolicyTypeWithXmlElementProperty");
    policyTemplate.setType(policyTypeQName);
    BackendUtils.initializeProperties(repository, policyTemplate);
    Assert.assertNull(policyTemplate.getProperties());
}
Also used : TPolicyTemplate(org.eclipse.winery.model.tosca.TPolicyTemplate) QName(javax.xml.namespace.QName) Definitions(org.eclipse.winery.model.tosca.Definitions) PolicyTemplateId(org.eclipse.winery.common.ids.definitions.PolicyTemplateId) Test(org.junit.Test)

Example 3 with PolicyTemplateId

use of org.eclipse.winery.common.ids.definitions.PolicyTemplateId in project winery by eclipse.

the class BackendUtilsTestWithGitBackedRepository method initializePropertiesGeneratesCorrectKvProperties.

@Test
public void initializePropertiesGeneratesCorrectKvProperties() throws Exception {
    this.setRevisionTo("origin/plain");
    PolicyTemplateId policyTemplateId = new PolicyTemplateId("http://www.example.org", "policytemplate", false);
    // create prepared policy template
    final IRepository repository = RepositoryFactory.getRepository();
    final Definitions definitions = BackendUtils.createWrapperDefinitionsAndInitialEmptyElement(repository, policyTemplateId);
    final TPolicyTemplate policyTemplate = (TPolicyTemplate) definitions.getElement();
    QName policyTypeQName = new QName("http://plain.winery.opentosca.org/policytypes", "PolicyTypeWithTwoKvProperties");
    policyTemplate.setType(policyTypeQName);
    BackendUtils.initializeProperties(repository, policyTemplate);
    Assert.assertNotNull(policyTemplate.getProperties());
    LinkedHashMap<String, String> kvProperties = policyTemplate.getProperties().getKVProperties();
    LinkedHashMap<String, String> expectedPropertyKVS = new LinkedHashMap<>();
    expectedPropertyKVS.put("key1", "");
    expectedPropertyKVS.put("key2", "");
    Assert.assertEquals(expectedPropertyKVS, kvProperties);
}
Also used : TPolicyTemplate(org.eclipse.winery.model.tosca.TPolicyTemplate) QName(javax.xml.namespace.QName) Definitions(org.eclipse.winery.model.tosca.Definitions) PolicyTemplateId(org.eclipse.winery.common.ids.definitions.PolicyTemplateId) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 4 with PolicyTemplateId

use of org.eclipse.winery.common.ids.definitions.PolicyTemplateId in project winery by eclipse.

the class IGenericRepository method getReferencedDefinitionsChildIds.

default Collection<DefinitionsChildId> getReferencedDefinitionsChildIds(ServiceTemplateId id) {
    // We have to use a HashSet to ensure that no duplicate ids are added
    // E.g., there may be multiple relationship templates having the same type
    Collection<DefinitionsChildId> ids = new HashSet<>();
    TServiceTemplate serviceTemplate = this.getElement(id);
    // add included things to export queue
    TBoundaryDefinitions boundaryDefs;
    if ((boundaryDefs = serviceTemplate.getBoundaryDefinitions()) != null) {
        TBoundaryDefinitions.Policies policies = boundaryDefs.getPolicies();
        if (policies != null) {
            for (TPolicy policy : policies.getPolicy()) {
                PolicyTypeId policyTypeId = new PolicyTypeId(policy.getPolicyType());
                ids.add(policyTypeId);
                PolicyTemplateId policyTemplateId = new PolicyTemplateId(policy.getPolicyRef());
                ids.add(policyTemplateId);
            }
        }
    // reqs and caps don't have to be exported here as they are references to existing reqs/caps (of nested node templates)
    }
    if (serviceTemplate.getTopologyTemplate() != null) {
        for (TEntityTemplate entityTemplate : serviceTemplate.getTopologyTemplate().getNodeTemplateOrRelationshipTemplate()) {
            QName qname = entityTemplate.getType();
            if (entityTemplate instanceof TNodeTemplate) {
                ids.add(new NodeTypeId(qname));
                TNodeTemplate n = (TNodeTemplate) entityTemplate;
                // crawl through deployment artifacts
                TDeploymentArtifacts deploymentArtifacts = n.getDeploymentArtifacts();
                if (deploymentArtifacts != null) {
                    List<TDeploymentArtifact> das = deploymentArtifacts.getDeploymentArtifact();
                    for (TDeploymentArtifact da : das) {
                        ids.add(new ArtifactTypeId(da.getArtifactType()));
                        if ((qname = da.getArtifactRef()) != null) {
                            ids.add(new ArtifactTemplateId(qname));
                        }
                    }
                }
                // crawl through reqs/caps
                TNodeTemplate.Requirements requirements = n.getRequirements();
                if (requirements != null) {
                    for (TRequirement req : requirements.getRequirement()) {
                        QName type = req.getType();
                        RequirementTypeId rtId = new RequirementTypeId(type);
                        ids.add(rtId);
                    }
                }
                TNodeTemplate.Capabilities capabilities = n.getCapabilities();
                if (capabilities != null) {
                    for (TCapability cap : capabilities.getCapability()) {
                        QName type = cap.getType();
                        CapabilityTypeId ctId = new CapabilityTypeId(type);
                        ids.add(ctId);
                    }
                }
                // crawl through policies
                org.eclipse.winery.model.tosca.TNodeTemplate.Policies policies = n.getPolicies();
                if (policies != null) {
                    for (TPolicy pol : policies.getPolicy()) {
                        QName type = pol.getPolicyType();
                        PolicyTypeId ctId = new PolicyTypeId(type);
                        ids.add(ctId);
                        QName template = pol.getPolicyRef();
                        if (template != null) {
                            PolicyTemplateId policyTemplateId = new PolicyTemplateId(template);
                            ids.add(policyTemplateId);
                        }
                    }
                }
            } else {
                assert (entityTemplate instanceof TRelationshipTemplate);
                ids.add(new RelationshipTypeId(qname));
            }
        }
    }
    return ids;
}
Also used : DefinitionsChildId(org.eclipse.winery.common.ids.definitions.DefinitionsChildId) ArtifactTypeId(org.eclipse.winery.common.ids.definitions.ArtifactTypeId) TRequirement(org.eclipse.winery.model.tosca.TRequirement) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) TDeploymentArtifact(org.eclipse.winery.model.tosca.TDeploymentArtifact) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) HashSet(java.util.HashSet) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) RelationshipTypeId(org.eclipse.winery.common.ids.definitions.RelationshipTypeId) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) CapabilityTypeId(org.eclipse.winery.common.ids.definitions.CapabilityTypeId) QName(javax.xml.namespace.QName) TCapability(org.eclipse.winery.model.tosca.TCapability) TBoundaryDefinitions(org.eclipse.winery.model.tosca.TBoundaryDefinitions) ArtifactTemplateId(org.eclipse.winery.common.ids.definitions.ArtifactTemplateId) TDeploymentArtifacts(org.eclipse.winery.model.tosca.TDeploymentArtifacts) PolicyTypeId(org.eclipse.winery.common.ids.definitions.PolicyTypeId) RequirementTypeId(org.eclipse.winery.common.ids.definitions.RequirementTypeId) TPolicy(org.eclipse.winery.model.tosca.TPolicy) PolicyTemplateId(org.eclipse.winery.common.ids.definitions.PolicyTemplateId) NodeTypeId(org.eclipse.winery.common.ids.definitions.NodeTypeId)

Example 5 with PolicyTemplateId

use of org.eclipse.winery.common.ids.definitions.PolicyTemplateId in project winery by eclipse.

the class AbstractComponentsResource method onPost.

/**
 * Creates a new component instance in the given namespace
 *
 * @param namespace plain namespace
 * @param name      the name; used as id
 */
protected ResourceCreationResult onPost(String namespace, String name) {
    ResourceCreationResult res;
    if (StringUtils.isEmpty(namespace) || StringUtils.isEmpty(name)) {
        res = new ResourceCreationResult(Status.BAD_REQUEST);
    } else {
        String id = RestUtils.createXMLidAsString(name);
        DefinitionsChildId tcId;
        try {
            tcId = this.getDefinitionsChildId(namespace, id, false);
            res = this.createComponentInstance(tcId);
            // in case the resource additionally supports a name attribute, we set the original name
            if (res.getStatus().equals(Status.CREATED)) {
                if ((tcId instanceof ServiceTemplateId) || (tcId instanceof ArtifactTemplateId) || (tcId instanceof PolicyTemplateId)) {
                    // these three types have an additional name (instead of a pure id)
                    // we store the name
                    IHasName resource = (IHasName) AbstractComponentsResource.getComponentInstaceResource(tcId);
                    resource.setName(name);
                }
            }
        } catch (Exception e) {
            AbstractComponentsResource.LOGGER.debug("Could not create id instance", e);
            res = new ResourceCreationResult(Status.INTERNAL_SERVER_ERROR);
        }
    }
    return res;
}
Also used : DefinitionsChildId(org.eclipse.winery.common.ids.definitions.DefinitionsChildId) PolicyTemplateId(org.eclipse.winery.common.ids.definitions.PolicyTemplateId) ServiceTemplateId(org.eclipse.winery.common.ids.definitions.ServiceTemplateId) ArtifactTemplateId(org.eclipse.winery.common.ids.definitions.ArtifactTemplateId) NotFoundException(com.sun.jersey.api.NotFoundException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

PolicyTemplateId (org.eclipse.winery.common.ids.definitions.PolicyTemplateId)5 QName (javax.xml.namespace.QName)3 ArtifactTemplateId (org.eclipse.winery.common.ids.definitions.ArtifactTemplateId)3 Definitions (org.eclipse.winery.model.tosca.Definitions)3 TPolicyTemplate (org.eclipse.winery.model.tosca.TPolicyTemplate)3 ArtifactTypeId (org.eclipse.winery.common.ids.definitions.ArtifactTypeId)2 CapabilityTypeId (org.eclipse.winery.common.ids.definitions.CapabilityTypeId)2 DefinitionsChildId (org.eclipse.winery.common.ids.definitions.DefinitionsChildId)2 NodeTypeId (org.eclipse.winery.common.ids.definitions.NodeTypeId)2 PolicyTypeId (org.eclipse.winery.common.ids.definitions.PolicyTypeId)2 RelationshipTypeId (org.eclipse.winery.common.ids.definitions.RelationshipTypeId)2 RequirementTypeId (org.eclipse.winery.common.ids.definitions.RequirementTypeId)2 ServiceTemplateId (org.eclipse.winery.common.ids.definitions.ServiceTemplateId)2 TServiceTemplate (org.eclipse.winery.model.tosca.TServiceTemplate)2 Test (org.junit.Test)2 NotFoundException (com.sun.jersey.api.NotFoundException)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1