Search in sources :

Example 11 with ViewRiksdagenPolitician

use of com.hack23.cia.model.internal.application.data.politician.impl.ViewRiksdagenPolitician in project cia by Hack23.

the class DataViewerITest method viewRiksdagenPartySummary.

/**
 * View riksdagen party summary.
 *
 * @throws Exception
 *             the exception
 */
@Test
public void viewRiksdagenPartySummary() throws Exception {
    final List<ViewRiksdagenPartySummary> committees = dataViewer.getAll(ViewRiksdagenPartySummary.class);
    assertNotNull(EXPECT_VALUE_IN_DATABASE, committees);
    if (committees.size() > 0) {
        final ViewRiksdagenPartySummary viewRiksdagenPartySummary = committees.get(4);
        final ViewRiksdagenPartySummary viewRiksdagenPartySummaryLoaded = dataViewer.load(ViewRiksdagenPartySummary.class, viewRiksdagenPartySummary.getParty());
        assertNotNull(EXPECT_VALUE_IN_DATABASE, viewRiksdagenPartySummaryLoaded);
        final ViewRiksdagenPartySummary viewRiksdagenPartySummaryFound = dataViewer.findFirstByProperty(ViewRiksdagenPartySummary.class, ViewRiksdagenPartySummary_.party, viewRiksdagenPartySummaryLoaded.getParty());
        assertEquals(EXPECT_SAME_OBJECT_LOADED, viewRiksdagenPartySummaryLoaded, viewRiksdagenPartySummaryFound);
    }
    long parliamentSum = 0;
    long euSum = 0;
    long governmentSum = 0;
    for (final ViewRiksdagenPartySummary viewRiksdagenPartySummary : committees) {
        if (viewRiksdagenPartySummary != null) {
            parliamentSum = parliamentSum + viewRiksdagenPartySummary.getTotalActiveParliament();
            euSum = euSum + viewRiksdagenPartySummary.getTotalActiveEu();
            governmentSum = governmentSum + viewRiksdagenPartySummary.getTotalActiveGovernment();
        }
    }
    final List<ViewRiksdagenPolitician> activeWithNoParty = dataViewer.findListByProperty(ViewRiksdagenPolitician.class, new Object[] { true, null }, ViewRiksdagenPolitician_.activeParliament, ViewRiksdagenPolitician_.party);
    assertEquals(SHOULD_ALWAYS_BE_349_IN_PARLIAMENT, 349, parliamentSum + activeWithNoParty.size());
    assertEquals("Should always be 20 in eu, but riksdagen data contains only 15", 15, euSum);
    assertEquals("Should always be 23 in current government", 23, governmentSum);
}
Also used : ViewRiksdagenPartySummary(com.hack23.cia.model.internal.application.data.party.impl.ViewRiksdagenPartySummary) ViewRiksdagenPolitician(com.hack23.cia.model.internal.application.data.politician.impl.ViewRiksdagenPolitician) Test(org.junit.Test)

Example 12 with ViewRiksdagenPolitician

use of com.hack23.cia.model.internal.application.data.politician.impl.ViewRiksdagenPolitician in project cia by Hack23.

the class RulesEngineImpl method insertPoliticians.

/**
 * Insert politicians.
 *
 * @param ksession
 *            the ksession
 * @param list
 *            the list
 */
