use of org.eclipse.winery.model.ids.extensions.ComplianceRuleId in project winery by eclipse.
the class ServiceTemplateComplianceRuleRuleChecker method checkComplianceRules.
public ServiceTemplateCheckingResult checkComplianceRules() {
StringBuilder checkingResult = new StringBuilder("Rulechecking result for servicetemplate " + serviceTemplate.getIdFromIdOrNameField() + System.lineSeparator());
ServiceTemplateCheckingResult result = new ServiceTemplateCheckingResult();
List<ComplianceRuleId> ruleIds = getRuleIds(serviceTemplate);
if (ruleIds.isEmpty()) {
checkingResult.append("No rules defined");
} else {
IRepository repository = RepositoryFactory.getRepository();
for (ComplianceRuleId ruleId : ruleIds) {
OTComplianceRule tComplianceRule = repository.getElement(ruleId);
ComplianceRuleChecker checker = new ComplianceRuleChecker(tComplianceRule, serviceTemplate.getTopologyTemplate());
List<GraphMapping> graphMappings;
try {
graphMappings = checker.checkComplianceRule();
if (graphMappings.size() > 0) {
result.getUnsatisfied().add(ruleId.getQName());
checkingResult.append(ruleId.getQName().toString() + " violated:");
checkingResult.append(System.lineSeparator());
for (GraphMapping mapping : graphMappings) {
Map<ToscaNode, ToscaNode> resultMap = checker.getSubGraphMappingAsMap(mapping, checker.getIdentifierGraph());
checkingResult.append(System.lineSeparator());
checkingResult.append(resultMap.values().stream().map(node -> node.getTemplate().getIdFromIdOrNameField()).collect(Collectors.joining(";", "NodeTemplateIds: ", "")));
}
} else {
result.getSatisfied().add(ruleId.getQName());
checkingResult.append(ruleId.getQName().toString() + " satisfied");
}
} catch (ComplianceCheckingException e) {
result.getException().add(ruleId.getQName());
LOGGER.debug("Could not check compliance at rule " + ruleId.getQName().toString(), e);
}
}
}
LOGGER.debug(checkingResult.toString());
return result;
}
Aggregations