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