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 UpdateBibIncludingGPFieldAction 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
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
62
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 }