22
22
import com .topcoder .management .phase .autopilot .ConfigurationException ;
23
23
import com .topcoder .management .phase .autopilot .PhaseOperationException ;
24
24
import com .topcoder .management .phase .autopilot .ProjectPilot ;
25
+ import com .topcoder .management .project .PersistenceException ;
26
+ import com .topcoder .management .project .ProjectManager ;
25
27
import com .topcoder .project .phases .Dependency ;
26
28
import com .topcoder .project .phases .Phase ;
27
29
import com .topcoder .project .phases .Project ;
@@ -86,6 +88,7 @@ public class DefaultProjectPilot implements ProjectPilot {
86
88
*/
87
89
private final PhaseManager phaseManager ;
88
90
91
+ private final ProjectManager projectManager ;
89
92
/**
90
93
* <p>
91
94
* Represents the log used to do auditing whenever a phase is started/ended. The audit log
@@ -138,7 +141,7 @@ public class DefaultProjectPilot implements ProjectPilot {
138
141
*/
139
142
public DefaultProjectPilot () throws ConfigurationException {
140
143
this (DefaultProjectPilot .class .getName (), PhaseManager .class .getName (),
141
- DEFAULT_SCHEDULED_STATUS_NAME , DEFAULT_OPEN_STATUS_NAME , DEFAULT_LOG_NAME );
144
+ DEFAULT_SCHEDULED_STATUS_NAME , DEFAULT_OPEN_STATUS_NAME , DEFAULT_LOG_NAME , ProjectManager . class . getName () );
142
145
}
143
146
144
147
/**
@@ -160,17 +163,23 @@ public DefaultProjectPilot() throws ConfigurationException {
160
163
* phase manager instance or the log
161
164
*/
162
165
public DefaultProjectPilot (String namespace , String phaseManagerKey ,
163
- String scheduledStatusName , String openStatusName , String logName )
166
+ String scheduledStatusName , String openStatusName , String logName , String projectManagerkey )
164
167
throws ConfigurationException {
165
168
// Check arguments.
166
169
checkArguments (namespace , phaseManagerKey , scheduledStatusName , openStatusName , logName );
167
170
168
171
// Create object factory to create phaseManager.
169
172
ObjectFactory of ;
170
173
Object objPhaseManager ;
174
+ Object objProjectManager ;
171
175
try {
172
176
of = new ObjectFactory (new ConfigManagerSpecificationFactory (namespace ));
173
177
178
+ objProjectManager = of .createObject (projectManagerkey );
179
+ if (!ProjectManager .class .isInstance (objProjectManager )) {
180
+ throw new ConfigurationException (
181
+ "fail to create ProjectManager object cause of bad type:" + objProjectManager );
182
+ }
174
183
objPhaseManager = of .createObject (phaseManagerKey );
175
184
if (!PhaseManager .class .isInstance (objPhaseManager )) {
176
185
throw new ConfigurationException (
@@ -190,6 +199,7 @@ public DefaultProjectPilot(String namespace, String phaseManagerKey,
190
199
// Assign to fields.
191
200
this .log = LogManager .getLog (logName );
192
201
this .phaseManager = (PhaseManager ) objPhaseManager ;
202
+ this .projectManager = (ProjectManager ) objProjectManager ;
193
203
this .scheduledStatusName = scheduledStatusName ;
194
204
this .openStatusName = openStatusName ;
195
205
}
@@ -207,8 +217,11 @@ public DefaultProjectPilot(String namespace, String phaseManagerKey,
207
217
* parameters are empty (trimmed) string
208
218
*/
209
219
public DefaultProjectPilot (PhaseManager phaseManager , String scheduledStatusName ,
210
- String openStatusName , Log log ) {
220
+ String openStatusName , Log log , ProjectManager projectManager ) {
211
221
// Check arguments.
222
+ if (null == projectManager ) {
223
+ throw new IllegalArgumentException ("projectManager cannot be null" );
224
+ }
212
225
if (null == phaseManager ) {
213
226
throw new IllegalArgumentException ("phaseManager cannot be null" );
214
227
}
@@ -234,6 +247,7 @@ public DefaultProjectPilot(PhaseManager phaseManager, String scheduledStatusName
234
247
throw new IllegalArgumentException ("log cannot be null" );
235
248
}
236
249
250
+ this .projectManager = projectManager ;
237
251
this .phaseManager = phaseManager ;
238
252
this .scheduledStatusName = scheduledStatusName ;
239
253
this .openStatusName = openStatusName ;
@@ -287,6 +301,7 @@ private void checkArguments(String namespace, String phaseManagerKey,
287
301
}
288
302
}
289
303
304
+ protected ProjectManager getProjectManager () { return this .projectManager ; }
290
305
/**
291
306
* <p>
292
307
* Return the phase manager instance used by this class.
@@ -466,7 +481,14 @@ protected int[] doPhaseOperation(Phase phase, String operator) throws PhaseOpera
466
481
467
482
phaseManager .end (phase , operator );
468
483
count [0 ]++;
469
- doAudit (phase , true , operator );
484
+ com .topcoder .management .project .Project project ;
485
+ try {
486
+ project = projectManager .getProject (phase .getProject ().getId ());
487
+ } catch (PersistenceException e ) {
488
+ throw new PhaseOperationException (phase .getProject ().getId (), phase , "Failed to get project status" );
489
+ }
490
+
491
+ doAudit (phase , true , operator , project .getProjectStatus ().getName ());
470
492
}
471
493
} catch (PhaseManagementException e ) {
472
494
getLog ().log (Level .ERROR , "fail to end the phase cause of phase management exception" );
@@ -508,6 +530,11 @@ protected int[] doPhaseOperation(Phase phase, String operator) throws PhaseOpera
508
530
* Badal : added sample json message for testing on dev
509
531
*/
510
532
protected void doAudit (Phase phase , boolean isEnd , String operator )
533
+ throws PhaseOperationException {
534
+ doAudit (phase , isEnd , operator , null );
535
+ }
536
+
537
+ protected void doAudit (Phase phase , boolean isEnd , String operator , String projectStatus )
511
538
throws PhaseOperationException {
512
539
getLog ().log (
513
540
Level .INFO ,
@@ -518,14 +545,15 @@ protected void doAudit(Phase phase, boolean isEnd, String operator)
518
545
+ phase .getId ()
519
546
+ " - phase type "
520
547
+ ((null == phase .getPhaseType ()) ? "Null Phase Type" : phase .getPhaseType ()
521
- .getName ()) + " - " + (isEnd ? "END" : "START" ) + " - operator " + operator );
548
+ .getName ()) + " - " + (isEnd ? "END" : "START" ) + " - operator " + operator
549
+ + " - projectStatus " + projectStatus );
522
550
523
551
DateFormat dateFormat = new SimpleDateFormat ("yyyy-MM-dd'T'HH:mm:ss'Z'" );
524
552
dateFormat .setTimeZone (TimeZone .getTimeZone ("UTC" ));
525
553
MessageFormat message = new MessageFormat (dateFormat .format (new Date ()),
526
554
phase .getProject ().getId (), phase .getId (),
527
555
(null == phase .getPhaseType ()) ? "Null Phase Type" : phase .getPhaseType ().getName (),
528
- isEnd ? "END" : "START" , operator );
556
+ isEnd ? "END" : "START" , operator , projectStatus );
529
557
530
558
getLog ().log (Level .INFO , "JSON_MESSAGE ::: WILL SEND" );
531
559
0 commit comments