01 /*
02 * Created on Aug 29, 2007
03 */
04 package com.x8ing.mc.bp.develop;
05
06 import java.util.Iterator;
07 import java.util.List;
08
09 import com.x8ing.lsm4j.Condition;
10 import com.x8ing.lsm4j.state.ProcessableState;
11 import com.x8ing.mc.bp.AbstractBusinessAction;
12 import com.x8ing.mc.bp.BalanceAccount;
13 import com.x8ing.mc.bp.Bug;
14 import com.x8ing.mc.bp.BusinessContext;
15 import com.x8ing.mc.distribution.RandomDistribution;
16 import com.x8ing.mc.distribution.RandomDistributionConstant;
17
18 /**
19 * @author Patrick Heusser
20 */
21 public class FixAllKnownBugsAction extends AbstractBusinessAction {
22
23 private RandomDistribution fixingSucess = new RandomDistributionConstant(0, 100);
24
25 /**
26 * all bugs in that state must be fixed.
27 */
28 public static final Bug.BugState[] STATES_TO_FIX = new Bug.BugState[] { Bug.BugState.STATE_BUG_NEW,
29 Bug.BugState.STATE_BUG_FIX_LATER, Bug.BugState.STATE_BUG_TEST_FAILED };
30
31 /**
32 * @see com.x8ing.mc.bp.AbstractBusinessAction#execute(com.x8ing.lsm4j.state.ProcessableState,
33 * com.x8ing.mc.bp.BusinessContext, com.x8ing.lsm4j.Condition, java.util.List)
34 */
35 public void execute(ProcessableState currentState, BusinessContext businessContext, Condition previousCondition,
36 List lastVisitedStatesHistory) {
37
38 // prepare bug list
39 List allBugs = businessContext.getBugs().getBugsWithState(STATES_TO_FIX);
40
41 if (allBugs.size() <= 0) {
42 // inconsistent model! we never get here if we have nothing to do.
43 throw new RuntimeException("inconsistent model state.");
44 }
45
46 addLogBookEntry("Go to fix all yet known bugs (" + allBugs.size()
47 + ") (bugs with states: new, fixLater, productionTestFailed.)");
48
49 for (Iterator it = allBugs.iterator(); it.hasNext();) {
50
51 Bug bug = (Bug) it.next();
52 double fixingCost = -bug.getEstimatedCostToFixBug();
53
54 // test if fixing did work out
55 boolean bugFixingWorkedOut = (fixingSucess.getNextRandomNumber() < businessContext.getConfiguration()
56 .getChanceFixBugWithSuccess() ? true : false);
57 if (bugFixingWorkedOut) {
58
59 bug.setBugState(Bug.BugState.STATE_BUG_FIXED);
60 addLogBookEntry("Fixed bug (id=" + bug.getBugID() + "). State is now: " + bug.getBugState());
61 addBalanceSheetTransaction("costs for fix of bug (id=" + bug.getBugID() + ")", fixingCost, BalanceAccount.DEVELOP);
62
63 } else {
64
65 addLogBookEntry("Fixing of bug failed (id=" + bug.getBugID() + ", state=" + bug.getBugState() + ").");
66 addBalanceSheetTransaction("costs for failed bug-fix (id=" + bug.getBugID() + ")", fixingCost,
67 BalanceAccount.DEVELOP);
68
69 }
70
71 }
72
73 }
74
75 protected void lazyInit() {
76 // empty
77 }
78
79 }
|