View Javadoc
1   /*
2    * Copyright 2006 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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   * This class implements the MigratePurapStatCodeToWorkflowDocumentService batch job.
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       * Constructs a AutoDisapproveDocumentsServiceImpl instance
49       */
50      public MigratePurapStatCodeToWorkflowDocumentServiceImpl() {
51  
52      }
53  
54      /**
55       * @see org.kuali.ole.module.purap.batch.service.MigratePurapStatCodeToWorkflowDocumentService#migratePurapStatCodeToWorkflowDocuments()
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          //Step 1: Go through REQ documents and move the status code to workflow documents
65          success &= processRequisitionDocumentsForStatusCodeMigration();
66  
67          //Step 2: Go through PO documents and move the status code to workflow documents
68          success &= processPurchaseOrderDocumentsForStatusCodeMigration();
69  
70          //Step 3: Go through PREQ documents and move the status code to workflow documents
71          success &= processPaymentRequestDocumentsForStatusCodeMigration();
72  
73          //Step 4: Go through Vendor Credit Memo documents and move the status code to workflow documents
74          success &= processVendorCreditMemoDocumentsForStatusCodeMigration();
75  
76          //Step 5: Go through Line Item Receiving documents and move the status code to workflow documents
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       * Helper method to write a no records to process message
88       *
89       * @param details     Name of the processing details, like Requisition Documents etc,.
90       * @param processType
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       * Processes the requisitions for status code migration.  Creates a list of documents numbers
100      * and current status code where status code needs migration and using that list the workflow documents
101      * will be retrieved.  Each workflow document then will be updated with the corresponding
102      * application document status that is new in KFS 5.0
103      *
104      * @return true if the requisitions status code successfully migrates else return false.
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         //get the status code/descriptions from the table pur_reqs_stat_t
116         Map<String, String> requisitionStatusMap = getStatusCodeAndDescriptionForPurapDocumentsDao().getRequisitionDocumentStatuses();
117 
118         //get the requisitions details where REQS_STAT_CD is not null....
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             //find the workflow document and update the app_doc_stat and app_doc_stat_mdfn_dt columns.
131             getPurapDocumentsStatusCodeMigrationDao().updateAndSaveMigratedApplicationDocumentStatuses(reqDocNumber, newApplicationDocumentStatus, getDateTimeService().getCurrentTimestamp());
132 
133             //now reindex the requistion for document search...
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      * Processes the payment request documents for status code migration.  Creates a list of documents numbers
146      * and current status code where status code needs migration and using that list the workflow documents
147      * will be retrieved.  Each workflow document then will be updated with the corresponding
148      * application document status that is new in KFS 5.0
149      *
150      * @return true if the payment request documents status code successfully migrates else return false.
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         //get the status code/descriptions from the table ap_pmt_rqst_stat_t
162         Map<String, String> paymentRequestStatusMap = getStatusCodeAndDescriptionForPurapDocumentsDao().getPaymentRequestDocumentStatuses();
163 
164         //get the payment request details where PMT_RQST_STAT_CD is not null....
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             //find the workflow document and update the app_doc_stat and app_doc_stat_mdfn_dt columns.
177             getPurapDocumentsStatusCodeMigrationDao().updateAndSaveMigratedApplicationDocumentStatuses(preqDocNumber, newApplicationDocumentStatus, getDateTimeService().getCurrentTimestamp());
178 
179             //now reindex the requistion for document search...
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      * Processes the purchase order documents for status code migration.  Creates a list of documents numbers
192      * and current status code where status code needs migration and using that list the workflow documents
193      * will be retrieved.  Each workflow document then will be updated with the corresponding
194      * application document status that is new in KFS 5.0
195      *
196      * @return true if the payment request status code successfully migrates else return false.
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         //get the status code/descriptions from the table PUR_PO_STAT_T
208         Map<String, String> purchaseOrderStatusMap = getStatusCodeAndDescriptionForPurapDocumentsDao().getPurchaseOrderDocumentStatuses();
209 
210         //get the purchase order details where PO_STAT_CD is not null....
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             //find the workflow document and update the app_doc_stat and app_doc_stat_mdfn_dt columns.
223             getPurapDocumentsStatusCodeMigrationDao().updateAndSaveMigratedApplicationDocumentStatuses(poDocNumber, newApplicationDocumentStatus, getDateTimeService().getCurrentTimestamp());
224 
225             //now reindex the requistion for document search...
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      * Processes the vendor credit memos for status code migration.  Creates a list of documents numbers
239      * and current status code where status code needs migration and using that list the workflow documents
240      * will be retrieved.  Each workflow document then will be updated with the corresponding
241      * application document status that is new in KFS 5.0
242      *
243      * @return true if the vendor credit memo status code successfully migrates else return false.
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         //get the status code/descriptions from the table ap_crdt_memo_stat_t
255         Map<String, String> vendorCreditMemoStatusMap = getStatusCodeAndDescriptionForPurapDocumentsDao().getVendorCreditMemoDocumentStatuses();
256 
257         //get the vendor credit memo details where CRDT_MEMO_STAT_CD is not null....
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             //find the workflow document and update the app_doc_stat and app_doc_stat_mdfn_dt columns.
270             getPurapDocumentsStatusCodeMigrationDao().updateAndSaveMigratedApplicationDocumentStatuses(vcmDocNumber, newApplicationDocumentStatus, getDateTimeService().getCurrentTimestamp());
271 
272             //now reindex the requistion for document search...
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      * Processes the Line Item Receiving for status code migration.  Creates a list of documents numbers
285      * and current status code where status code needs migration and using that list the workflow documents
286      * will be retrieved.  Each workflow document then will be updated with the corresponding
287      * application document status that is new in KFS 5.0
288      *
289      * @return true if the Line Item Receiving status code successfully migrates else return false.
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         //get the status cde/descriptions from the table PUR_RCVNG_LN_STAT_T
301         Map<String, String> lineItemReceivingStatusMap = getStatusCodeAndDescriptionForPurapDocumentsDao().getLineItemReceivingDocumentStatuses();
302 
303         //get the line item receiving documents details where RCVNG_LN_STAT_CD is not null....        
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             //find the workflow document and update the app_doc_stat and app_doc_stat_mdfn_dt columns.
316             getPurapDocumentsStatusCodeMigrationDao().updateAndSaveMigratedApplicationDocumentStatuses(lineItemRecvDocNumber, newApplicationDocumentStatus, getDateTimeService().getCurrentTimestamp());
317 
318             //now reindex the requistion for document search...
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      * Gets the migratePurapStatCodeReportService attribute.
332      *
333      * @return Returns the migratePurapStatCodeReportService.
334      */
335     protected ReportWriterService getMigratePurapStatCodeReportService() {
336         return migratePurapStatCodeReportService;
337     }
338 
339     /**
340      * Sets the migratePurapStatCodeReportService attribute value.
341      *
342      * @param migratePurapStatCodeReportService
343      *         The autoDisapproveErrorReportWriterService to set.
344      */
345     public void setMigratePurapStatCodeReportService(ReportWriterService migratePurapStatCodeReportService) {
346         this.migratePurapStatCodeReportService = migratePurapStatCodeReportService;
347     }
348 
349     /**
350      * Gets the businessObjectService attribute.
351      *
352      * @return Returns the businessObjectService
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      * Sets the businessObjectService attribute.
365      *
366      * @param businessObjectService The businessObjectService to set.
367      */
368     public void setBusinessObjectService(BusinessObjectService businessObjectService) {
369         this.businessObjectService = businessObjectService;
370     }
371 
372     /**
373      * Gets the statusCodeAndDescriptionForPurapDocumentsDao attribute.
374      *
375      * @return Returns the statusCodeAndDescriptionForPurapDocumentsDao
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      * Sets the statusCodeAndDescriptionForPurapDocumentsDao attribute.
388      *
389      * @param statusCodeAndDescriptionForPurapDocumentsDao
390      *         The statusCodeAndDescriptionForPurapDocumentsDao to set.
391      */
392     public void setStatusCodeAndDescriptionForPurapDocumentsDao(StatusCodeAndDescriptionForPurapDocumentsDao statusCodeAndDescriptionForPurapDocumentsDao) {
393         this.statusCodeAndDescriptionForPurapDocumentsDao = statusCodeAndDescriptionForPurapDocumentsDao;
394     }
395 
396     /**
397      * Gets the dateTimeService attribute.
398      *
399      * @return Returns the dateTimeService
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      * Sets the dateTimeService attribute.
412      *
413      * @param dateTimeService The dateTimeService to set.
414      */
415     public void setDateTimeService(DateTimeService dateTimeService) {
416         this.dateTimeService = dateTimeService;
417     }
418 
419     /**
420      * Gets the purapDocumentsStatusCodeMigrationDao attribute.
421      *
422      * @return Returns the purapDocumentsStatusCodeMigrationDao
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      * Sets the purapDocumentsStatusCodeMigrationDao attribute.
435      *
436      * @param purapDocumentsStatusCodeMigrationDao
437      *         The purapDocumentsStatusCodeMigrationDao to set.
438      */
439     public void setPurapDocumentsStatusCodeMigrationDao(PurapDocumentsStatusCodeMigrationDao purapDocumentsStatusCodeMigrationDao) {
440         this.purapDocumentsStatusCodeMigrationDao = purapDocumentsStatusCodeMigrationDao;
441     }
442 
443 
444 }