DeployAndReleaseAction.java
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 DeployAndReleaseAction extends AbstractBusinessAction {
22 
23   private RandomDistribution deploymentSuccess = new RandomDistributionConstant(0100);;
24 
25   /**
26    @see com.x8ing.mc.bp.AbstractBusinessAction#execute(com.x8ing.lsm4j.state.ProcessableState,
27    *      com.x8ing.mc.bp.BusinessContext, com.x8ing.lsm4j.Condition, java.util.List)
28    */
29   public void execute(ProcessableState currentState, BusinessContext businessContext, Condition previousCondition,
30       List lastVisitedStatesHistory) {
31 
32     boolean deployedWithSucess = (deploymentSuccess.getNextRandomNumber() < businessContext.getConfiguration()
33         .getChanceDeployAndRealeaseDeploymentSuccess() true false);
34 
35     // set it on context (for condition)
36     businessContext.setDeployedWithSucess(deployedWithSucess);
37 
38     if (deployedWithSucess) {
39       addBalanceSheetTransaction("deployment of new software (with success)", -businessContext.getConfiguration()
40           .getCostActionDeployAndRelease(), BalanceAccount.DEPLOYMENT);
41 
42       // change bug state
43       StringBuffer sb = new StringBuffer();
44       sb.append("deployed now bugs with IDs:");
45 
46       List bugsToDeploy = businessContext.getBugs().getBugsWithState(Bug.BugState.STATE_BUG_TEST_SUCESS);
47 
48       double totalProcessImprove = 0;
49 
50       for (Iterator it = bugsToDeploy.iterator(); it.hasNext();) {
51         Bug bug = (Bugit.next();
52         bug.setBugState(Bug.BugState.STATE_BUG_DEPLOYED);
53         sb.append(bug.getBugID());
54         sb.append(" ");
55 
56         double loss = bug.getNegativImpactOnBusinessProcess();
57         if (loss < 0) {
58           // remove this if sure that working
59           throw new RuntimeException("negativ loss");
60         }
61 
62         totalProcessImprove += loss;
63       }
64 
65       double processGainOld = businessContext.getCurrentProcessGain();
66 
67       // since we released the bugs, the process works now more efficient
68       // therefore: update process value
69       businessContext.setProcessLossCausedByBugsCurrentValue(businessContext.getProcessLossCausedByBugsCurrentValue()
70           - totalProcessImprove);
71 
72       double processGainNew = businessContext.getCurrentProcessGain();
73 
74       addLogBookEntry("the new release improved the business process. gainOld:" + Math.round(processGainOld" gainNew:"
75           + Math.round(processGainNew));
76 
77     else {
78       addBalanceSheetTransaction("deployment of new software (with failure)", -businessContext.getConfiguration()
79           .getCostActionDeployAndRelease(), BalanceAccount.DEPLOYMENT);
80 
81     }
82 
83   }
84 
85   protected void lazyInit() {
86     // empty
87   }
88 
89 }