Search in sources :

Example 11 with TEntityTemplate

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

the class BehaviorPatternDetection method addCompatibleBehaviorPatterns.

private void addCompatibleBehaviorPatterns(TEntityTemplate refinementElement, RefinementCandidate refinement) {
    OTPatternRefinementModel prm = (OTPatternRefinementModel) refinement.getRefinementModel();
    TEntityTemplate detectorElement = prm.getStayMappings().stream().filter(stayMapping -> stayMapping.getRefinementElement().getId().equals(refinementElement.getId())).findFirst().get().getDetectorElement();
    ToscaEntity detectorEntity = refinement.getDetectorGraph().getVertexOrEdge(detectorElement.getId()).get();
    TEntityTemplate stayingElement = getEntityCorrespondence(detectorEntity, refinement.getGraphMapping());
    List<TPolicy> refinementPolicies = ((HasPolicies) refinementElement).getPolicies();
    List<TPolicy> stayingPolicies = ((HasPolicies) stayingElement).getPolicies();
    if (refinementPolicies != null) {
        if (stayingPolicies != null) {
            // avoid duplicates
            refinementPolicies.forEach(refinementPolicy -> {
                boolean policyExists = stayingPolicies.stream().anyMatch(stayingPolicy -> stayingPolicy.getPolicyType().equals(refinementPolicy.getPolicyType()));
                if (!policyExists) {
                    stayingPolicies.add(refinementPolicy);
                }
            });
        } else {
            ((HasPolicies) stayingElement).setPolicies(new ArrayList<>(refinementPolicies));
        }
        removeIncompatibleBehaviorPatterns(refinementElement, stayingElement, refinement);
    }
}
Also used : TPolicy(org.eclipse.winery.model.tosca.TPolicy) HasPolicies(org.eclipse.winery.model.tosca.HasPolicies) PatternDetectionUtils(org.eclipse.winery.topologygraph.matching.patterndetection.PatternDetectionUtils) TopologyFragmentRefinement(org.eclipse.winery.model.adaptation.substitution.refinement.topologyrefinement.TopologyFragmentRefinement) RefinementChooser(org.eclipse.winery.model.adaptation.substitution.refinement.RefinementChooser) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) IToscaMatcher(org.eclipse.winery.topologygraph.matching.IToscaMatcher) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) ArrayList(java.util.ArrayList) OTPatternRefinementModel(org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel) List(java.util.List) PatternRefinementModelId(org.eclipse.winery.model.ids.extensions.PatternRefinementModelId) ToscaEntity(org.eclipse.winery.topologygraph.model.ToscaEntity) Map(java.util.Map) OTRefinementModel(org.eclipse.winery.model.tosca.extensions.OTRefinementModel) ToscaBehaviorPatternMatcher(org.eclipse.winery.topologygraph.matching.patterndetection.ToscaBehaviorPatternMatcher) ModelUtilities(org.eclipse.winery.model.tosca.utils.ModelUtilities) PatternDetectionUtils.getEntityCorrespondence(org.eclipse.winery.topologygraph.matching.patterndetection.PatternDetectionUtils.getEntityCorrespondence) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) RefinementCandidate(org.eclipse.winery.model.adaptation.substitution.refinement.RefinementCandidate) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) TPolicy(org.eclipse.winery.model.tosca.TPolicy) ToscaEntity(org.eclipse.winery.topologygraph.model.ToscaEntity) HasPolicies(org.eclipse.winery.model.tosca.HasPolicies) OTPatternRefinementModel(org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel)

Example 12 with TEntityTemplate

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

the class GenericArtifactsResource method storeProperties.

private void storeProperties(ArtifactTemplateId artifactTemplateId, DefinitionsChildId typeId, String name) {
    // We generate the properties by hand instead of using JAX-B as using JAX-B causes issues at org.eclipse.winery.common.ModelUtilities.getPropertiesKV(TEntityTemplate):
    // getAny() does not always return "w3c.dom.element" anymore
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder;
    try {
        builder = dbf.newDocumentBuilder();
    } catch (ParserConfigurationException e) {
        LOGGER.error(e.getMessage(), e);
        return;
    }
    Document doc = builder.newDocument();
    String namespace = QNames.QNAME_ARTIFACT_TYPE_WAR.getNamespaceURI();
    Element root = doc.createElementNS(namespace, "WSProperties");
    doc.appendChild(root);
    Element element = doc.createElementNS(namespace, "ServiceEndpoint");
    Text text = doc.createTextNode("/services/" + name + "Port");
    element.appendChild(text);
    root.appendChild(element);
    element = doc.createElementNS(namespace, "PortType");
    text = doc.createTextNode("{" + typeId.getNamespace().getDecoded() + "}" + name);
    element.appendChild(text);
    root.appendChild(element);
    element = doc.createElementNS(namespace, "InvocationType");
    text = doc.createTextNode("SOAP/HTTP");
    element.appendChild(text);
    root.appendChild(element);
    TEntityTemplate.XmlProperties properties = new TEntityTemplate.XmlProperties();
    properties.setAny(root);
    final IRepository repository = RepositoryFactory.getRepository();
    final TArtifactTemplate artifactTemplate = repository.getElement(artifactTemplateId);
    artifactTemplate.setProperties(properties);
    try {
        repository.setElement(artifactTemplateId, artifactTemplate);
    } catch (IOException e) {
        throw new WebApplicationException(e);
    }
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) WebApplicationException(javax.ws.rs.WebApplicationException) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) TArtifactTemplate(org.eclipse.winery.model.tosca.TArtifactTemplate) Element(org.w3c.dom.Element) Text(org.w3c.dom.Text) IOException(java.io.IOException) Document(org.w3c.dom.Document) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IRepository(org.eclipse.winery.repository.backend.IRepository)