private void insertPoliticians(final KieSession ksession, final List<ViewRiksdagenPolitician> list) {
    final Map<String, List<ViewRiksdagenVoteDataBallotPoliticianSummaryAnnual>> politicanBallotSummaryAnnualMap = dataViewer.getAll(ViewRiksdagenVoteDataBallotPoliticianSummaryAnnual.class).stream().collect(Collectors.groupingBy(p -> p.getEmbeddedId().getIntressentId()));
    final Map<String, List<ViewRiksdagenVoteDataBallotPoliticianSummaryMonthly>> politicanBallotSummaryMontlyMap = dataViewer.getAll(ViewRiksdagenVoteDataBallotPoliticianSummaryMonthly.class).stream().collect(Collectors.groupingBy(p -> p.getEmbeddedId().getIntressentId()));
    final Map<String, List<ViewRiksdagenVoteDataBallotPoliticianSummaryDaily>> politicanBallotSummaryDailyMap = dataViewer.getAll(ViewRiksdagenVoteDataBallotPoliticianSummaryDaily.class).stream().collect(Collectors.groupingBy(p -> p.getEmbeddedId().getIntressentId()));
    for (final ViewRiksdagenPolitician politicianData : list) {
        if (politicianData != null) {
            final List<ViewRiksdagenVoteDataBallotPoliticianSummaryDaily> dailyList = politicanBallotSummaryDailyMap.get(politicianData.getPersonId());
            final List<ViewRiksdagenVoteDataBallotPoliticianSummaryMonthly> monthlyList = politicanBallotSummaryMontlyMap.get(politicianData.getPersonId());
            final List<ViewRiksdagenVoteDataBallotPoliticianSummaryAnnual> annualList = politicanBallotSummaryAnnualMap.get(politicianData.getPersonId());
            if (politicianData.isActiveParliament() && dailyList != null && monthlyList != null && annualList != null) {
                Collections.sort(dailyList, (e1, e2) -> e1.getEmbeddedId().getVoteDate().compareTo(e2.getEmbeddedId().getVoteDate()));
                Collections.sort(monthlyList, (e1, e2) -> e1.getEmbeddedId().getVoteDate().compareTo(e2.getEmbeddedId().getVoteDate()));
                Collections.sort(annualList, (e1, e2) -> e1.getEmbeddedId().getVoteDate().compareTo(e2.getEmbeddedId().getVoteDate()));
                final PoliticianComplianceCheckImpl politicianComplianceCheckImpl = new PoliticianComplianceCheckImpl(politicianData, Iterables.getFirst(dailyList, null), Iterables.getFirst(monthlyList, null), Iterables.getFirst(annualList, null));
                ksession.insert(politicianComplianceCheckImpl);
            } else {
                final PoliticianComplianceCheckImpl politicianComplianceCheckImpl = new PoliticianComplianceCheckImpl(politicianData, null, null, null);
                ksession.insert(politicianComplianceCheckImpl);
            }
        }
    }
}
Also used : Iterables(com.google.common.collect.Iterables) ViewRiksdagenVoteDataBallotPartySummaryMonthly(com.hack23.cia.model.internal.application.data.committee.impl.ViewRiksdagenVoteDataBallotPartySummaryMonthly) ViewRiksdagenVoteDataBallotPoliticianSummaryDaily(com.hack23.cia.model.internal.application.data.committee.impl.ViewRiksdagenVoteDataBallotPoliticianSummaryDaily) Cacheable(org.springframework.cache.annotation.Cacheable) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) ViewRiksdagenVoteDataBallotPartySummaryAnnual(com.hack23.cia.model.internal.application.data.committee.impl.ViewRiksdagenVoteDataBallotPartySummaryAnnual) ComplianceCheck(com.hack23.cia.service.api.action.kpi.ComplianceCheck) ArrayList(java.util.ArrayList) ViewRiksdagenPolitician(com.hack23.cia.model.internal.application.data.politician.impl.ViewRiksdagenPolitician) ViewRiksdagenVoteDataBallotPoliticianSummaryMonthly(com.hack23.cia.model.internal.application.data.committee.impl.ViewRiksdagenVoteDataBallotPoliticianSummaryMonthly) Propagation(org.springframework.transaction.annotation.Propagation) Service(org.springframework.stereotype.Service) Map(java.util.Map) AfterMatchFiredEvent(org.kie.api.event.rule.AfterMatchFiredEvent) Qualifier(org.springframework.beans.factory.annotation.Qualifier) DefaultAgendaEventListener(org.kie.api.event.rule.DefaultAgendaEventListener) KieSession(org.kie.api.runtime.KieSession) ViewRiksdagenVoteDataBallotPartySummaryDaily(com.hack23.cia.model.internal.application.data.committee.impl.ViewRiksdagenVoteDataBallotPartySummaryDaily) ViewRiksdagenVoteDataBallotPoliticianSummaryAnnual(com.hack23.cia.model.internal.application.data.committee.impl.ViewRiksdagenVoteDataBallotPoliticianSummaryAnnual) KieContainer(org.kie.api.runtime.KieContainer) Collectors(java.util.stream.Collectors) DefaultFactHandle(org.drools.core.common.DefaultFactHandle) List(java.util.List) Collections(java.util.Collections) DataViewer(com.hack23.cia.service.data.api.DataViewer) Transactional(org.springframework.transaction.annotation.Transactional) ViewRiksdagenPartySummary(com.hack23.cia.model.internal.application.data.party.impl.ViewRiksdagenPartySummary) ViewRiksdagenVoteDataBallotPoliticianSummaryMonthly(com.hack23.cia.model.internal.application.data.committee.impl.ViewRiksdagenVoteDataBallotPoliticianSummaryMonthly) ArrayList(java.util.ArrayList) List(java.util.List) ViewRiksdagenVoteDataBallotPoliticianSummaryAnnual(com.hack23.cia.model.internal.application.data.committee.impl.ViewRiksdagenVoteDataBallotPoliticianSummaryAnnual) ViewRiksdagenVoteDataBallotPoliticianSummaryDaily(com.hack23.cia.model.internal.application.data.committee.impl.ViewRiksdagenVoteDataBallotPoliticianSummaryDaily) ViewRiksdagenPolitician(com.hack23.cia.model.internal.application.data.politician.impl.ViewRiksdagenPolitician)

