Search in sources :

Example 1 with TArtifactType

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

the class BackendUtils method createWrapperDefinitionsAndInitialEmptyElement.

public static TDefinitions createWrapperDefinitionsAndInitialEmptyElement(IRepository repository, DefinitionsChildId id) {
    final TDefinitions definitions = createWrapperDefinitions(id, repository);
    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 DataTypeId) {
        element = new TDataType();
    } 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 ComplianceRuleId) {
        element = new OTComplianceRule(new OTComplianceRule.Builder(id.getXmlId().getDecoded()));
    } else if (id instanceof PatternRefinementModelId) {
        element = new OTPatternRefinementModel(new OTPatternRefinementModel.Builder());
    } else if (id instanceof TopologyFragmentRefinementModelId) {
        element = new OTTopologyFragmentRefinementModel(new OTPatternRefinementModel.Builder());
    } else if (id instanceof TestRefinementModelId) {
        element = new OTTestRefinementModel(new OTTestRefinementModel.Builder());
    } else if (id instanceof InterfaceTypeId) {
        element = new TInterfaceType();
    } 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 : OTTopologyFragmentRefinementModel(org.eclipse.winery.model.tosca.extensions.OTTopologyFragmentRefinementModel) ArtifactTypeId(org.eclipse.winery.model.ids.definitions.ArtifactTypeId) TArtifactTemplate(org.eclipse.winery.model.tosca.TArtifactTemplate) TestRefinementModelId(org.eclipse.winery.model.ids.extensions.TestRefinementModelId) TImport(org.eclipse.winery.model.tosca.TImport) TCapabilityType(org.eclipse.winery.model.tosca.TCapabilityType) TDataType(org.eclipse.winery.model.tosca.TDataType) OTTestRefinementModel(org.eclipse.winery.model.tosca.extensions.OTTestRefinementModel) TRequirementType(org.eclipse.winery.model.tosca.TRequirementType) TNodeTypeImplementation(org.eclipse.winery.model.tosca.TNodeTypeImplementation) HasIdInIdOrNameField(org.eclipse.winery.model.tosca.HasIdInIdOrNameField) ComplianceRuleId(org.eclipse.winery.model.ids.extensions.ComplianceRuleId) InterfaceTypeId(org.eclipse.winery.model.ids.definitions.InterfaceTypeId) TArtifactType(org.eclipse.winery.model.tosca.TArtifactType) TPolicyType(org.eclipse.winery.model.tosca.TPolicyType) TopologyFragmentRefinementModelId(org.eclipse.winery.model.ids.extensions.TopologyFragmentRefinementModelId) TDefinitions(org.eclipse.winery.model.tosca.TDefinitions) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) NodeTypeImplementationId(org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId) XSDImportId(org.eclipse.winery.model.ids.definitions.imports.XSDImportId) RelationshipTypeId(org.eclipse.winery.model.ids.definitions.RelationshipTypeId) CapabilityTypeId(org.eclipse.winery.model.ids.definitions.CapabilityTypeId) RelationshipTypeImplementationId(org.eclipse.winery.model.ids.definitions.RelationshipTypeImplementationId) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) TNodeType(org.eclipse.winery.model.tosca.TNodeType) TRelationshipType(org.eclipse.winery.model.tosca.TRelationshipType) TPolicyTemplate(org.eclipse.winery.model.tosca.TPolicyTemplate) PatternRefinementModelId(org.eclipse.winery.model.ids.extensions.PatternRefinementModelId) PolicyTypeId(org.eclipse.winery.model.ids.definitions.PolicyTypeId) TRelationshipTypeImplementation(org.eclipse.winery.model.tosca.TRelationshipTypeImplementation) RequirementTypeId(org.eclipse.winery.model.ids.definitions.RequirementTypeId) DataTypeId(org.eclipse.winery.model.ids.definitions.DataTypeId) TInterfaceType(org.eclipse.winery.model.tosca.TInterfaceType) PolicyTemplateId(org.eclipse.winery.model.ids.definitions.PolicyTemplateId) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) OTComplianceRule(org.eclipse.winery.model.tosca.extensions.OTComplianceRule) OTPatternRefinementModel(org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel)

