View Javadoc
1   package org.kuali.ole;
2   
3   import org.kuali.ole.ingest.FileUtil;
4   import org.kuali.ole.ingest.krms.builder.OleKrmsBuilder;
5   import org.kuali.rice.core.api.impex.xml.XmlDocCollection;
6   import org.kuali.rice.core.api.impex.xml.XmlIngesterService;
7   //import sun.management.resources.agent;
8   
9   import java.io.File;
10  import java.util.Collection;
11  import java.util.Iterator;
12  import java.util.LinkedList;
13  import java.util.List;
14  
15  /**
16   * Created by pvsubrah on 12/6/13.
17   */
18  public class CircPoliciesIngesterService implements XmlIngesterService {
19      protected OleKrmsBuilder circPolicyBuilder;
20  
21      @Override
22      public Collection<XmlDocCollection> ingest(List<XmlDocCollection> xmlDocCollections) throws Exception {
23          boolean failedRecords = false;
24          for (Iterator<XmlDocCollection> iterator = xmlDocCollections.iterator(); iterator.hasNext(); ) {
25              XmlDocCollection xmlDocCollection = iterator.next();
26              File file = xmlDocCollection.getFile();
27              String fileContent = new FileUtil().readFile(file);
28  
29              List<String> agendas = circPolicyBuilder.persistKrmsFromFileContent(fileContent);
30              failedRecords = !(agendas.size() > 0);
31  
32          }
33          if (!failedRecords) {
34              return new LinkedList<>();
35          }
36          return xmlDocCollections;
37      }
38  
39      @Override
40      public Collection<XmlDocCollection> ingest(List<XmlDocCollection> xmlDocCollections, String principalId) throws Exception {
41          return null;
42      }
43  
44      public OleKrmsBuilder getCircPolicyBuilder() {
45          return circPolicyBuilder;
46      }
47  
48      public void setCircPolicyBuilder(OleKrmsBuilder circPolicyBuilder) {
49          this.circPolicyBuilder = circPolicyBuilder;
50      }
51  }