Example 13 with ViewRiksdagenPolitician

use of com.hack23.cia.model.internal.application.data.politician.impl.ViewRiksdagenPolitician in project cia by Hack23.

the class PartyMemberHistoryPageModContentFactoryImpl 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();
    final String pageId = getPageId(parameters);
    final DataContainer<ViewRiksdagenParty, String> dataContainer = getApplicationManager().getDataContainer(ViewRiksdagenParty.class);
    final ViewRiksdagenParty viewRiksdagenParty = dataContainer.load(pageId);
    if (viewRiksdagenParty != null) {
        getPartyMenuItemFactory().createPartyMenuBar(menuBar, pageId);
        LabelFactory.createHeader2Label(panelContent, MEMBER_HISTORY);
        final DataContainer<ViewRiksdagenPolitician, String> politicianDataContainer = getApplicationManager().getDataContainer(ViewRiksdagenPolitician.class);
        getGridFactory().createBasicBeanItemGrid(panelContent, ViewRiksdagenPolitician.class, politicianDataContainer.getAllBy(ViewRiksdagenPolitician_.party, viewRiksdagenParty.getPartyId()), POLITICIANS, COLUMN_ORDER, HIDE_COLUMNS, LISTENER, null, null);
        pageCompleted(parameters, panel, pageId, viewRiksdagenParty);
    }
    return panelContent;
}
Also used : ViewRiksdagenParty(com.hack23.cia.model.internal.application.data.party.impl.ViewRiksdagenParty) VerticalLayout(com.vaadin.ui.VerticalLayout) ViewRiksdagenPolitician(com.hack23.cia.model.internal.application.data.politician.impl.ViewRiksdagenPolitician) Secured(org.springframework.security.access.annotation.Secured)

Example 14 with ViewRiksdagenPolitician

use of com.hack23.cia.model.internal.application.data.politician.impl.ViewRiksdagenPolitician in project cia by Hack23.

the class PoliticianRoleListPageModContentFactoryImpl 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();
    final String pageId = getPageId(parameters);
    final DataContainer<PersonData, String> dataContainer = getApplicationManager().getDataContainer(PersonData.class);
    final PersonData personData = dataContainer.load(pageId);
    if (personData != null) {
        final DataContainer<ViewRiksdagenPolitician, String> politicianDataContainer = getApplicationManager().getDataContainer(ViewRiksdagenPolitician.class);
        final ViewRiksdagenPolitician viewRiksdagenPolitician = politicianDataContainer.load(personData.getId());
        getPoliticianMenuItemFactory().createPoliticianMenuBar(menuBar, pageId);
        LabelFactory.createHeader2Label(panelContent, PoliticianPageMode.ROLELIST.toString());
        final List<AssignmentData> assignmentList = personData.getPersonAssignmentData().getAssignmentList();
        createRoleList(panelContent, assignmentList);
        pageCompleted(parameters, panel, pageId, viewRiksdagenPolitician);
    }
    return panelContent;
}
Also used : PersonData(com.hack23.cia.model.external.riksdagen.person.impl.PersonData) VerticalLayout(com.vaadin.ui.VerticalLayout) ViewRiksdagenPolitician(com.hack23.cia.model.internal.application.data.politician.impl.ViewRiksdagenPolitician) AssignmentData(com.hack23.cia.model.external.riksdagen.person.impl.AssignmentData) Secured(org.springframework.security.access.annotation.Secured)

Example 15 with ViewRiksdagenPolitician

use of com.hack23.cia.model.internal.application.data.politician.impl.ViewRiksdagenPolitician in project cia by Hack23.

