Skip to content

Commit

Permalink
#8 create rules based on specfic
Browse files Browse the repository at this point in the history
issues voted on.
  • Loading branch information
pethers committed Jul 20, 2018
1 parent 3648747 commit 384517f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,15 @@ public List<ViewRiksdagenCommitteeBallotDecisionPoliticianSummary> getBallotDeci
return Collections.unmodifiableList(ballotDecisions);
}

public boolean supports(final String committeeReport,final String rm) {
for (ViewRiksdagenCommitteeBallotDecisionPoliticianSummary summary : ballotDecisions) {
if (summary.getRm().equalsIgnoreCase(rm) && summary.getCommitteeReport().equalsIgnoreCase(committeeReport)) {
return summary.getVote().equalsIgnoreCase("JA");
}
}
return false;
}

/**
* Sets the ballot decisions.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.hack23.cia.model.internal.application.data.committee.impl.ViewRiksdagenCommitteeBallotDecisionPoliticianEmbeddedId;
import com.hack23.cia.model.internal.application.data.committee.impl.ViewRiksdagenCommitteeBallotDecisionPoliticianEmbeddedId_;
import com.hack23.cia.model.internal.application.data.committee.impl.ViewRiksdagenCommitteeBallotDecisionPoliticianSummary;
import com.hack23.cia.model.internal.application.data.committee.impl.ViewRiksdagenCommitteeBallotDecisionPoliticianSummary_;
import com.hack23.cia.model.internal.application.data.committee.impl.ViewRiksdagenVoteDataBallotPartySummaryAnnual;
import com.hack23.cia.model.internal.application.data.committee.impl.ViewRiksdagenVoteDataBallotPartySummaryDaily;
import com.hack23.cia.model.internal.application.data.committee.impl.ViewRiksdagenVoteDataBallotPartySummaryMonthly;
Expand Down Expand Up @@ -103,17 +107,22 @@ private void insertPoliticians(final KieSession ksession, final List<ViewRiksdag
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) {

List<ViewRiksdagenCommitteeBallotDecisionPoliticianSummary> ballots = new ArrayList<>();
//dataViewer.findListByEmbeddedProperty(ViewRiksdagenCommitteeBallotDecisionPoliticianSummary.class,ViewRiksdagenCommitteeBallotDecisionPoliticianSummary_.embeddedId,ViewRiksdagenCommitteeBallotDecisionPoliticianEmbeddedId.class,ViewRiksdagenCommitteeBallotDecisionPoliticianEmbeddedId_.intressentId,"JA");

insertPoliticians(ksession, politicianData, politicanBallotSummaryDailyMap
.get(politicianData.getPersonId()), politicanBallotSummaryMontlyMap
.get(politicianData.getPersonId()), politicanBallotSummaryAnnualMap
.get(politicianData.getPersonId()));
.get(politicianData.getPersonId()),ballots);
}
}
}
Expand All @@ -126,11 +135,12 @@ private void insertPoliticians(final KieSession ksession, final List<ViewRiksdag
* @param dailyList the daily list
* @param monthlyList the monthly list
* @param annualList the annual list
* @param decisionList
*/
private static void insertPoliticians(final KieSession ksession, final ViewRiksdagenPolitician politicianData,
final List<ViewRiksdagenVoteDataBallotPoliticianSummaryDaily> dailyList,
final List<ViewRiksdagenVoteDataBallotPoliticianSummaryMonthly> monthlyList,
final List<ViewRiksdagenVoteDataBallotPoliticianSummaryAnnual> annualList) {
final List<ViewRiksdagenVoteDataBallotPoliticianSummaryAnnual> annualList, List<ViewRiksdagenCommitteeBallotDecisionPoliticianSummary> decisionList) {
if (politicianData.isActiveParliament() && dailyList != null && monthlyList != null
&& annualList != null) {
Collections.sort(dailyList,
Expand All @@ -148,6 +158,7 @@ private static void insertPoliticians(final KieSession ksession, final ViewRiksd
final PoliticianComplianceCheckImpl politicianComplianceCheckImpl = new PoliticianComplianceCheckImpl(
politicianData, dailyListFirst.get(), monthlyListFirst.get(),
annualListFirst.get());
politicianComplianceCheckImpl.setBallotDecisions(decisionList);
ksession.insert(politicianComplianceCheckImpl);
}
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.hack23.cia.service.impl.rules
import org.kie.api.runtime.KieRuntime
import com.hack23.cia.model.internal.application.data.politician.impl.ViewRiksdagenPolitician
import com.hack23.cia.service.api.action.kpi.Status
import com.hack23.cia.service.impl.rules.PoliticianComplianceCheckImpl
import java.util.Calendar

rule "We have an politician supporting FRA committee_report=FöU15 and rm=2007/08"
dialect "java"
salience 50
when
$p : PoliticianComplianceCheckImpl( supports("FöU15","2007/08" ) )
then
$p.addViolation( Status.MINOR, "PoliticianSupports","Behavior", kcontext.getRule().getName(),"Authoritarian");
end

0 comments on commit 384517f

Please sign in to comment.