View Javadoc
1   package org.kuali.ole;
2   
3   import org.kuali.ole.describe.defaultload.LoadDefaultLocationsBean;
4   import org.kuali.ole.ingest.FileUtil;
5   import org.kuali.ole.service.OleLocationConverterService;
6   import org.kuali.rice.core.api.impex.xml.XmlDocCollection;
7   import org.kuali.rice.core.api.impex.xml.XmlIngesterService;
8   
9   import java.io.File;
10  import java.util.*;
11  
12  /**
13   * Created by pvsubrah on 12/5/13.
14   */
15  public class LocationsIngesterService implements XmlIngesterService {
16      OleLocationConverterService oleLocationConverterService;
17  
18      @Override
19      public Collection<XmlDocCollection> ingest(List<XmlDocCollection> xmlDocCollections) throws Exception {
20          boolean failedRecords = false;
21          for (Iterator<XmlDocCollection> iterator = xmlDocCollections.iterator(); iterator.hasNext(); ) {
22              XmlDocCollection xmlDocCollection = iterator.next();
23              File file = xmlDocCollection.getFile();
24              String fileContent = new FileUtil().readFile(file);
25  
26              oleLocationConverterService.persistLocationFromFileContent(fileContent, file.getName());
27              failedRecords = oleLocationConverterService.getRejectLocationList().size() > 0;
28  
29          }
30          if (!failedRecords) {
31              return new LinkedList<>();
32          }
33          return xmlDocCollections;
34      }
35  
36  
37  //    TODO:Refactor to make use the principal id.
38      @Override
39      public Collection<XmlDocCollection> ingest(List<XmlDocCollection> xmlDocCollections, String principalId) throws Exception {
40          return ingest(xmlDocCollections);
41      }
42  
43      public OleLocationConverterService getOleLocationConverterService() {
44          return oleLocationConverterService;
45      }
46  
47      public void setOleLocationConverterService(OleLocationConverterService oleLocationConverterService) {
48          this.oleLocationConverterService = oleLocationConverterService;
49      }
50  }