Example 2 with TArtifactType

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

the class DASpecification method getConcreteDA.

private static TDeploymentArtifact getConcreteDA(TDeploymentArtifact abstractDeploymentArtifact, List<TDeploymentArtifact> candidates) {
    for (TDeploymentArtifact candidate : candidates) {
        List<TArtifactType> artifactTypeHierarchy = getArtifactTypeHierarchy(getArtifactTypeOfDA(candidate));
        TArtifactType abstractArtifactType = getArtifactTypeOfDA(abstractDeploymentArtifact);
        for (TArtifactType containedArtifacts : artifactTypeHierarchy) {
            // Can not be realized with streams because a check if the abstract Type is contained in the hierarchy doesn't work
            if (containedArtifacts.getTargetNamespace().equals(abstractArtifactType.getTargetNamespace()) && containedArtifacts.getName() != null && containedArtifacts.getName().equals(abstractArtifactType.getName())) {
                return candidate;
            }
        }
    }
    return null;
}
Also used : TArtifactType(org.eclipse.winery.model.tosca.TArtifactType) TDeploymentArtifact(org.eclipse.winery.model.tosca.TDeploymentArtifact)

Example 3 with TArtifactType

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

the class Y2XConverter method refactorImplementationArtifacts.

private Map<String, TArtifactDefinition> refactorImplementationArtifacts(Map<String, TArtifactDefinition> map, org.eclipse.winery.model.tosca.yaml.TNodeType node) {
    Map<String, TArtifactDefinition> implementationArtifacts = new LinkedHashMap<>(map.entrySet().stream().filter(entry -> Objects.nonNull(entry.getValue()) && !referenceVisitor.getTypes(entry.getValue().getType(), "TArtifactType").getNames().contains(Defaults.DEPLOYMENT_ARTIFACTS)).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)));
    // Convert Interface.Operations Artifacts to ArtifactDefinition
    for (Map.Entry<String, TInterfaceDefinition> entry : node.getInterfaces().entrySet()) {
        entry.getValue().getOperations().entrySet().stream().filter(operation -> operation.getValue() != null && operation.getValue().getImplementation() != null).forEach(operation -> {
            String interfaceName = entry.getKey();
            String operationName = operation.getKey();
            TImplementation implementation = operation.getValue().getImplementation();
            List<QName> list = implementation.getDependencies();
            if (implementation.getPrimary() != null) {
                list.add(implementation.getPrimary());
            }
            for (QName artifactQName : list) {
                String artifactName = artifactQName.getLocalPart();
                if (implementationArtifacts.containsKey(artifactName)) {
                    TImplementationArtifactDefinition.Builder iABuilder = new TImplementationArtifactDefinition.Builder(implementationArtifacts.get(artifactName));
                    TArtifactDefinition old = implementationArtifacts.get(artifactName);
                    // Check if implementation artifact is already defined for other interfaces
                    if (!(old instanceof TImplementationArtifactDefinition) || ((TImplementationArtifactDefinition) old).getInterfaceName() == null || ((TImplementationArtifactDefinition) old).getInterfaceName().equals(interfaceName)) {
                        iABuilder.setInterfaceName(interfaceName);
                        // Check if ArtifactDefinition is used in more than one operation implementation
                        if (old instanceof TImplementationArtifactDefinition && ((TImplementationArtifactDefinition) old).getInterfaceName().equals(interfaceName) && !(((TImplementationArtifactDefinition) old).getOperationName().equals(operationName))) {
                            iABuilder.setOperationName(null);
                        } else {
                            iABuilder.setOperationName(operationName);
                        }
                    } else {
                        // if interface is not ImplementationArtifactDefinition
                        // or interface not set
                        // or interface already defined
                        iABuilder.setInterfaceName(null);
                    }
                    iABuilder.setOperationName(operationName);
                    implementationArtifacts.put(artifactName, iABuilder.build());
                }
            }
        });
    }
    return implementationArtifacts;
}
Also used : java.util(java.util) SchemaVisitor(org.eclipse.winery.yaml.converter.yaml.visitors.SchemaVisitor) TRequirementDefinition(org.eclipse.winery.model.tosca.TRequirementDefinition) TMapRequirementAssignment(org.eclipse.winery.model.tosca.yaml.support.TMapRequirementAssignment) ReferenceVisitor(org.eclipse.winery.yaml.converter.yaml.visitors.ReferenceVisitor) LoggerFactory(org.slf4j.LoggerFactory) Reader(org.eclipse.winery.yaml.common.reader.yaml.Reader) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) TPolicyType(org.eclipse.winery.model.tosca.TPolicyType) Nullable(org.eclipse.jdt.annotation.Nullable) TCapabilityType(org.eclipse.winery.model.tosca.TCapabilityType) MultiException(org.eclipse.winery.yaml.common.exception.MultiException) Namespaces(org.eclipse.winery.yaml.common.Namespaces) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) Defaults(org.eclipse.winery.yaml.common.Defaults) TypeConverter(org.eclipse.winery.yaml.converter.yaml.support.TypeConverter) Path(java.nio.file.Path) TArtifactType(org.eclipse.winery.model.tosca.TArtifactType) org.eclipse.winery.model.tosca.yaml(org.eclipse.winery.model.tosca.yaml) TCapabilityDefinition(org.eclipse.winery.model.tosca.TCapabilityDefinition) TEntityType(org.eclipse.winery.model.tosca.TEntityType) Logger(org.slf4j.Logger) TNodeType(org.eclipse.winery.model.tosca.TNodeType) Util(org.eclipse.winery.common.Util) Collectors(java.util.stream.Collectors) File(java.io.File) TImplementationArtifactDefinition(org.eclipse.winery.yaml.converter.yaml.support.extension.TImplementationArtifactDefinition) Stream(java.util.stream.Stream) org.eclipse.winery.model.tosca(org.eclipse.winery.model.tosca) IRepository(org.eclipse.winery.repository.backend.IRepository) TRelationshipType(org.eclipse.winery.model.tosca.TRelationshipType) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) Metadata(org.eclipse.winery.model.tosca.yaml.support.Metadata) WriterUtils(org.eclipse.winery.yaml.common.writer.WriterUtils) QName(javax.xml.namespace.QName) NonNull(org.eclipse.jdt.annotation.NonNull) Converter(org.eclipse.winery.yaml.converter.Converter) AssignmentBuilder(org.eclipse.winery.yaml.converter.yaml.support.AssignmentBuilder) QName(javax.xml.namespace.QName) AssignmentBuilder(org.eclipse.winery.yaml.converter.yaml.support.AssignmentBuilder) TImplementationArtifactDefinition(org.eclipse.winery.yaml.converter.yaml.support.extension.TImplementationArtifactDefinition)

