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.editor.service.DiscoveryHelperService;
6 import org.kuali.ole.editor.service.DocstoreHelperService;
7 import org.kuali.ole.pojo.bib.BibliographicRecord;
8 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
9 import org.kuali.rice.krms.api.engine.ExecutionEnvironment;
10 import org.kuali.rice.krms.framework.engine.Action;
11
12 import java.util.Iterator;
13 import java.util.List;
14 import java.util.Map;
15
16
17
18
19 public class UpdateItemAction implements Action {
20
21 private DocstoreHelperService docstoreHelperService;
22 private DiscoveryHelperService discoveryHelperService;
23
24
25
26
27
28 @Override
29 public void execute(ExecutionEnvironment executionEnvironment) {
30
31 DataCarrierService dataCarrierService = getDataCarrierService();
32 BibliographicRecord bibliographicRecord = (BibliographicRecord) dataCarrierService.getData(OLEConstants.REQUEST_BIB_RECORD);
33 List bibInfoList = (List) dataCarrierService.getData(OLEConstants.BIB_INFO_LIST_FROM_SOLR_RESPONSE);
34 String bibUUID = null;
35 for (Iterator iterator = bibInfoList.iterator(); iterator.hasNext(); ) {
36 Map map = (Map) iterator.next();
37 if (map.containsKey(OLEConstants.BIB_UNIQUE_ID)) {
38 bibUUID = (String) map.get(OLEConstants.BIB_UNIQUE_ID);
39 break;
40 }
41 }
42
43 List responseFromSOLR = getDiscoveryHelperService().getResponseFromSOLR("DocType=bibliographic and id", bibUUID);
44 String instanceUUID = null;
45 for (Iterator iterator = responseFromSOLR.iterator(); iterator.hasNext(); ) {
46 Map map = (Map) iterator.next();
47 if (map.containsKey(OLEConstants.BIB_INSTANCE_ID)) {
48 List list =(List)map.get(OLEConstants.BIB_INSTANCE_ID);
49 instanceUUID =list !=null & list.size()>0 ?(String) list.get(0):null;
50 break;
51 }
52 }
53
54 List responseFromSOLR1 = getDiscoveryHelperService().getResponseFromSOLR("DocType=instance and id", instanceUUID);
55 String itemUUID = null;
56 for (Iterator iterator = responseFromSOLR1.iterator(); iterator.hasNext(); ) {
57 Map map = (Map) iterator.next();
58 if (map.containsKey(OLEConstants.BIB_ITEM_ID)) {
59 List list = (List)map.get(OLEConstants.BIB_ITEM_ID);
60 itemUUID = list !=null & list.size()>0 ?(String) list.get(0):null;
61 break;
62 }
63 }
64
65 getDocstoreHelperService().updateItem(bibliographicRecord, itemUUID);
66 executionEnvironment.getEngineResults().setAttribute(OLEConstants.UPDATE_ITEM_FLAG, true);
67 }
68
69
70
71
72
73 protected DataCarrierService getDataCarrierService() {
74 return GlobalResourceLoader.getService(OLEConstants.DATA_CARRIER_SERVICE);
75 }
76
77
78
79
80
81 @Override
82 public void executeSimulation(ExecutionEnvironment executionEnvironment) {
83 execute(executionEnvironment);
84 }
85
86
87
88
89
90 public void setDocstoreHelperService(DocstoreHelperService docstoreHelperService) {
91 this.docstoreHelperService = docstoreHelperService;
92 }
93
94
95
96
97
98 public DocstoreHelperService getDocstoreHelperService() {
99 if (null == docstoreHelperService) {
100 docstoreHelperService = new DocstoreHelperService();
101 }
102 return docstoreHelperService;
103 }
104
105
106
107
108
109 public DiscoveryHelperService getDiscoveryHelperService() {
110 if (null == discoveryHelperService) {
111 discoveryHelperService = new DiscoveryHelperService();
112 }
113 return discoveryHelperService;
114 }
115
116
117
118
119
120 public void setDiscoveryHelperService(DiscoveryHelperService discoveryHelperService) {
121 this.discoveryHelperService = discoveryHelperService;
122 }
123 }