1 package org.kuali.ole.describe.service.impl;
2
3 import org.apache.commons.lang.StringUtils;
4 import org.apache.log4j.Logger;
5 import org.kuali.ole.describe.bo.OleLocation;
6 import org.kuali.ole.describe.bo.SearchResultDisplayRow;
7 import org.kuali.ole.describe.form.CallNumberBrowseForm;
8 import org.kuali.ole.describe.form.OLESearchForm;
9 import org.kuali.ole.describe.service.BrowseService;
10 import org.kuali.ole.docstore.common.client.DocstoreClient;
11 import org.kuali.ole.docstore.common.client.DocstoreClientLocator;
12 import org.kuali.ole.docstore.common.document.*;
13 import org.kuali.ole.docstore.common.search.*;
14 import org.kuali.ole.docstore.discovery.model.CallNumberBrowseParams;
15 import org.kuali.ole.docstore.model.enums.DocType;
16 import org.kuali.ole.sys.context.SpringContext;
17 import org.kuali.ole.utility.callnumber.CallNumber;
18 import org.kuali.ole.utility.callnumber.CallNumberFactory;
19 import org.kuali.rice.krad.service.BusinessObjectService;
20 import org.kuali.rice.krad.service.KRADServiceLocator;
21
22 import java.util.ArrayList;
23 import java.util.Collection;
24 import java.util.Collections;
25 import java.util.List;
26
27
28
29
30
31
32
33
34 public class BrowseServiceImpl implements BrowseService {
35
36 private static final Logger LOG = Logger.getLogger(BrowseServiceImpl.class);
37 private DocstoreClientLocator docstoreClientLocator;
38
39 protected int totRecCount = 0;
40 protected int pageSize = 0;
41 protected int matchIndex = 0;
42 protected int startIndex = 0;
43 protected String nextBrowseValue = "";
44 protected String previousBrowseValue = "";
45
46 private DocstoreClient docstoreClient;
47
48 public DocstoreClient getDocstoreClient() throws Exception {
49 if(docstoreClient == null) {
50 docstoreClient = getDocstoreClientLocator().getDocstoreClient();
51 }
52 return docstoreClient;
53 }
54
55 public DocstoreClientLocator getDocstoreClientLocator() {
56 if (null == docstoreClientLocator) {
57 return SpringContext.getBean(DocstoreClientLocator.class);
58 }
59 return docstoreClientLocator;
60 }
61
62 public int getTotRecCount() {
63 return totRecCount;
64 }
65
66 public void setTotRecCount(int totRecCount) {
67 this.totRecCount = totRecCount;
68 }
69
70 public int getPageSize() {
71 return pageSize;
72 }
73
74 public void setPageSize(int pageSize) {
75 this.pageSize = pageSize;
76 }
77
78 public int getMatchIndex() {
79 return matchIndex;
80 }
81
82 public void setMatchIndex(int matchIndex) {
83 this.matchIndex = matchIndex;
84 }
85
86 public int getStartIndex() {
87 return startIndex;
88 }
89
90 public void setStartIndex(int startIndex) {
91 this.startIndex = startIndex;
92 }
93
94 public String validateLocation(String locationString) {
95 if (locationString != null) {
96 String[] arr = locationString.split("/");
97 for (String location : arr) {
98 if (isValidLibraryLevel(location)) {
99 return location;
100 }
101 }
102 }
103 return null;
104 }
105
106 protected List browseBibs (BrowseParams browseParams ) throws Exception{
107 SearchResponse searchResponse = getDocstoreClientLocator().getDocstoreClient().search(browseParams);
108 List<SearchResultDisplayRow> searchResultDisplayRows = new ArrayList<>();
109 for (SearchResult searchResult : searchResponse.getSearchResults()) {
110 SearchResultDisplayRow searchResultDisplayRow = new SearchResultDisplayRow();
111 for (SearchResultField searchResultField : searchResult.getSearchResultFields()) {
112 if (searchResultField.getDocType().equalsIgnoreCase(DocType.BIB.getCode())) {
113 if (searchResultField.getFieldName().equalsIgnoreCase("LocalId_display")) {
114 searchResultDisplayRow.setLocalId(searchResultField.getFieldValue());
115 searchResultDisplayRow.setBibIdentifier(searchResultField.getFieldValue());
116 }
117 if (searchResultField.getFieldName().equalsIgnoreCase("Title_display")) {
118 searchResultDisplayRow.setTitle(searchResultField.getFieldValue());
119 }
120 if (searchResultField.getFieldName().equalsIgnoreCase("Author_display")) {
121 searchResultDisplayRow.setAuthor(searchResultField.getFieldValue());
122 }
123 if (searchResultField.getFieldName().equalsIgnoreCase("PublicationDate_display")) {
124 searchResultDisplayRow.setPublicationDate(searchResultField.getFieldValue());
125 }
126 if (searchResultField.getFieldName().equalsIgnoreCase("DocFormat")) {
127 searchResultDisplayRow.setDocFormat(searchResultField.getFieldValue());
128 }
129
130 }
131 }
132 searchResultDisplayRows.add(searchResultDisplayRow);
133 }
134 return searchResultDisplayRows;
135 }
136
137
138 protected List browseItems (BrowseParams browseParams ) throws Exception{
139 SearchResponse searchResponse = getDocstoreClient().browseItems(browseParams);
140 List<Item> itemList = new ArrayList<Item>();
141 for (SearchResult searchResult : searchResponse.getSearchResults()) {
142 Item item = new Item();
143 for (SearchResultField searchResultField : searchResult.getSearchResultFields()) {
144 if (searchResultField.getDocType().equalsIgnoreCase(DocType.ITEM.getCode())) {
145 if (searchResultField.getFieldName().equalsIgnoreCase("id")) {
146 item.setId(searchResultField.getFieldValue());
147
148
149 Holdings holdings = new PHoldings();
150 item.setHolding(holdings);
151 Bib bib = new BibMarc();
152 item.getHolding().setBib(bib);
153 }
154 if (searchResultField.getFieldName().equalsIgnoreCase("LocalId_display")) {
155 item.setLocalId(searchResultField.getFieldValue());
156 }
157 if (searchResultField.getFieldName().equalsIgnoreCase("CallNumber_display")) {
158 item.setCallNumber(searchResultField.getFieldValue());
159 }
160 if (searchResultField.getFieldName().equalsIgnoreCase("Location_search")) {
161 item.setLocationName(searchResultField.getFieldValue());
162 }
163 if (searchResultField.getFieldName().equalsIgnoreCase("bibIdentifier")) {
164 item.getHolding().getBib().setId(searchResultField.getFieldValue());
165 }
166 if (searchResultField.getFieldName().equalsIgnoreCase("Author_display")) {
167 item.getHolding().getBib().setAuthor(searchResultField.getFieldValue());
168 }
169 if (searchResultField.getFieldName().equalsIgnoreCase("Title_display")) {
170 item.getHolding().getBib().setTitle(searchResultField.getFieldValue());
171 }
172 if (searchResultField.getFieldName().equalsIgnoreCase("ShelvingOrder_sort")) {
173 item.setShelvingOrder(searchResultField.getFieldValue());
174 }
175 }
176 }
177 itemList.add(item);
178 }
179 return itemList;
180 }
181
182
183
184 protected List browseHoldings(BrowseParams browseParams) throws Exception {
185 SearchResponse searchResponse = getDocstoreClient().browseHoldings(browseParams);
186 List<Holdings> holdingsList = new ArrayList<Holdings>();
187 for (SearchResult searchResult : searchResponse.getSearchResults()) {
188 Holdings holdings = new Holdings();
189 for (SearchResultField searchResultField : searchResult.getSearchResultFields()) {
190 if (searchResultField.getDocType().equalsIgnoreCase(DocType.HOLDINGS.getCode())) {
191 if (searchResultField.getFieldName().equalsIgnoreCase("id")) {
192 holdings.setId(searchResultField.getFieldValue());
193
194
195 Bib bib = new BibMarc();
196 holdings.setBib(bib);
197 }
198 if (searchResultField.getFieldName().equalsIgnoreCase("LocalId_display")) {
199 holdings.setLocalId(searchResultField.getFieldValue());
200 }
201 if (searchResultField.getFieldName().equalsIgnoreCase("CallNumber_display")) {
202 holdings.setCallNumber(searchResultField.getFieldValue());
203 }
204 if (searchResultField.getFieldName().equalsIgnoreCase("Location_search")) {
205 holdings.setLocationName(searchResultField.getFieldValue());
206 }
207 if (searchResultField.getFieldName().equalsIgnoreCase("bibIdentifier")) {
208 holdings.getBib().setId(searchResultField.getFieldValue());
209 }
210 if (searchResultField.getFieldName().equalsIgnoreCase("Author_display")) {
211 holdings.getBib().setAuthor(searchResultField.getFieldValue());
212 }
213 if (searchResultField.getFieldName().equalsIgnoreCase("Title_display")) {
214 holdings.getBib().setTitle(searchResultField.getFieldValue());
215 }
216 if (searchResultField.getFieldName().equalsIgnoreCase("ShelvingOrder_sort")) {
217 holdings.setShelvingOrder(searchResultField.getFieldValue());
218 }
219
220 }
221 }
222 holdingsList.add(holdings);
223 }
224
225 return holdingsList;
226 }
227
228 protected List buildBrowseBibsResults(SearchResponse searchResponse) throws Exception{
229
230 List<SearchResultDisplayRow> searchResultDisplayRows = new ArrayList<>();
231 for (SearchResult searchResult : searchResponse.getSearchResults()) {
232 SearchResultDisplayRow searchResultDisplayRow = new SearchResultDisplayRow();
233 for (SearchResultField searchResultField : searchResult.getSearchResultFields()) {
234 if (searchResultField.getDocType().equalsIgnoreCase(DocType.BIB.getCode())) {
235 if (searchResultField.getFieldName().equalsIgnoreCase("LocalId_display")) {
236 searchResultDisplayRow.setLocalId(searchResultField.getFieldValue());
237 searchResultDisplayRow.setBibIdentifier(searchResultField.getFieldValue());
238 }
239 if (searchResultField.getFieldName().equalsIgnoreCase("Title_display")) {
240 searchResultDisplayRow.setTitle(searchResultField.getFieldValue());
241 }
242 if (searchResultField.getFieldName().equalsIgnoreCase("Author_display")) {
243 searchResultDisplayRow.setAuthor(searchResultField.getFieldValue());
244 }
245 if (searchResultField.getFieldName().equalsIgnoreCase("PublicationDate_display")) {
246 searchResultDisplayRow.setPublicationDate(searchResultField.getFieldValue());
247 }
248 if (searchResultField.getFieldName().equalsIgnoreCase("DocFormat")) {
249 searchResultDisplayRow.setDocFormat(searchResultField.getFieldValue());
250 }
251
252 }
253 }
254 searchResultDisplayRows.add(searchResultDisplayRow);
255 }
256 return searchResultDisplayRows;
257 }
258
259
260 protected List buildBrowseHoldingsResults(SearchResponse searchResponse) throws Exception{
261 List<Holdings> holdingsList = new ArrayList<Holdings>();
262 for (SearchResult searchResult : searchResponse.getSearchResults()) {
263 Holdings holdings = new Holdings();
264 for (SearchResultField searchResultField : searchResult.getSearchResultFields()) {
265 if (searchResultField.getDocType().equalsIgnoreCase(DocType.HOLDINGS.getCode())) {
266 if (searchResultField.getFieldName().equalsIgnoreCase("id")) {
267 holdings.setId(searchResultField.getFieldValue());
268 Bib bib = new BibMarc();
269 holdings.setBib(bib);
270 }
271 if (searchResultField.getFieldName().equalsIgnoreCase("LocalId_display")) {
272 holdings.setLocalId(searchResultField.getFieldValue());
273 }
274 if (searchResultField.getFieldName().equalsIgnoreCase("CallNumber_display")) {
275 holdings.setCallNumber(searchResultField.getFieldValue());
276 }
277 if (searchResultField.getFieldName().equalsIgnoreCase("Location_search")) {
278 holdings.setLocationName(searchResultField.getFieldValue());
279 }
280 if (searchResultField.getFieldName().equalsIgnoreCase("bibIdentifier")) {
281 holdings.getBib().setId(searchResultField.getFieldValue());
282 }
283 if (searchResultField.getFieldName().equalsIgnoreCase("Author_display")) {
284 holdings.getBib().setAuthor(searchResultField.getFieldValue());
285 }
286 if (searchResultField.getFieldName().equalsIgnoreCase("Title_display")) {
287 holdings.getBib().setTitle(searchResultField.getFieldValue());
288 }
289 if (searchResultField.getFieldName().equalsIgnoreCase("Title_display")) {
290 holdings.getBib().setTitle(searchResultField.getFieldValue());
291 }
292 if (searchResultField.getFieldName().equalsIgnoreCase("ShelvingOrder_sort")) {
293 holdings.setShelvingOrder(searchResultField.getFieldValue());
294 }
295
296 }
297 }
298 holdingsList.add(holdings);
299 }
300 previousBrowseValue = "[ * TO " + holdingsList.get(0).getShelvingOrder() +"]";
301 nextBrowseValue = "[" + holdingsList.get(holdingsList.size() - 1).getShelvingOrder() + " TO * ]";
302
303 return holdingsList;
304 }
305
306
307
308 protected List buildBrowseItemsResults(SearchResponse searchResponse) throws Exception {
309 List<Item> itemList = new ArrayList<Item>();
310 for (SearchResult searchResult : searchResponse.getSearchResults()) {
311 Item item = new Item();
312 for (SearchResultField searchResultField : searchResult.getSearchResultFields()) {
313 if (searchResultField.getDocType().equalsIgnoreCase(DocType.ITEM.getCode())) {
314 if (searchResultField.getFieldName().equalsIgnoreCase("id")) {
315 item.setId(searchResultField.getFieldValue());
316
317
318 Holdings holdings = new PHoldings();
319 item.setHolding(holdings);
320 Bib bib = new BibMarc();
321 item.getHolding().setBib(bib);
322 }
323 if (searchResultField.getFieldName().equalsIgnoreCase("LocalId_display")) {
324 item.setLocalId(searchResultField.getFieldValue());
325 }
326 if (searchResultField.getFieldName().equalsIgnoreCase("CallNumber_display")) {
327 item.setCallNumber(searchResultField.getFieldValue());
328 }
329 if (searchResultField.getFieldName().equalsIgnoreCase("Location_search")) {
330 item.setLocationName(searchResultField.getFieldValue());
331 }
332 if (searchResultField.getFieldName().equalsIgnoreCase("holdingsIdentifier")) {
333 item.getHolding().setId(searchResultField.getFieldValue());
334 }
335 if (searchResultField.getFieldName().equalsIgnoreCase("bibIdentifier")) {
336 item.getHolding().getBib().setId(searchResultField.getFieldValue());
337 }
338 if (searchResultField.getFieldName().equalsIgnoreCase("Author_display")) {
339 item.getHolding().getBib().setAuthor(searchResultField.getFieldValue());
340 }
341 if (searchResultField.getFieldName().equalsIgnoreCase("Title_display")) {
342 item.getHolding().getBib().setTitle(searchResultField.getFieldValue());
343 }
344 if (searchResultField.getFieldName().equalsIgnoreCase("ShelvingOrder_sort")) {
345 item.setShelvingOrder(searchResultField.getFieldValue());
346 }
347
348 }
349 }
350 itemList.add(item);
351 }
352
353 previousBrowseValue = "[ * TO " + itemList.get(0).getShelvingOrder() +"]";
354 nextBrowseValue = "[" + itemList.get(itemList.size() - 1).getShelvingOrder() + " TO * ]";
355
356 return itemList;
357 }
358
359 protected List browseList(CallNumberBrowseParams callNumberBrowseParams) {
360 List list = null;
361 try {
362 BrowseParams browseParams = totalBrowseParams(callNumberBrowseParams);
363 browseParams.setPageSize(callNumberBrowseParams.getNumRows());
364 String docType = callNumberBrowseParams.getDocTye();
365 if (DocType.BIB.getCode().equals(docType)) {
366 list = browseBibs(browseParams);
367 } else {
368 if (docType.equalsIgnoreCase(DocType.ITEM.getCode())) {
369 list = browseItems(browseParams);
370 } else {
371 list = browseHoldings(browseParams);
372 }
373 }
374 } catch (Exception e) {
375 LOG.info("Exception in callNumberBrowse " + e);
376 }
377 return list;
378 }
379
380 protected List browseListNext(CallNumberBrowseParams callNumberBrowseParams) {
381 List list = null;
382 try {
383 BrowseParams browseParams = totalBrowseParamsNext(callNumberBrowseParams, nextBrowseValue);
384 browseParams.setPageSize(callNumberBrowseParams.getNumRows());
385 String docType = callNumberBrowseParams.getDocTye();
386 if (DocType.BIB.getCode().equals(docType)) {
387 list = browseBibs(browseParams);
388 } else {
389 if (docType.equalsIgnoreCase(DocType.ITEM.getCode())) {
390 List<Item> itemList = browseItems(browseParams);
391 previousBrowseValue = "[ * TO " + itemList.get(0).getShelvingOrder() +"]";
392 nextBrowseValue = "[" + itemList.get(itemList.size() - 1).getShelvingOrder() + " TO * ]";
393 return itemList;
394 } else {
395 List<Holdings> holdingsList = browseHoldings(browseParams);
396 previousBrowseValue = "[ * TO " + holdingsList.get(0).getShelvingOrder() +"]";
397 nextBrowseValue = "[" + holdingsList.get(holdingsList.size() - 1).getShelvingOrder() + " TO * ]";
398 return holdingsList;
399 }
400
401 }
402 } catch (Exception e) {
403 LOG.info("Exception in callNumberBrowse " + e);
404 }
405 return list;
406 }
407
408 protected List browseListPrevious(CallNumberBrowseParams callNumberBrowseParams) {
409 List list = null;
410 try {
411 BrowseParams browseParams = totalBrowseParamsNextPrevious(callNumberBrowseParams, previousBrowseValue);
412 browseParams.setPageSize(callNumberBrowseParams.getNumRows());
413 String docType = callNumberBrowseParams.getDocTye();
414 if (DocType.BIB.getCode().equals(docType)) {
415 list = browseBibs(browseParams);
416 } else {
417 if (docType.equalsIgnoreCase(DocType.ITEM.getCode())) {
418 List<Item> itemList = browseItems(browseParams);
419 if(startIndex >= pageSize) {
420 Collections.reverse(itemList);
421 }
422 previousBrowseValue = "[ * TO " + itemList.get(0).getShelvingOrder() +"]";
423 nextBrowseValue = "[" + itemList.get(itemList.size() - 1).getShelvingOrder() + " TO * ]";
424 return itemList;
425
426 } else {
427 List<Holdings> holdingsList = browseHoldings(browseParams);
428 if(startIndex >= pageSize) {
429 Collections.reverse(holdingsList);
430 }
431 previousBrowseValue = "[ * TO " + holdingsList.get(0).getShelvingOrder() +"]";
432 nextBrowseValue = "[" + holdingsList.get(holdingsList.size() - 1).getShelvingOrder() + " TO * ]";
433 return holdingsList;
434 }
435 }
436 } catch (Exception e) {
437 LOG.info("Exception in callNumberBrowse " + e);
438 }
439 return list;
440 }
441
442 protected boolean isValidLibraryLevel(String location) {
443 boolean valid = false;
444 BusinessObjectService businessObjectService = KRADServiceLocator.getBusinessObjectService();
445 Collection<OleLocation> oleLocationCollection = businessObjectService.findAll(OleLocation.class);
446 for (OleLocation oleLocation : oleLocationCollection) {
447 String locationCode = oleLocation.getLocationCode();
448 String levelCode = oleLocation.getOleLocationLevel().getLevelCode();
449 if ("LIBRARY".equals(levelCode) && (locationCode.equals(location))) {
450 valid = true;
451 return valid;
452 }
453 }
454 return valid;
455 }
456
457 public boolean getPreviosFlag() {
458 if (this.startIndex == 0)
459 return false;
460 return true;
461 }
462
463 public boolean getNextFlag() {
464 if (this.startIndex + this.pageSize < this.totRecCount)
465 return true;
466 return false;
467 }
468
469 public String getPageShowEntries() {
470 return "Showing " + ((this.startIndex == 0) ? 1 : this.startIndex + 1) + " to "
471 + (((this.startIndex + this.pageSize) > this.totRecCount) ? this.totRecCount : (this.startIndex + this.pageSize))
472 + " of " + this.totRecCount + " entries";
473 }
474
475 protected List initBrowse(CallNumberBrowseParams callNumberBrowseParams) throws Exception {
476 List list = null;
477 int startIndex = 0;
478 int totalCount = 0;
479 int totalForwardCount = 0;
480 String classificationScheme = callNumberBrowseParams.getClassificationScheme();
481 String callNumberBrowseText = callNumberBrowseParams.getCallNumberBrowseText();
482 String title = callNumberBrowseParams.getTitle();
483 String docType = callNumberBrowseParams.getDocTye();
484 SearchResponse searchResponse = null;
485
486 if (DocType.BIB.getCode().equals(docType)) {
487 BrowseParams browseParams = totalBrowseParams(callNumberBrowseParams);
488 searchResponse = getDocstoreClient().search(browseParams);
489 totalCount = (int) searchResponse.getTotalRecordCount();
490 LOG.info("Total Call Number count:" + totalCount);
491
492 if(StringUtils.isNotEmpty(title)) {
493 browseParams = buildBrowseParams(callNumberBrowseParams);
494 searchResponse = getDocstoreClient().search(browseParams);
495 totalForwardCount = (int) searchResponse.getTotalRecordCount();
496 LOG.info("Total Call Number count:" + totalCount);
497 }
498 else {
499 totalForwardCount = totalCount;
500 }
501 list = buildBrowseBibsResults(searchResponse);
502
503 } else {
504 if (StringUtils.isNotEmpty(classificationScheme)) {
505 BrowseParams browseParamsForTotalCallNumber = totalBrowseParams(callNumberBrowseParams);
506 if (callNumberBrowseParams.getDocTye().equalsIgnoreCase(DocType.ITEM.getCode())) {
507 searchResponse = getDocstoreClient().browseItems(browseParamsForTotalCallNumber);
508 list = buildBrowseItemsResults(searchResponse);
509 } else {
510 searchResponse = getDocstoreClient().browseHoldings(browseParamsForTotalCallNumber);
511 list = buildBrowseHoldingsResults(searchResponse);
512 }
513 totalCount = (int) searchResponse.getTotalRecordCount();
514 LOG.info("Total Call Number count:" + totalCount);
515
516 if (StringUtils.isNotEmpty(callNumberBrowseText)) {
517 CallNumber callNumber = CallNumberFactory.getInstance().getCallNumber(classificationScheme);
518 String normalizedCallNumberBrowseText = callNumber.getSortableKey(callNumberBrowseText);
519 normalizedCallNumberBrowseText = normalizedCallNumberBrowseText.replaceAll(" ", "-");
520 callNumberBrowseParams.setCallNumberBrowseText(normalizedCallNumberBrowseText);
521 BrowseParams browseParamsForwardCallNumberCount = buildBrowseParams(callNumberBrowseParams);
522 if (callNumberBrowseParams.getDocTye().equalsIgnoreCase(DocType.ITEM.getCode())) {
523 searchResponse = getDocstoreClient().browseItems(browseParamsForwardCallNumberCount);
524 list = buildBrowseItemsResults(searchResponse);
525 } else {
526 searchResponse = getDocstoreClient().browseHoldings(browseParamsForwardCallNumberCount);
527 list = buildBrowseHoldingsResults(searchResponse);
528 }
529 totalForwardCount = (int) searchResponse.getTotalRecordCount();
530 } else {
531 totalForwardCount = totalCount;
532 }
533
534 }
535 }
536 LOG.info("Total Forward Call Number Count:" + totalForwardCount);
537 startIndex = (totalCount - totalForwardCount);
538 callNumberBrowseParams.setStartIndex(startIndex);
539 callNumberBrowseParams.setTotalCallNumberCount(totalCount);
540 callNumberBrowseParams.setTotalForwardCallNumberCount(totalForwardCount);
541 return list;
542 }
543
544 protected BrowseParams buildBrowseParams(CallNumberBrowseParams callNumberBrowseParams) {
545
546 BrowseParams browseParams = new BrowseParams();
547 List<SearchCondition> searchConditions = new ArrayList<>();
548 String docType = callNumberBrowseParams.getDocTye();
549 browseParams.getSearchResultFields().add(browseParams.buildSearchResultField(docType,"id"));
550 browseParams.getSearchResultFields().add(browseParams.buildSearchResultField(docType,"LocalId_display"));
551 browseParams.getSearchResultFields().add(browseParams.buildSearchResultField(docType,"DocFormat"));
552 if(DocType.BIB.getCode().equals(callNumberBrowseParams.getDocTye())) {
553 browseParams.getSortConditions().add(browseParams.buildSortCondition("Title_sort","asc"));
554 if(StringUtils.isNotEmpty(callNumberBrowseParams.getTitle())) {
555 searchConditions.add(browseParams.buildSearchCondition("NONE", browseParams.buildSearchField(docType, "Title_sort", "[\""+callNumberBrowseParams.getTitle().toLowerCase()+"\" TO *]"), "AND"));
556 }
557 else {
558 searchConditions.add(browseParams.buildSearchCondition("NONE", browseParams.buildSearchField(docType, "Title_sort", "{ * TO *}"), "AND"));
559 }
560
561 browseParams.getSearchResultFields().add(browseParams.buildSearchResultField(docType,"Title_display"));
562 browseParams.getSearchResultFields().add(browseParams.buildSearchResultField(docType,"Author_display"));
563 browseParams.getSearchResultFields().add(browseParams.buildSearchResultField(docType,"PublicationDate_display"));
564 browseParams.setStartIndex(0);
565 }
566 else {
567 browseParams.getSortConditions().add(browseParams.buildSortCondition("ShelvingOrder_sort","asc"));
568
569 if(StringUtils.isNotEmpty(callNumberBrowseParams.getLocation())) {
570 searchConditions.add(browseParams.buildSearchCondition("AND", browseParams.buildSearchField(docType, "Location_search", callNumberBrowseParams.getLocation()), "AND"));
571 }
572 if(StringUtils.isNotEmpty(callNumberBrowseParams.getClassificationScheme())) {
573 searchConditions.add(browseParams.buildSearchCondition("AND", browseParams.buildSearchField(docType, "ShelvingSchemeCode_search", callNumberBrowseParams.getClassificationScheme()), "AND"));
574 }
575 if(StringUtils.isNotEmpty(callNumberBrowseParams.getCallNumberBrowseText())){
576 searchConditions.add(browseParams.buildSearchCondition("NONE", browseParams.buildSearchField(docType, "ShelvingOrder_sort", "[" + callNumberBrowseParams.getCallNumberBrowseText() + " TO *]"), "AND"));
577 }
578 else {
579 searchConditions.add(browseParams.buildSearchCondition("NONE", browseParams.buildSearchField(docType, "ShelvingOrder_sort", "{ * TO *}"), "AND"));
580 }
581 if(StringUtils.isNotEmpty(docType)) {
582 searchConditions.add(browseParams.buildSearchCondition("AND", browseParams.buildSearchField(docType, "DocType", docType), "AND"));
583 }
584 browseParams.getSearchResultFields().add(browseParams.buildSearchResultField(docType,"Location_search"));
585 browseParams.getSearchResultFields().add(browseParams.buildSearchResultField(docType,"ShelvingOrder_search"));
586 browseParams.getSearchResultFields().add(browseParams.buildSearchResultField(docType,"ShelvingOrder_sort"));
587 browseParams.getSearchResultFields().add(browseParams.buildSearchResultField(docType,"CallNumber_display"));
588 browseParams.getSearchResultFields().add(browseParams.buildSearchResultField(docType,"Title_display"));
589 browseParams.getSearchResultFields().add(browseParams.buildSearchResultField(docType,"Author_display"));
590 browseParams.getSearchResultFields().add(browseParams.buildSearchResultField(docType,"bibIdentifier"));
591 browseParams.getSearchResultFields().add(browseParams.buildSearchResultField(docType,"holdingsIdentifier"));
592 browseParams.setStartIndex(0);
593 }
594 browseParams.setPageSize(callNumberBrowseParams.getNumRows());
595 browseParams.getSearchConditions().addAll(searchConditions);
596 return browseParams;
597 }
598
599 protected BrowseParams totalBrowseParams(CallNumberBrowseParams callNumberBrowseParams) {
600
601 BrowseParams browseParams = new BrowseParams();
602
603 List<SearchCondition> searchConditions = new ArrayList<>();
604 String docType = callNumberBrowseParams.getDocTye();
605
606 browseParams.getSearchResultFields().add(browseParams.buildSearchResultField(docType,"id"));
607 browseParams.getSearchResultFields().add(browseParams.buildSearchResultField(docType,"LocalId_display"));
608 browseParams.getSearchResultFields().add(browseParams.buildSearchResultField(docType,"DocFormat"));
609
610 if(DocType.BIB.getCode().equals(callNumberBrowseParams.getDocTye())) {
611 browseParams.getSortConditions().add(browseParams.buildSortCondition("Title_sort","asc"));
612 searchConditions.add(browseParams.buildSearchCondition("NONE", browseParams.buildSearchField(docType, "Title_sort", "{ * TO *}"), "AND"));
613 browseParams.getSearchResultFields().add(browseParams.buildSearchResultField(docType,"Title_display"));
614 browseParams.getSearchResultFields().add(browseParams.buildSearchResultField(docType,"Author_display"));
615 browseParams.getSearchResultFields().add(browseParams.buildSearchResultField(docType,"PublicationDate_display"));
616 }
617 else {
618 browseParams.getSortConditions().add(browseParams.buildSortCondition("ShelvingOrder_sort","asc"));
619 if(StringUtils.isNotEmpty(callNumberBrowseParams.getLocation())) {
620 searchConditions.add(browseParams.buildSearchCondition("AND", browseParams.buildSearchField(docType, "Location_search", callNumberBrowseParams.getLocation()), "AND"));
621 }
622 if(StringUtils.isNotEmpty(callNumberBrowseParams.getClassificationScheme())) {
623 searchConditions.add(browseParams.buildSearchCondition("AND", browseParams.buildSearchField(docType, "ShelvingSchemeCode_search", callNumberBrowseParams.getClassificationScheme()), "AND"));
624 }
625 searchConditions.add(browseParams.buildSearchCondition("NONE", browseParams.buildSearchField(docType, "ShelvingOrder_sort", "{ * TO *}"), "AND"));
626 browseParams.getSearchResultFields().add(browseParams.buildSearchResultField(docType,"Location_search"));
627 browseParams.getSearchResultFields().add(browseParams.buildSearchResultField(docType,"ShelvingOrder_search"));
628 browseParams.getSearchResultFields().add(browseParams.buildSearchResultField(docType,"ShelvingOrder_sort"));
629 browseParams.getSearchResultFields().add(browseParams.buildSearchResultField(docType,"CallNumber_display"));
630 browseParams.getSearchResultFields().add(browseParams.buildSearchResultField(docType,"Title_display"));
631 browseParams.getSearchResultFields().add(browseParams.buildSearchResultField(docType,"Author_display"));
632 browseParams.getSearchResultFields().add(browseParams.buildSearchResultField(docType,"bibIdentifier"));
633 browseParams.getSearchResultFields().add(browseParams.buildSearchResultField(docType,"holdingsIdentifier"));
634 }
635
636 if(StringUtils.isNotEmpty(docType)) {
637 searchConditions.add(browseParams.buildSearchCondition("AND", browseParams.buildSearchField(docType, "DocType", docType), "AND"));
638 }
639
640 browseParams.setStartIndex(startIndex);
641 browseParams.setPageSize(callNumberBrowseParams.getNumRows());
642 browseParams.getSearchConditions().addAll(searchConditions);
643 return browseParams;
644 }
645 protected BrowseParams totalBrowseParamsNext(CallNumberBrowseParams callNumberBrowseParams, String nextBrowseValue) {
646
647 BrowseParams browseParams = new BrowseParams();
648
649 List<SearchCondition> searchConditions = new ArrayList<>();
650 String docType = callNumberBrowseParams.getDocTye();
651
652 browseParams.getSearchResultFields().add(browseParams.buildSearchResultField(docType,"id"));
653 browseParams.getSearchResultFields().add(browseParams.buildSearchResultField(docType,"LocalId_display"));
654 browseParams.getSearchResultFields().add(browseParams.buildSearchResultField(docType,"DocFormat"));
655
656 if(DocType.BIB.getCode().equals(callNumberBrowseParams.getDocTye())) {
657 browseParams.getSortConditions().add(browseParams.buildSortCondition("Title_sort","asc"));
658 searchConditions.add(browseParams.buildSearchCondition("NONE", browseParams.buildSearchField(docType, "Title_sort", "{ * TO *}"), "AND"));
659 browseParams.getSearchResultFields().add(browseParams.buildSearchResultField(docType,"Title_display"));
660 browseParams.getSearchResultFields().add(browseParams.buildSearchResultField(docType,"Author_display"));
661 browseParams.getSearchResultFields().add(browseParams.buildSearchResultField(docType,"PublicationDate_display"));
662 browseParams.setStartIndex(startIndex);
663
664 }
665 else {
666 browseParams.getSortConditions().add(browseParams.buildSortCondition("ShelvingOrder_sort","asc"));
667 if(StringUtils.isNotEmpty(callNumberBrowseParams.getLocation())) {
668 searchConditions.add(browseParams.buildSearchCondition("AND", browseParams.buildSearchField(docType, "Location_search", callNumberBrowseParams.getLocation()), "AND"));
669 }
670 if(StringUtils.isNotEmpty(callNumberBrowseParams.getClassificationScheme())) {
671 searchConditions.add(browseParams.buildSearchCondition("AND", browseParams.buildSearchField(docType, "ShelvingSchemeCode_search", callNumberBrowseParams.getClassificationScheme()), "AND"));
672 }
673 searchConditions.add(browseParams.buildSearchCondition("NONE", browseParams.buildSearchField(docType, "ShelvingOrder_sort", nextBrowseValue), "AND"));
674 browseParams.getSearchResultFields().add(browseParams.buildSearchResultField(docType,"Location_search"));
675 browseParams.getSearchResultFields().add(browseParams.buildSearchResultField(docType,"ShelvingOrder_search"));
676 browseParams.getSearchResultFields().add(browseParams.buildSearchResultField(docType,"ShelvingOrder_sort"));
677 browseParams.getSearchResultFields().add(browseParams.buildSearchResultField(docType,"CallNumber_display"));
678 browseParams.getSearchResultFields().add(browseParams.buildSearchResultField(docType,"Title_display"));
679 browseParams.getSearchResultFields().add(browseParams.buildSearchResultField(docType,"Author_display"));
680 browseParams.getSearchResultFields().add(browseParams.buildSearchResultField(docType,"bibIdentifier"));
681 browseParams.getSearchResultFields().add(browseParams.buildSearchResultField(docType,"holdingsIdentifier"));
682 browseParams.setStartIndex(1);
683
684 }
685
686 if(StringUtils.isNotEmpty(docType)) {
687 searchConditions.add(browseParams.buildSearchCondition("AND", browseParams.buildSearchField(docType, "DocType", docType), "AND"));
688 }
689 browseParams.setPageSize(callNumberBrowseParams.getNumRows());
690 browseParams.getSearchConditions().addAll(searchConditions);
691 return browseParams;
692 }
693 protected BrowseParams totalBrowseParamsNextPrevious(CallNumberBrowseParams callNumberBrowseParams, String previousBrowseValue) {
694
695 BrowseParams browseParams = new BrowseParams();
696
697 List<SearchCondition> searchConditions = new ArrayList<>();
698 String docType = callNumberBrowseParams.getDocTye();
699
700 browseParams.getSearchResultFields().add(browseParams.buildSearchResultField(docType,"id"));
701 browseParams.getSearchResultFields().add(browseParams.buildSearchResultField(docType,"LocalId_display"));
702 browseParams.getSearchResultFields().add(browseParams.buildSearchResultField(docType,"DocFormat"));
703
704 if(DocType.BIB.getCode().equals(callNumberBrowseParams.getDocTye())) {
705 browseParams.getSortConditions().add(browseParams.buildSortCondition("Title_sort","asc"));
706 searchConditions.add(browseParams.buildSearchCondition("NONE", browseParams.buildSearchField(docType, "Title_sort", "{ * TO *}"), "AND"));
707 browseParams.getSearchResultFields().add(browseParams.buildSearchResultField(docType,"Title_display"));
708 browseParams.getSearchResultFields().add(browseParams.buildSearchResultField(docType,"Author_display"));
709 browseParams.getSearchResultFields().add(browseParams.buildSearchResultField(docType,"PublicationDate_display"));
710 browseParams.setStartIndex(startIndex);
711 }
712 else {
713
714 if(StringUtils.isNotEmpty(callNumberBrowseParams.getLocation())) {
715 searchConditions.add(browseParams.buildSearchCondition("AND", browseParams.buildSearchField(docType, "Location_search", callNumberBrowseParams.getLocation()), "AND"));
716 }
717 if(StringUtils.isNotEmpty(callNumberBrowseParams.getClassificationScheme())) {
718 searchConditions.add(browseParams.buildSearchCondition("AND", browseParams.buildSearchField(docType, "ShelvingSchemeCode_search", callNumberBrowseParams.getClassificationScheme()), "AND"));
719 }
720 if(startIndex == 0) {
721 browseParams.getSortConditions().add(browseParams.buildSortCondition("ShelvingOrder_sort","asc"));
722 searchConditions.add(browseParams.buildSearchCondition("NONE", browseParams.buildSearchField(docType, "ShelvingOrder_sort", "[* TO *]"), "AND"));
723 browseParams.setStartIndex(0);
724 }
725 else {
726 browseParams.getSortConditions().add(browseParams.buildSortCondition("ShelvingOrder_sort","desc"));
727 searchConditions.add(browseParams.buildSearchCondition("NONE", browseParams.buildSearchField(docType, "ShelvingOrder_sort", previousBrowseValue), "AND"));
728 browseParams.setStartIndex(1);
729 }
730 browseParams.getSearchResultFields().add(browseParams.buildSearchResultField(docType,"Location_search"));
731 browseParams.getSearchResultFields().add(browseParams.buildSearchResultField(docType,"ShelvingOrder_search"));
732 browseParams.getSearchResultFields().add(browseParams.buildSearchResultField(docType,"ShelvingOrder_sort"));
733 browseParams.getSearchResultFields().add(browseParams.buildSearchResultField(docType,"CallNumber_display"));
734 browseParams.getSearchResultFields().add(browseParams.buildSearchResultField(docType,"Title_display"));
735 browseParams.getSearchResultFields().add(browseParams.buildSearchResultField(docType,"Author_display"));
736 browseParams.getSearchResultFields().add(browseParams.buildSearchResultField(docType,"bibIdentifier"));
737 browseParams.getSearchResultFields().add(browseParams.buildSearchResultField(docType,"holdingsIdentifier"));
738 }
739
740 if(StringUtils.isNotEmpty(docType)) {
741 searchConditions.add(browseParams.buildSearchCondition("AND", browseParams.buildSearchField(docType, "DocType", docType), "AND"));
742 }
743
744 browseParams.setPageSize(callNumberBrowseParams.getNumRows());
745 browseParams.getSearchConditions().addAll(searchConditions);
746 return browseParams;
747 }
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781 protected CallNumberBrowseParams getBrowseParams(OLESearchForm oleSearchForm) {
782 CallNumberBrowseParams callNumberBrowseParams = new CallNumberBrowseParams();
783
784 if(StringUtils.isNotEmpty(oleSearchForm.getBrowseText())) {
785 callNumberBrowseParams.setTitle(oleSearchForm.getBrowseText());
786 }
787 else {
788 callNumberBrowseParams.setClassificationScheme(oleSearchForm.getClassificationScheme());
789 callNumberBrowseParams.setLocation(oleSearchForm.getLocation());
790 callNumberBrowseParams.setCallNumberBrowseText(oleSearchForm.getCallNumberBrowseText());
791 }
792 callNumberBrowseParams.setNumRows(oleSearchForm.getPageSize());
793 callNumberBrowseParams.setDocTye(oleSearchForm.getDocType());
794 this.pageSize = oleSearchForm.getPageSize();
795 return callNumberBrowseParams;
796 }
797
798
799 public List callNumberBrowse(CallNumberBrowseForm callNumberBrowseForm) {
800
801 List list = null;
802 try {
803 CallNumberBrowseParams callNumberBrowseParams = getCallNumberBrowseParams(callNumberBrowseForm);
804 initBrowse(callNumberBrowseParams);
805 this.totRecCount = callNumberBrowseParams.getTotalCallNumberCount();
806 this.startIndex = Math.max(0 ,(int)callNumberBrowseParams.getStartIndex());
807 callNumberBrowseParams.setStartIndex(this.startIndex);
808 list = browseList(callNumberBrowseParams);
809 } catch (Exception e) {
810 LOG.info("Exception in callNumberBrowse " + e);
811 }
812 return list;
813 }
814
815 public List callNumberBrowsePrev(CallNumberBrowseForm callNumberBrowseForm) {
816
817 List list =null;
818 try {
819 CallNumberBrowseParams callNumberBrowseParams = getCallNumberBrowseParams(callNumberBrowseForm);
820 this.startIndex = Math.max(0, this.startIndex - this.pageSize);
821 callNumberBrowseParams.setStartIndex((this.startIndex == 0) ? 0 : this.startIndex - 1);
822 list = browseList(callNumberBrowseParams);
823 } catch (Exception e) {
824 LOG.info("Exception in callNumberBrowsePrev " + e);
825 }
826 return list;
827 }
828
829 public List callNumberBrowseNext(CallNumberBrowseForm callNumberBrowseForm) {
830
831 List list = null;
832 try {
833 CallNumberBrowseParams callNumberBrowseParams = getCallNumberBrowseParams(callNumberBrowseForm);
834 this.startIndex = Math.max(0, this.startIndex + this.pageSize);
835 callNumberBrowseParams.setStartIndex(this.startIndex);
836 list = browseList(callNumberBrowseParams);
837 } catch (Exception e) {
838 LOG.info("Exception in callNumberBrowseNext " + e);
839 }
840 return list;
841 }
842
843 private CallNumberBrowseParams getCallNumberBrowseParams(CallNumberBrowseForm callNumberBrowseForm) {
844 CallNumberBrowseParams callNumberBrowseParams = new CallNumberBrowseParams();
845 callNumberBrowseParams.setClassificationScheme(callNumberBrowseForm.getClassificationScheme());
846 callNumberBrowseParams.setLocation(callNumberBrowseForm.getLocation());
847 callNumberBrowseParams.setCallNumberBrowseText(callNumberBrowseForm.getCallNumberBrowseText());
848 callNumberBrowseParams.setNumRows(callNumberBrowseForm.getPageSize());
849 callNumberBrowseParams.setDocTye(callNumberBrowseForm.getDocType());
850 this.pageSize = callNumberBrowseForm.getPageSize();
851 return callNumberBrowseParams;
852 }
853
854 @Override
855 public List browse(OLESearchForm oleSearchForm) {
856 List list = null;
857 try {
858 startIndex = 0;
859 if(pageSize != 0) {
860 oleSearchForm.getSearchParams().setPageSize(pageSize);
861 }
862 CallNumberBrowseParams callNumberBrowseParams = getBrowseParams(oleSearchForm);
863 list = initBrowse(callNumberBrowseParams);
864 totRecCount = callNumberBrowseParams.getTotalCallNumberCount();
865 startIndex = Math.max(0, (int) callNumberBrowseParams.getStartIndex());
866 callNumberBrowseParams.setStartIndex(startIndex);
867
868 } catch (Exception e) {
869 LOG.info("Exception in title browse " + e);
870 }
871 return list;
872 }
873
874 @Override
875 public List browseOnChange(OLESearchForm oleSearchForm) {
876 List list = null;
877 try {
878 oleSearchForm.getSearchParams().setStartIndex(startIndex);
879 CallNumberBrowseParams callNumberBrowseParams = getBrowseParams(oleSearchForm);
880 list = initBrowse(callNumberBrowseParams);
881 totRecCount = callNumberBrowseParams.getTotalCallNumberCount();
882
883 callNumberBrowseParams.setStartIndex(startIndex);
884
885 } catch (Exception e) {
886 LOG.info("Exception in title browse " + e);
887 }
888 return list;
889
890 }
891
892 @Override
893 public List browsePrev(OLESearchForm oleSearchForm) {
894 List list =null;
895 try {
896 CallNumberBrowseParams callNumberBrowseParams = getBrowseParams(oleSearchForm);
897 this.startIndex = Math.max(0, this.startIndex - this.pageSize);
898 callNumberBrowseParams.setStartIndex((this.startIndex == 0) ? 0 : this.startIndex - 1);
899 list = browseListPrevious(callNumberBrowseParams);
900 } catch (Exception e) {
901 LOG.info("Exception in callNumberBrowsePrev " + e);
902 }
903 return list;
904 }
905
906 @Override
907 public List browseNext(OLESearchForm oleSearchForm) {
908 List list = null;
909 try {
910 CallNumberBrowseParams callNumberBrowseParams = getBrowseParams(oleSearchForm);
911 this.startIndex = Math.max(0, this.startIndex + this.pageSize);
912 callNumberBrowseParams.setStartIndex(this.startIndex);
913 list = browseListNext(callNumberBrowseParams);
914 } catch (Exception e) {
915 LOG.info("Exception in callNumberBrowseNext " + e);
916 }
917 return list;
918 }
919
920 }