Search in sources :

Example 1 with TPolicyTemplate

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

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

the class IGenericRepository method getReferencedDefinitionsChildIds.

default Collection<DefinitionsChildId> getReferencedDefinitionsChildIds(PolicyTemplateId id) {
    Collection<DefinitionsChildId> ids = new ArrayList<>();
    final TPolicyTemplate element = this.getElement(id);
    ids.add(new PolicyTypeId(element.getType()));
    return ids;
}
Also used : TPolicyTemplate(org.eclipse.winery.model.tosca.TPolicyTemplate) PolicyTypeId(org.eclipse.winery.common.ids.definitions.PolicyTypeId) DefinitionsChildId(org.eclipse.winery.common.ids.definitions.DefinitionsChildId) ArrayList(java.util.ArrayList)

Example 3 with TPolicyTemplate

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

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

Aggregations

TPolicyTemplate (org.eclipse.winery.model.tosca.TPolicyTemplate)4 PolicyTemplateId (org.eclipse.winery.common.ids.definitions.PolicyTemplateId)3 Definitions (org.eclipse.winery.model.tosca.Definitions)3 QName (javax.xml.namespace.QName)2 PolicyTypeId (org.eclipse.winery.common.ids.definitions.PolicyTypeId)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 ArtifactTemplateId (org.eclipse.winery.common.ids.definitions.ArtifactTemplateId)1 ArtifactTypeId (org.eclipse.winery.common.ids.definitions.ArtifactTypeId)1 CapabilityTypeId (org.eclipse.winery.common.ids.definitions.CapabilityTypeId)1 DefinitionsChildId (org.eclipse.winery.common.ids.definitions.DefinitionsChildId)1 NodeTypeId (org.eclipse.winery.common.ids.definitions.NodeTypeId)1 NodeTypeImplementationId (org.eclipse.winery.common.ids.definitions.NodeTypeImplementationId)1 RelationshipTypeId (org.eclipse.winery.common.ids.definitions.RelationshipTypeId)1 RelationshipTypeImplementationId (org.eclipse.winery.common.ids.definitions.RelationshipTypeImplementationId)1 RequirementTypeId (org.eclipse.winery.common.ids.definitions.RequirementTypeId)1 ServiceTemplateId (org.eclipse.winery.common.ids.definitions.ServiceTemplateId)1 XSDImportId (org.eclipse.winery.common.ids.definitions.imports.XSDImportId)1 HasIdInIdOrNameField (org.eclipse.winery.model.tosca.HasIdInIdOrNameField)1