Search in sources :

Example 1 with PolicyTypeId

use of org.eclipse.winery.model.ids.definitions.PolicyTypeId 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 PolicyTypeId

use of org.eclipse.winery.model.ids.definitions.PolicyTypeId 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 3 with PolicyTypeId

use of org.eclipse.winery.model.ids.definitions.PolicyTypeId 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 4 with PolicyTypeId

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

the class YamlRepository method convertToYamlModel.

private YTServiceTemplate convertToYamlModel(RepositoryFileReference existing, TDefinitions definitions) throws IOException, MultiException {
    FromCanonical converter = new FromCanonical(this);
    YTServiceTemplate serviceTemplate;
    if (existing.getParent() instanceof NodeTypeImplementationId) {
        serviceTemplate = readServiceTemplate(existing);
        serviceTemplate = converter.convertNodeTypeImplementation(serviceTemplate, definitions.getNodeTypeImplementations().get(0));
    } else if (existing.getParent() instanceof RelationshipTypeImplementationId) {
        serviceTemplate = readServiceTemplate(existing);
        serviceTemplate = converter.convertRelationshipTypeImplementation(serviceTemplate, definitions.getRelationshipTypeImplementations().get(0));
    } else if (existing.getParent() instanceof NodeTypeId) {
        serviceTemplate = converter.convert(definitions);
        if (exists(existing)) {
            YTServiceTemplate oldServiceTemplate = readServiceTemplate(existing);
            serviceTemplate = replaceOldWithNewData(serviceTemplate, oldServiceTemplate);
        }
    } else if (existing.getParent() instanceof RelationshipTypeId) {
        serviceTemplate = converter.convert(definitions);
        if (exists(existing)) {
            YTServiceTemplate oldServiceTemplate = readServiceTemplate(existing);
            serviceTemplate = replaceOldRelationshipTypeWithNewData(serviceTemplate, oldServiceTemplate);
        }
    } else if (existing.getParent() instanceof ArtifactTemplateId) {
        ArtifactTemplateId id = (ArtifactTemplateId) existing.getParent();
        TArtifactTemplate artifactTemplate = definitions.getArtifactTemplates().get(0);
        YTArtifactDefinition artifact = converter.convertArtifactTemplate(artifactTemplate);
        List<YTMapImportDefinition> imports = converter.convertImports();
        Path targetPath = ref2AbsolutePath(existing);
        if (Files.exists(targetPath)) {
            serviceTemplate = readServiceTemplate(targetPath);
            if (serviceTemplate == null) {
                serviceTemplate = createNewCacheNodeTypeWithArtifact(existing, artifactTemplate, artifact, imports);
            } else if (getTypeFromArtifactName(id.getQName().getLocalPart()).equalsIgnoreCase("nodetypes")) {
                YTNodeType nodeType = serviceTemplate.getNodeTypes().entrySet().iterator().next().getValue();
                Map<String, YTArtifactDefinition> artifacts = nodeType.getArtifacts();
                if (artifacts.containsKey(artifactTemplate.getIdFromIdOrNameField())) {
                    artifacts.replace(artifactTemplate.getIdFromIdOrNameField(), artifact);
                } else {
                    artifacts.put(artifactTemplate.getIdFromIdOrNameField(), artifact);
                }
            } else if (existing.getParent() instanceof PolicyTypeId || existing.getParent() instanceof CapabilityTypeId) {
                // we simply take the new definition as is
                serviceTemplate = converter.convert(definitions);
            } else {
                serviceTemplate = converter.convert(definitions);
                if (exists(existing)) {
                    YTServiceTemplate existingServiceTemplate = readServiceTemplate(existing);
                    serviceTemplate = replaceTopologyTemplate(serviceTemplate, existingServiceTemplate);
                }
            }
        } else {
            serviceTemplate = createNewCacheNodeTypeWithArtifact(existing, artifactTemplate, artifact, imports);
        }
    } else {
        serviceTemplate = converter.convert(definitions);
    }
    return serviceTemplate;
}
Also used : Path(java.nio.file.Path) NodeTypeImplementationId(org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId) RelationshipTypeId(org.eclipse.winery.model.ids.definitions.RelationshipTypeId) YTArtifactDefinition(org.eclipse.winery.model.tosca.yaml.YTArtifactDefinition) FromCanonical(org.eclipse.winery.repository.yaml.converter.FromCanonical) CapabilityTypeId(org.eclipse.winery.model.ids.definitions.CapabilityTypeId) TArtifactTemplate(org.eclipse.winery.model.tosca.TArtifactTemplate) YTServiceTemplate(org.eclipse.winery.model.tosca.yaml.YTServiceTemplate) YTMapImportDefinition(org.eclipse.winery.model.tosca.yaml.support.YTMapImportDefinition) RelationshipTypeImplementationId(org.eclipse.winery.model.ids.definitions.RelationshipTypeImplementationId) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) PolicyTypeId(org.eclipse.winery.model.ids.definitions.PolicyTypeId) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) YTNodeType(org.eclipse.winery.model.tosca.yaml.YTNodeType)

