View Javadoc
1   package org.kuali.ole.batch.bo;
2   
3   
4   import org.kuali.ole.batch.ingest.BatchProcessBibImport;
5   import org.kuali.ole.docstore.common.document.*;
6   import org.kuali.ole.docstore.common.document.content.bib.marc.BibMarcRecord;
7   import org.kuali.ole.docstore.common.document.content.bib.marc.OrderBibMarcRecord;
8   import org.kuali.ole.docstore.common.document.ids.BibId;
9   import org.kuali.ole.docstore.common.document.ids.HoldingsId;
10  import org.apache.log4j.Logger;
11  import java.util.*;
12  
13  /**
14   * Created with IntelliJ IDEA.
15   * User: jayabharathreddy
16   * Date: 7/2/14
17   * Time: 4:06 PM
18   * To change this template use File | Settings | File Templates.
19   */
20  public class OLEBatchBibImportDataObjects {
21      private static final Logger LOG = Logger.getLogger(OLEBatchBibImportDataObjects.class);
22      private BibTrees bibTrees;
23  
24      public BibTrees getBibTrees() {
25          if (bibTrees == null) {
26              bibTrees = new BibTrees();
27          }
28          return bibTrees;
29      }
30  
31      public void setBibTreesObj(BibTrees bibTrees) {
32          this.bibTrees = bibTrees;
33      }
34  
35  
36      public List<OrderBibMarcRecord> getResponseOrderRecord(List<OrderBibMarcRecord> orderBibMarcRecords) {
37  
38          for (int i = 0; i < getBibTrees().getBibTrees().size(); i++) {
39              BibTree bibTree = getBibTrees().getBibTrees().get(i);
40              OrderBibMarcRecord orderBibMarcRecord = orderBibMarcRecords.get(i);
41              if (bibTree.getBib().getResult().equals(DocstoreDocument.ResultType.FAILURE)) {
42                  orderBibMarcRecord.setFailureReason(bibTree.getBib().getMessage());
43                  continue;
44              } else {
45                  BibId bibId = new BibId();
46                  bibId.setId(bibTree.getBib().getId());
47                  orderBibMarcRecord.setBibId(bibId);
48              }
49              for (int j = 0; j < bibTree.getHoldingsTrees().size(); j++) {
50  
51                  HoldingsTree holdingsTree = bibTree.getHoldingsTrees().get(j);
52                  HoldingsId holdingsId = new HoldingsId();
53                  if (holdingsTree.getHoldings().getResult().equals(DocstoreDocument.ResultType.FAILURE)) {
54                      orderBibMarcRecord.setFailureReason(holdingsTree.getHoldings().getMessage());
55                      continue;
56                  } else {
57                      holdingsId.setId(holdingsTree.getHoldings().getId());
58                      orderBibMarcRecord.getBibId().getHoldingsIds().add(holdingsId);
59                  }
60                  for (Item item : holdingsTree.getItems()) {
61                      if (item.getResult().equals(DocstoreDocument.ResultType.FAILURE)) {
62                          orderBibMarcRecord.setFailureReason(item.getMessage());
63                          continue;
64                      } else {
65                          holdingsId.getItems().add(item.getId());
66  
67                      }
68                  }
69              }
70  
71          }
72  
73          return orderBibMarcRecords;
74      }
75  
76      public List<OrderBibMarcRecord> processBibImport(List<BibMarcRecord> records,BatchProcessBibImport batchProcessBibImport)throws Exception{
77          List<OrderBibMarcRecord> orderBibMarcRecords = new ArrayList<>();
78          for(BibMarcRecord record:records){
79              OrderBibMarcRecord orderBibMarcRecord = new OrderBibMarcRecord();
80              orderBibMarcRecord.setBibMarcRecord(record);
81              orderBibMarcRecords.add(orderBibMarcRecord);
82          }
83          try {
84              orderBibMarcRecords= batchProcessBibImport.processBatchOrder(orderBibMarcRecords);
85          } catch (Exception e) {
86              LOG.error("Exception when calling  bib import: ", e);
87          }
88          return orderBibMarcRecords;
89      }
90  }
91