Search in sources :

Example 1 with RuleViolation

use of com.hack23.cia.model.internal.application.data.rules.impl.RuleViolation 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 2 with RuleViolation

use of com.hack23.cia.model.internal.application.data.rules.impl.RuleViolation in project cia by Hack23.

the class DashboardViewOverviewPageModContentFactoryImpl method createDashboardPartRiskByType.

private void createDashboardPartRiskByType(final ResponsiveRow row) {
    final CssLayout layout = new CssLayout();
    layout.addStyleName("v-layout-content-overview-dashboard-panel-level2");
    Responsive.makeResponsive(layout);
    layout.setSizeUndefined();
    final Label titleLabel = new Label("Number of risk by each type");
    Responsive.makeResponsive(titleLabel);
    // button.setStyleName(LINK_STYLE_NAME);
    titleLabel.addStyleName("title");
    titleLabel.setWidth(100, Unit.PERCENTAGE);
    layout.addComponent(titleLabel);
    final HorizontalLayout horizontalLayout = new HorizontalLayout();
    Responsive.makeResponsive(horizontalLayout);
    final DataContainer<RuleViolation, String> dataContainer = getApplicationManager().getDataContainer(RuleViolation.class);
    final List<RuleViolation> ruleViolations = dataContainer.getAll();
    for (final Entry<ResourceType, List<RuleViolation>> statusEntry : ruleViolations.stream().collect(Collectors.groupingBy(RuleViolation::getResourceType)).entrySet()) {
        horizontalLayout.addComponent(new CounterStatisticsCard(VaadinIcons.WARNING, new CounterStatisticModel("" + statusEntry.getKey(), statusEntry.getValue().size()).withShow(StatisticShow.Sum).withIconHidden().withShowOnlyStatistic(true), "" + statusEntry.getKey()));
    }
    layout.addComponent(horizontalLayout);
    row.addColumn().withDisplayRules(DISPLAY_SIZE_XS_DEVICE, DISPLAYS_SIZE_XM_DEVICE, DISPLAY_SIZE_MD_DEVICE, DISPLAY_SIZE_LG_DEVICE).withComponent(layout);
}
Also used : CssLayout(com.vaadin.ui.CssLayout) CounterStatisticsCard(com.github.markash.ui.component.card.CounterStatisticsCard) Label(com.vaadin.ui.Label) ResourceType(com.hack23.cia.model.internal.application.data.rules.impl.ResourceType) List(java.util.List) RuleViolation(com.hack23.cia.model.internal.application.data.rules.impl.RuleViolation) CounterStatisticModel(com.github.markash.ui.component.card.CounterStatisticModel) HorizontalLayout(com.vaadin.ui.HorizontalLayout)

Example 3 with RuleViolation

use of com.hack23.cia.model.internal.application.data.rules.impl.RuleViolation in project cia by Hack23.

the class RulesManagerImpl method processService.

@Override
public void processService() {
    LOGGER.info("{}", RulesManagerImpl.class.getClass().getSimpleName());
    final List<ComplianceCheck> complianceList = rulesEngine.checkRulesCompliance();
    for (final RuleViolation ruleViolation : ruleViolationDAO.getAll()) {
        ruleViolationDAO.delete(ruleViolation);
    }
    for (final ComplianceCheck complianceCheck : complianceList) {
        ruleViolationDAO.persist(complianceCheck.getRuleViolations());
    }
}
Also used : ComplianceCheck(com.hack23.cia.service.api.action.kpi.ComplianceCheck) RuleViolation(com.hack23.cia.model.internal.application.data.rules.impl.RuleViolation)

Example 4 with RuleViolation

use of com.hack23.cia.model.internal.application.data.rules.impl.RuleViolation in project cia by Hack23.

the class RuleViolationPageItemRendererClickListenerTest method clickPartyTest.

/**
 * Click party test.
 */
