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 UpdateBibExcludingGPFieldAction 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              List<String> gpfFieldList = overlayRetrivalService.getGloballyProtectedFieldsModificationList();
53              String updateBibResponseString = overlayHelperService.updateBibliographicRecordExcludingGPFToDocStore(existingBibUUID, oldBibliographicRecord, newBibliographicRecord, gpfFieldList, overlayOptionList);
54              executionEnvironment.getEngineResults().setAttribute(OLEConstants.UPDATE_BIB_EXCLUDING_GPF, true);
55          } catch (Exception e) {
56              e.printStackTrace();
57              executionEnvironment.getEngineResults().setAttribute(OLEConstants.UPDATE_BIB_EXCLUDING_GPF, null);
58          }
59      }
60  
61      /**
62       *   This method simulate the executionEnvironment.
63       * @param executionEnvironment
64       */
65  
66      @Override
67      public void executeSimulation(ExecutionEnvironment executionEnvironment) {
68          execute(executionEnvironment);
69      }
70  
71      /**
72       *  Gets the dataCarrierService attribute.
73       * @return  Returns dataCarrierService.
74       */
75      protected DataCarrierService getDataCarrierService() {
76          if(dataCarrierService == null){
77              return GlobalResourceLoader.getService(OLEConstants.DATA_CARRIER_SERVICE);
78          }
79          return dataCarrierService;
80      }
81  
82      public OverlayHelperService getOverlayHelperService() {
83          if(overlayHelperService==null){
84              overlayHelperService = GlobalResourceLoader.getService(OLEConstants.OVERLAY_HELPER_SERVICE);
85          }
86          return overlayHelperService;
87      }
88  
89      public OverlayRetrivalService getOverlayRetrivalService() {
90          if(overlayRetrivalService == null){
91              overlayRetrivalService = GlobalResourceLoader.getService(OLEConstants.OVERLAY_RETRIVAL_SERVICE);
92          }
93          return overlayRetrivalService;
94      }
95  
96  }