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