Search in sources :

Example 6 with DefinitionsChildId

use of org.eclipse.winery.model.ids.definitions.DefinitionsChildId in project winery by eclipse.

the class IRepository method getReferencedDefinitionsChildIds.

default Collection<DefinitionsChildId> getReferencedDefinitionsChildIds(ComplianceRuleId 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<>();
    OTComplianceRule complianceRule = this.getElement(id);
    // TODO extend to required Structure
    if (complianceRule.getIdentifier() != null) {
        for (TEntityTemplate entityTemplate : complianceRule.getIdentifier().getNodeTemplateOrRelationshipTemplate()) {
            QName qname = entityTemplate.getType();
            if (entityTemplate instanceof TNodeTemplate) {
                ids.add(new NodeTypeId(qname));
                TNodeTemplate n = (TNodeTemplate) entityTemplate;
                // crawl through deployment artifacts
                List<TDeploymentArtifact> deploymentArtifacts = n.getDeploymentArtifacts();
                if (deploymentArtifacts != null) {
                    for (TDeploymentArtifact da : deploymentArtifacts) {
                        ids.add(new ArtifactTypeId(da.getArtifactType()));
                        if ((qname = da.getArtifactRef()) != null) {
                            ids.add(new ArtifactTemplateId(qname));
                        }
                    }
                }
                getReferencedRequirementTypeIds(ids, n);
                getCapabilitiesReferences(ids, n);
                // crawl through policies
                List<TPolicy> policies = n.getPolicies();
                if (policies != null) {
                    for (TPolicy pol : policies) {
                        QName type = pol.getPolicyType();
                        PolicyTypeId ctId = new PolicyTypeId(type);
                        ids.add(ctId);
                    }
                }
            } else {
                assert (entityTemplate instanceof TRelationshipTemplate);
                ids.add(new RelationshipTypeId(qname));
            }
        }
    }
    return ids;
}
Also used : RelationshipTypeId(org.eclipse.winery.model.ids.definitions.RelationshipTypeId) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) ArtifactTypeId(org.eclipse.winery.model.ids.definitions.ArtifactTypeId) QName(javax.xml.namespace.QName) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) PolicyTypeId(org.eclipse.winery.model.ids.definitions.PolicyTypeId) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) TPolicy(org.eclipse.winery.model.tosca.TPolicy) TDeploymentArtifact(org.eclipse.winery.model.tosca.TDeploymentArtifact) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) OTComplianceRule(org.eclipse.winery.model.tosca.extensions.OTComplianceRule) HashSet(java.util.HashSet)

Example 7 with DefinitionsChildId

use of org.eclipse.winery.model.ids.definitions.DefinitionsChildId in project winery by eclipse.

the class IRepository method getReferencedDefinitionsChildIds.

default Collection<DefinitionsChildId> getReferencedDefinitionsChildIds(NodeTypeImplementationId id) {
    // We have to use a HashSet to ensure that no duplicate ids are added
    // There may be multiple DAs/IAs referencing the same type
    Collection<DefinitionsChildId> ids = new HashSet<>();
    final TNodeTypeImplementation element = this.getElement(id);
    // DAs
    List<TDeploymentArtifact> deploymentArtifacts = element.getDeploymentArtifacts();
    if (deploymentArtifacts != null) {
        for (TDeploymentArtifact da : deploymentArtifacts) {
            QName qname;
            if ((qname = da.getArtifactRef()) != null) {
                ids.add(new ArtifactTemplateId(qname));
            }
            ids.add(new ArtifactTypeId(da.getArtifactType()));
        }
    }
    // IAs
    return this.getReferencedTOSCAComponentImplementationArtifactIds(ids, element.getImplementationArtifacts(), id);
}
Also used : DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) ArtifactTypeId(org.eclipse.winery.model.ids.definitions.ArtifactTypeId) QName(javax.xml.namespace.QName) TDeploymentArtifact(org.eclipse.winery.model.tosca.TDeploymentArtifact) TNodeTypeImplementation(org.eclipse.winery.model.tosca.TNodeTypeImplementation) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) HashSet(java.util.HashSet)

Example 8 with DefinitionsChildId

use of org.eclipse.winery.model.ids.definitions.DefinitionsChildId in project winery by eclipse.

the class IRepository 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.model.ids.definitions.PolicyTypeId) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) ArrayList(java.util.ArrayList)

Example 9 with DefinitionsChildId

use of org.eclipse.winery.model.ids.definitions.DefinitionsChildId in project winery by eclipse.

the class ConsistencyChecker method checkAllDefinitions.

