001 /*
002 * Created on Aug 29, 2007
003 *
004 */
005 package com.x8ing.mc.bp;
006
007 import java.util.ArrayList;
008 import java.util.Calendar;
009 import java.util.GregorianCalendar;
010 import java.util.Iterator;
011 import java.util.List;
012
013 import com.x8ing.lsm4j.StateContext;
014 import com.x8ing.mc.Configuration;
015
016 /**
017 * @author Patrick Heusser
018 *
019 */
020 public class BusinessContext implements StateContext {
021
022 private Configuration configuration = null;
023
024 private BalanceSheet balanceSheet = new BalanceSheet();
025
026 private LogBook logBook = new LogBook();
027
028 private boolean productionSystemRunning = true;
029
030 /**
031 * if the changeProcess is already running we queue the bugs and wait<br>
032 * type: Bug
033 */
034 private List queuedBugs = new ArrayList();
035
036 /**
037 * is the develop department already doing something?
038 */
039 private boolean developProcessBusy = false;
040
041 private boolean deployedWithSucess = true;
042
043 /**
044 * bugs the develop (change) process is operating on.
045 */
046 private BugList bugs = new BugList();
047
048 /**
049 * all losses that are caused through remaining bugs in software. this value changes if a deployment is done!
050 */
051 private double processLossCausedByBugsCurrentValue = 0;
052
053 /**
054 * the simulation date
055 */
056 private Calendar currentDate = GregorianCalendar.getInstance();
057
058 private boolean noMoreDiscoveringOfBugs = false;
059
060 public BusinessContext(Configuration configuration) {
061
062 this.configuration = configuration;
063
064 init();
065 }
066
067 private void init() {
068
069 processLossCausedByBugsCurrentValue = configuration.getSoftwareInitialNoncCnformityCost();
070
071 }
072
073 public void transferQueuedBugsToDevelopBugList() {
074
075 for (Iterator it = queuedBugs.iterator(); it.hasNext();) {
076 Bug bug = (Bug) it.next();
077 bugs.addBug(bug);
078 getLogBook().addLogEntry(getCurrentDate(), "transfered bug to developers. bugID=" + bug.getBugID());
079
080 // remove from queues list
081 it.remove();
082 }
083
084 }
085
086 public double calculateTotalProcessLossOfAllBugsEverFound() {
087
088 final Bug.BugState[] ALL_STATES = new Bug.BugState[] { Bug.BugState.STATE_BUG_DEPLOYED, Bug.BugState.STATE_BUG_FIX_LATER,
089 Bug.BugState.STATE_BUG_FIXED, Bug.BugState.STATE_BUG_NEW, Bug.BugState.STATE_BUG_TEST_FAILED,
090 Bug.BugState.STATE_BUG_TEST_SUCESS
091
092 };
093
094 return calculateTotalProcessLoss(ALL_STATES);
095
096 }
097
098 /**
099 *
100 * @return the total process losscaused by all bugs that could be fixed but are not yet.
101 */
102 public double calculateTotalProcessLossOfAllBugsNotDeployedYet() {
103
104 final Bug.BugState[] STATES_NOT_FIXED_YET = new Bug.BugState[] { Bug.BugState.STATE_BUG_NEW,
105 Bug.BugState.STATE_BUG_FIX_LATER, Bug.BugState.STATE_BUG_TEST_FAILED, Bug.BugState.STATE_BUG_FIXED };
106
107 return calculateTotalProcessLoss(STATES_NOT_FIXED_YET);
108
109 }
110
111 private double calculateTotalProcessLoss(final Bug.BugState[] states) {
112
113 List allBugs = getBugs().getBugsWithState(states);
114
115 double totalLoss = 0;
116 for (Iterator iter = allBugs.iterator(); iter.hasNext();) {
117 Bug bug = (Bug) iter.next();
118 totalLoss += bug.getNegativImpactOnBusinessProcess();
119 }
120
121 return totalLoss;
122 }
123
124 /**
125 * what is the current value of the process.
126 */
127 public double getCurrentProcessGain() {
128 return configuration.getPannedProcessGain() - getProcessLossCausedByBugsCurrentValue();
129 }
130
131 /**
132 * @return Returns the balanceSheet.
133 */
134 public BalanceSheet getBalanceSheet() {
135 return balanceSheet;
136 }
137
138 /**
139 * @return Returns the currentDate.
140 */
141 public Calendar getCurrentDate() {
142 return currentDate;
143 }
144
145 /**
146 * @param currentDate
147 * The currentDate to set.
148 */
149 public void setCurrentDate(GregorianCalendar currentDate) {
150 this.currentDate = currentDate;
151 }
152
153 /**
154 * @return Returns the productionSystemRunning.
155 */
156 public boolean isProductionSystemRunning() {
157 return productionSystemRunning;
158 }
159
160 /**
161 * @return Returns the logBook.
162 */
163 public LogBook getLogBook() {
164 return logBook;
165 }
166
167 public void setProductionSystemRunning(boolean productionSystemRunning) {
168 this.productionSystemRunning = productionSystemRunning;
169 }
170
171 public BugList getBugs() {
172 return bugs;
173 }
174
175 public void setBugs(BugList bugs) {
176 this.bugs = bugs;
177 }
178
179 public boolean isDeployedWithSucess() {
180 return deployedWithSucess;
181 }
182
183 public void setDeployedWithSucess(boolean deployedWithSucess) {
184 this.deployedWithSucess = deployedWithSucess;
185 }
186
187 public boolean isDevelopProcessBusy() {
188 return developProcessBusy;
189 }
190
191 public void setDevelopProcessBusy(boolean developProcessBusy) {
192 this.developProcessBusy = developProcessBusy;
193 }
194
195 public List getQueuedBugs() {
196 return queuedBugs;
197 }
198
199 public void setQueuedBugs(List queuedBugs) {
200 this.queuedBugs = queuedBugs;
201 }
202
203 public double getProcessLossCausedByBugsCurrentValue() {
204 return processLossCausedByBugsCurrentValue;
205 }
206
207 public void setProcessLossCausedByBugsCurrentValue(double processLossCausedByBugsCurrentValue) {
208 this.processLossCausedByBugsCurrentValue = processLossCausedByBugsCurrentValue;
209 }
210
211 public Configuration getConfiguration() {
212 return configuration;
213 }
214
215 public boolean isNoMoreDiscoveringOfBugs() {
216 return noMoreDiscoveringOfBugs;
217 }
218
219 public void setNoMoreDiscoveringOfBugs(boolean noMoreDiscoveringOfBugs) {
220 this.noMoreDiscoveringOfBugs = noMoreDiscoveringOfBugs;
221 }
222
223 }
|