Search in sources :

Example 1 with ComplianceCheckRequest

use of com.hack23.cia.service.api.action.kpi.ComplianceCheckRequest in project cia by Hack23.

the class ParliamentRiskPageModContentFactoryImpl method createContent.

@Secured({ "ROLE_ANONYMOUS", "ROLE_USER", "ROLE_ADMIN" })
@Override
public Layout createContent(final String parameters, final MenuBar menuBar, final Panel panel) {
    final VerticalLayout panelContent = createPanelContent();
    getParliamentMenuItemFactory().createParliamentTopicMenu(menuBar);
    final String pageId = getPageId(parameters);
    final ComplianceCheckRequest serviceRequest = new ComplianceCheckRequest();
    serviceRequest.setSessionId(RequestContextHolder.currentRequestAttributes().getSessionId());
    final ComplianceCheckResponse serviceResponse = (ComplianceCheckResponse) getApplicationManager().service(serviceRequest);
    final HorizontalLayout horizontalLayout = new HorizontalLayout();
    for (final Entry<Status, List<RuleViolation>> statusEntry : serviceResponse.getStatusMap().entrySet()) {
        horizontalLayout.addComponent(new CounterStatisticsCard(VaadinIcons.WARNING, new CounterStatisticModel("ALL:" + statusEntry.getKey(), statusEntry.getValue().size()).withShow(StatisticShow.Sum).withIconHidden().withShowOnlyStatistic(true), "ALL:" + statusEntry.getKey()));
    }
    for (final Entry<ResourceType, List<RuleViolation>> statusEntry : serviceResponse.getResourceTypeMap().entrySet()) {
        horizontalLayout.addComponent(new CounterStatisticsCard(VaadinIcons.WARNING, new CounterStatisticModel("ALL:" + statusEntry.getKey(), statusEntry.getValue().size()).withShow(StatisticShow.Sum).withIconHidden().withShowOnlyStatistic(true), "ALL:" + statusEntry.getKey()));
    }
    panelContent.addComponent(horizontalLayout);
    getGridFactory().createBasicBeanItemGrid(panelContent, ComplianceCheck.class, serviceResponse.getList(), "Risk", new String[] { "name", "resourceType", "numberRuleViolations", "ruleSummary" }, new String[] { "id", "ruleViolations" }, CLICK_LISTENER, null, null);
    getPageActionEventHelper().createPageEvent(ViewAction.VISIT_PARLIAMENT_RANKING_VIEW, ApplicationEventGroup.USER, NAME, parameters, pageId);
    panel.setCaption(new StringBuilder().append(NAME).append("::").append(PARLIAMENT_RISK_SUMMARY).toString());
    return panelContent;
}
Also used : Status(com.hack23.cia.service.api.action.kpi.Status) CounterStatisticsCard(com.github.markash.ui.component.card.CounterStatisticsCard) ComplianceCheckResponse(com.hack23.cia.service.api.action.kpi.ComplianceCheckResponse) ResourceType(com.hack23.cia.service.api.action.kpi.ResourceType) HorizontalLayout(com.vaadin.ui.HorizontalLayout) VerticalLayout(com.vaadin.ui.VerticalLayout) List(java.util.List) CounterStatisticModel(com.github.markash.ui.component.card.CounterStatisticModel) ComplianceCheckRequest(com.hack23.cia.service.api.action.kpi.ComplianceCheckRequest) Secured(org.springframework.security.access.annotation.Secured)

Example 2 with ComplianceCheckRequest

use of com.hack23.cia.service.api.action.kpi.ComplianceCheckRequest 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;
}
Also used : ConstraintViolation(javax.validation.ConstraintViolation) ArrayList(java.util.ArrayList) ComplianceCheckResponse(com.hack23.cia.service.api.action.kpi.ComplianceCheckResponse) CreateApplicationEventRequest(com.hack23.cia.service.api.action.application.CreateApplicationEventRequest) ComplianceCheck(com.hack23.cia.service.api.action.kpi.ComplianceCheck) RuleViolation(com.hack23.cia.service.api.action.kpi.RuleViolation) UserAccount(com.hack23.cia.model.internal.application.user.impl.UserAccount) Secured(org.springframework.security.access.annotation.Secured)

