use of org.eclipse.winery.topologygraph.model.ToscaEntity 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.topologygraph.model.ToscaEntity in project winery by eclipse.
the class BehaviorPatternDetection method removeIncompatibleBehaviorPatterns.
private void removeIncompatibleBehaviorPatterns(TEntityTemplate refinementElement, TEntityTemplate addedElement, RefinementCandidate refinement) {
OTPatternRefinementModel prm = (OTPatternRefinementModel) refinement.getRefinementModel();
List<TPolicy> addedElementPolicies = ((HasPolicies) addedElement).getPolicies();
prm.getBehaviorPatternMappings().stream().filter(bpm -> bpm.getRefinementElement().getId().equals(refinementElement.getId())).forEach(bpm -> {
ToscaEntity detectorElement = refinement.getDetectorGraph().getVertexOrEdge(bpm.getDetectorElement().getId()).get();
TEntityTemplate candidateElement = getEntityCorrespondence(detectorElement, refinement.getGraphMapping());
if (ModelUtilities.hasKvProperties(detectorElement.getTemplate()) && ModelUtilities.hasKvProperties(candidateElement)) {
String detectorValue = ModelUtilities.getPropertiesKV(detectorElement.getTemplate()).get(bpm.getProperty().getKey());
String candidateValue = ModelUtilities.getPropertiesKV(candidateElement).get(bpm.getProperty().getKey());
boolean propsNotCompatible = (detectorValue != null && !detectorValue.isEmpty()) && !detectorValue.equalsIgnoreCase(candidateValue) && (!detectorValue.equals("*") || (candidateValue == null || candidateValue.isEmpty()));
if (propsNotCompatible) {
TPolicy behaviorPattern = ((HasPolicies) refinementElement).getPolicies().stream().filter(policy -> bpm.getBehaviorPattern().equals(policy.getName())).findFirst().get();
addedElementPolicies.removeIf(policy -> policy.getPolicyType().equals(behaviorPattern.getPolicyType()));
}
}
});
}
use of org.eclipse.winery.topologygraph.model.ToscaEntity in project winery by eclipse.
the class ToscaComponentPatternMatcher method componentPatternsCompatible.
protected boolean componentPatternsCompatible(ToscaEntity left, ToscaEntity right) {
// By convention, the left node is always the element to search in right.
TEntityTemplate detectorElement = left.getTemplate();
TEntityTemplate candidateElement = right.getTemplate();
if (!(detectorElement instanceof TNodeTemplate) || !(candidateElement instanceof TNodeTemplate)) {
return false;
}
if (prm.getPermutationMappings() == null || prm.getPermutationMappings().isEmpty()) {
return false;
}
List<OTPermutationMapping> detectorMappings = prm.getPermutationMappings().stream().filter(mapping -> isOneToOne(mapping, prm) && mapping.getDetectorElement().getId().equals(detectorElement.getId())).collect(Collectors.toList());
if (detectorMappings.isEmpty()) {
return false;
}
TEntityTemplate refinementElement = detectorMappings.get(0).getRefinementElement();
return refinementModels.stream().map(OTPatternRefinementModel.class::cast).filter(otherPrm -> otherPrm.getPermutationMappings() != null && !otherPrm.getPermutationMappings().isEmpty()).anyMatch(otherPrm -> {
List<OTPermutationMapping> matchingDetectorMappings = otherPrm.getPermutationMappings().stream().filter(mapping -> isOneToOne(mapping, otherPrm) && super.isCompatible(mapping.getDetectorElement(), candidateElement) && mapping.getRefinementElement().getType().equals(refinementElement.getType())).collect(Collectors.toList());
if (!matchingDetectorMappings.isEmpty()) {
componentPatternCandidates.get(prm).add(new ComponentPatternCandidate((TNodeTemplate) detectorElement, (TNodeTemplate) refinementElement, otherPrm, (TNodeTemplate) matchingDetectorMappings.get(0).getDetectorElement()));
return true;
}
return false;
});
}
Aggregations