private void checkAllDefinitions(IRepository repository) {
    final Path tempCsar;
    try {
        tempCsar = Files.createTempFile("Export", ".csar");
    } catch (IOException e) {
        LOGGER.debug("Could not create temp CSAR file", e);
        errorCollector.error("Could not create temp CSAR file");
        return;
    }
    float elementsChecked = 0;
    int size = allDefinitionsChildIds.size();
    Map<QName, TDefinitions> allQNameToDefinitionMapping = repository.getAllQNameToDefinitionsMapping();
    for (DefinitionsChildId id : allDefinitionsChildIds) {
        float progress = ++elementsChecked / size;
        if (configuration.getVerbosity().contains(ConsistencyCheckerVerbosity.OUTPUT_CURRENT_TOSCA_COMPONENT_ID)) {
            progressListener.updateProgress(progress, id.toReadableString());
        } else {
            progressListener.updateProgress(progress);
        }
        checkId(id, allQNameToDefinitionMapping);
        checkXmlSchemaValidation(id);
        checkReferencedQNames(id, allQNameToDefinitionMapping);
        checkPropertiesValidation(id);
        if (id instanceof ServiceTemplateId) {
            checkServiceTemplate((ServiceTemplateId) id);
        }
        if (configuration.isCheckDocumentation()) {
            checkDocumentation(id);
        }
        checkPlainConformance(id, tempCsar);
        checkCsar(id, tempCsar, repository);
    }
}
Also used : Path(java.nio.file.Path) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) QName(javax.xml.namespace.QName) IOException(java.io.IOException) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) TDefinitions(org.eclipse.winery.model.tosca.TDefinitions)

Example 10 with DefinitionsChildId

use of org.eclipse.winery.model.ids.definitions.DefinitionsChildId in project winery by eclipse.

the class ConsistencyChecker method checkNamespaceUri.