Example 13 with TEntityTemplate

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

the class AttributeMappingsResource method addAttributeMappingFromApi.

@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public List<OTAttributeMapping> addAttributeMappingFromApi(PrmAttributeMappingApiData mapping) {
    TEntityTemplate refinementElement = this.res.getRefinementTopologyResource().getTopologyTemplate().getNodeTemplateOrRelationshipTemplate().stream().filter(entityTemplate -> entityTemplate.getId().equals(mapping.refinementElement)).findFirst().orElse(null);
    TEntityTemplate detectorElement = this.res.getDetectorResource().getTopologyTemplate().getNodeTemplateOrRelationshipTemplate().stream().filter(entityTemplate -> entityTemplate.getId().equals(mapping.detectorElement)).findFirst().orElse(null);
    return this.addMapping(mapping.createTPrmPropertyMapping(detectorElement, refinementElement));
}
Also used : TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 14 with TEntityTemplate

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

the class DeploymentArtifactMappingsResource method addDeploymentArtifactMapping.

@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public List<OTDeploymentArtifactMapping> addDeploymentArtifactMapping(PrmDeploymentArtifactMappingApiData mapping) {
    TEntityTemplate detectorElement = this.res.getDetectorResource().getTopologyTemplate().getNodeTemplate(mapping.detectorElement);
    TEntityTemplate refinementElement = this.res.getRefinementTopologyResource().getTopologyTemplate().getNodeTemplate(mapping.refinementElement);
    return this.addMapping(mapping.createDeploymentArtifactMapping(detectorElement, refinementElement));
}
Also used : TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 15 with TEntityTemplate

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

the class ToscaPrmPropertyMatcher method characterizingPatternsCompatible.

public boolean characterizingPatternsCompatible(TEntityTemplate detectorEntityElement, TEntityTemplate candidateEntityElement) {
    // if the detector has no patterns attached but the candidate has --> it's a match
    boolean characterizingPatternsCompatible = true;
    if (detectorEntityElement instanceof HasPolicies && candidateEntityElement instanceof HasPolicies) {
        HasPolicies detectorElement = (HasPolicies) detectorEntityElement;
        HasPolicies candidate = (HasPolicies) candidateEntityElement;
        if (Objects.nonNull(detectorElement.getPolicies()) && Objects.nonNull(candidate.getPolicies())) {
            List<TPolicy> candidatePolicies = candidate.getPolicies();
            characterizingPatternsCompatible = detectorElement.getPolicies().stream().allMatch(detectorPolicy -> {
                if (this.namespaceManager.isPatternNamespace(detectorPolicy.getPolicyType().getNamespaceURI())) {
                    return candidatePolicies.stream().anyMatch(candidatePolicy -> {
                        boolean typeEquals = candidatePolicy.getPolicyType().equals(detectorPolicy.getPolicyType());
                        if (typeEquals && Objects.nonNull(detectorPolicy.getPolicyRef())) {
                            return Objects.nonNull(candidatePolicy.getPolicyRef()) && candidatePolicy.getPolicyRef().equals(detectorPolicy.getPolicyRef());
                        }
                        return typeEquals;
                    });
                }
                return true;
            });
        } else if (Objects.nonNull(detectorElement.getPolicies())) {
            // only if there are patterns attached
            characterizingPatternsCompatible = detectorElement.getPolicies().stream().noneMatch(detectorPolicy -> this.namespaceManager.isPatternNamespace(detectorPolicy.getPolicyType().getNamespaceURI()));
        }
    }
    return characterizingPatternsCompatible;
}
Also used : Objects(java.util.Objects) TPolicy(org.eclipse.winery.model.tosca.TPolicy) List(java.util.List) HasPolicies(org.eclipse.winery.model.tosca.HasPolicies) ToscaNode(org.eclipse.winery.topologygraph.model.ToscaNode) NamespaceManager(org.eclipse.winery.repository.backend.NamespaceManager) ToscaEntity(org.eclipse.winery.topologygraph.model.ToscaEntity) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) ToscaEdge(org.eclipse.winery.topologygraph.model.ToscaEdge) TPolicy(org.eclipse.winery.model.tosca.TPolicy) HasPolicies(org.eclipse.winery.model.tosca.HasPolicies)

Aggregations

TEntityTemplate (org.eclipse.winery.model.tosca.TEntityTemplate)42 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)19 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)14 QName (javax.xml.namespace.QName)13 ArrayList (java.util.ArrayList)9 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)9 Map (java.util.Map)8 HashSet (java.util.HashSet)7 List (java.util.List)7 Consumes (javax.ws.rs.Consumes)7 Produces (javax.ws.rs.Produces)7 TDeploymentArtifact (org.eclipse.winery.model.tosca.TDeploymentArtifact)7 TPolicy (org.eclipse.winery.model.tosca.TPolicy)7 PUT (javax.ws.rs.PUT)6 OTPatternRefinementModel (org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel)6 TEntityType (org.eclipse.winery.model.tosca.TEntityType)5 HashMap (java.util.HashMap)4 LinkedHashMap (java.util.LinkedHashMap)4 Objects (java.util.Objects)4 Collectors (java.util.stream.Collectors)4