1 package org.kuali.ole.deliver.lookup;
2
3 import org.jfree.util.Log;
4 import org.kuali.ole.deliver.bo.OLEFlaggedItems;
5 import org.kuali.ole.docstore.common.client.DocstoreClientLocator;
6 import org.kuali.ole.docstore.common.document.*;
7 import org.kuali.ole.docstore.common.document.content.enums.DocType;
8 import org.kuali.ole.docstore.common.search.SearchParams;
9 import org.kuali.ole.docstore.common.search.SearchResponse;
10 import org.kuali.ole.docstore.common.search.SearchResult;
11 import org.kuali.ole.docstore.common.search.SearchResultField;
12 import org.kuali.ole.sys.context.SpringContext;
13 import org.kuali.rice.krad.lookup.LookupableImpl;
14 import org.kuali.rice.krad.web.form.LookupForm;
15 import org.apache.commons.lang.StringUtils;
16 import org.kuali.ole.OLEConstants;
17
18 import java.util.*;
19
20
21
22
23
24
25
26
27 public class OLEFlaggedItemsLookupableImpl extends LookupableImpl {
28
29 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OLEFlaggedItemsLookupableImpl.class);
30 private DocstoreClientLocator docstoreClientLocator;
31
32 public DocstoreClientLocator getDocstoreClientLocator() {
33 if (docstoreClientLocator == null) {
34 docstoreClientLocator = SpringContext.getBean(DocstoreClientLocator.class);
35 }
36 return docstoreClientLocator;
37 }
38
39 @Override
40 public Collection<?> performSearch(LookupForm form, Map<String, String> searchCriteria, boolean bounded) {
41 LOG.debug("Inside performSearch()");
42 List<OLEFlaggedItems> oleFlaggedItemses = new ArrayList<>();
43 SearchResponse searchResponse = new SearchResponse();
44 SearchParams searchParams = new SearchParams();
45 org.kuali.ole.docstore.common.document.Item item = new ItemOleml();
46
47 String barcode = StringUtils.isNotEmpty(searchCriteria.get("barcode")) ? searchCriteria.get("barcode") : "";
48 String flagType = StringUtils.isNotEmpty(searchCriteria.get("flagType")) ? searchCriteria.get("flagType") : "";
49 boolean isClaimsReturned = false;
50 boolean isDamaged = false;
51 boolean isMissingPieceEnabled = false;
52 boolean defaultSearch = false;
53 int maxRowSize=10000;
54 if (StringUtils.isEmpty(barcode) && StringUtils.isEmpty(flagType)) {
55 defaultSearch = true;
56 }
57 try {
58 searchParams.getSearchConditions().add(searchParams.buildSearchCondition("", searchParams.buildSearchField(DocType.ITEM.getCode(), "", ""), ""));
59 SearchResponse maxRowCountResponse = getDocstoreClientLocator().getDocstoreClient().search(searchParams);
60 maxRowSize=maxRowCountResponse.getTotalRecordCount();
61 } catch (Exception e) {
62 LOG.error("Exception occurred in retrieving the row doc count "+e);
63 }
64 if (defaultSearch) {
65 searchParams.getSearchConditions().add(searchParams.buildSearchCondition("", searchParams.buildSearchField(DocType.ITEM.getCode(), "ClaimsReturnedFlag_search", "true"), "OR"));
66 searchParams.getSearchConditions().add(searchParams.buildSearchCondition("", searchParams.buildSearchField(DocType.ITEM.getCode(), "MissingPieceFlag_search", "true"), "OR"));
67 searchParams.getSearchConditions().add(searchParams.buildSearchCondition("", searchParams.buildSearchField(DocType.ITEM.getCode(), "ItemDamagedStatus_search", "true"), "OR"));
68 }
69 if (StringUtils.isNotEmpty(barcode)) {
70 searchParams.getSearchConditions().add(searchParams.buildSearchCondition("", searchParams.buildSearchField(DocType.ITEM.getCode(), Item.ITEM_BARCODE, barcode), "AND"));
71 }
72 if (StringUtils.isNotEmpty(flagType)) {
73 Boolean val = Boolean.valueOf("true");
74 if (flagType.equalsIgnoreCase(OLEConstants.FLAG_TYP_ITM_DAMAGED)) {
75 isDamaged = true;
76 searchParams.getSearchConditions().add(searchParams.buildSearchCondition("", searchParams.buildSearchField(DocType.ITEM.getCode(), "ItemDamagedStatus_search", "true"), "AND"));
77 }
78 if (flagType.equalsIgnoreCase(OLEConstants.FLAG_TYP_ITM_MISSING)) {
79 isMissingPieceEnabled = true;
80 searchParams.getSearchConditions().add(searchParams.buildSearchCondition("", searchParams.buildSearchField(DocType.ITEM.getCode(), "MissingPieceFlag_search", "true"), "AND"));
81 }
82 if (flagType.equalsIgnoreCase(OLEConstants.FLAG_TYP_ITM_CLAIMS_RETURNED)) {
83 isClaimsReturned = true;
84 searchParams.getSearchConditions().add(searchParams.buildSearchCondition("", searchParams.buildSearchField(DocType.ITEM.getCode(), "ClaimsReturnedFlag_search", "true"), "AND"));
85 }
86 }
87 searchParams.setPageSize(maxRowSize);
88 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("bibliographic", "Title"));
89 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "itembarcode"));
90 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "bibIdentifier"));
91 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "id"));
92 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("holdings", "CallNumber_display"));
93 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "CopyNumber_display"));
94 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "MissingPieceFlag_display"));
95 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "ClaimsReturnedFlag_display"));
96 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "ItemDamagedStatus_display"));
97 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "MissingPieceFlagNote_display"));
98 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "DamagedItemNote_display"));
99 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "ClaimsReturnedNote_display"));
100 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("holdings", "CallNumber_display"));
101 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("item", "Location_display"));
102 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField("holdings", "Location_display"));
103
104
105 try {
106 searchResponse = getDocstoreClientLocator().getDocstoreClient().search(searchParams);
107 if (LOG.isDebugEnabled()){
108 if(searchResponse.getSearchResults()!=null && searchResponse.getSearchResults().size()>0){
109 LOG.debug("Flagged Item Records Size"+searchResponse.getSearchResults().size());
110 } else {
111 LOG.debug("Flagged Item Records Size is Null");
112 }
113 }
114 for (SearchResult searchResult : searchResponse.getSearchResults()) {
115 OLEFlaggedItems flaggedItems = new OLEFlaggedItems();
116 boolean isItemLevelCallNumberExist = true;
117 boolean isItemLevelLocationExist = true;
118 LOG.debug("DOCSTORE RECORD--------->");
119 for (SearchResultField searchResultField : searchResult.getSearchResultFields()) {
120 String fieldName = searchResultField.getFieldName();
121 String fieldValue = searchResultField.getFieldValue() != null ? searchResultField.getFieldValue() : "";
122 if (LOG.isDebugEnabled()){
123 LOG.debug("Field Name"+fieldName+" :: " +fieldValue );
124 }
125 if (fieldName.equalsIgnoreCase("itemBarcode") && !fieldValue.isEmpty() && searchResultField.getDocType().equalsIgnoreCase("item")) {
126 flaggedItems.setBarcode(fieldValue);
127 } else if (fieldName.equalsIgnoreCase("MissingPieceFlag_display") && !fieldValue.isEmpty() && searchResultField.getDocType().equalsIgnoreCase("item")) {
128 if (Boolean.valueOf(fieldValue) || fieldValue.equalsIgnoreCase("true")) {
129 flaggedItems.setMissingPiece(true);
130 }
131 } else if (fieldName.equalsIgnoreCase("ClaimsReturnedFlag_display") && !fieldValue.isEmpty() && searchResultField.getDocType().equalsIgnoreCase("item")) {
132 if (Boolean.valueOf(fieldValue) || fieldValue.equalsIgnoreCase("true")) {
133 flaggedItems.setClaimsReturned(true);
134 }
135 } else if (fieldName.equalsIgnoreCase("ItemDamagedStatus_display") && !fieldValue.isEmpty() && searchResultField.getDocType().equalsIgnoreCase("item")) {
136 if (Boolean.valueOf(fieldValue) || fieldValue.equalsIgnoreCase("true")) {
137 flaggedItems.setDamaged(true);
138 }
139 } else if (fieldName.equalsIgnoreCase("title") && !fieldValue.isEmpty() && searchResultField.getDocType().equalsIgnoreCase(DocType.BIB.getCode())) {
140 flaggedItems.setTitle(fieldValue);
141 } else if (fieldName.equalsIgnoreCase("CallNumber_display") && !fieldValue.isEmpty() && searchResultField.getDocType().equalsIgnoreCase("holdings")) {
142 if (isItemLevelCallNumberExist) {
143 flaggedItems.setCallNumber(fieldValue);
144 }
145 } else if (fieldName.equalsIgnoreCase("CallNumber_display") && !fieldValue.isEmpty() && searchResultField.getDocType().equalsIgnoreCase("item")) {
146 flaggedItems.setCallNumber(fieldValue);
147 isItemLevelCallNumberExist = true;
148 } else if (fieldName.equalsIgnoreCase("CopyNumber_display") && !fieldValue.isEmpty() && searchResultField.getDocType().equalsIgnoreCase("item")) {
149 flaggedItems.setCopyNumber(fieldValue);
150 } else if (fieldName.equalsIgnoreCase("Location_display") && !fieldValue.isEmpty() && searchResultField.getDocType().equalsIgnoreCase("holdings")) {
151 if (isItemLevelLocationExist) {
152 flaggedItems.setLocation(fieldValue);
153 }
154 } else if (fieldName.equalsIgnoreCase("Location_display") && !fieldValue.isEmpty() && searchResultField.getDocType().equalsIgnoreCase("item")) {
155 flaggedItems.setLocation(fieldValue);
156 isItemLevelLocationExist = true;
157 } else if (fieldName.equalsIgnoreCase("bibIdentifier") && !fieldValue.isEmpty() && searchResultField.getDocType().equalsIgnoreCase("item")) {
158 flaggedItems.setBibUuid(fieldValue);
159 } else if (fieldName.equalsIgnoreCase("id") && !fieldValue.isEmpty() && searchResultField.getDocType().equalsIgnoreCase("item")) {
160 flaggedItems.setItemUuid(fieldValue);
161 flaggedItems.setInstanceUuid(fieldValue);
162 } else if (fieldName.equalsIgnoreCase("MissingPieceFlagNote_display") && !fieldValue.isEmpty() && searchResultField.getDocType().equalsIgnoreCase("item")) {
163 flaggedItems.setMissingPieceNote(fieldValue);
164 } else if (fieldName.equalsIgnoreCase("DamagedItemNote_display") && !fieldValue.isEmpty() && searchResultField.getDocType().equalsIgnoreCase("item")) {
165 flaggedItems.setDamagedNote(fieldValue);
166 } else if (fieldName.equalsIgnoreCase("ClaimsReturnedNote_display") && !fieldValue.isEmpty() && searchResultField.getDocType().equalsIgnoreCase("item")) {
167 flaggedItems.setClaimsReturnedNote(fieldValue);
168 }
169
170 }
171 if (LOG.isDebugEnabled()){
172 LOG.debug(flaggedItems.toString());
173 }
174 oleFlaggedItemses.add(flaggedItems);
175 }
176
177 } catch (Exception ex) {
178 ex.printStackTrace();
179 }
180 return buildResultForDisplay(oleFlaggedItemses, isClaimsReturned, isDamaged, isMissingPieceEnabled, "");
181 }
182
183 public List<OLEFlaggedItems> buildResultForDisplay(List<OLEFlaggedItems> docResults, boolean isClaimsReturned, boolean isDamaged, boolean isMissingPieceEnabled, String flagNote) {
184 List<OLEFlaggedItems> result = new ArrayList<OLEFlaggedItems>();
185 if (LOG.isDebugEnabled()){
186 LOG.debug("Flagged Item Search : Before building the docItems size"+docResults.size());
187 }
188 boolean defaultSearch = false;
189 if (!(isClaimsReturned || isDamaged || isMissingPieceEnabled)) {
190 defaultSearch = true;
191 }
192 for (OLEFlaggedItems docResult : docResults) {
193 if (defaultSearch) {
194 if (docResult.isClaimsReturned()) {
195 OLEFlaggedItems flagItem = new OLEFlaggedItems();
196 flagItem.setBarcode(docResult.getBarcode());
197 flagItem.setTitle(docResult.getTitle());
198 flagItem.setCopyNumber(docResult.getCopyNumber());
199 flagItem.setCallNumber(docResult.getCallNumber());
200 flagItem.setFlagType("Claims Returned");
201 flagItem.setFlagNote(docResult.getClaimsReturnedNote());
202 flagItem.setLocation(docResult.getLocation());
203 flagItem.setBibUuid(docResult.getBibUuid());
204 flagItem.setInstanceUuid(docResult.getInstanceUuid());
205 flagItem.setItemUuid(docResult.getItemUuid());
206 result.add(flagItem);
207 }
208 if (docResult.isDamaged()) {
209 OLEFlaggedItems flagItem = new OLEFlaggedItems();
210 flagItem.setBarcode(docResult.getBarcode());
211 flagItem.setTitle(docResult.getTitle());
212 flagItem.setCopyNumber(docResult.getCopyNumber());
213 flagItem.setCallNumber(docResult.getCallNumber());
214 flagItem.setFlagType("Damaged");
215 flagItem.setFlagNote(docResult.getDamagedNote());
216 flagItem.setLocation(docResult.getLocation());
217 flagItem.setBibUuid(docResult.getBibUuid());
218 flagItem.setInstanceUuid(docResult.getInstanceUuid());
219 flagItem.setItemUuid(docResult.getItemUuid());
220 result.add(flagItem);
221 }
222 if (docResult.isMissingPiece()) {
223 OLEFlaggedItems flagItem = new OLEFlaggedItems();
224 flagItem.setBarcode(docResult.getBarcode());
225 flagItem.setTitle(docResult.getTitle());
226 flagItem.setCopyNumber(docResult.getCopyNumber());
227 flagItem.setCallNumber(docResult.getCallNumber());
228 flagItem.setFlagType("Missing Piece");
229 flagItem.setFlagNote(docResult.getMissingPieceNote());
230 flagItem.setLocation(docResult.getLocation());
231 flagItem.setBibUuid(docResult.getBibUuid());
232 flagItem.setInstanceUuid(docResult.getInstanceUuid());
233 flagItem.setItemUuid(docResult.getItemUuid());
234 result.add(flagItem);
235 }
236 }
237 if (docResult.isClaimsReturned() && isClaimsReturned && !defaultSearch) {
238 OLEFlaggedItems flagItem = new OLEFlaggedItems();
239 flagItem.setBarcode(docResult.getBarcode());
240 flagItem.setTitle(docResult.getTitle());
241 flagItem.setCopyNumber(docResult.getCopyNumber());
242 flagItem.setCallNumber(docResult.getCallNumber());
243 flagItem.setFlagType("Claims Returned");
244 flagItem.setFlagNote(docResult.getClaimsReturnedNote());
245 flagItem.setLocation(docResult.getLocation());
246 flagItem.setBibUuid(docResult.getBibUuid());
247 flagItem.setInstanceUuid(docResult.getInstanceUuid());
248 flagItem.setItemUuid(docResult.getItemUuid());
249 result.add(flagItem);
250 }
251 if (docResult.isDamaged() && isDamaged && !defaultSearch) {
252 OLEFlaggedItems flagItem = new OLEFlaggedItems();
253 flagItem.setBarcode(docResult.getBarcode());
254 flagItem.setTitle(docResult.getTitle());
255 flagItem.setCopyNumber(docResult.getCopyNumber());
256 flagItem.setCallNumber(docResult.getCallNumber());
257 flagItem.setFlagType("Damaged");
258 flagItem.setFlagNote(docResult.getDamagedNote());
259 flagItem.setLocation(docResult.getLocation());
260 flagItem.setBibUuid(docResult.getBibUuid());
261 flagItem.setInstanceUuid(docResult.getInstanceUuid());
262 flagItem.setItemUuid(docResult.getItemUuid());
263 result.add(flagItem);
264 }
265 if (docResult.isMissingPiece() && isMissingPieceEnabled && !defaultSearch) {
266 OLEFlaggedItems flagItem = new OLEFlaggedItems();
267 flagItem.setBarcode(docResult.getBarcode());
268 flagItem.setTitle(docResult.getTitle());
269 flagItem.setCopyNumber(docResult.getCopyNumber());
270 flagItem.setCallNumber(docResult.getCallNumber());
271 flagItem.setFlagType("Missing Piece");
272 flagItem.setFlagNote(docResult.getMissingPieceNote());
273 flagItem.setLocation(docResult.getLocation());
274 flagItem.setBibUuid(docResult.getBibUuid());
275 flagItem.setInstanceUuid(docResult.getInstanceUuid());
276 flagItem.setItemUuid(docResult.getItemUuid());
277 result.add(flagItem);
278 }
279 }
280 if (LOG.isDebugEnabled()){
281 LOG.debug("Flagged Item Search : After building the docItems size"+result.size());
282 }
283 return result;
284 }
285
286
287 }