1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.select.service.impl;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.ole.OLEConstants;
20 import org.kuali.ole.deliver.bo.OleDeliverRequestBo;
21 import org.kuali.ole.deliver.bo.OleLoanDocument;
22 import org.kuali.ole.select.OleSelectConstant;
23 import org.kuali.ole.select.bo.OLESerialReceivingDocument;
24 import org.kuali.ole.select.businessobject.*;
25 import org.kuali.ole.select.service.OleUuidCheckWebService;
26 import org.kuali.ole.sys.context.SpringContext;
27 import org.kuali.rice.krad.service.BusinessObjectService;
28
29 import java.util.*;
30
31 public class OleUuidCheckWebServiceImpl implements OleUuidCheckWebService {
32
33 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OleUuidCheckWebServiceImpl.class);
34 private BusinessObjectService businessObjectService;
35
36
37
38
39 @Override
40 public String checkUuidExsistence(String uuids) {
41
42 String[] uuidArr = StringUtils.split(uuids, ",");
43 List<String> uuidList = new ArrayList(Arrays.asList(uuidArr));
44 StringBuilder linksSb = new StringBuilder();
45 StringBuilder uuidsSb = new StringBuilder();
46 String responseString = null;
47 uuidList = checkUuidInRequisitionItem(uuidList, linksSb);
48 if (uuidList.size() > 0)
49 uuidList = checkUuidInPOItem(uuidList, linksSb);
50 if (uuidList.size() > 0)
51 uuidList = checkUuidInPaymentRequestItem(uuidList, linksSb);
52 if (uuidList.size() > 0)
53 uuidList = checkUuidInReceivingLineItem(uuidList, linksSb);
54 if (uuidList.size() > 0)
55 uuidList = checkUuidInCopies(uuidList, linksSb);
56 if (uuidList.size() > 0)
57 uuidList = checkUuidInRequest(uuidList, linksSb);
58 if (uuidList.size() > 0)
59 uuidList = checkUuidInLoan(uuidList, linksSb);
60 if (uuidList.size() > 0)
61 uuidList = checkUuidInSerialReceiving(uuidList, linksSb);
62
63 for (String titleId : uuidList) {
64 uuidsSb.append(titleId);
65 uuidsSb.append(",");
66 }
67 if (uuidsSb.length() > 0 || linksSb.length() > 0) {
68 responseString = (uuidsSb.length() > 0 ? uuidsSb.substring(0, uuidsSb.length() - 1) : "") + (linksSb.length() > 0 ? "|" + linksSb.substring(0, linksSb.length() - 2) : "");
69 return responseString;
70 } else {
71 return "";
72 }
73 }
74
75
76
77
78
79
80
81 public List<String> checkUuidInRequisitionItem(List<String> uuid, StringBuilder linksSb) {
82 boolean isLinked = false;
83 Map<String, List> uuidMap = new HashMap<String, List>();
84 uuidMap.put(OleSelectConstant.ITEMTITLEID, uuid);
85 List<OleRequisitionItem> requisitionItems = (List<OleRequisitionItem>) getBusinessObjectService().findMatching(OleRequisitionItem.class, uuidMap);
86 if (requisitionItems.size() > 0) {
87 for (OleRequisitionItem requisitionItem : requisitionItems) {
88 for (int i = 0; i < uuid.size(); i++) {
89 if (uuid.get(i).equalsIgnoreCase(requisitionItem.getItemTitleId())) {
90 uuid.remove(i);
91 isLinked = true;
92 }
93 }
94 }
95 }
96 if (isLinked) {
97 linksSb.append(OLEConstants.REQUISITION).append(OLEConstants.COMMA).append(OLEConstants.SPACE);
98 }
99 return uuid;
100 }
101
102
103
104
105
106
107
108 public List<String> checkUuidInPOItem(List<String> uuid, StringBuilder linksSb) {
109 boolean isLinked = false;
110 Map<String, List> uuidMap = new HashMap<String, List>();
111 uuidMap.put(OleSelectConstant.ITEMTITLEID, uuid);
112 List<OlePurchaseOrderItem> poItems = (List<OlePurchaseOrderItem>) getBusinessObjectService().findMatching(OlePurchaseOrderItem.class, uuidMap);
113 if (poItems.size() > 0) {
114 for (OlePurchaseOrderItem purchaseOrderItem : poItems) {
115 for (int i = 0; i < uuid.size(); i++) {
116 if (uuid.get(i).equalsIgnoreCase(purchaseOrderItem.getItemTitleId())) {
117 uuid.remove(i);
118 isLinked = true;
119 }
120 }
121 }
122 }
123 if (isLinked) {
124 linksSb.append(OLEConstants.PURCHASE_ORDER).append(OLEConstants.COMMA).append(OLEConstants.SPACE);
125 }
126 return uuid;
127 }
128
129
130
131
132
133
134
135 public List<String> checkUuidInPaymentRequestItem(List<String> uuid, StringBuilder linksSb) {
136 boolean isLinked = false;
137 Map<String, List> uuidMap = new HashMap<String, List>();
138 uuidMap.put(OleSelectConstant.ITEMTITLEID, uuid);
139 List<OlePaymentRequestItem> paymentRequestItems = (List<OlePaymentRequestItem>) getBusinessObjectService().findMatching(OlePaymentRequestItem.class, uuidMap);
140 if (paymentRequestItems.size() > 0) {
141 for (OlePaymentRequestItem paymentRequestItem : paymentRequestItems) {
142 for (int i = 0; i < uuid.size(); i++) {
143 if (uuid.get(i).equalsIgnoreCase(paymentRequestItem.getItemTitleId())) {
144 uuid.remove(i);
145 isLinked = true;
146 }
147 }
148 }
149 }
150 if (isLinked) {
151 linksSb.append(OLEConstants.PAYMENT_REQUEST).append(OLEConstants.COMMA).append(OLEConstants.SPACE);
152 }
153 return uuid;
154 }
155
156
157
158
159
160
161
162 public List<String> checkUuidInReceivingLineItem(List<String> uuid, StringBuilder linksSb) {
163 boolean isLinked = false;
164 Map<String, List> uuidMap = new HashMap<String, List>();
165 uuidMap.put(OleSelectConstant.ITEMTITLEID, uuid);
166 List<OleLineItemReceivingDoc> lineItemReceivingItems = (List<OleLineItemReceivingDoc>) getBusinessObjectService().findMatching(OleLineItemReceivingDoc.class, uuidMap);
167 if (lineItemReceivingItems.size() > 0) {
168 for (OleLineItemReceivingDoc linItemReceivingDocItem : lineItemReceivingItems) {
169 for (int i = 0; i < uuid.size(); i++) {
170 if (uuid.get(i).equalsIgnoreCase(linItemReceivingDocItem.getItemTitleId())) {
171 uuid.remove(i);
172 isLinked = true;
173 }
174 }
175 }
176 }
177 if (isLinked) {
178 linksSb.append(OLEConstants.LINE_ITEM).append(OLEConstants.COMMA).append(OLEConstants.SPACE);
179 }
180 return uuid;
181 }
182
183
184
185
186
187
188
189
190 public List<String> checkUuidInCopies(List<String> uuids, StringBuilder linksSb) {
191 boolean isLinked = false;
192 Set<OleCopy> copies = new TreeSet<>(new Comparator<OleCopy>() {
193 @Override
194 public int compare(OleCopy copy1, OleCopy copy2) {
195 if (copy1.getCopyId().equals(copy2.getCopyId())) {
196 return 0;
197 } else {
198 return -1;
199 }
200 }
201 });
202 Map<String, List> uuidMap = new HashMap<String, List>();
203 uuidMap.put(OLEConstants.OleDeliverRequest.ITEM_UUID, uuids);
204 copies.addAll(getBusinessObjectService().findMatching(OleCopy.class, uuidMap));
205 uuidMap.clear();
206 uuidMap.put(OLEConstants.INSTANCE_ID, uuids);
207 copies.addAll(getBusinessObjectService().findMatching(OleCopy.class, uuidMap));
208 uuidMap.clear();
209 uuidMap.put(OLEConstants.BIB_ID, uuids);
210 copies.addAll(getBusinessObjectService().findMatching(OleCopy.class, uuidMap));
211 if (copies.size() > 0) {
212 for (OleCopy oleCopy : copies) {
213 for (int i = 0; i < uuids.size(); i++) {
214 if (uuids.get(i).equalsIgnoreCase(oleCopy.getItemUUID()) || uuids.get(i).equalsIgnoreCase(oleCopy.getInstanceId()) || uuids.get(i).equalsIgnoreCase(oleCopy.getBibId())) {
215 uuids.remove(i);
216 isLinked = true;
217 }
218 }
219 }
220 }
221 if (isLinked) {
222 linksSb.append(OLEConstants.COPY).append(OLEConstants.COMMA).append(OLEConstants.SPACE);
223 }
224 return uuids;
225 }
226
227
228
229
230
231
232
233 public List<String> checkUuidInRequest(List<String> uuids, StringBuilder linksSb) {
234 boolean isLinked = false;
235 Map<String, List> uuidMap = new HashMap<String, List>();
236 uuidMap.put(OLEConstants.ITEM_UUID, uuids);
237 List<OleDeliverRequestBo> oleDeliverRequestBos = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, uuidMap);
238 if (oleDeliverRequestBos.size() > 0) {
239 for (OleDeliverRequestBo oleDeliverRequestBo : oleDeliverRequestBos) {
240 for (int i = 0; i < uuids.size(); i++) {
241 if (uuids.get(i).equalsIgnoreCase(oleDeliverRequestBo.getItemUuid())) {
242 uuids.remove(i);
243 isLinked = true;
244 }
245 }
246 }
247 }
248 if (isLinked) {
249 linksSb.append(OLEConstants.REQUEST).append(OLEConstants.COMMA).append(OLEConstants.SPACE);
250 }
251 return uuids;
252 }
253
254
255
256
257
258
259
260 public List<String> checkUuidInLoan(List<String> uuids, StringBuilder linksSb) {
261 boolean isLinked = false;
262 Map<String, List> uuidMap = new HashMap<String, List>();
263 uuidMap.put(OLEConstants.ITEM_UUID, uuids);
264 List<OleLoanDocument> oleLoanDocuments = (List<OleLoanDocument>) getBusinessObjectService().findMatching(OleLoanDocument.class, uuidMap);
265 if (oleLoanDocuments.size() > 0) {
266 for (OleLoanDocument oleLoanDocument : oleLoanDocuments) {
267 for (int i = 0; i < uuids.size(); i++) {
268 if (uuids.get(i).equalsIgnoreCase(oleLoanDocument.getItemUuid())) {
269 uuids.remove(i);
270 isLinked = true;
271 }
272 }
273 }
274 }
275 if (isLinked) {
276 linksSb.append(OLEConstants.LOAN).append(OLEConstants.COMMA).append(OLEConstants.SPACE);
277 }
278 return uuids;
279 }
280
281
282
283
284
285
286
287 public List<String> checkUuidInSerialReceiving(List<String> uuids, StringBuilder linksSb) {
288 boolean isLinked = false;
289 Map<String, List> uuidMap = new HashMap<String, List>();
290 uuidMap.put(OLEConstants.INSTANCE_ID, uuids);
291 List<OLESerialReceivingDocument> oleSerialReceivingDocuments = (List<OLESerialReceivingDocument>) getBusinessObjectService().findMatching(OLESerialReceivingDocument.class, uuidMap);
292 if (oleSerialReceivingDocuments.size() > 0) {
293 for (OLESerialReceivingDocument oleSerialReceivingDocument : oleSerialReceivingDocuments) {
294 for (int i = 0; i < uuids.size(); i++) {
295 if (uuids.get(i).equalsIgnoreCase(oleSerialReceivingDocument.getInstanceId()) && oleSerialReceivingDocument.isActive()) {
296 uuids.remove(i);
297 isLinked = true;
298 }
299 }
300 }
301 }
302 if (isLinked) {
303 linksSb.append(OLEConstants.SERIAL_RECEIVING).append(OLEConstants.COMMA).append(OLEConstants.SPACE);
304 }
305 return uuids;
306 }
307
308
309
310
311
312
313
314 public BusinessObjectService getBusinessObjectService() {
315 if (businessObjectService == null)
316 businessObjectService = SpringContext.getBean(org.kuali.rice.krad.service.BusinessObjectService.class);
317 return businessObjectService;
318 }
319
320 }