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