1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.module.purap.batch.service.impl;
17
18 import org.kuali.ole.module.purap.batch.service.MigratePurapStatCodeToWorkflowDocumentService;
19 import org.kuali.ole.module.purap.dataaccess.PurapDocumentsStatusCodeMigrationDao;
20 import org.kuali.ole.module.purap.dataaccess.StatusCodeAndDescriptionForPurapDocumentsDao;
21 import org.kuali.ole.sys.context.SpringContext;
22 import org.kuali.ole.sys.service.ReportWriterService;
23 import org.kuali.rice.core.api.datetime.DateTimeService;
24 import org.kuali.rice.kew.api.KewApiServiceLocator;
25 import org.kuali.rice.kew.api.document.attribute.DocumentAttributeIndexingQueue;
26 import org.kuali.rice.krad.service.BusinessObjectService;
27 import org.kuali.rice.krad.workflow.service.WorkflowDocumentService;
28 import org.springframework.transaction.annotation.Transactional;
29
30 import java.util.Map;
31
32
33
34
35 @Transactional
36 public class MigratePurapStatCodeToWorkflowDocumentServiceImpl implements MigratePurapStatCodeToWorkflowDocumentService {
37 protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(MigratePurapStatCodeToWorkflowDocumentServiceImpl.class);
38 public static final String WORKFLOW_DOCUMENT_HEADER_ID_SEARCH_RESULT_KEY = "routeHeaderId";
39
40 protected WorkflowDocumentService workflowDocumentService;
41 protected StatusCodeAndDescriptionForPurapDocumentsDao statusCodeAndDescriptionForPurapDocumentsDao;
42 protected ReportWriterService migratePurapStatCodeReportService;
43 protected BusinessObjectService businessObjectService;
44 protected DateTimeService dateTimeService;
45 protected PurapDocumentsStatusCodeMigrationDao purapDocumentsStatusCodeMigrationDao;
46
47
48
49
50 public MigratePurapStatCodeToWorkflowDocumentServiceImpl() {
51
52 }
53
54
55
56
57 public boolean migratePurapStatCodeToWorkflowDocuments() {
58 LOG.debug("migratePurapStatCodeToWorkflowDocuments() started");
59
60 boolean success = true;
61
62 migratePurapStatCodeReportService.writeFormattedMessageLine("******************** Migration of StatusCode to Workflow document started ********************\n");
63
64
65 success &= processRequisitionDocumentsForStatusCodeMigration();
66
67
68 success &= processPurchaseOrderDocumentsForStatusCodeMigration();
69
70
71 success &= processPaymentRequestDocumentsForStatusCodeMigration();
72
73
74 success &= processVendorCreditMemoDocumentsForStatusCodeMigration();
75
76
77 success &= processLineItemReceivingDocumentsForStatusCodeMigration();
78
79 LOG.debug("migratePurapStatCodeToWorkflowDocuments() completed");
80
81 migratePurapStatCodeReportService.writeFormattedMessageLine("\n******************** Migration of StatusCode to Workflow document completed ********************\n");
82
83 return success;
84 }
85
86
87
88
89
90
91
92 protected void writeNoRecordsMessage(Map<String, String> details, String detailName) {
93 if (details == null || details.size() == 0) {
94 migratePurapStatCodeReportService.writeFormattedMessageLine("\t\tNo Data exists for processing in " + detailName);
95 }
96 }
97
98
99
100
101
102
103
104
105
106 protected boolean processRequisitionDocumentsForStatusCodeMigration() {
107 LOG.debug("processRequisitionDocumentsForStatusCodeMigration() started");
108
109 boolean success = true;
110
111 migratePurapStatCodeReportService.writeFormattedMessageLine("********** Migration of Requistions StatusCode to Workflow document started **********\n");
112
113 final DocumentAttributeIndexingQueue documentAttributeIndexingQueue = KewApiServiceLocator.getDocumentAttributeIndexingQueue();
114
115
116 Map<String, String> requisitionStatusMap = getStatusCodeAndDescriptionForPurapDocumentsDao().getRequisitionDocumentStatuses();
117
118
119 Map<String, String> requisitionDetails = getPurapDocumentsStatusCodeMigrationDao().getRequisitionDocumentDetails();
120
121 writeNoRecordsMessage(requisitionDetails, "Requisition Documents.");
122
123 for (String reqDocNumber : requisitionDetails.keySet()) {
124 String statusCode = requisitionDetails.get(reqDocNumber);
125
126 String newApplicationDocumentStatus = requisitionStatusMap.get(statusCode);
127
128 migratePurapStatCodeReportService.writeFormattedMessageLine("\t\tREQ Doc: " + reqDocNumber + " Status Code: " + statusCode + " Status Description: " + newApplicationDocumentStatus);
129
130
131 getPurapDocumentsStatusCodeMigrationDao().updateAndSaveMigratedApplicationDocumentStatuses(reqDocNumber, newApplicationDocumentStatus, getDateTimeService().getCurrentTimestamp());
132
133
134 documentAttributeIndexingQueue.indexDocument(reqDocNumber);
135 }
136
137 migratePurapStatCodeReportService.writeFormattedMessageLine("\n********** Migration of Requistions StatusCode to Workflow document completed **********\n\n");
138
139 LOG.debug("processRequisitionDocumentsForStatusCodeMigration() completed");
140
141 return success;
142 }
143
144
145
146
147
148
149
150
151
152 protected boolean processPaymentRequestDocumentsForStatusCodeMigration() {
153 LOG.debug("processPaymentRequestDocumentsForStatusCodeMigration() started");
154
155 boolean success = true;
156
157 migratePurapStatCodeReportService.writeFormattedMessageLine("********** Migration of Payment Requests StatusCode to Workflow document started **********\n");
158
159 final DocumentAttributeIndexingQueue documentAttributeIndexingQueue = KewApiServiceLocator.getDocumentAttributeIndexingQueue();
160
161
162 Map<String, String> paymentRequestStatusMap = getStatusCodeAndDescriptionForPurapDocumentsDao().getPaymentRequestDocumentStatuses();
163
164
165 Map<String, String> paymentRequestDetails = getPurapDocumentsStatusCodeMigrationDao().getPaymentRequestDocumentDetails();
166
167 writeNoRecordsMessage(paymentRequestDetails, "Payment Request Documents.");
168
169 for (String preqDocNumber : paymentRequestDetails.keySet()) {
170 String statusCode = paymentRequestDetails.get(preqDocNumber);
171
172 String newApplicationDocumentStatus = paymentRequestStatusMap.get(statusCode);
173
174 migratePurapStatCodeReportService.writeFormattedMessageLine("\t\tPREQ Doc: " + preqDocNumber + " Status Code: " + statusCode + " Status Description: " + newApplicationDocumentStatus);
175
176
177 getPurapDocumentsStatusCodeMigrationDao().updateAndSaveMigratedApplicationDocumentStatuses(preqDocNumber, newApplicationDocumentStatus, getDateTimeService().getCurrentTimestamp());
178
179
180 documentAttributeIndexingQueue.indexDocument(preqDocNumber);
181 }
182
183 migratePurapStatCodeReportService.writeFormattedMessageLine("\n********** Migration of Payment Requests StatusCode to Workflow document completed **********\n\n");
184
185 LOG.debug("processPaymentRequestDocumentsForStatusCodeMigration() completed");
186
187 return success;
188 }
189
190
191
192
193
194
195
196
197
198 protected boolean processPurchaseOrderDocumentsForStatusCodeMigration() {
199 LOG.debug("processPurchaseOrderDocumentsForStatusCodeMigration() started");
200
201 boolean success = true;
202
203 migratePurapStatCodeReportService.writeFormattedMessageLine("********** Migration of Purchase Order StatusCode to Workflow document started **********\n");
204
205 final DocumentAttributeIndexingQueue documentAttributeIndexingQueue = KewApiServiceLocator.getDocumentAttributeIndexingQueue();
206
207
208 Map<String, String> purchaseOrderStatusMap = getStatusCodeAndDescriptionForPurapDocumentsDao().getPurchaseOrderDocumentStatuses();
209
210
211 Map<String, String> poDetails = getPurapDocumentsStatusCodeMigrationDao().getPurchaseOrderDocumentDetails();
212
213 writeNoRecordsMessage(poDetails, "Purchase Order Documents.");
214
215 for (String poDocNumber : poDetails.keySet()) {
216 String statusCode = poDetails.get(poDocNumber);
217
218 String newApplicationDocumentStatus = purchaseOrderStatusMap.get(statusCode);
219
220 migratePurapStatCodeReportService.writeFormattedMessageLine("\t\tPO Doc: " + poDocNumber + " Status Code: " + statusCode + " Status Description: " + newApplicationDocumentStatus);
221
222
223 getPurapDocumentsStatusCodeMigrationDao().updateAndSaveMigratedApplicationDocumentStatuses(poDocNumber, newApplicationDocumentStatus, getDateTimeService().getCurrentTimestamp());
224
225
226 documentAttributeIndexingQueue.indexDocument(poDocNumber);
227 }
228
229 migratePurapStatCodeReportService.writeFormattedMessageLine("\n********** Migration of Purchase Order StatusCode to Workflow document completed **********\n\n");
230
231 LOG.debug("processPurchaseOrderDocumentsForStatusCodeMigration() completed");
232
233 return success;
234 }
235
236
237
238
239
240
241
242
243
244
245 protected boolean processVendorCreditMemoDocumentsForStatusCodeMigration() {
246 LOG.debug("processVendorCreditMemoDocumentsForStatusCodeMigration() started");
247
248 boolean success = true;
249
250 migratePurapStatCodeReportService.writeFormattedMessageLine("********** Migration of Vendor Credit Memo StatusCode to Workflow document started **********\n");
251
252 final DocumentAttributeIndexingQueue documentAttributeIndexingQueue = KewApiServiceLocator.getDocumentAttributeIndexingQueue();
253
254
255 Map<String, String> vendorCreditMemoStatusMap = getStatusCodeAndDescriptionForPurapDocumentsDao().getVendorCreditMemoDocumentStatuses();
256
257
258 Map<String, String> vcmDetails = getPurapDocumentsStatusCodeMigrationDao().getVendorCreditMemoDocumentDetails();
259
260 writeNoRecordsMessage(vcmDetails, "Vendor Credit Memo Documents.");
261
262 for (String vcmDocNumber : vcmDetails.keySet()) {
263 String statusCode = vcmDetails.get(vcmDocNumber);
264
265 String newApplicationDocumentStatus = vendorCreditMemoStatusMap.get(statusCode);
266
267 migratePurapStatCodeReportService.writeFormattedMessageLine("\t\tVendor Credit Memo Doc: " + vcmDocNumber + " Status Code: " + statusCode + " Status Description: " + newApplicationDocumentStatus);
268
269
270 getPurapDocumentsStatusCodeMigrationDao().updateAndSaveMigratedApplicationDocumentStatuses(vcmDocNumber, newApplicationDocumentStatus, getDateTimeService().getCurrentTimestamp());
271
272
273 documentAttributeIndexingQueue.indexDocument(vcmDocNumber);
274 }
275
276 migratePurapStatCodeReportService.writeFormattedMessageLine("\n********** Migration of Vendor Credit Memo StatusCode to Workflow document completed **********\n\n");
277
278 LOG.debug("processVendorCreditMemoDocumentsForStatusCodeMigration() completed");
279
280 return success;
281 }
282
283
284
285
286
287
288
289
290
291 protected boolean processLineItemReceivingDocumentsForStatusCodeMigration() {
292 LOG.debug("processLineItemReceivingDocumentsForStatusCodeMigration() started");
293
294 boolean success = true;
295
296 migratePurapStatCodeReportService.writeFormattedMessageLine("********** Migration of Line Item Receiving StatusCode to Workflow document started **********\n");
297
298 final DocumentAttributeIndexingQueue documentAttributeIndexingQueue = KewApiServiceLocator.getDocumentAttributeIndexingQueue();
299
300
301 Map<String, String> lineItemReceivingStatusMap = getStatusCodeAndDescriptionForPurapDocumentsDao().getLineItemReceivingDocumentStatuses();
302
303
304 Map<String, String> lineItemRecvDetails = getPurapDocumentsStatusCodeMigrationDao().getLineItemReceivingDocumentDetails();
305
306 writeNoRecordsMessage(lineItemRecvDetails, "Line Item Receiving Documents.");
307
308 for (String lineItemRecvDocNumber : lineItemRecvDetails.keySet()) {
309 String statusCode = lineItemRecvDetails.get(lineItemRecvDocNumber);
310
311 String newApplicationDocumentStatus = lineItemReceivingStatusMap.get(statusCode);
312
313 migratePurapStatCodeReportService.writeFormattedMessageLine("\t\tLine Item Receiving Doc: " + lineItemRecvDocNumber + " Status Code: " + statusCode + " Status Description: " + newApplicationDocumentStatus);
314
315
316 getPurapDocumentsStatusCodeMigrationDao().updateAndSaveMigratedApplicationDocumentStatuses(lineItemRecvDocNumber, newApplicationDocumentStatus, getDateTimeService().getCurrentTimestamp());
317
318
319 documentAttributeIndexingQueue.indexDocument(lineItemRecvDocNumber);
320 }
321
322 migratePurapStatCodeReportService.writeFormattedMessageLine("\n********** Migration of Line Item Receiving StatusCode to Workflow document completed **********\n\n");
323
324 LOG.debug("processVendorCreditMemoDocumentsForStatusCodeMigration() completed");
325
326 return success;
327 }
328
329
330
331
332
333
334
335 protected ReportWriterService getMigratePurapStatCodeReportService() {
336 return migratePurapStatCodeReportService;
337 }
338
339
340
341
342
343
344
345 public void setMigratePurapStatCodeReportService(ReportWriterService migratePurapStatCodeReportService) {
346 this.migratePurapStatCodeReportService = migratePurapStatCodeReportService;
347 }
348
349
350
351
352
353
354
355 public BusinessObjectService getBusinessObjectService() {
356 if (businessObjectService == null) {
357 businessObjectService = SpringContext.getBean(BusinessObjectService.class);
358 }
359
360 return businessObjectService;
361 }
362
363
364
365
366
367
368 public void setBusinessObjectService(BusinessObjectService businessObjectService) {
369 this.businessObjectService = businessObjectService;
370 }
371
372
373
374
375
376
377
378 public StatusCodeAndDescriptionForPurapDocumentsDao getStatusCodeAndDescriptionForPurapDocumentsDao() {
379 if (statusCodeAndDescriptionForPurapDocumentsDao == null) {
380 statusCodeAndDescriptionForPurapDocumentsDao = SpringContext.getBean(StatusCodeAndDescriptionForPurapDocumentsDao.class);
381 }
382
383 return statusCodeAndDescriptionForPurapDocumentsDao;
384 }
385
386
387
388
389
390
391
392 public void setStatusCodeAndDescriptionForPurapDocumentsDao(StatusCodeAndDescriptionForPurapDocumentsDao statusCodeAndDescriptionForPurapDocumentsDao) {
393 this.statusCodeAndDescriptionForPurapDocumentsDao = statusCodeAndDescriptionForPurapDocumentsDao;
394 }
395
396
397
398
399
400
401
402 public DateTimeService getDateTimeService() {
403 if (dateTimeService == null) {
404 dateTimeService = SpringContext.getBean(DateTimeService.class);
405 }
406
407 return dateTimeService;
408 }
409
410
411
412
413
414
415 public void setDateTimeService(DateTimeService dateTimeService) {
416 this.dateTimeService = dateTimeService;
417 }
418
419
420
421
422
423
424
425 public PurapDocumentsStatusCodeMigrationDao getPurapDocumentsStatusCodeMigrationDao() {
426 if (purapDocumentsStatusCodeMigrationDao == null) {
427 purapDocumentsStatusCodeMigrationDao = SpringContext.getBean(PurapDocumentsStatusCodeMigrationDao.class);
428 }
429
430 return purapDocumentsStatusCodeMigrationDao;
431 }
432
433
434
435
436
437
438
439 public void setPurapDocumentsStatusCodeMigrationDao(PurapDocumentsStatusCodeMigrationDao purapDocumentsStatusCodeMigrationDao) {
440 this.purapDocumentsStatusCodeMigrationDao = purapDocumentsStatusCodeMigrationDao;
441 }
442
443
444 }