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);
}
}
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);
}
}
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));
}
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));
}
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;
}
Aggregations