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