Example 4 with TArtifactType

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

the class DASpecificationTest method getArtifactTypeOfDA.

@Test
public void getArtifactTypeOfDA() throws Exception {
    setRevisionTo("af529e513388dc9358a8f700757d8dc59aba3a55");
    ServiceTemplateId id = new ServiceTemplateId("http://winery.opentosca.org/test/servicetemplates/ponyuniverse/daspecifier", "DASpecificationTest", false);
    TTopologyTemplate topologyTemplate = this.repository.getElement(id).getTopologyTemplate();
    assertNotNull(topologyTemplate);
    TNodeTemplate nodeTemplateWithAbstractDA = topologyTemplate.getNodeTemplate("shetland_pony");
    assertNotNull(nodeTemplateWithAbstractDA);
    assertNotNull(nodeTemplateWithAbstractDA.getDeploymentArtifacts());
    TDeploymentArtifact deploymentArtifact = nodeTemplateWithAbstractDA.getDeploymentArtifacts().get(0);
    QName artifactTypeQName = deploymentArtifact.getArtifactType();
    ArtifactTypeId artifactTypeId = new ArtifactTypeId(artifactTypeQName);
    TArtifactType artifactType = this.repository.getElement(artifactTypeId);
    assertEquals(artifactType.getTargetNamespace(), DASpecification.getArtifactTypeOfDA(nodeTemplateWithAbstractDA.getDeploymentArtifacts().get(0)).getTargetNamespace());
    assertEquals(artifactType.getName(), DASpecification.getArtifactTypeOfDA(nodeTemplateWithAbstractDA.getDeploymentArtifacts().get(0)).getName());
}
Also used : ArtifactTypeId(org.eclipse.winery.model.ids.definitions.ArtifactTypeId) QName(javax.xml.namespace.QName) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) TArtifactType(org.eclipse.winery.model.tosca.TArtifactType) TDeploymentArtifact(org.eclipse.winery.model.tosca.TDeploymentArtifact) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) Test(org.junit.jupiter.api.Test)

