Skip to content

Commit

Permalink
#8 cleanup, wip add support for
Browse files Browse the repository at this point in the history
multiple violations.
  • Loading branch information
pethers committed Mar 3, 2018
1 parent dfcd85b commit 9036d2a
Show file tree
Hide file tree
Showing 10 changed files with 173 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package com.hack23.cia.service.api.action.kpi;

import java.io.Serializable;
import java.util.List;

/**
* The Interface ComplianceCheck.
Expand Down Expand Up @@ -53,6 +54,13 @@ public interface ComplianceCheck extends Serializable {
*/
ResourceType getResourceType();

/**
* Gets the rule violations.
*
* @return the rule violations
*/
List<RuleViolation> getRuleViolations();

/**
* Gets the id.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* Copyright 2010 James Pether Sörling
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* $Id$
* $HeadURL$
*/
package com.hack23.cia.service.api.action.kpi;

/**
* The Class RuleViolation.
*/
public final class RuleViolation {

/** The rule name. */
private String ruleName;

/** The rule description. */
private String ruleDescription;

/** The rule group. */
private String ruleGroup;

/** The status. */
private Status status = Status.OK;

/**
* Instantiates a new rule violation.
*
* @param ruleName
* the rule name
* @param ruleDescription
* the rule description
* @param ruleGroup
* the rule group
* @param status
* the status
*/
public RuleViolation(final String ruleName, final String ruleDescription, final String ruleGroup, final Status status) {
super();
this.ruleName = ruleName;
this.ruleDescription = ruleDescription;
this.ruleGroup = ruleGroup;
this.status = status;
}

/**
* Gets the rule name.
*
* @return the rule name
*/
public String getRuleName() {
return ruleName;
}

/**
* Gets the rule description.
*
* @return the rule description
*/
public String getRuleDescription() {
return ruleDescription;
}

/**
* Gets the rule group.
*
* @return the rule group
*/
public String getRuleGroup() {
return ruleGroup;
}

/**
* Gets the status.
*
* @return the status
*/
public Status getStatus() {
return status;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@
*/
package com.hack23.cia.service.impl.rules;

import java.util.ArrayList;
import java.util.List;

import com.hack23.cia.service.api.action.kpi.ComplianceCheck;
import com.hack23.cia.service.api.action.kpi.ResourceType;
import com.hack23.cia.service.api.action.kpi.RuleViolation;
import com.hack23.cia.service.api.action.kpi.Status;

/**
Expand All @@ -39,6 +43,9 @@ public abstract class AbstractComplianceCheckImpl implements ComplianceCheck {
/** The status. */
private Status status = Status.OK;

/** The violations. */
private List<RuleViolation> violations = new ArrayList();

/**
* Instantiates a new abstract compliance check impl.
*
Expand Down Expand Up @@ -99,4 +106,27 @@ public ResourceType getResourceType() {
public Status getStatus() {
return status;
}

/**
* Gets the violations.
*
* @return the violations
*/
public List<RuleViolation> getViolations() {
return violations;
}

/**
* Adds the violation.
*
* @param status
* the status
* @param violation
* the violation
*/
public void addViolation(final Status status,final String violation) {
setStatus(status);
this.violations.add(new RuleViolation(violation,null,null,status));
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.hack23.cia.service.impl.rules


import org.kie.api.runtime.KieRuntime

import com.hack23.cia.model.internal.application.data.party.impl.ViewRiksdagenPartySummary
import com.hack23.cia.service.api.action.kpi.Status
import com.hack23.cia.service.impl.rules.PartyComplianceCheckImpl
Expand All @@ -10,7 +12,5 @@ rule "We have an active Party with no government experience"
when
$p : PartyComplianceCheckImpl( party.active == true && party.totalDaysServedGovernment == 0 )
then
modify( $p ) {
setStatus( Status.MINOR )
}
$p.addViolation( Status.MINOR, kcontext.getRule().getName());
end
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
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
Expand All @@ -12,30 +14,27 @@ function long busyFactor(Date firstAssignmentDate, long totalDaysServed){

rule "We have an politician with busy schedule, more than 4 current roles and busy past"
dialect "java"
salience 1000
when
$p : PoliticianComplianceCheckImpl( politician.active == true && politician.currentAssignments > 4 && ( busyFactor(politician.firstAssignmentDate, politician.totalDaysServed ) > 4 ))
then
modify( $p ) {
setStatus( Status.MINOR )
}
$p.addViolation( Status.MINOR, kcontext.getRule().getName());
end

rule "We have an politician with busy schedule, more than 5 current roles and busy past"
dialect "java"
salience 100
when
$p : PoliticianComplianceCheckImpl( politician.active == true && politician.currentAssignments > 5 && ( busyFactor(politician.firstAssignmentDate, politician.totalDaysServed ) > 5 ))
then
modify( $p ) {
setStatus( Status.MAJOR )
}
$p.addViolation( Status.MAJOR, kcontext.getRule().getName());
end

rule "We have an politician with busy schedule, more than 6 current roles and busy past"
dialect "java"
salience 10
when
$p : PoliticianComplianceCheckImpl( politician.active == true && politician.currentAssignments > 6 && ( busyFactor(politician.firstAssignmentDate, politician.totalDaysServed ) > 6 ))
then
modify( $p ) {
setStatus( Status.CRITICAL )
}
end
$p.addViolation( Status.CRITICAL, kcontext.getRule().getName());
end
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
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.model.internal.application.data.committee.impl.ViewRiksdagenVoteDataBallotPoliticianSummaryAnnual
import com.hack23.cia.model.internal.application.data.committee.impl.ViewRiksdagenVoteDataBallotPoliticianSummaryDaily
Expand All @@ -14,9 +16,7 @@ rule "We have a lazy politician, absent 100 % last day of ballots in parliament"
when
$p : PoliticianComplianceCheckImpl(politician.activeParliament == true && dailySummary != null && dailySummary.politicianPercentageAbsent == 100)
then
modify( $p ) {
setStatus( Status.MINOR )
}
$p.addViolation( Status.MINOR, kcontext.getRule().getName());
end

rule "We have a lazy politician, absent more than 20 % of ballots last month"
Expand All @@ -25,9 +25,7 @@ rule "We have a lazy politician, absent more than 20 % of ballots last month"
when
$p : PoliticianComplianceCheckImpl( politician.activeParliament == true && monthlySummary != null && monthlySummary.politicianPercentageAbsent >= 20)
then
modify( $p ) {
setStatus( Status.MAJOR )
}
$p.addViolation( Status.MAJOR, kcontext.getRule().getName());
end

rule "We have a lazy politician, absent more than 20 % of ballots last year"
Expand All @@ -36,7 +34,5 @@ rule "We have a lazy politician, absent more than 20 % of ballots last year"
when
$p : PoliticianComplianceCheckImpl( politician.activeParliament == true && annualSummary != null && annualSummary.politicianPercentageAbsent >= 20)
then
modify( $p ) {
setStatus( Status.CRITICAL )
}
$p.addViolation( Status.CRITICAL, kcontext.getRule().getName());
end
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
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
Expand All @@ -9,7 +11,5 @@ rule "We have an politician that left the party still holding assignments"
when
$p : PoliticianComplianceCheckImpl(politician.party == "-" && politician.active == true )
then
modify( $p ) {
setStatus( Status.MINOR )
}
$p.addViolation( Status.CRITICAL, kcontext.getRule().getName());
end
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
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
Expand All @@ -9,7 +11,5 @@ rule "We have an politician minister that has no experience from parliament"
when
$p : PoliticianComplianceCheckImpl(politician.activeGovernment == true && politician.totalDaysServedCommittee == 0)
then
modify( $p ) {
setStatus( Status.MINOR )
}
$p.addViolation( Status.MINOR, kcontext.getRule().getName());
end
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
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.model.internal.application.data.committee.impl.ViewRiksdagenVoteDataBallotPoliticianSummaryAnnual
import com.hack23.cia.model.internal.application.data.committee.impl.ViewRiksdagenVoteDataBallotPoliticianSummaryDaily
Expand All @@ -14,9 +16,7 @@ rule "We have a party rebel politician, voted against party majority at least on
when
$p : PoliticianComplianceCheckImpl(politician.activeParliament == true && politician.party != "-" && dailySummary != null && dailySummary.rebelTotal > 0)
then
modify( $p ) {
setStatus( Status.MINOR )
}
$p.addViolation( Status.MINOR, kcontext.getRule().getName());
end

rule "We have a party rebel politician, voted against party majority at least 1% of ballots last month"
Expand All @@ -25,9 +25,7 @@ rule "We have a party rebel politician, voted against party majority at least 1%
when
$p : PoliticianComplianceCheckImpl( politician.activeParliament == true && politician.party != "-" && monthlySummary != null && monthlySummary.rebelPercentage > 1)
then
modify( $p ) {
setStatus( Status.MAJOR )
}
$p.addViolation( Status.MAJOR, kcontext.getRule().getName());
end

rule "We have a party rebel politician, voted against party majority at least 1% of ballots last year"
Expand All @@ -36,7 +34,5 @@ rule "We have a party rebel politician, voted against party majority at least 1%
when
$p : PoliticianComplianceCheckImpl( politician.activeParliament == true && politician.party != "-" && annualSummary != null && annualSummary.rebelPercentage >= 1)
then
modify( $p ) {
setStatus( Status.CRITICAL )
}
$p.addViolation( Status.CRITICAL, kcontext.getRule().getName());
end
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
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
Expand All @@ -14,27 +16,21 @@ rule "We have an politician older than 65, retirement age in Sweden"
when
$p : PoliticianComplianceCheckImpl( politician.active == true && (currentYear() - politician.bornYear) > 65 )
then
modify( $p ) {
setStatus( Status.MINOR )
}
$p.addViolation( Status.MINOR, kcontext.getRule().getName());
end

rule "We have an politician older than 70, passed retirement age in Sweden"
dialect "java"
when
$p : PoliticianComplianceCheckImpl( politician.active == true && (currentYear() - politician.bornYear) > 70 )
then
modify( $p ) {
setStatus( Status.MAJOR )
}
$p.addViolation( Status.MAJOR, kcontext.getRule().getName());
end

rule "We have an politician older than 80, way passed retirement age in Sweden"
dialect "java"
when
$p : PoliticianComplianceCheckImpl( politician.active == true && (currentYear() - politician.bornYear) > 80 )
then
modify( $p ) {
setStatus( Status.CRITICAL )
}
$p.addViolation( Status.CRITICAL, kcontext.getRule().getName());
end

0 comments on commit 9036d2a

Please sign in to comment.