01: package org.osbl.riskmanagement.process;
02:
03: import org.concern.controller.AbstractCondition;
04: import org.concern.controller.ConditionEvaluationException;
05:
06: import org.osbl.riskmanagement.model.Risk;
07: import org.osbl.riskmanagement.model.Criticality;
08:
09: import java.math.BigDecimal;
10:
11: public class UpToDate extends AbstractCondition<Risk> {
12: Integer mediumThreshold;
13: Integer highThreshold;
14: Integer criticalThreshold;
15:
16: public void setMediumThreshold(Integer mediumThreshold) {
17: this .mediumThreshold = mediumThreshold;
18: }
19:
20: public void setHighThreshold(Integer highThreshold) {
21: this .highThreshold = highThreshold;
22: }
23:
24: public void setCriticalThreshold(Integer criticalThreshold) {
25: this .criticalThreshold = criticalThreshold;
26: }
27:
28: public boolean eval(Risk subject)
29: throws ConditionEvaluationException {
30: /*PROTECTED REGION ID(org.osbl.riskmanagement.process.UpToDate.eval) ENABLED START*/
31: return subject.getCriticality() == criticality(subject);
32: /*PROTECTED REGION END*/
33: }
34:
35: private Criticality criticality(Risk risk) {
36: BigDecimal amount = risk.getAmount();
37: BigDecimal probability = risk.getProbability();
38: BigDecimal coverage = risk.getCoverage();
39: if (amount == null || probability == null || coverage == null)
40: return Criticality.UNKNOWN;
41:
42: BigDecimal percentage = amount.multiply(probability).divide(
43: coverage, 2);
44: System.out.println("percentage = " + percentage);
45: if (percentage.intValue() > criticalThreshold)
46: return Criticality.CRITICAL;
47: else if (percentage.intValue() > highThreshold)
48: return Criticality.HIGH;
49: else if (percentage.intValue() > mediumThreshold)
50: return Criticality.MEDIUM;
51: else
52: return Criticality.LOW;
53: }
54: }
|