@Test
public void clickPartyTest() {
    final RuleViolationPageItemRendererClickListener listener = new RuleViolationPageItemRendererClickListener();
    final UI uiMock = Mockito.mock(UI.class);
    UI.setCurrent(uiMock);
    final Navigator navigatorMock = Mockito.mock(Navigator.class);
    Mockito.when(uiMock.getNavigator()).thenReturn(navigatorMock);
    final RendererClickEvent event = Mockito.mock(RendererClickEvent.class);
    Mockito.when(event.getItem()).thenReturn(new RuleViolation("partyid", null, ResourceType.PARTY, null, null, null, null, null));
    listener.click(event);
    Mockito.verify(navigatorMock, times(1)).navigateTo("party/partyid");
}
Also used : UI(com.vaadin.ui.UI) Navigator(com.vaadin.navigator.Navigator) RendererClickEvent(com.vaadin.ui.renderers.ClickableRenderer.RendererClickEvent) RuleViolation(com.hack23.cia.model.internal.application.data.rules.impl.RuleViolation) AbstractUnitTest(com.hack23.cia.testfoundation.AbstractUnitTest) Test(org.junit.Test)

Example 5 with RuleViolation

use of com.hack23.cia.model.internal.application.data.rules.impl.RuleViolation 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 HorizontalLayout horizontalLayout = new HorizontalLayout();
    final DataContainer<RuleViolation, String> dataContainer = getApplicationManager().getDataContainer(RuleViolation.class);
    final List<RuleViolation> ruleViolations = dataContainer.getAll();
    final List<ComplianceCheckImpl> checks = new ArrayList<>();
    for (final Entry<String, List<RuleViolation>> idMapViolations : ruleViolations.stream().collect(Collectors.groupingBy(RuleViolation::getReferenceId)).entrySet()) {
        checks.add(new ComplianceCheckImpl(idMapViolations.getValue()));
    }
    Collections.sort(checks, (o1, o2) -> Integer.compare(o2.getRuleViolations().size(), o1.getRuleViolations().size()));
    for (final Entry<Status, List<RuleViolation>> statusEntry : ruleViolations.stream().collect(Collectors.groupingBy(RuleViolation::getStatus)).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 : ruleViolations.stream().collect(Collectors.groupingBy(RuleViolation::getResourceType)).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, ComplianceCheckImpl.class, checks, "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.model.internal.application.data.rules.impl.Status) CounterStatisticsCard(com.github.markash.ui.component.card.CounterStatisticsCard) ArrayList(java.util.ArrayList) ResourceType(com.hack23.cia.model.internal.application.data.rules.impl.ResourceType) RuleViolation(com.hack23.cia.model.internal.application.data.rules.impl.RuleViolation) HorizontalLayout(com.vaadin.ui.HorizontalLayout) ComplianceCheckImpl(com.hack23.cia.web.impl.ui.application.views.user.parliament.pagemode.risk.ComplianceCheckImpl) VerticalLayout(com.vaadin.ui.VerticalLayout) ArrayList(java.util.ArrayList) List(java.util.List) CounterStatisticModel(com.github.markash.ui.component.card.CounterStatisticModel) Secured(org.springframework.security.access.annotation.Secured)

Aggregations

RuleViolation (com.hack23.cia.model.internal.application.data.rules.impl.RuleViolation)7 CounterStatisticModel (com.github.markash.ui.component.card.CounterStatisticModel)4 CounterStatisticsCard (com.github.markash.ui.component.card.CounterStatisticsCard)4 HorizontalLayout (com.vaadin.ui.HorizontalLayout)4 List (java.util.List)4 ResourceType (com.hack23.cia.model.internal.application.data.rules.impl.ResourceType)3 Status (com.hack23.cia.model.internal.application.data.rules.impl.Status)3 Secured (org.springframework.security.access.annotation.Secured)3 ComplianceCheck (com.hack23.cia.service.api.action.kpi.ComplianceCheck)2 RuleViolation (com.hack23.cia.service.api.action.kpi.RuleViolation)2 AbstractUnitTest (com.hack23.cia.testfoundation.AbstractUnitTest)2 Navigator (com.vaadin.navigator.Navigator)2 CssLayout (com.vaadin.ui.CssLayout)2 Label (com.vaadin.ui.Label)2 UI (com.vaadin.ui.UI)2 VerticalLayout (com.vaadin.ui.VerticalLayout)2 RendererClickEvent (com.vaadin.ui.renderers.ClickableRenderer.RendererClickEvent)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 UserAccount (com.hack23.cia.model.internal.application.user.impl.UserAccount)1