1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.select.lookup;
17
18 import org.kuali.ole.docstore.common.client.DocstoreClientLocator;
19 import org.kuali.ole.docstore.common.document.Bib;
20 import org.kuali.ole.select.businessobject.BibInfoBean;
21 import org.kuali.ole.select.businessobject.DocInfoBean;
22 import org.kuali.ole.select.service.BibInfoWrapperService;
23 import org.kuali.ole.select.service.impl.BibInfoWrapperServiceImpl;
24 import org.kuali.ole.select.service.impl.BuildDocInfoBean;
25 import org.kuali.ole.sys.OLEConstants;
26 import org.kuali.ole.sys.context.SpringContext;
27 import org.kuali.ole.sys.service.NonTransactional;
28 import org.kuali.rice.core.api.config.property.ConfigurationService;
29 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
30
31 import java.util.*;
32
33
34 @NonTransactional
35 public class DocLookupSearch extends PlatformAwareDaoBaseOjb implements IDocLookupSearch {
36 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DocLookupSearch.class);
37 static HashMap<String, String> cache = new HashMap<String, String>();
38 private DocstoreClientLocator docstoreClientLocator;
39
40 public DocstoreClientLocator getDocstoreClientLocator() {
41 if (docstoreClientLocator == null) {
42 docstoreClientLocator = SpringContext.getBean(DocstoreClientLocator.class);
43 }
44 return docstoreClientLocator;
45 }
46
47
48
49
50
51
52
53
54
55
56
57 private List<DocData> getAllData() {
58 List<DocData> ress = new ArrayList<DocData>(0);
59 Iterator<String> iter = cache.values().iterator();
60 for (String st : cache.values()) {
61 String[] vals = st.split("\\^");
62 DocData ss = new DocData(vals[0], vals[1], vals[2], vals[3], vals[4], vals[5], vals[6], vals[7], vals[8], vals[9], vals[10], vals[11]);
63 ress.add(ss);
64 }
65 return ress;
66 }
67
68 private void setCache(Map arg1) throws Exception {
69 BibInfoWrapperService docStore = SpringContext.getBean(BibInfoWrapperServiceImpl.class);
70 List<BibInfoBean> bibInfoBeanList = docStore.searchBibInfo(arg1);
71 for (BibInfoBean bean : bibInfoBeanList) {
72 String bibString = bean.getAuthor() + "^" + bean.getTitle() + "^" + bean.getStandardNumber() + "^" + bean.getPublisher() + "^" + bean.getLocalIdentifier() + "^" + bean.getPlaceOfPublication() + "^" + bean.getYearOfPublication() + "^" + bean.getFormat() + "^" + bean.getPrice() + "^" + bean.getTitleId();
73 cache.put(bean.getTitleId(), bibString);
74 }
75 }
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99 private List<DocData> getDocResult(Map arg1) throws Exception {
100 BibInfoBean bibInfoBean = new BibInfoBean();
101 List<Bib> bibs=new ArrayList<>();
102 bibInfoBean.setTitleId((String) arg1.get("titleId"));
103 Bib bib = getDocstoreClientLocator().getDocstoreClient().retrieveBib((String) arg1.get("titleId"));
104 List<DocData> ress = new ArrayList<DocData>(0);
105 bibs.add(bib);
106 ress = getDocResult(bibs);
107 return ress;
108 }
109
110 private List<DocData> getDocResult(List<Bib> bibs) throws Exception {
111 List<DocData> ress = new ArrayList<DocData>(0);
112 for(Bib bib:bibs){
113 DocData res = new DocData(bib.getAuthor(), bib.getTitle(), bib.getIsbn(), bib.getLocalId(), bib.getPublisher(), "", bib.getPublicationDate(), bib.getType(), "", bib.getId(), bib.getId(), bib.getId());
114 ress.add(res);
115 }
116 return ress;
117 }
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142 public Object findObjectByMap(Object arg0, Map arg1) {
143
144 return null;
145 }
146
147 public List getResult(Class cl, String attr, List<Object> vals) throws Exception {
148 List result = new ArrayList(0);
149 int maxLimit = Integer.parseInt(SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(OLEConstants.DOCSEARCH_ORDERQUEUE_LIMIT_KEY));
150 HashMap titleIdMap = new HashMap();
151 List<String> bibIds=new ArrayList<>();
152 List<Bib> bibs=new ArrayList<>();
153 String bibId = null;
154 for (Object iv : vals) {
155 String id = iv.toString();
156 boolean isIdExists = titleIdMap.containsValue(id);
157 titleIdMap.put(id, id);
158 if (!isIdExists) {
159 bibIds.add(id);
160 }
161 }
162 if(bibIds.size()>0){
163 for(String id:bibIds){
164 Bib bib = getDocstoreClientLocator().getDocstoreClient().retrieveBib(id);
165 bibs.add(bib);
166 }
167 }
168 result = getDocResult(bibs);
169 return result;
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206 }
207
208 public List getResult(Class cl, Map<String, List<Object>> val) {
209 List resul = new ArrayList(0);
210 for (String key : val.keySet()) {
211 List ll;
212 try {
213 ll = getResult(cl, key, val.get(key));
214 if (ll != null && ll.size() > 0)
215 resul.addAll(ll);
216 } catch (Exception e) {
217 e.printStackTrace();
218 }
219
220
221 }
222 return resul;
223
224 }
225
226 public List getResult(Class cl, String attr, List<Object> val, Map vas) {
227 try {
228 if (vas == null || vas.size() < 1) {
229 return getResult(cl, attr, val);
230 } else {
231 return getDocResult(vas);
232 }
233 } catch (Exception e) {
234 return null;
235 }
236 }
237
238 private List<DocInfoBean> getResponse(String query) {
239 List<DocInfoBean> docInfoBeanList = new ArrayList<DocInfoBean>(0);
240 BuildDocInfoBean buildDocInfoBean = new BuildDocInfoBean();
241 docInfoBeanList = buildDocInfoBean.getDocInfoBeanList(query);
242 return docInfoBeanList;
243 }
244 }