Example 3 with ComplianceCheckRequest

use of com.hack23.cia.service.api.action.kpi.ComplianceCheckRequest in project cia by Hack23.

the class ComplianceCheckServiceITest method Test.

/**
 * Test.
 *
 * @throws Exception
 *             the exception
 */
@Test
public void Test() throws Exception {
    setAuthenticatedAnonymousUser();
    final CreateApplicationSessionRequest createSessionRequest = createTestApplicationSession();
    final ComplianceCheckRequest serviceRequest = new ComplianceCheckRequest();
    serviceRequest.setSessionId(createSessionRequest.getSessionId());
    final ComplianceCheckResponse response = (ComplianceCheckResponse) applicationManager.service(serviceRequest);
    assertNotNull(EXPECT_A_RESULT, response);
    assertNotNull(EXPECT_A_RESULT, response.getList());
    assertFalse(response.getList().isEmpty());
    assertNotNull(EXPECT_A_RESULT, response.getStatusMap());
    assertFalse(response.getStatusMap().isEmpty());
    assertNotNull(EXPECT_A_RESULT, response.getResourceTypeMap());
    assertFalse(response.getResourceTypeMap().isEmpty());
}
Also used : CreateApplicationSessionRequest(com.hack23.cia.service.api.action.application.CreateApplicationSessionRequest) ComplianceCheckResponse(com.hack23.cia.service.api.action.kpi.ComplianceCheckResponse) ComplianceCheckRequest(com.hack23.cia.service.api.action.kpi.ComplianceCheckRequest) Test(org.junit.Test) AbstractServiceFunctionalIntegrationTest(com.hack23.cia.service.impl.AbstractServiceFunctionalIntegrationTest)

Example 4 with ComplianceCheckRequest

use of com.hack23.cia.service.api.action.kpi.ComplianceCheckRequest in project cia by Hack23.

the class ComplianceCheckServiceImpl method createApplicationEventForService.

@Override
protected CreateApplicationEventRequest createApplicationEventForService(final ComplianceCheckRequest serviceRequest) {
    final CreateApplicationEventRequest eventRequest = new CreateApplicationEventRequest();
    eventRequest.setEventGroup(ApplicationEventGroup.USER);
    eventRequest.setApplicationOperation(ApplicationOperationType.READ);
    eventRequest.setActionName(ComplianceCheckRequest.class.getSimpleName());
    eventRequest.setSessionId(serviceRequest.getSessionId());
    return eventRequest;
}
Also used : CreateApplicationEventRequest(com.hack23.cia.service.api.action.application.CreateApplicationEventRequest) ComplianceCheckRequest(com.hack23.cia.service.api.action.kpi.ComplianceCheckRequest)

Example 5 with ComplianceCheckRequest

use of com.hack23.cia.service.api.action.kpi.ComplianceCheckRequest in project cia by Hack23.

the class ParliamentRuleViolationsPageModContentFactoryImpl method createContent.

