use of com.hack23.cia.service.api.action.kpi.ComplianceCheck in project cia by Hack23.
the class ComplianceCheckServiceImpl method processService.
@Override
@Secured({ "ROLE_USER", "ROLE_ADMIN", "ROLE_ANONYMOUS" })
public ComplianceCheckResponse processService(final ComplianceCheckRequest serviceRequest) {
final ComplianceCheckResponse inputValidation = inputValidation(serviceRequest);
if (inputValidation != null) {
return inputValidation;
}
LOGGER.info("{}", serviceRequest.getClass().getSimpleName());
final CreateApplicationEventRequest eventRequest = createApplicationEventForService(serviceRequest);
final UserAccount userAccount = getUserAccountFromSecurityContext();
if (userAccount != null) {
eventRequest.setUserId(userAccount.getUserId());
}
final ComplianceCheckResponse response;
final Set<ConstraintViolation<ComplianceCheckRequest>> requestConstraintViolations = validateRequest(serviceRequest);
if (!requestConstraintViolations.isEmpty()) {
response = handleInputViolations(eventRequest, requestConstraintViolations, new ComplianceCheckResponse(ServiceResult.FAILURE));
} else {
final List<ComplianceCheck> complianceList = rulesEngine.checkRulesCompliance();
final List<RuleViolation> ruleViolations = new ArrayList<>();
for (final ComplianceCheck check : complianceList) {
ruleViolations.addAll(check.getRuleViolations());
}
Collections.sort(complianceList, new Comparator<ComplianceCheck>() {
@Override
public int compare(final ComplianceCheck o1, final ComplianceCheck o2) {
return Integer.compare(o2.getRuleViolations().size(), o1.getRuleViolations().size());
}
});
response = new ComplianceCheckResponse(ServiceResult.SUCCESS);
response.setList(complianceList);
response.setStatusMap(ruleViolations.stream().collect(Collectors.groupingBy(RuleViolation::getStatus)));
response.setResourceTypeMap(ruleViolations.stream().collect(Collectors.groupingBy(RuleViolation::getResourceType)));
eventRequest.setApplicationMessage(response.getResult().toString());
}
getCreateApplicationEventService().processService(eventRequest);
return response;
}
use of com.hack23.cia.service.api.action.kpi.ComplianceCheck in project cia by Hack23.
the class RulesEngineImpl method checkRulesCompliance.
@Override
@Cacheable("checkRulesCompliance")
public List<ComplianceCheck> checkRulesCompliance() {
final KieSession ksession = rulesContainer.newKieSession();
final Map<String, ComplianceCheck> complianceChecks = new HashMap<>();
ksession.addEventListener(new ComplianceCheckAgendaEventListener(complianceChecks));
insertPoliticians(ksession, dataViewer.getAll(ViewRiksdagenPolitician.class));
insertParties(ksession, dataViewer.getAll(ViewRiksdagenPartySummary.class));
ksession.fireAllRules();
ksession.dispose();
return new ArrayList<>(complianceChecks.values());
}
use of com.hack23.cia.service.api.action.kpi.ComplianceCheck in project cia by Hack23.
the class RuleEngineITest method checkRulesComplianceTest.
/**
* Rule engine test.
*
* @throws Exception
* the exception
*/
@Test
public void checkRulesComplianceTest() throws Exception {
final List<ComplianceCheck> checkRulesCompliance = rulesEngine.checkRulesCompliance();
assertNotNull(checkRulesCompliance);
assertFalse(checkRulesCompliance.isEmpty());
for (final ComplianceCheck complianceCheck : checkRulesCompliance) {
System.out.println(complianceCheck.getName() + "" + complianceCheck.getRuleViolations());
}
}
Aggregations