1 package org.kuali.ole;
2
3 import org.kuali.ole.deliver.bo.OlePatronDocument;
4 import org.kuali.ole.deliver.bo.OlePatronIngestSummaryRecord;
5 import org.kuali.ole.ingest.FileUtil;
6 import org.kuali.ole.service.OlePatronConverterService;
7 import org.kuali.rice.core.api.impex.xml.XmlDocCollection;
8 import org.kuali.rice.core.api.impex.xml.XmlIngesterService;
9
10 import java.io.File;
11 import java.util.Collection;
12 import java.util.Iterator;
13 import java.util.LinkedList;
14 import java.util.List;
15
16
17
18
19 public class PatronsIngesterService implements XmlIngesterService {
20 private OlePatronConverterService olePatronConverterService;
21
22 @Override
23 public Collection<XmlDocCollection> ingest(List<XmlDocCollection> xmlDocCollections) throws Exception {
24 boolean failedRecords = false;
25 for (Iterator<XmlDocCollection> iterator = xmlDocCollections.iterator(); iterator.hasNext(); ) {
26 XmlDocCollection xmlDocCollection = iterator.next();
27 File file = xmlDocCollection.getFile();
28 String fileContent = new FileUtil().readFile(file);
29
30 OlePatronIngestSummaryRecord olePatronIngestSummaryRecord = new OlePatronIngestSummaryRecord();
31 List<OlePatronDocument> olePatronDocuments = olePatronConverterService.persistPatronFromFileContent(fileContent,
32 true,
33 file.getName(),
34 olePatronIngestSummaryRecord, null, "");
35 failedRecords = !(olePatronIngestSummaryRecord.getPatronRejectCount() > 0);
36
37 }
38 if (!failedRecords) {
39 return new LinkedList<>();
40 }
41 return xmlDocCollections;
42 }
43
44 @Override
45 public Collection<XmlDocCollection> ingest(List<XmlDocCollection> xmlDocCollections, String principalId) throws Exception {
46 return null;
47 }
48
49 public void setOlePatronConverterService(OlePatronConverterService olePatronConverterService) {
50 this.olePatronConverterService = olePatronConverterService;
51 }
52
53 public OlePatronConverterService getOlePatronConverterService() {
54 return olePatronConverterService;
55 }
56 }