1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.select.document;
17
18 import org.apache.commons.lang.StringEscapeUtils;
19 import org.kuali.ole.docstore.common.client.DocstoreClientLocator;
20 import org.kuali.ole.docstore.common.document.Bib;
21 import org.kuali.ole.docstore.common.document.BibMarc;
22 import org.kuali.ole.docstore.model.bo.WorkBibDocument;
23 import org.kuali.ole.docstore.model.bo.WorkInstanceDocument;
24 import org.kuali.ole.docstore.model.bo.WorkItemDocument;
25 import org.kuali.ole.docstore.model.enums.DocType;
26 import org.kuali.ole.module.purap.document.CorrectionReceivingDocument;
27 import org.kuali.ole.module.purap.document.LineItemReceivingDocument;
28 import org.kuali.ole.select.businessobject.*;
29 import org.kuali.ole.select.document.service.OleLineItemReceivingService;
30 import org.kuali.ole.select.document.service.impl.OleLineItemReceivingServiceImpl;
31 import org.kuali.ole.select.document.service.impl.OleReceivingServiceImpl;
32 import org.kuali.ole.select.service.BibInfoWrapperService;
33 import org.kuali.ole.select.service.FileProcessingService;
34 import org.kuali.ole.select.service.impl.BibInfoWrapperServiceImpl;
35 import org.kuali.ole.sys.OLEConstants;
36 import org.kuali.ole.sys.context.SpringContext;
37 import org.kuali.ole.sys.service.impl.OleParameterConstants;
38 import org.kuali.rice.core.api.config.property.ConfigurationService;
39 import org.kuali.rice.core.api.util.type.KualiDecimal;
40 import org.kuali.rice.core.api.util.type.KualiInteger;
41 import org.kuali.rice.coreservice.framework.parameter.ParameterConstants.COMPONENT;
42 import org.kuali.rice.coreservice.framework.parameter.ParameterConstants.NAMESPACE;
43 import org.kuali.rice.kew.framework.postprocessor.DocumentRouteStatusChange;
44 import org.kuali.rice.krad.service.BusinessObjectService;
45
46 import java.lang.reflect.Method;
47 import java.util.*;
48
49 @NAMESPACE(namespace = OleParameterConstants.PURCHASING_NAMESPACE)
50 @COMPONENT(component = "CorrectionReceivingDocument")
51 public class OleCorrectionReceivingDocument extends CorrectionReceivingDocument {
52
53 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OleCorrectionReceivingDocument.class);
54 private static transient BusinessObjectService businessObjectService;
55 private static transient OleLineItemReceivingService oleCorrectionItemReceivingService;
56 private DocstoreClientLocator docstoreClientLocator;
57
58 public DocstoreClientLocator getDocstoreClientLocator() {
59 if (docstoreClientLocator == null) {
60 docstoreClientLocator = SpringContext.getBean(DocstoreClientLocator.class);
61 }
62 return docstoreClientLocator;
63 }
64 public static OleLineItemReceivingService getOleCorrectionItemReceivingService() {
65 if (oleCorrectionItemReceivingService == null) {
66 oleCorrectionItemReceivingService = SpringContext.getBean(OleLineItemReceivingService.class);
67 }
68 return oleCorrectionItemReceivingService;
69 }
70
71 public static void setOleCorrectionItemReceivingService(OleLineItemReceivingService oleLineItemReceivingService) {
72 OleCorrectionReceivingDocument.oleCorrectionItemReceivingService = oleLineItemReceivingService;
73 }
74
75 @Override
76 public BusinessObjectService getBusinessObjectService() {
77 if (businessObjectService == null) {
78 businessObjectService = SpringContext.getBean(BusinessObjectService.class);
79 }
80 return businessObjectService;
81 }
82
83 public void setBusinessObjectService(BusinessObjectService businessObjectService) {
84 this.businessObjectService = businessObjectService;
85 }
86
87
88
89
90 public void initiateDocument() {
91 super.initiateDocument();
92 getOleCorrectionItemReceivingService().getInitialCollapseSections(this);
93
94 }
95
96
97
98
99
100
101 @Override
102 public void populateCorrectionReceivingFromReceivingLine(LineItemReceivingDocument rlDoc) {
103 LOG.debug("Inside populateCorrectionReceivingFromReceivingLine of OleCorrectionReceivingDocument");
104
105 this.setPurchaseOrderIdentifier(rlDoc.getPurchaseOrderIdentifier());
106 this.getDocumentHeader().setDocumentDescription(rlDoc.getDocumentHeader().getDocumentDescription());
107 this.getDocumentHeader().setOrganizationDocumentNumber(rlDoc.getDocumentHeader().getOrganizationDocumentNumber());
108 this.setAccountsPayablePurchasingDocumentLinkIdentifier(rlDoc.getAccountsPayablePurchasingDocumentLinkIdentifier());
109 this.setLineItemReceivingDocumentNumber(rlDoc.getDocumentNumber());
110
111
112 for (OleLineItemReceivingItem rli : (List<OleLineItemReceivingItem>) rlDoc.getItems()) {
113 OleLineItemReceivingService oleLineItemReceivingService = SpringContext.getBean(OleLineItemReceivingServiceImpl.class);
114 OleLineItemReceivingDoc oleLineItemReceivingDoc = oleLineItemReceivingService.getOleLineItemReceivingDoc(rli.getReceivingItemIdentifier());
115 rli.setItemTitleId(oleLineItemReceivingDoc.getItemTitleId());
116 this.getItems().add(new OleCorrectionReceivingItem(rli, this));
117 }
118 LOG.debug("Leaving populateCorrectionReceivingFromReceivingLine of OleCorrectionReceivingDocument");
119 }
120
121
122
123
124
125 @Override
126 public void processAfterRetrieve() {
127 try {
128 LOG.debug("Inside processAfterRetrieve of OleCorrectionReceivingDocument");
129 super.processAfterRetrieve();
130 BibInfoWrapperService docStore = SpringContext.getBean(BibInfoWrapperServiceImpl.class);
131 FileProcessingService fileProcessingService = SpringContext.getBean(FileProcessingService.class);
132 String itemDescription = "";
133 List<OleCorrectionReceivingItem> items = new ArrayList<OleCorrectionReceivingItem>();
134 items = this.getItems();
135 Iterator<OleCorrectionReceivingItem> iterator = items.iterator();
136 String titleId = null;
137 int itemCount = 0;
138 boolean isBibFileExist = false;
139 boolean isBibEdit = false;
140 List<OleCorrectionReceivingItemReceiptNotes> receiptNoteList;
141 List<OleCorrectionReceivingItemReceiptNotes> specialHandlingNoteList;
142 for (OleCorrectionReceivingItem item : items) {
143 receiptNoteList = new ArrayList<OleCorrectionReceivingItemReceiptNotes>();
144 specialHandlingNoteList = new ArrayList<OleCorrectionReceivingItemReceiptNotes>();
145 List<OleCorrectionReceivingItemReceiptNotes> notes = new ArrayList<OleCorrectionReceivingItemReceiptNotes>();
146 notes = item.getCorrectionNoteList();
147 for (OleCorrectionReceivingItemReceiptNotes note : notes) {
148 String noteType = note.getNoteType().getNoteType();
149 if (noteType.equalsIgnoreCase(OLEConstants.SPECIAL_PROCESSING_INSTRUCTION_NOTE)) {
150 specialHandlingNoteList.add(note);
151 } else {
152 receiptNoteList.add(note);
153 }
154 item.setCorrectionSpecialHandlingNoteList(specialHandlingNoteList);
155 item.setCorrectionReceiptNoteList(receiptNoteList);
156 item.setCorrectionReceiptNoteListSize(receiptNoteList.size());
157 }
158 while (iterator.hasNext()) {
159 LOG.debug("###########inside processAfterRetrieve item loop###########");
160 Object object = iterator.next();
161 if (object instanceof OleCorrectionReceivingItem) {
162 LOG.debug("###########inside processAfterRetrieve ole requisition item###########");
163 OleCorrectionReceivingItem singleItem = (OleCorrectionReceivingItem) object;
164 if (LOG.isDebugEnabled()) {
165 LOG.debug("Title id while retriving ------>" + singleItem.getItemTitleId());
166 }
167 if (singleItem.getItemTitleId() == null) {
168 singleItem.setItemTitleId(getOleCorrectionItemReceivingService().getCorrectionItemDocItemTitleId(singleItem));
169 }
170
171 if (singleItem.getItemTitleId() != null) {
172 Bib bib = new BibMarc();
173 if(singleItem.getItemTitleId()!=null && singleItem.getItemTitleId()!=""){
174 bib= getDocstoreClientLocator().getDocstoreClient().retrieveBib(singleItem.getItemTitleId());
175 singleItem.setBibUUID(bib.getId());
176 }
177 itemDescription = (bib.getTitle() != null ? bib.getTitle() : "") + (bib.getAuthor() != null ? "," + bib.getAuthor() : "") + (bib.getPublisher() != null ? "," + bib.getPublisher() : "") + (bib.getIsbn() != null ? "," + bib.getIsbn() : "");
178 StringEscapeUtils stringEscapeUtils = new StringEscapeUtils();
179 itemDescription = stringEscapeUtils.unescapeXml(itemDescription);
180 singleItem.setItemDescription(itemDescription);
181 }
182 OleLineItemReceivingService oleLineItemReceivingService = SpringContext.getBean(OleLineItemReceivingServiceImpl.class);
183 OlePurchaseOrderItem olePurchaseOrderItem = null;
184 if (singleItem.getPurchaseOrderIdentifier() != null) {
185 olePurchaseOrderItem = oleLineItemReceivingService.getOlePurchaseOrderItem(singleItem.getPurchaseOrderIdentifier());
186 } else {
187 olePurchaseOrderItem = oleLineItemReceivingService.getOlePurchaseOrderItem(getPurchaseOrderIdentifier());
188 }
189 if (olePurchaseOrderItem != null && olePurchaseOrderItem.getItemTitleId() != null) {
190 singleItem.setItemTitleId(olePurchaseOrderItem.getItemTitleId());
191 } else {
192 singleItem.setItemTitleId(getOleCorrectionItemReceivingService()
193 .getCorrectionItemDocItemTitleId(singleItem));
194 }
195
196 Integer rcvnitemIdentifier = item.getReceivingItemIdentifier();
197 Map<String, Integer> recItemIdentifer = new HashMap<String, Integer>();
198 recItemIdentifer.put(OLEConstants.RCV_LN_ITM_IDN, rcvnitemIdentifier);
199 OleCorrectionReceivingItem oleCorrectionReceivingItems = new OleCorrectionReceivingItem();
200 List<OleLineItemCorrectionReceivingDoc> oleLineItemCorrectionReceivingDocs = (List<OleLineItemCorrectionReceivingDoc>) getBusinessObjectService().findMatching(OleLineItemCorrectionReceivingDoc.class, recItemIdentifer);
201 if (oleLineItemCorrectionReceivingDocs != null && oleLineItemCorrectionReceivingDocs.size() > 0) {
202 for (int i = 0; i < oleLineItemCorrectionReceivingDocs.size(); i++) {
203 Integer rcvnItemIdentifier = oleLineItemCorrectionReceivingDocs.get(i).getReceivingLineItemIdentifier();
204 if (!rcvnItemIdentifier.equals(item.getReceivingItemIdentifier())) {
205 OleLineItemCorrectionReceivingDoc corr = new OleLineItemCorrectionReceivingDoc();
206 corr.setReceivingLineItemIdentifier(item.getReceivingItemIdentifier());
207 corr.setItemTitleId(item.getItemTitleId());
208 oleLineItemReceivingService.saveOleLineItemReceivingCorrection(corr);
209 }
210 }
211 } else {
212 OleLineItemCorrectionReceivingDoc corr = new OleLineItemCorrectionReceivingDoc();
213 corr.setReceivingLineItemIdentifier(item.getReceivingItemIdentifier());
214 corr.setItemTitleId(item.getItemTitleId());
215 oleLineItemReceivingService.saveOleLineItemReceivingCorrection(corr);
216 }
217 Map cpySection = new HashMap();
218 cpySection.put("itemIdentifier", singleItem.getPurchaseOrderIdentifier());
219
220 List<OlePurchaseOrderItem> olePurchaseOrderItems = (List<OlePurchaseOrderItem>) getBusinessObjectService().findMatching(OlePurchaseOrderItem.class, cpySection);
221 if (olePurchaseOrderItems.size() > 0) {
222 for (OlePurchaseOrderItem purItem : olePurchaseOrderItems) {
223 singleItem.setCopyList(purItem.getCopyList());
224 }
225 }
226 }
227 }
228 LOG.debug("Leaving processAfterRetrieve of OleCorrectionReceivingDocument");
229 }
230 } catch (Exception e) {
231 LOG.error(e);
232 throw new RuntimeException(e);
233 }
234 }
235
236
237
238
239
240
241 public String getBibeditorCreateURL() {
242 String bibeditorCreateURL = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(OLEConstants.BIBEDITOR_CREATE_URL_KEY);
243 return bibeditorCreateURL;
244 }
245
246 public String getBibSearchURL() {
247 String bibSearchURL = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(OLEConstants.BIBEDITOR_SEARCH_URL_KEY);
248 return bibSearchURL;
249 }
250
251
252
253
254
255
256 public String getBibeditorEditURL() {
257 String bibeditorEditURL = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(OLEConstants.BIBEDITOR_URL_KEY);
258 return bibeditorEditURL;
259 }
260
261
262
263
264
265
266 public String getBibeditorViewURL() {
267 String bibeditorViewURL = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(OLEConstants.DOCSTORE_APP_URL_KEY);
268 return bibeditorViewURL;
269 }
270
271
272
273
274
275
276 public String getMarcXMLFileDirLocation() throws Exception {
277 FileProcessingService fileProcessingService = SpringContext.getBean(FileProcessingService.class);
278 String externaleDirectory = fileProcessingService.getMarcXMLFileDirLocation();
279 return externaleDirectory;
280 }
281
282
283
284
285
286
287 public boolean getIsSaved() {
288 if (this.getDocumentHeader().getWorkflowDocument().isSaved() || this.getDocumentHeader().getWorkflowDocument().isInitiated()) {
289 return true;
290 }
291 return false;
292 }
293
294 @Override
295 public void doRouteStatusChange(DocumentRouteStatusChange statusChangeEvent) {
296
297 if (this.getFinancialSystemDocumentHeader().getWorkflowDocument().isProcessed()) {
298 OleReceivingServiceImpl service = new OleReceivingServiceImpl();
299 service.completeCorrectionReceivingDocument(this);
300 }
301 }
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340 public List<OleCopies> setCopiesToLineItem(OleCorrectionReceivingItem singleItem, WorkBibDocument workBibDocument) {
341 List<WorkInstanceDocument> instanceDocuments = workBibDocument.getWorkInstanceDocumentList();
342 List<OleCopies> copies = new ArrayList<OleCopies>();
343 for (WorkInstanceDocument workInstanceDocument : instanceDocuments) {
344 List<WorkItemDocument> itemDocuments = workInstanceDocument.getItemDocumentList();
345 StringBuffer enumeration = new StringBuffer();
346 for (int itemDocs = 0; itemDocs < itemDocuments.size(); itemDocs++) {
347 if (itemDocs + 1 == itemDocuments.size()) {
348 enumeration = enumeration.append(itemDocuments.get(itemDocs).getEnumeration());
349 } else {
350 enumeration = enumeration.append(itemDocuments.get(itemDocs).getEnumeration() + ",");
351 }
352
353 }
354 int startingCopy = 0;
355 if (singleItem.getItemReceivedTotalParts().intValue() != 0 && null != enumeration) {
356 String enumerationSplit = enumeration.substring(1, 2);
357 boolean isint = checkIsEnumerationSplitIsIntegerOrNot(enumerationSplit);
358 if (isint) {
359 startingCopy = Integer.parseInt(enumerationSplit);
360 }
361 }
362 int parts = 1;
363 if (null != singleItem.getPurchaseOrderIdentifier()) {
364 parts = getPONoOfPartsOrdered(singleItem.getPurchaseOrderIdentifier());
365 } else {
366 parts = singleItem.getItemReceivedTotalParts().intValue();
367 }
368
369
370
371
372 int noOfCopies = workInstanceDocument.getItemDocumentList().size()
373 / parts;
374 OleRequisitionCopies copy = new OleRequisitionCopies();
375 copy.setParts(new KualiInteger(parts));
376 copy.setLocationCopies(workInstanceDocument.getHoldingsDocument().getLocationName());
377 copy.setItemCopies(new KualiDecimal(noOfCopies));
378 copy.setPartEnumeration(enumeration.toString());
379 copy.setStartingCopyNumber(new KualiInteger(startingCopy));
380 copies.add(copy);
381
382 }
383 return copies;
384 }
385
386 public int getPONoOfPartsOrdered(int poId) {
387 OleLineItemReceivingService oleLineItemReceivingService = SpringContext
388 .getBean(OleLineItemReceivingServiceImpl.class);
389 OlePurchaseOrderItem olePurchaseOrderItem = oleLineItemReceivingService.getOlePurchaseOrderItem(poId);
390 return olePurchaseOrderItem.getItemNoOfParts().intValue();
391 }
392
393 public boolean checkIsEnumerationSplitIsIntegerOrNot(String enumerationSplit) {
394 try {
395 int startingCopy = Integer.parseInt(enumerationSplit);
396 } catch (NumberFormatException e) {
397 return false;
398 }
399 return true;
400 }
401
402 public boolean getIsATypeOfRCVGDoc() {
403 return false;
404 }
405
406 public boolean getIsATypeOfCORRDoc() {
407 return true;
408 }
409
410 public boolean getIsFinalReqs() {
411 if (this.getDocumentHeader().getWorkflowDocument().isFinal()) {
412 return true;
413 }
414 return false;
415 }
416
417 }