1 package org.kuali.ole.batch.ingest;
2
3 import org.apache.log4j.Logger;
4 import org.kuali.ole.OLEConstants;
5 import org.kuali.ole.batch.impl.AbstractBatchProcess;
6 import org.kuali.ole.ingest.OlePatronXMLSchemaValidator;
7 import org.kuali.ole.deliver.bo.OlePatronIngestSummaryRecord;
8 import org.kuali.ole.service.OlePatronConverterService;
9 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
10 import org.kuali.rice.krad.util.GlobalVariables;
11
12 import java.io.ByteArrayInputStream;
13 import java.io.InputStream;
14
15
16
17
18
19
20
21
22 public class BatchProcessPatronIngest extends AbstractBatchProcess {
23 private static final Logger LOG = Logger.getLogger(BatchProcessPatronIngest.class);
24 private OlePatronConverterService olePatronRecordService;
25 private String principalName = GlobalVariables.getUserSession().getPrincipalName();
26 private OlePatronIngestSummaryRecord olePatronIngestSummaryRecord;
27 private OlePatronXMLSchemaValidator olePatronXMLSchemaValidator;
28 private String fileContent = null;
29
30 @Override
31 public void prepareForRead() throws Exception {
32 olePatronRecordService = GlobalResourceLoader.getService(OLEConstants.PATRON_CONVERTER_SERVICE);
33 olePatronIngestSummaryRecord = new OlePatronIngestSummaryRecord();
34 olePatronXMLSchemaValidator = new OlePatronXMLSchemaValidator();
35 fileContent = getBatchProcessFileContent();
36 job.setNoOfSuccessRecords("0");
37 job.setNoOfFailureRecords("0");
38 job.setNoOfRecordsProcessed("0");
39 }
40
41
42 @Override
43 public void prepareForWrite() throws Exception {
44 InputStream inputStream = new ByteArrayInputStream(fileContent.getBytes());
45 boolean schemaFlag = olePatronXMLSchemaValidator.validateContentsAgainstSchema(inputStream);
46 if (!schemaFlag) {
47 job.setStatus(OLEConstants.OLEBatchProcess.JOB_STATUS_COMPLETED);
48 deleteBatchFile();
49 createBatchFailureFile(fileContent);
50 throw new Exception("patron ingest schema Failed");
51 }
52
53 olePatronRecordService.persistPatronFromFileContent(fileContent, processDef.isAddUnmatchedPatron(), job.getUploadFileName(), olePatronIngestSummaryRecord, "", principalName);
54 String failedRecords = olePatronIngestSummaryRecord.getFailureRecords();
55 if (!"".equals(failedRecords) && failedRecords != null) {
56 createBatchFailureFile(failedRecords);
57 }
58 deleteBatchFile();
59 int totalCount = olePatronIngestSummaryRecord.getPatronCreateCount() + olePatronIngestSummaryRecord.getPatronUpdateCount() + olePatronIngestSummaryRecord.getPatronFailedCount();
60 int faiCount = olePatronIngestSummaryRecord.getPatronFailedCount();
61 job.setTotalNoOfRecords(totalCount + "");
62 job.setNoOfRecordsProcessed(totalCount + "");
63 job.setNoOfSuccessRecords(totalCount - faiCount + "");
64 job.setNoOfFailureRecords(faiCount + "");
65 job.setStatus(OLEConstants.OLEBatchProcess.JOB_STATUS_COMPLETED);
66
67 }
68
69 @Override
70 public void getNextBatch() {
71
72 }
73
74 @Override
75 public void processBatch() {
76
77 }
78 }