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
19
20
21
22
23
24 public class UpdateBibExcludingGPFieldAction implements Action {
25 private OverlayHelperService overlayHelperService;
26 private OverlayRetrivalService overlayRetrivalService;
27 private DataCarrierService dataCarrierService;
28
29
30
31
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
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
63
64
65
66 @Override
67 public void executeSimulation(ExecutionEnvironment executionEnvironment) {
68 execute(executionEnvironment);
69 }
70
71
72
73
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 }