Example 5 with TArtifactType

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

the class DASpecificationTest method getArtifactTypeHierarchy.

@Test
public void getArtifactTypeHierarchy() throws Exception {
    setRevisionTo("af529e513388dc9358a8f700757d8dc59aba3a55");
    ServiceTemplateId id = new ServiceTemplateId("http://winery.opentosca.org/test/servicetemplates/ponyuniverse/daspecifier", "DASpecificationTest", false);
    TTopologyTemplate topologyTemplate = this.repository.getElement(id).getTopologyTemplate();
    assertNotNull(topologyTemplate);
    TNodeTemplate nodeTemplate = topologyTemplate.getNodeTemplate("westernequipment");
    assertNotNull(nodeTemplate);
    assertNotNull(nodeTemplate.getDeploymentArtifacts());
    List<TArtifactType> artifactTypes = DASpecification.getArtifactTypeHierarchy(DASpecification.getArtifactTypeOfDA(nodeTemplate.getDeploymentArtifacts().get(0)));
    List<String> artifactTypeNames = new ArrayList<>();
    artifactTypes.forEach(at -> artifactTypeNames.add(at.getName()));
    assertEquals(2, artifactTypes.size());
    assertTrue(artifactTypeNames.contains("WesternEquipment_Pony"));
    assertTrue(artifactTypeNames.contains("PonyEquipment"));
}
Also used : TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) TArtifactType(org.eclipse.winery.model.tosca.TArtifactType) ArrayList(java.util.ArrayList) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) Test(org.junit.jupiter.api.Test)

Aggregations

TArtifactType (org.eclipse.winery.model.tosca.TArtifactType)7 QName (javax.xml.namespace.QName)4 ArtifactTypeId (org.eclipse.winery.model.ids.definitions.ArtifactTypeId)4 ServiceTemplateId (org.eclipse.winery.model.ids.definitions.ServiceTemplateId)3 TDeploymentArtifact (org.eclipse.winery.model.tosca.TDeploymentArtifact)3 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)3 ArrayList (java.util.ArrayList)2 NonNull (org.eclipse.jdt.annotation.NonNull)2 ArtifactTemplateId (org.eclipse.winery.model.ids.definitions.ArtifactTemplateId)2 TArtifactTemplate (org.eclipse.winery.model.tosca.TArtifactTemplate)2 TCapabilityType (org.eclipse.winery.model.tosca.TCapabilityType)2 TNodeType (org.eclipse.winery.model.tosca.TNodeType)2 TPolicyType (org.eclipse.winery.model.tosca.TPolicyType)2 TRelationshipType (org.eclipse.winery.model.tosca.TRelationshipType)2 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)2 IRepository (org.eclipse.winery.repository.backend.IRepository)2 Test (org.junit.jupiter.api.Test)2 ApiOperation (io.swagger.annotations.ApiOperation)1 File (java.io.File)1 IOException (java.io.IOException)1