View Javadoc

1   package org.kuali.ole.ingest.action;
2   
3   import org.kuali.ole.DataCarrierService;
4   import org.kuali.ole.OLEConstants;
5   import org.kuali.ole.ingest.pojo.OverlayOption;
6   import org.kuali.ole.pojo.bib.BibliographicRecord;
7   import org.kuali.ole.service.OverlayHelperService;
8   import org.kuali.ole.service.OverlayRetrivalService;
9   import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
10  import org.kuali.rice.krms.api.engine.ExecutionEnvironment;
11  import org.kuali.rice.krms.framework.engine.Action;
12  
13  import java.util.Iterator;
14  import java.util.List;
15  import java.util.Map;
16  
17  /**
18   * Created by IntelliJ IDEA.
19   * User: premkb
20   * Date: 12/11/12
21   * Time: 3:14 PM
22   * To change this template use File | Settings | File Templates.
23   */
24  public class UpdateBibIncludingGPFieldAction implements Action {
25      private OverlayHelperService overlayHelperService;
26      private OverlayRetrivalService overlayRetrivalService;
27      private DataCarrierService dataCarrierService;
28  
29      /**
30       *  This will update the existing Bib and Instance record ignoring the Globally Protected field.
31       * @param executionEnvironment
32       */
33      @Override
34      public void execute(ExecutionEnvironment executionEnvironment) {
35          dataCarrierService = getDataCarrierService();
36          overlayHelperService = getOverlayHelperService();
37          overlayRetrivalService = getOverlayRetrivalService();
38          List<OverlayOption> overlayOptionList = (List<OverlayOption>) dataCarrierService.getData(OLEConstants.OVERLAY_OPTION_LIST);
39          BibliographicRecord newBibliographicRecord = (BibliographicRecord) dataCarrierService.getData(OLEConstants.REQUEST_BIB_RECORD);
40          try {
41              List bibInfoList = (List) dataCarrierService.getData(OLEConstants.BIB_INFO_LIST_FROM_SOLR_RESPONSE);
42              String existingBibUUID = null;
43              for (Iterator iterator = bibInfoList.iterator(); iterator.hasNext(); ) {
44                  Map map = (Map) iterator.next();
45                  if (map.containsKey(OLEConstants.BIB_UNIQUE_ID)) {
46                      existingBibUUID = (String) map.get(OLEConstants.BIB_UNIQUE_ID);
47                      break;
48                  }
49              }
50              BibliographicRecord oldBibliographicRecord = overlayHelperService.getBibliographicRecord(existingBibUUID);
51              //List<String> gpfFieldList = overlayRetrivalService.getGloballyProtectedFieldsList();
52              //String updateBibResponseString = overlayHelperService.updateBibliographicRecordToDocStore(existingBibUUID, oldBibliographicRecord, newBibliographicRecord);
53              String updateBibResponseString = overlayHelperService.updateBibliographicRecordIncludingGPFToDocStore(existingBibUUID, oldBibliographicRecord, newBibliographicRecord, null,overlayOptionList);
54              executionEnvironment.getEngineResults().setAttribute(OLEConstants.UPDATE_BIB_INCLUDING_GPF, true);
55          } catch (Exception e) {
56              e.printStackTrace();
57              executionEnvironment.getEngineResults().setAttribute(OLEConstants.UPDATE_BIB_INCLUDING_GPF, null);
58          }
59      }
60      /**
61       *   This method simulate the executionEnvironment.
62       * @param executionEnvironment
63       */
64  
65      @Override
66      public void executeSimulation(ExecutionEnvironment executionEnvironment) {
67          execute(executionEnvironment);
68      }
69  
70      protected DataCarrierService getDataCarrierService() {
71          if(dataCarrierService == null){
72              return GlobalResourceLoader.getService(OLEConstants.DATA_CARRIER_SERVICE);
73          }
74          return dataCarrierService;
75      }
76  
77      public OverlayHelperService getOverlayHelperService() {
78          if(overlayHelperService==null){
79              overlayHelperService = GlobalResourceLoader.getService(OLEConstants.OVERLAY_HELPER_SERVICE);
80          }
81          return overlayHelperService;
82      }
83  
84      public OverlayRetrivalService getOverlayRetrivalService() {
85          if(overlayRetrivalService == null){
86              overlayRetrivalService = GlobalResourceLoader.getService(OLEConstants.OVERLAY_RETRIVAL_SERVICE);
87          }
88          return overlayRetrivalService;
89      }
90  }