Example 5 with PolicyTypeId

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

the class ThreatModelingUtils method setupThreatModelingTypes.

/**
 * create all Policy Types and Node Types required for threat modeling
 *
 * @throws Exception if setup was already done
 */
public void setupThreatModelingTypes() throws Exception {
    if (checkPrerequisites()) {
        throw new Exception("Threat modeling already set up.");
    }
    TPolicyType threat = new TPolicyType();
    threat.setId(ThreatModelingConstants.THREAT_POLICY_NAME);
    threat.setName(ThreatModelingConstants.THREAT_POLICY_NAME);
    threat.setAbstract(false);
    threat.setFinal(false);
    threat.setTargetNamespace(ThreatModelingConstants.THREATMODELING_NAMESPACE);
    threat.setProperties(null);
    WinerysPropertiesDefinition threatProps = new WinerysPropertiesDefinition();
    threatProps.setElementName("properties");
    threatProps.setNamespace(ThreatModelingConstants.THREATMODELING_NAMESPACE.concat("/propertiesdefinition/winery"));
    List<PropertyDefinitionKV> threatPropList = new ArrayList<>(Arrays.asList(new PropertyDefinitionKV(ThreatModelingProperties.description.toString(), "xsd:string"), new PropertyDefinitionKV(ThreatModelingProperties.strideClassification.toString(), "xsd:string"), new PropertyDefinitionKV(ThreatModelingProperties.severity.toString(), "xsd:string")));
    threatProps.setPropertyDefinitions(threatPropList);
    ModelUtilities.replaceWinerysPropertiesDefinition(threat, threatProps);
    PolicyTypeId threatID = BackendUtils.getDefinitionsChildId(PolicyTypeId.class, ThreatModelingConstants.THREATMODELING_NAMESPACE, ThreatModelingConstants.THREAT_POLICY_NAME, false);
    TDefinitions threatDefinitions = BackendUtils.createWrapperDefinitions(threatID, repository);
    threatDefinitions.setElement(threat);
    TPolicyType mitigation = new TPolicyType();
    mitigation.setId(ThreatModelingConstants.MITIGATION_POLICY_NAME);
    mitigation.setName(ThreatModelingConstants.MITIGATION_POLICY_NAME);
    mitigation.setAbstract(false);
    mitigation.setFinal(false);
    mitigation.setTargetNamespace(ThreatModelingConstants.THREATMODELING_NAMESPACE);
    mitigation.setProperties(null);
    WinerysPropertiesDefinition mitigationProps = new WinerysPropertiesDefinition();
    List<PropertyDefinitionKV> mitigationPropList = new ArrayList<>();
    mitigationProps.setElementName("properties");
    mitigationProps.setNamespace(ThreatModelingConstants.THREATMODELING_NAMESPACE.concat("/propertiesdefinition/winery"));
    mitigationPropList.add(new PropertyDefinitionKV(ThreatModelingProperties.ThreatReference.toString(), "xsd:string"));
    mitigationProps.setPropertyDefinitions(mitigationPropList);
    ModelUtilities.replaceWinerysPropertiesDefinition(mitigation, mitigationProps);
    PolicyTypeId mitigationID = BackendUtils.getDefinitionsChildId(PolicyTypeId.class, ThreatModelingConstants.THREATMODELING_NAMESPACE, ThreatModelingConstants.MITIGATION_POLICY_NAME, false);
    TDefinitions mitigationDefinitions = BackendUtils.createWrapperDefinitions(mitigationID, repository);
    mitigationDefinitions.setElement(mitigation);
    TNodeType svnf = new TNodeType.Builder("S-VNF-w1_wip1").setTargetNamespace(ThreatModelingConstants.SECURITY_NAMESPACE).setAbstract(true).build();
    NodeTypeId svnfID = new NodeTypeId(QName.valueOf(ThreatModelingConstants.SVNF_NODE_TYPE));
    TDefinitions svnfDefinitions = BackendUtils.createWrapperDefinitions(svnfID, repository);
    svnfDefinitions.setElement(svnf);
    try {
        BackendUtils.persist(repository, threatID, threatDefinitions);
        BackendUtils.persist(repository, mitigationID, mitigationDefinitions);
        BackendUtils.persist(repository, svnfID, svnfDefinitions);
    } catch (IOException i) {
        LOGGER.debug("Could not set up threat modeling", i);
    }
}
Also used : PolicyTypeId(org.eclipse.winery.model.ids.definitions.PolicyTypeId) PropertyDefinitionKV(org.eclipse.winery.model.tosca.extensions.kvproperties.PropertyDefinitionKV) TPolicyType(org.eclipse.winery.model.tosca.TPolicyType) WinerysPropertiesDefinition(org.eclipse.winery.model.tosca.extensions.kvproperties.WinerysPropertiesDefinition) ArrayList(java.util.ArrayList) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) IOException(java.io.IOException) TDefinitions(org.eclipse.winery.model.tosca.TDefinitions) IOException(java.io.IOException) TNodeType(org.eclipse.winery.model.tosca.TNodeType)