@Secured({ "ROLE_ANONYMOUS", "ROLE_USER", "ROLE_ADMIN" })
@Override
public Layout createContent(final String parameters, final MenuBar menuBar, final Panel panel) {
    final VerticalLayout panelContent = createPanelContent();
    getParliamentMenuItemFactory().createParliamentTopicMenu(menuBar);
    final ComplianceCheckRequest serviceRequest = new ComplianceCheckRequest();
    serviceRequest.setSessionId(RequestContextHolder.currentRequestAttributes().getSessionId());
    final ComplianceCheckResponse serviceResponse = (ComplianceCheckResponse) getApplicationManager().service(serviceRequest);
    final HorizontalLayout horizontalLayout = new HorizontalLayout();
    for (final Entry<Status, List<RuleViolation>> statusEntry : serviceResponse.getStatusMap().entrySet()) {
        horizontalLayout.addComponent(new CounterStatisticsCard(VaadinIcons.WARNING, new CounterStatisticModel("ALL:" + statusEntry.getKey(), statusEntry.getValue().size()).withShow(StatisticShow.Sum).withIconHidden().withShowOnlyStatistic(true), "ALL:" + statusEntry.getKey()));
    }
    final List<RuleViolation> ruleViolations = new ArrayList<>();
    for (final Entry<ResourceType, List<RuleViolation>> statusEntry : serviceResponse.getResourceTypeMap().entrySet()) {
        horizontalLayout.addComponent(new CounterStatisticsCard(VaadinIcons.WARNING, new CounterStatisticModel("ALL:" + statusEntry.getKey(), statusEntry.getValue().size()).withShow(StatisticShow.Sum).withIconHidden().withShowOnlyStatistic(true), "ALL:" + statusEntry.getKey()));
        ruleViolations.addAll(statusEntry.getValue());
    }
    panelContent.addComponent(horizontalLayout);
    Collections.sort(ruleViolations, new Comparator<RuleViolation>() {

        @Override
        public int compare(final RuleViolation o1, final RuleViolation o2) {
            return o2.getStatus().compareTo(o1.getStatus());
        }
    });
    getGridFactory().createBasicBeanItemGrid(panelContent, RuleViolation.class, ruleViolations, "Risk", new String[] { "name", "status", "resourceType", "ruleName", "ruleGroup", "ruleDescription", "positive" }, new String[] { "id" }, CLICK_LISTENER, null, null);
    final String pageId = getPageId(parameters);
    getPageActionEventHelper().createPageEvent(ViewAction.VISIT_PARLIAMENT_RANKING_VIEW, ApplicationEventGroup.USER, NAME, parameters, pageId);
    panel.setCaption(new StringBuilder().append(NAME).append("::").append(PARLIAMENT_RULE_VIOLATIONS).toString());
    return panelContent;
}
Also used : Status(com.hack23.cia.service.api.action.kpi.Status) CounterStatisticsCard(com.github.markash.ui.component.card.CounterStatisticsCard) ArrayList(java.util.ArrayList) ComplianceCheckResponse(com.hack23.cia.service.api.action.kpi.ComplianceCheckResponse) ResourceType(com.hack23.cia.service.api.action.kpi.ResourceType) RuleViolation(com.hack23.cia.service.api.action.kpi.RuleViolation) HorizontalLayout(com.vaadin.ui.HorizontalLayout) VerticalLayout(com.vaadin.ui.VerticalLayout) ArrayList(java.util.ArrayList) List(java.util.List) CounterStatisticModel(com.github.markash.ui.component.card.CounterStatisticModel) ComplianceCheckRequest(com.hack23.cia.service.api.action.kpi.ComplianceCheckRequest) Secured(org.springframework.security.access.annotation.Secured)

Aggregations

ComplianceCheckRequest (com.hack23.cia.service.api.action.kpi.ComplianceCheckRequest)4 ComplianceCheckResponse (com.hack23.cia.service.api.action.kpi.ComplianceCheckResponse)4 Secured (org.springframework.security.access.annotation.Secured)3 CounterStatisticModel (com.github.markash.ui.component.card.CounterStatisticModel)2 CounterStatisticsCard (com.github.markash.ui.component.card.CounterStatisticsCard)2 CreateApplicationEventRequest (com.hack23.cia.service.api.action.application.CreateApplicationEventRequest)2 ResourceType (com.hack23.cia.service.api.action.kpi.ResourceType)2 RuleViolation (com.hack23.cia.service.api.action.kpi.RuleViolation)2 Status (com.hack23.cia.service.api.action.kpi.Status)2 HorizontalLayout (com.vaadin.ui.HorizontalLayout)2 VerticalLayout (com.vaadin.ui.VerticalLayout)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 UserAccount (com.hack23.cia.model.internal.application.user.impl.UserAccount)1 CreateApplicationSessionRequest (com.hack23.cia.service.api.action.application.CreateApplicationSessionRequest)1 ComplianceCheck (com.hack23.cia.service.api.action.kpi.ComplianceCheck)1 AbstractServiceFunctionalIntegrationTest (com.hack23.cia.service.impl.AbstractServiceFunctionalIntegrationTest)1 ConstraintViolation (javax.validation.ConstraintViolation)1 Test (org.junit.Test)1