View Javadoc
1   package org.kuali.ole.batch.bo;
2   
3   import org.apache.log4j.Logger;
4   import org.kuali.ole.OLEConstants;
5   import org.kuali.ole.batch.document.OLEBatchProcessDefinitionDocument;
6   import org.kuali.ole.batch.form.OLEBatchProcessJobDetailsForm;
7   import org.kuali.ole.batch.helper.OLEBatchProcessDataHelper;
8   import org.kuali.rice.coreservice.impl.parameter.ParameterBo;
9   import org.kuali.rice.krad.document.TransactionalDocumentBase;
10  import org.kuali.rice.krad.service.KRADServiceLocator;
11  
12  import java.io.File;
13  import java.nio.file.FileSystems;
14  import java.sql.Timestamp;
15  import java.util.Date;
16  import java.util.HashMap;
17  import java.util.List;
18  import java.util.Map;
19  
20  /**
21   * Created with IntelliJ IDEA.
22   * User: krishnamohanv
23   * Date: 7/11/13
24   * Time: 6:53 PM
25   * To change this template use File | Settings | File Templates.
26   */
27  public class OLEBatchProcessJobDetailsBo extends TransactionalDocumentBase {
28  
29  
30      private String sNo;
31      private String jobId;
32      private String jobIdNum;
33      private String jobName;
34      private String userName;
35      private Timestamp startTime = new Timestamp(new Date().getTime()); //default value
36      private String timeSpent="0:0:0";
37      private String recordsExported;
38      private String perCompleted = "0.0%"; //default value
39      private String status;
40      private String batchProfileName;
41      private String uploadFileName;
42      private Timestamp createTime = new Timestamp(new Date().getTime()); //default value
43      private Timestamp endTime;
44      private String statusDesc;
45      private String oleBatchPrcsScheduleId;
46      private String batchProcessId;
47      private String batchProcessType;
48      private String totalNoOfRecords="0";
49      private String noOfRecordsProcessed="0";
50      private String noOfSuccessRecords="0";
51      private String noOfFailureRecords="0";
52      private String noOfDeletedRecords="0";
53      private boolean failureAttachmentFlag;
54      private boolean errorAttachmentFlag;
55  
56      private boolean fileCreatedWithOutLinkFlag;
57      private boolean fileCreatedWithMoreThanOneLinkFlag;
58  
59      private boolean failureCSVAttachmentFlag;
60      private String bibErrorPath;
61      private String batchDeletePath;
62  
63      private String serialCSVErrorPath;
64      private String hstrySucceesCount="0";
65      private String hstryFailureCount="0";
66      private String typeSuccessCount="0";
67      private String typeFailureCount="0";
68      private boolean documentFlag;
69      private boolean historyFlag;
70      private boolean typeFlag;
71      private boolean inputCSVFormatFlag;
72      private Integer orderImportSuccessCount;
73      private Integer orderImportFailureCount;
74      private Integer createBibCount;
75      private Integer updateBibCount;
76      private Integer createHoldingsCount;
77      private Integer updateHoldingsCount;
78  
79      private Integer noOfEinstanceAdded;
80      private Integer noOfEinstanceDeleted;
81      private Integer noOfEinstanceCreatedWithOutLink;
82      private Integer noOfbibsHaveMoreThanOneEinstance;
83      private boolean bibsDeletedForExportFlag;
84  
85      private OLEBatchProcessScheduleBo oleBatchProcessScheduleBo;
86      private List<OLEBatchProcessScheduleBo> oleBatchProcessScheduleBoList;
87  
88      private OLEBatchProcessDefinitionDocument oLEBatchProcessDefinitionDocument;
89      public OLEBatchProcessJobDetailsForm form;
90  
91      private OrderImportHelperBo orderImportHelperBo = new OrderImportHelperBo();
92  
93      private static final Logger LOG = Logger.getLogger(OLEBatchProcessJobDetailsBo.class);
94  
95  
96      public boolean isFailureAttachmentFlag() {
97          File file = new File(getBatchProcessFilePath(this.getBatchProcessType(), this.getJobId()) + this.getJobId() + "_FailureRecord" + "_" + this.getUploadFileName());
98          if (file.exists()) {
99              return true;
100         } else if ((this.getBatchProcessType() != null && !this.getBatchProcessType().equals(OLEConstants.OLEBatchProcess.ORDER_RECORD_IMPORT)) && isFileCreatedWithMoreThanOneLinkFlag()) {
101             return true;
102         } else if ((this.getBatchProcessType() != null && !this.getBatchProcessType().equals(OLEConstants.OLEBatchProcess.ORDER_RECORD_IMPORT)) && isFileCreatedWithOutLinkFlag()) {
103             return true;
104         }
105         return false;
106     }
107 
108     public boolean isErrorAttachmentFlag() {
109         String uploadFileName = this.getUploadFileName();
110         String errorFileName = null;
111         String[] fileNames = uploadFileName.split(",");
112         errorFileName = fileNames.length == 2 ? fileNames[0]:uploadFileName;
113         if(errorFileName.endsWith(".mrc")){
114             errorFileName = errorFileName.replace(".mrc",".txt");
115         }
116         else if(errorFileName.endsWith(".INV")){
117             errorFileName = errorFileName.replace(".INV",".txt");
118         }
119         else if(errorFileName.endsWith(".edi")){
120             errorFileName = errorFileName.replace(".edi",".txt");
121         }
122         File file = new File(getBatchProcessFilePath(this.getBatchProcessType() , this.getJobId())+this.getJobId()+ "_FailureRecord" + "_" + errorFileName);
123         if(file.exists())
124             return true;
125         return false;
126     }
127 
128     public void setErrorAttachmentFlag(boolean errorAttachmentFlag) {
129         this.errorAttachmentFlag= errorAttachmentFlag;
130     }
131 
132     public boolean isFileCreatedWithOutLinkFlag() {
133         File file = new File(getBatchProcessFilePath(this.getBatchProcessType() , this.getJobId())+ this.getJobId() + OLEConstants.OLEBatchProcess.RECORDS_CREATED_WITHOUT_LINK  + this.getUploadFileName());
134         if(file.exists())
135             return true;
136         return false;
137     }
138 
139     public void setFileCreatedWithOutLinkFlag(boolean fileCreatedWithOutLinkFlag) {
140         this.fileCreatedWithOutLinkFlag = fileCreatedWithOutLinkFlag;
141     }
142 
143     public boolean isFileCreatedWithMoreThanOneLinkFlag() {
144         File file = new File(getBatchProcessFilePath(this.getBatchProcessType() , this.getJobId()) +  this.getJobId()  + OLEConstants.OLEBatchProcess.RECORDS_CREATED_WITH_MORE_THAN_ONE_LINK + this.getUploadFileName());
145         if(file.exists())
146             return true;
147         return false;
148     }
149 
150     public void setFileCreatedWithMoreThanOneLinkFlag(boolean fileCreatedWithMoreThanOneLinkFlag) {
151         this.fileCreatedWithMoreThanOneLinkFlag = fileCreatedWithMoreThanOneLinkFlag;
152     }
153 
154     public boolean isBibsDeletedForExportFlag() {
155         File file = new File(getBatchProcessFilePath(this.getBatchProcessType(), this.getJobId()) + this.getJobId() + OLEConstants.OLEBatchProcess.DELETED_BIB_IDS_FILE_NAME);
156         if (file.exists()) {
157             return true;
158         }
159         return false;
160     }
161 
162     public void setBibsDeletedForExportFlag(boolean bibsDeletedForExportFlag) {
163         this.bibsDeletedForExportFlag = bibsDeletedForExportFlag;
164     }
165 
166     public Integer getNoOfEinstanceAdded() {
167         return noOfEinstanceAdded;
168     }
169 
170     public void setNoOfEinstanceAdded(Integer noOfEinstanceAdded) {
171         this.noOfEinstanceAdded = noOfEinstanceAdded;
172     }
173 
174     public Integer getNoOfEinstanceDeleted() {
175         return noOfEinstanceDeleted;
176     }
177 
178     public void setNoOfEinstanceDeleted(Integer noOfEinstanceDeleted) {
179         this.noOfEinstanceDeleted = noOfEinstanceDeleted;
180     }
181 
182     public Integer getNoOfEinstanceCreatedWithOutLink() {
183         return noOfEinstanceCreatedWithOutLink;
184     }
185 
186     public void setNoOfEinstanceCreatedWithOutLink(Integer noOfEinstanceCreatedWithOutLink) {
187         this.noOfEinstanceCreatedWithOutLink = noOfEinstanceCreatedWithOutLink;
188     }
189 
190     public Integer getNoOfbibsHaveMoreThanOneEinstance() {
191         return noOfbibsHaveMoreThanOneEinstance;
192     }
193 
194     public void setNoOfbibsHaveMoreThanOneEinstance(Integer noOfbibsHaveMoreThanOneEinstance) {
195         this.noOfbibsHaveMoreThanOneEinstance = noOfbibsHaveMoreThanOneEinstance;
196     }
197 
198     public void setFailureAttachmentFlag(boolean failureAttachmentFlag) {
199         this.failureAttachmentFlag = failureAttachmentFlag;
200     }
201 
202     public boolean isFailureCSVAttachmentFlag() {
203         String[] fileNames=this.getUploadFileName().split(",");
204         for (String fileName:fileNames){
205             if (fileName.contains(getParameter(OLEConstants.OLEBatchProcess.SERIAL_RECORD_NAME))){
206                 File file = new File(getBatchProcessFilePath(this.getBatchProcessType(), jobId) + this.getJobId() + "_FailureRecord" + "_" + fileName.replace("csv","xml"));
207                 if(file.exists())
208                     return true;
209             }
210             else if (fileName.contains(getParameter(OLEConstants.OLEBatchProcess.SERIAL_HISTORY_NAME))){
211                 File file = new File(getBatchProcessFilePath(this.getBatchProcessType(),jobId) + this.getJobId() + "_FailureRecord" + "_" + fileName.replace("csv","xml"));
212                 if(file.exists())
213                     return true;
214             } else if (fileName.contains(getParameter(OLEConstants.OLEBatchProcess.SERIAL_TYPE_NAME))){
215                 File file = new File(getBatchProcessFilePath(this.getBatchProcessType(),jobId) + this.getJobId() + "_FailureRecord" + "_" + fileName.replace("csv","xml"));
216                 if(file.exists())
217                     return true;
218             }
219         }
220         return false;
221     }
222 
223     public void setFailureCSVAttachmentFlag(boolean failureCSVAttachmentFlag) {
224         this.failureCSVAttachmentFlag = failureCSVAttachmentFlag;
225     }
226 
227     public void getJobDisplay(){
228         LOG.info("get Report.....");
229     }
230 
231 
232     public String getTotalNoOfRecords() {
233         return totalNoOfRecords;
234     }
235 
236     public void setTotalNoOfRecords(String totalNoOfRecords) {
237         this.totalNoOfRecords = totalNoOfRecords;
238     }
239 
240     public String getNoOfRecordsProcessed() {
241         return noOfRecordsProcessed;
242     }
243 
244     public void setNoOfRecordsProcessed(String noOfRecordsProcessed) {
245         this.noOfRecordsProcessed = noOfRecordsProcessed;
246     }
247 
248     public OLEBatchProcessJobDetailsForm getForm() {
249         return form;
250     }
251 
252     public void setForm(OLEBatchProcessJobDetailsForm form) {
253         this.form = form;
254     }
255 
256     public String getsNo() {
257         return sNo;
258     }
259 
260     public void setsNo(String sNo) {
261         this.sNo = sNo;
262     }
263 
264     public String getJobId() {
265         return jobId;
266     }
267 
268     public void setJobId(String jobId) {
269         this.jobId = jobId;
270     }
271 
272     public String getJobName() {
273         return jobName;
274     }
275 
276     public void setJobName(String jobName) {
277         this.jobName = jobName;
278     }
279 
280     public String getUserName() {
281         return userName;
282     }
283 
284     public void setUserName(String userName) {
285         this.userName = userName;
286     }
287 
288     public String getRecordsExported() {
289         return recordsExported;
290     }
291 
292     public void setRecordsExported(String recordsExported) {
293         this.recordsExported = recordsExported;
294     }
295 
296     public String getPerCompleted() {
297         return perCompleted;
298     }
299 
300     public void setPerCompleted(String perCompleted) {
301         this.perCompleted = perCompleted;
302     }
303 
304     public String getStatus() {
305         return status;
306     }
307 
308     public void setStatus(String status) {
309         this.status = status;
310     }
311 
312     public String getBatchProfileName() {
313         return batchProfileName;
314     }
315 
316     public void setBatchProfileName(String batchProfileName) {
317         this.batchProfileName = batchProfileName;
318     }
319 
320 
321     public String getUploadFileName() {
322         return uploadFileName;
323     }
324 
325     public void setUploadFileName(String uploadFileName) {
326         this.uploadFileName = uploadFileName;
327     }
328 
329 
330     public Timestamp getStartTime() {
331         return startTime;
332     }
333 
334     public void setStartTime(Timestamp startTime) {
335         this.startTime = startTime;
336     }
337 
338 
339     public Timestamp getEndTime() {
340         return endTime;
341     }
342 
343     public void setEndTime(Timestamp endTime) {
344         this.endTime = endTime;
345     }
346 
347     public String getStatusDesc() {
348         return statusDesc;
349     }
350 
351     public void setStatusDesc(String statusDesc) {
352         this.statusDesc = statusDesc;
353     }
354 
355     public String getOleBatchPrcsScheduleId() {
356         return oleBatchPrcsScheduleId;
357     }
358 
359     public void setOleBatchPrcsScheduleId(String oleBatchPrcsScheduleId) {
360         this.oleBatchPrcsScheduleId = oleBatchPrcsScheduleId;
361     }
362 
363     public String getBatchProcessId() {
364         return batchProcessId;
365     }
366 
367     public Timestamp getCreateTime() {
368         return createTime;
369     }
370 
371     public void setCreateTime(Timestamp createTime) {
372         this.createTime = createTime;
373     }
374 
375     public void setBatchProcessId(String batchProcessId) {
376         this.batchProcessId = batchProcessId;
377     }
378 
379     public OLEBatchProcessScheduleBo getOleBatchProcessScheduleBo() {
380         return oleBatchProcessScheduleBo;
381     }
382 
383     public void setOleBatchProcessScheduleBo(OLEBatchProcessScheduleBo oleBatchProcessScheduleBo) {
384         this.oleBatchProcessScheduleBo = oleBatchProcessScheduleBo;
385     }
386 
387     public List<OLEBatchProcessScheduleBo> getOleBatchProcessScheduleBoList() {
388         return oleBatchProcessScheduleBoList;
389     }
390 
391     public void setOleBatchProcessScheduleBoList(List<OLEBatchProcessScheduleBo> oleBatchProcessScheduleBoList) {
392         this.oleBatchProcessScheduleBoList = oleBatchProcessScheduleBoList;
393     }
394 
395     public String getBatchProcessType() {
396         return batchProcessType;
397     }
398 
399     public void setBatchProcessType(String batchProcessType) {
400         this.batchProcessType = batchProcessType;
401     }
402 
403     public OLEBatchProcessDefinitionDocument getOLEBatchProcessDefinitionDocument() {
404         return oLEBatchProcessDefinitionDocument;
405     }
406 
407     public void setOLEBatchProcessDefinitionDocument(OLEBatchProcessDefinitionDocument oLEBatchProcessDefinitionDocument) {
408         this.oLEBatchProcessDefinitionDocument = oLEBatchProcessDefinitionDocument;
409     }
410 
411     public String getTimeSpent() {
412         return timeSpent;
413     }
414 
415     public void setTimeSpent(String timeSpent) {
416         this.timeSpent = timeSpent;
417     }
418 
419     public String getNoOfSuccessRecords() {
420         return noOfSuccessRecords;
421     }
422 
423     public void setNoOfSuccessRecords(String noOfSuccessRecords) {
424         this.noOfSuccessRecords = noOfSuccessRecords;
425     }
426 
427     public String getNoOfFailureRecords() {
428         return noOfFailureRecords;
429     }
430 
431     public void setNoOfFailureRecords(String noOfFailureRecords) {
432         this.noOfFailureRecords = noOfFailureRecords;
433     }
434 
435     public String getNoOfDeletedRecords() {
436         return noOfDeletedRecords;
437     }
438 
439     public void setNoOfDeletedRecords(String noOfDeletedRecords) {
440         this.noOfDeletedRecords = noOfDeletedRecords;
441     }
442 
443     private String getBatchProcessFilePath(String batchProceesType) {
444         String batchProcessLocation =  OLEBatchProcessDataHelper.getInstance().getBatchProcessFilePath(batchProceesType);
445         return batchProcessLocation;
446     }
447     private String getBatchProcessFilePath(String batchProceesType,String jobId) {
448         String batchProcessLocation =  OLEBatchProcessDataHelper.getInstance().getBatchProcessFilePath(batchProceesType,jobId);
449         return batchProcessLocation;
450     }
451 
452     public String getBibErrorPath() {
453         return bibErrorPath;
454     }
455 
456     public void setBibErrorPath(String bibErrorPath) {
457         this.bibErrorPath = bibErrorPath;
458     }
459 
460     public String getBatchDeletePath() {
461         return batchDeletePath;
462     }
463 
464     public void setBatchDeletePath(String batchDeletePath) {
465         this.batchDeletePath = batchDeletePath;
466     }
467 
468     public void setJobIdNum(String jobIdNum) {
469         this.jobIdNum = jobIdNum;
470     }
471 
472     public String getJobIdNum() {
473         return String.format("%08d", Integer.parseInt(jobId)) ;
474     }
475 
476     public String getHstrySucceesCount() {
477         return hstrySucceesCount;
478     }
479 
480     public void setHstrySucceesCount(String hstrySucceesCount) {
481         this.hstrySucceesCount = hstrySucceesCount;
482     }
483 
484     public String getHstryFailureCount() {
485         return hstryFailureCount;
486     }
487 
488     public void setHstryFailureCount(String hstryFailureCount) {
489         this.hstryFailureCount = hstryFailureCount;
490     }
491 
492     public String getTypeSuccessCount() {
493         return typeSuccessCount;
494     }
495 
496     public void setTypeSuccessCount(String typeSuccessCount) {
497         this.typeSuccessCount = typeSuccessCount;
498     }
499 
500     public String getTypeFailureCount() {
501         return typeFailureCount;
502     }
503 
504     public void setTypeFailureCount(String typeFailureCount) {
505         this.typeFailureCount = typeFailureCount;
506     }
507 
508     public boolean isDocumentFlag() {
509         if (uploadFileName.contains(getParameter(OLEConstants.OLEBatchProcess.SERIAL_RECORD_NAME)+".csv")){
510             return true;
511         }
512         return false;
513     }
514 
515     public void setDocumentFlag(boolean documentFlag) {
516         this.documentFlag = documentFlag;
517     }
518 
519     public boolean isHistoryFlag() {
520         if (uploadFileName.contains(getParameter(OLEConstants.OLEBatchProcess.SERIAL_HISTORY_NAME)+".csv")){
521             return true;
522         }
523         return false;
524     }
525 
526     public void setHistoryFlag(boolean historyFlag) {
527         this.historyFlag = historyFlag;
528     }
529 
530     public boolean isTypeFlag() {
531         if (uploadFileName.contains(getParameter(OLEConstants.OLEBatchProcess.SERIAL_TYPE_NAME)+".csv")){
532             return true;
533         }
534         return false;
535     }
536 
537     public void setTypeFlag(boolean typeFlag) {
538         this.typeFlag = typeFlag;
539     }
540     private String getParameter(String name) {
541         String parameter = "";
542         try {
543             Map<String, String> criteriaMap = new HashMap<String, String>();
544             criteriaMap.put("namespaceCode", OLEConstants.SYS_NMSPC);
545             criteriaMap.put("componentCode", OLEConstants.BATCH_CMPNT);
546             criteriaMap.put("name", name);
547             List<ParameterBo> parametersList = (List<ParameterBo>) KRADServiceLocator.getBusinessObjectService().findMatching(ParameterBo.class, criteriaMap);
548             for (ParameterBo parameterBo : parametersList) {
549                 parameter = parameterBo.getValue();
550             }
551         } catch (Exception e) {
552             e.printStackTrace();
553         }
554         return parameter;
555     }
556 
557     public String getSerialCSVErrorPath() {
558         return serialCSVErrorPath;
559     }
560 
561     public void setSerialCSVErrorPath(String serialCSVErrorPath) {
562         this.serialCSVErrorPath = serialCSVErrorPath;
563     }
564 
565     public boolean isInputCSVFormatFlag() {
566         if (uploadFileName.contains(".csv")) {
567             return true;
568         }
569         return false;
570     }
571 
572     public void setInputCSVFormatFlag(boolean inputCSVFormatFlag) {
573         this.inputCSVFormatFlag = inputCSVFormatFlag;
574     }
575 
576     public Integer getOrderImportSuccessCount() {
577         return orderImportSuccessCount;
578     }
579 
580     public void setOrderImportSuccessCount(Integer orderImportSuccessCount) {
581         this.orderImportSuccessCount = orderImportSuccessCount;
582     }
583 
584     public Integer getOrderImportFailureCount() {
585         return orderImportFailureCount;
586     }
587 
588     public void setOrderImportFailureCount(Integer orderImportFailureCount) {
589         this.orderImportFailureCount = orderImportFailureCount;
590     }
591 
592     public Integer getCreateBibCount() {
593         return createBibCount;
594     }
595 
596     public void setCreateBibCount(Integer createBibCount) {
597         this.createBibCount = createBibCount;
598     }
599 
600     public Integer getUpdateBibCount() {
601         return updateBibCount;
602     }
603 
604     public void setUpdateBibCount(Integer updateBibCount) {
605         this.updateBibCount = updateBibCount;
606     }
607 
608     public Integer getCreateHoldingsCount() {
609         return createHoldingsCount;
610     }
611 
612     public void setCreateHoldingsCount(Integer createHoldingsCount) {
613         this.createHoldingsCount = createHoldingsCount;
614     }
615 
616     public OrderImportHelperBo getOrderImportHelperBo() {
617         return orderImportHelperBo;
618     }
619 
620     public void setOrderImportHelperBo(OrderImportHelperBo orderImportHelperBo) {
621         this.orderImportHelperBo = orderImportHelperBo;
622     }
623 
624     public Integer getUpdateHoldingsCount() {
625         return updateHoldingsCount;
626     }
627 
628     public void setUpdateHoldingsCount(Integer updateHoldingsCount) {
629         this.updateHoldingsCount = updateHoldingsCount;
630     }
631 
632     public void setJobstatistics(OLEBatchBibImportStatistics bibImportStatistics) {
633         setNoOfRecordsProcessed(Integer.parseInt(noOfRecordsProcessed) + bibImportStatistics.getTotalCount() + "");
634         setNoOfSuccessRecords(bibImportStatistics.getSuccessRecord() + "");
635         setNoOfFailureRecords((bibImportStatistics.getMismatchRecordList().size()) + "");
636         setNoOfEinstanceAdded(bibImportStatistics.getNoOfEinstanceAdded());
637         setNoOfEinstanceDeleted(bibImportStatistics.getNoOfEinstanceDeleted());
638         setNoOfEinstanceCreatedWithOutLink(bibImportStatistics.getNoOfEinstanceCreatedWithOutLink());
639         setNoOfbibsHaveMoreThanOneEinstance(bibImportStatistics.getNoOfbibsHaveMoreThanOneEinstance());
640 
641     }
642     
643     
644     public void setIntailJob(OLEBatchBibImportStatistics bibImportStatistics){
645        setNoOfSuccessRecords("0");
646        setNoOfFailureRecords("0");
647        setNoOfRecordsProcessed("0");
648        setNoOfEinstanceAdded(0);
649        setNoOfEinstanceDeleted(0);
650        setNoOfEinstanceCreatedWithOutLink(0);
651        setNoOfbibsHaveMoreThanOneEinstance(0);
652        setTotalNoOfRecords(bibImportStatistics.getBibMarcRecordList().size()+"");
653     }
654 
655 }