Aggregations

PolicyTypeId (org.eclipse.winery.model.ids.definitions.PolicyTypeId)10 NodeTypeId (org.eclipse.winery.model.ids.definitions.NodeTypeId)8 ArtifactTemplateId (org.eclipse.winery.model.ids.definitions.ArtifactTemplateId)6 RelationshipTypeId (org.eclipse.winery.model.ids.definitions.RelationshipTypeId)6 ArtifactTypeId (org.eclipse.winery.model.ids.definitions.ArtifactTypeId)5 CapabilityTypeId (org.eclipse.winery.model.ids.definitions.CapabilityTypeId)4 NodeTypeImplementationId (org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId)4 RelationshipTypeImplementationId (org.eclipse.winery.model.ids.definitions.RelationshipTypeImplementationId)4 ArrayList (java.util.ArrayList)3 QName (javax.xml.namespace.QName)3 DefinitionsChildId (org.eclipse.winery.model.ids.definitions.DefinitionsChildId)3 InterfaceTypeId (org.eclipse.winery.model.ids.definitions.InterfaceTypeId)3 PolicyTemplateId (org.eclipse.winery.model.ids.definitions.PolicyTemplateId)3 RequirementTypeId (org.eclipse.winery.model.ids.definitions.RequirementTypeId)3 TArtifactTemplate (org.eclipse.winery.model.tosca.TArtifactTemplate)3 TDefinitions (org.eclipse.winery.model.tosca.TDefinitions)3 TNodeType (org.eclipse.winery.model.tosca.TNodeType)3 TPolicyType (org.eclipse.winery.model.tosca.TPolicyType)3 HashSet (java.util.HashSet)2 LinkedHashMap (java.util.LinkedHashMap)2