the class PoliticianRoleSummaryPageModContentFactoryImpl 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();
    final String pageId = getPageId(parameters);
    final DataContainer<PersonData, String> dataContainer = getApplicationManager().getDataContainer(PersonData.class);
    final PersonData personData = dataContainer.load(pageId);
    if (personData != null) {
        final DataContainer<ViewRiksdagenPolitician, String> politicianDataContainer = getApplicationManager().getDataContainer(ViewRiksdagenPolitician.class);
        final ViewRiksdagenPolitician viewRiksdagenPolitician = politicianDataContainer.load(personData.getId());
        getPoliticianMenuItemFactory().createPoliticianMenuBar(menuBar, pageId);
        LabelFactory.createHeader2Label(panelContent, PoliticianPageMode.ROLESUMMARY.toString());
        final List<AssignmentData> assignmentList = personData.getPersonAssignmentData().getAssignmentList();
        createRoleSummary(panelContent, assignmentList, viewRiksdagenPolitician);
        pageCompleted(parameters, panel, pageId, viewRiksdagenPolitician);
    }
    return panelContent;
}
Also used : PersonData(com.hack23.cia.model.external.riksdagen.person.impl.PersonData) VerticalLayout(com.vaadin.ui.VerticalLayout) ViewRiksdagenPolitician(com.hack23.cia.model.internal.application.data.politician.impl.ViewRiksdagenPolitician) AssignmentData(com.hack23.cia.model.external.riksdagen.person.impl.AssignmentData) Secured(org.springframework.security.access.annotation.Secured)

Aggregations

ViewRiksdagenPolitician (com.hack23.cia.model.internal.application.data.politician.impl.ViewRiksdagenPolitician)17 VerticalLayout (com.vaadin.ui.VerticalLayout)13 Secured (org.springframework.security.access.annotation.Secured)13 PersonData (com.hack23.cia.model.external.riksdagen.person.impl.PersonData)10 AssignmentData (com.hack23.cia.model.external.riksdagen.person.impl.AssignmentData)3 Test (org.junit.Test)3 ViewRiksdagenParty (com.hack23.cia.model.internal.application.data.party.impl.ViewRiksdagenParty)2 ViewRiksdagenPartySummary (com.hack23.cia.model.internal.application.data.party.impl.ViewRiksdagenPartySummary)2 Iterables (com.google.common.collect.Iterables)1 ViewRiksdagenCommitteeBallotDecisionPoliticianEmbeddedId (com.hack23.cia.model.internal.application.data.committee.impl.ViewRiksdagenCommitteeBallotDecisionPoliticianEmbeddedId)1 ViewRiksdagenCommitteeBallotDecisionPoliticianSummary (com.hack23.cia.model.internal.application.data.committee.impl.ViewRiksdagenCommitteeBallotDecisionPoliticianSummary)1 ViewRiksdagenVoteDataBallotPartySummaryAnnual (com.hack23.cia.model.internal.application.data.committee.impl.ViewRiksdagenVoteDataBallotPartySummaryAnnual)1 ViewRiksdagenVoteDataBallotPartySummaryDaily (com.hack23.cia.model.internal.application.data.committee.impl.ViewRiksdagenVoteDataBallotPartySummaryDaily)1 ViewRiksdagenVoteDataBallotPartySummaryMonthly (com.hack23.cia.model.internal.application.data.committee.impl.ViewRiksdagenVoteDataBallotPartySummaryMonthly)1 ViewRiksdagenVoteDataBallotPoliticianSummaryAnnual (com.hack23.cia.model.internal.application.data.committee.impl.ViewRiksdagenVoteDataBallotPoliticianSummaryAnnual)1 ViewRiksdagenVoteDataBallotPoliticianSummaryDaily (com.hack23.cia.model.internal.application.data.committee.impl.ViewRiksdagenVoteDataBallotPoliticianSummaryDaily)1 ViewRiksdagenVoteDataBallotPoliticianSummaryMonthly (com.hack23.cia.model.internal.application.data.committee.impl.ViewRiksdagenVoteDataBallotPoliticianSummaryMonthly)1 ViewRiksdagenPoliticianDocument (com.hack23.cia.model.internal.application.data.document.impl.ViewRiksdagenPoliticianDocument)1 ComplianceCheck (com.hack23.cia.service.api.action.kpi.ComplianceCheck)1 DataViewer (com.hack23.cia.service.data.api.DataViewer)1