public void checkNamespaceUri(@NonNull DefinitionsChildId id) {
    Objects.requireNonNull(id);
    String uriStr = id.getNamespace().getDecoded();
    if (!uriStr.trim().equals(uriStr)) {
        printAndAddError(id, "Namespace starts or ends with white spaces");
    }
    URI uri;
    try {
        uri = new URI(uriStr);
    } catch (URISyntaxException e) {
        LOGGER.debug("Invalid URI", e);
        printAndAddError(id, "Invalid URI: " + e.getMessage());
        return;
    }
    if (!uri.isAbsolute()) {
        printAndAddError(id, "URI is relative");
    }
    if ((uriStr.startsWith("http://www.opentosca.org/") && (!uriStr.toLowerCase().equals(uriStr)))) {
        // URI is not lowercase
        // There are some special URIs, which are OK
        String[] splitUri = uriStr.split("/");
        String lastElement = splitUri[splitUri.length - 1];
        String uriStrWithoutLastElement = uriStr.substring(0, (uriStr.length() - lastElement.length()));
        if (!(id.getXmlId().toString().startsWith(lastElement)) || (!uriStrWithoutLastElement.toLowerCase().equals(uriStrWithoutLastElement))) {
            printAndAddError(id, "opentosca URI is not lowercase");
        }
    }
    if (uriStr.endsWith("/")) {
        printAndAddError(id, "URI ends with a slash");
    }
    if (uriStr.contains(ARTEFACT_BE)) {
        printAndAddError(id, "artifact is spelled with i in American English, not artefact as in British English");
    }
    // We could just check OpenTOSCA namespace rule examples. However, this would be too strict
    // Here, the idea is to check whether a string of another (!) id class appers in the namespace
    // If this is the case, the namespace is not consistent
    // For instance, a node type residing in the namespace: http://servicetemplates.example.org should not exist.
    boolean namespaceUriContainsDifferentType = DefinitionsChildId.ALL_TOSCA_COMPONENT_ID_CLASSES.stream().filter(definitionsChildIdClass -> !definitionsChildIdClass.isAssignableFrom(id.getClass())).flatMap(definitionsChildIdClass -> {
        final String lowerCaseIdClass = IdUtil.getTypeForComponentId(definitionsChildIdClass).toLowerCase();
        return Stream.of(lowerCaseIdClass + "s", lowerCaseIdClass + "/");
    }).anyMatch(uriStr::contains);
    if (namespaceUriContainsDifferentType) {
        if ((id instanceof ServiceTemplateId) && (id.getNamespace().getDecoded().contains("compliance"))) {
            // special case, because TComplianceRule models a service template, but Compliance Rules are treated as Service Template during modeling
            // example: class org.eclipse.winery.common.ids.definitions.ServiceTemplateId / {http://www.compliance.opentosca.org/compliancerules}Satisfied_Compliance_Rule_Example_w1
            printAndAddWarning(id, "Cannot perform checks for compliance rules...");
        } else {
            printAndAddError(id, "Namespace URI contains tosca definitions name from other type. E.g., Namespace is ...servicetemplates..., but the type is an artifact template");
        }
    }
}
Also used : HasIdInIdOrNameField(org.eclipse.winery.model.tosca.HasIdInIdOrNameField) IdUtil(org.eclipse.winery.model.ids.IdUtil) URISyntaxException(java.net.URISyntaxException) LoggerFactory(org.slf4j.LoggerFactory) Namespace(org.eclipse.winery.model.ids.Namespace) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) Nullable(org.eclipse.jdt.annotation.Nullable) Map(java.util.Map) URI(java.net.URI) Path(java.nio.file.Path) ZipEntry(java.util.zip.ZipEntry) TDefinitions(org.eclipse.winery.model.tosca.TDefinitions) TEntityType(org.eclipse.winery.model.tosca.TEntityType) RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) StandardOpenOption(java.nio.file.StandardOpenOption) Set(java.util.Set) TNodeType(org.eclipse.winery.model.tosca.TNodeType) WinerysPropertiesDefinition(org.eclipse.winery.model.tosca.extensions.kvproperties.WinerysPropertiesDefinition) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) PropertyDefinitionKV(org.eclipse.winery.model.tosca.extensions.kvproperties.PropertyDefinitionKV) Stream(java.util.stream.Stream) TExtensibleElements(org.eclipse.winery.model.tosca.TExtensibleElements) IRepository(org.eclipse.winery.repository.backend.IRepository) RepositoryCorruptException(org.eclipse.winery.repository.exceptions.RepositoryCorruptException) SAXException(org.xml.sax.SAXException) QName(javax.xml.namespace.QName) NonNull(org.eclipse.jdt.annotation.NonNull) DOMSource(javax.xml.transform.dom.DOMSource) ZipInputStream(java.util.zip.ZipInputStream) StreamSource(javax.xml.transform.stream.StreamSource) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) HashMap(java.util.HashMap) Source(javax.xml.transform.Source) Schema(javax.xml.validation.Schema) ArrayList(java.util.ArrayList) ToscaDocumentBuilderFactory(org.eclipse.winery.common.ToscaDocumentBuilderFactory) BackendUtils(org.eclipse.winery.repository.backend.BackendUtils) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) XMLConstants(javax.xml.XMLConstants) OutputStream(java.io.OutputStream) CsarExporter(org.eclipse.winery.repository.export.CsarExporter) SchemaFactory(javax.xml.validation.SchemaFactory) Logger(org.slf4j.Logger) Files(java.nio.file.Files) IOException(java.io.IOException) Validator(javax.xml.validation.Validator) EntityTemplateId(org.eclipse.winery.model.ids.definitions.EntityTemplateId) Element(org.w3c.dom.Element) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ModelUtilities(org.eclipse.winery.model.tosca.utils.ModelUtilities) Comparator(java.util.Comparator) Collections(java.util.Collections) InputStream(java.io.InputStream) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) URISyntaxException(java.net.URISyntaxException) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) URI(java.net.URI)

Aggregations

DefinitionsChildId (org.eclipse.winery.model.ids.definitions.DefinitionsChildId)77 NodeTypeId (org.eclipse.winery.model.ids.definitions.NodeTypeId)29 Test (org.junit.jupiter.api.Test)21 QName (javax.xml.namespace.QName)19 IOException (java.io.IOException)18 ArrayList (java.util.ArrayList)17 ServiceTemplateId (org.eclipse.winery.model.ids.definitions.ServiceTemplateId)16 TDefinitions (org.eclipse.winery.model.tosca.TDefinitions)16 HashMap (java.util.HashMap)15 IRepository (org.eclipse.winery.repository.backend.IRepository)14 TNodeType (org.eclipse.winery.model.tosca.TNodeType)13 Path (java.nio.file.Path)12 Map (java.util.Map)12 RelationshipTypeId (org.eclipse.winery.model.ids.definitions.RelationshipTypeId)12 TExtensibleElements (org.eclipse.winery.model.tosca.TExtensibleElements)12 Logger (org.slf4j.Logger)11 LoggerFactory (org.slf4j.LoggerFactory)11 InputStream (java.io.InputStream)10 HashSet (java.util.HashSet)10 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)10