View Javadoc
1   /*
2    * Copyright 2011 The Kuali Foundation.
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.select.document.web.struts;
17  
18  import org.apache.commons.lang.StringEscapeUtils;
19  import org.apache.commons.lang.StringUtils;
20  import org.apache.struts.action.ActionForm;
21  import org.apache.struts.action.ActionForward;
22  import org.apache.struts.action.ActionMapping;
23  import org.kuali.ole.docstore.common.document.Bib;
24  import org.kuali.ole.module.purap.PurapConstants;
25  import org.kuali.ole.module.purap.PurapConstants.CorrectionReceivingDocumentStrings;
26  import org.kuali.ole.module.purap.PurapConstants.PREQDocumentsStrings;
27  import org.kuali.ole.module.purap.PurapKeyConstants;
28  import org.kuali.ole.module.purap.PurapPropertyConstants;
29  import org.kuali.ole.module.purap.document.LineItemReceivingDocument;
30  import org.kuali.ole.module.purap.document.PurchaseOrderDocument;
31  import org.kuali.ole.module.purap.document.ReceivingDocument;
32  import org.kuali.ole.module.purap.document.service.PurchaseOrderService;
33  import org.kuali.ole.module.purap.document.service.ReceivingService;
34  import org.kuali.ole.module.purap.document.validation.event.AddReceivingItemEvent;
35  import org.kuali.ole.module.purap.document.web.struts.LineItemReceivingAction;
36  import org.kuali.ole.module.purap.document.web.struts.LineItemReceivingForm;
37  import org.kuali.ole.module.purap.util.ReceivingQuestionCallback;
38  import org.kuali.ole.pojo.OleBibRecord;
39  import org.kuali.ole.pojo.OleEditorResponse;
40  import org.kuali.ole.select.OleSelectConstant;
41  import org.kuali.ole.select.bo.OLEDonor;
42  import org.kuali.ole.select.bo.OLEEditorResponse;
43  import org.kuali.ole.select.bo.OLELinkPurapDonor;
44  import org.kuali.ole.select.businessobject.*;
45  import org.kuali.ole.select.document.OleLineItemReceivingDocument;
46  import org.kuali.ole.select.document.service.OleCopyHelperService;
47  import org.kuali.ole.select.document.service.OleDocstoreHelperService;
48  import org.kuali.ole.select.document.service.OleLineItemReceivingService;
49  import org.kuali.ole.select.document.service.OleNoteTypeService;
50  import org.kuali.ole.select.document.service.impl.OleLineItemReceivingServiceImpl;
51  import org.kuali.ole.select.document.validation.event.OleLineItemReceivingDescEvent;
52  import org.kuali.ole.select.service.BibInfoWrapperService;
53  import org.kuali.ole.select.service.FileProcessingService;
54  import org.kuali.ole.select.service.impl.BibInfoWrapperServiceImpl;
55  import org.kuali.ole.sys.OLEConstants;
56  import org.kuali.ole.sys.OLEKeyConstants;
57  import org.kuali.ole.sys.OLEPropertyConstants;
58  import org.kuali.ole.sys.context.SpringContext;
59  import org.kuali.rice.core.api.config.property.ConfigurationService;
60  import org.kuali.rice.core.api.datetime.DateTimeService;
61  import org.kuali.rice.core.api.util.type.KualiDecimal;
62  import org.kuali.rice.core.api.util.type.KualiInteger;
63  import org.kuali.rice.kim.api.KimConstants;
64  import org.kuali.rice.kim.api.services.IdentityManagementService;
65  import org.kuali.rice.kns.service.DocumentHelperService;
66  import org.kuali.rice.kns.web.struts.form.KualiDocumentFormBase;
67  import org.kuali.rice.krad.exception.DocumentAuthorizationException;
68  import org.kuali.rice.krad.service.KRADServiceLocator;
69  import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
70  import org.kuali.rice.krad.service.KualiRuleService;
71  import org.kuali.rice.krad.service.LookupService;
72  import org.kuali.rice.krad.util.GlobalVariables;
73  import org.kuali.rice.krad.util.KRADConstants;
74  import org.kuali.rice.krad.util.ObjectUtils;
75  import org.kuali.rice.krad.util.UrlFactory;
76  
77  import javax.servlet.http.HttpServletRequest;
78  import javax.servlet.http.HttpServletResponse;
79  import java.util.*;
80  
81  /**
82   * This class performs actions for Line Item Receiving with respect to OLE
83   */
84  public class OleLineItemReceivingAction extends LineItemReceivingAction {
85  
86      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OleLineItemReceivingAction.class);
87      private static transient ConfigurationService kualiConfigurationService;
88      private static transient OleLineItemReceivingService oleLineItemReceivingService;
89  
90      /**
91       * This method sets parts received value for each item to zero.
92       *
93       * @param mapping
94       * @param form
95       * @param request
96       * @param response
97       * @return
98       * @throws Exception
99       */
100     @Override
101     public ActionForward clearQty(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
102         LOG.debug("Inside clearQty of OleLineItemReceivingAction");
103         OleLineItemReceivingForm lineItemReceivingForm = (OleLineItemReceivingForm) form;
104 
105         OleLineItemReceivingDocument lineItemReceivingDocument = (OleLineItemReceivingDocument) lineItemReceivingForm.getDocument();
106 
107         for (OleLineItemReceivingItem item : (List<OleLineItemReceivingItem>) lineItemReceivingDocument.getItems()) {
108             item.setItemReceivedTotalParts(KualiDecimal.ZERO);
109         }
110         LOG.debug("Leaving clearQty of OleLineItemReceivingAction");
111         return super.clearQty(mapping, lineItemReceivingForm, request, response);
112     }
113 
114     /**
115      * This method loads total order parts minus prior received parts into total received parts for each item.
116      *
117      * @param mapping
118      * @param form
119      * @param request
120      * @param response
121      * @return
122      * @throws Exception
123      */
124     @Override
125     public ActionForward loadQty(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
126         LOG.debug("Inside loadQty of OleLineItemReceivingAction");
127         OleLineItemReceivingForm lineItemReceivingForm = (OleLineItemReceivingForm) form;
128 
129         OleLineItemReceivingDocument lineItemReceivingDocument = (OleLineItemReceivingDocument) lineItemReceivingForm.getDocument();
130 
131         for (OleLineItemReceivingItem item : (List<OleLineItemReceivingItem>) lineItemReceivingDocument.getItems()) {
132             if (item.isOrderedItem()) {
133                 if (item.getItemOrderedParts().subtract(item.getItemReceivedPriorParts()).isGreaterEqual(KualiDecimal.ZERO)) {
134                     item.setItemReceivedTotalParts(item.getItemOrderedQuantity().subtract(item.getItemReceivedPriorParts()));
135                 } else {
136                     item.setItemReceivedTotalParts(KualiDecimal.ZERO);
137                 }
138             }
139         }
140         LOG.debug("Leaving loadQty of OleLineItemReceivingAction");
141         return super.loadQty(mapping, form, request, response);
142     }
143 
144     /**
145      * This method is used to add an exception note to the specified item.
146      *
147      * @param mapping
148      * @param form
149      * @param request
150      * @param response
151      * @return
152      * @throws Exception
153      */
154     public ActionForward addExceptionNote(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
155         LOG.debug("Inside addExceptionNote of OleLineItemReceivingAction");
156         OleLineItemReceivingForm receiveForm = (OleLineItemReceivingForm) form;
157         OleLineItemReceivingDocument receiveDocument = (OleLineItemReceivingDocument) receiveForm.getDocument();
158         OleLineItemReceivingItem selectedItem = (OleLineItemReceivingItem) receiveDocument.getItem(this.getSelectedLine(request));
159         OleReceivingLineExceptionNotes exceptionNotes = new OleReceivingLineExceptionNotes();
160         exceptionNotes.setExceptionTypeId(selectedItem.getExceptionTypeId());
161         exceptionNotes.setExceptionNotes(selectedItem.getExceptionNotes());
162         exceptionNotes.setReceivingLineItemIdentifier(selectedItem.getReceivingItemIdentifier());
163         selectedItem.addExceptionNote(exceptionNotes);
164         ((OleLineItemReceivingItem) receiveDocument.getItem(this.getSelectedLine(request))).setExceptionTypeId(null);
165         ((OleLineItemReceivingItem) receiveDocument.getItem(this.getSelectedLine(request))).setExceptionNotes(null);
166         LOG.debug("Leaving addExceptionNote of OleLineItemReceivingAction");
167         return mapping.findForward(OLEConstants.MAPPING_BASIC);
168     }
169 
170     /**
171      * This method is used to delete an exception note from the specified item
172      *
173      * @param mapping
174      * @param form
175      * @param request
176      * @param response
177      * @return
178      * @throws Exception
179      */
180     public ActionForward deleteExceptionNote(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
181         LOG.debug("Inside deleteExceptionNote of OleLineItemReceivingAction");
182         OleLineItemReceivingForm receiveForm = (OleLineItemReceivingForm) form;
183         OleLineItemReceivingDocument receiveDocument = (OleLineItemReceivingDocument) receiveForm.getDocument();
184         String[] indexes = getSelectedLineForDelete(request);
185         int itemIndex = Integer.parseInt(indexes[0]);
186         int noteIndex = Integer.parseInt(indexes[1]);
187         OleLineItemReceivingItem item = (OleLineItemReceivingItem) receiveDocument.getItem((itemIndex));
188         item.getExceptionNoteList().remove(noteIndex);
189         LOG.debug("Leaving deleteExceptionNote of OleLineItemReceivingAction");
190         return mapping.findForward(OLEConstants.MAPPING_BASIC);
191     }
192 
193     /**
194      * This method is used to add a receipt note to the specified item.
195      *
196      * @param mapping
197      * @param form
198      * @param request
199      * @param response
200      * @return
201      * @throws Exception
202      */
203     public ActionForward addReceiptNote(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
204         LOG.debug("Inside addReceiptNote of OleLineItemReceivingAction");
205         OleLineItemReceivingForm receiveForm = (OleLineItemReceivingForm) form;
206         OleLineItemReceivingDocument receiveDocument = (OleLineItemReceivingDocument) receiveForm.getDocument();
207         OleLineItemReceivingItem selectedItem = (OleLineItemReceivingItem) receiveDocument.getItem(this.getSelectedLine(request));
208         OleLineItemReceivingReceiptNotes receiptNotes = new OleLineItemReceivingReceiptNotes();
209         OleNoteType oleNoteType = SpringContext.getBean(OleNoteTypeService.class).getNoteTypeDetails(selectedItem.getNoteTypeId());
210         receiptNotes.setNoteTypeId(selectedItem.getNoteTypeId());
211         receiptNotes.setNotes(selectedItem.getReceiptNotes());
212         receiptNotes.setReceivingLineItemIdentifier(selectedItem.getReceivingItemIdentifier());
213         receiptNotes.setNoteType(oleNoteType);
214         selectedItem.addReceiptNote(receiptNotes);
215         selectedItem.addNote(receiptNotes);
216         ((OleLineItemReceivingItem) receiveDocument.getItem(this.getSelectedLine(request))).setNoteTypeId(null);
217         ((OleLineItemReceivingItem) receiveDocument.getItem(this.getSelectedLine(request))).setReceiptNotes(null);
218         LOG.debug("Leaving addReceiptNote of OleLineItemReceivingAction");
219         return mapping.findForward(OLEConstants.MAPPING_BASIC);
220     }
221 
222     /**
223      * This method is used to delete a receipt note from the specified item.
224      *
225      * @param mapping
226      * @param form
227      * @param request
228      * @param response
229      * @return
230      * @throws Exception
231      */
232     public ActionForward deleteReceiptNote(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
233         LOG.debug("Inside deleteReceiptNote of OleLineItemReceivingAction");
234         OleLineItemReceivingForm receiveForm = (OleLineItemReceivingForm) form;
235         OleLineItemReceivingDocument receiveDocument = (OleLineItemReceivingDocument) receiveForm.getDocument();
236         String[] indexes = getSelectedLineForDelete(request);
237         int itemIndex = Integer.parseInt(indexes[0]);
238         int noteIndex = Integer.parseInt(indexes[1]);
239         OleLineItemReceivingItem item = (OleLineItemReceivingItem) receiveDocument.getItem((itemIndex));
240         item.getReceiptNoteList().remove(noteIndex);
241         int index = ObjectUtils.isNotNull(item.getReceiptNoteListSize()) ? item.getReceiptNoteListSize() : 0;
242         index = index + (ObjectUtils.isNotNull(item.getSpecialHandlingNoteList()) ? item.getSpecialHandlingNoteList().size() : 0);
243         if (ObjectUtils.isNotNull(item.getReceiptNoteListSize()) || (ObjectUtils.isNotNull(item.getSpecialHandlingNoteList()) && item.getSpecialHandlingNoteList().size() > 0)) {
244             index = index - 1;
245         }
246         item.getNoteList().remove(index + noteIndex);
247         LOG.debug("leaving deleteReceiptNote of OleLineItemReceivingAction");
248         return mapping.findForward(OLEConstants.MAPPING_BASIC);
249     }
250 
251     /**
252      * Will return an array of Strings containing 2 indexes, the first String is the item index and the second String is the account
253      * index. These are obtained by parsing the method to call parameter from the request, between the word ".line" and "." The
254      * indexes are separated by a semicolon (:)
255      *
256      * @param request The HttpServletRequest
257      * @return An array of Strings containing pairs of two indices, an item index and a account index
258      */
259     protected String[] getSelectedLineForDelete(HttpServletRequest request) {
260         LOG.debug("Inside getSelectedLineForDelete of OleLineItemReceivingAction");
261         String accountString = new String();
262         String parameterName = (String) request.getAttribute(OLEConstants.METHOD_TO_CALL_ATTRIBUTE);
263         if (StringUtils.isNotBlank(parameterName)) {
264             accountString = StringUtils.substringBetween(parameterName, ".line", ".");
265         }
266         String[] result = StringUtils.split(accountString, ":");
267         LOG.debug("Leaving getSelectedLineForDelete of OleLineItemReceivingAction");
268         return result;
269     }
270 
271 
272     /**
273      * This method is overridden to set doctype name as OLE_RCVC and to change receivingUrl to ole receiving url
274      *
275      * @param mapping
276      * @param form
277      * @param request
278      * @param response
279      * @return
280      * @throws Exception
281      * @see org.kuali.ole.module.purap.document.web.struts.LineItemReceivingAction#createReceivingCorrection(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
282      */
283     @Override
284     public ActionForward createReceivingCorrection(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
285         LOG.debug("Inside createReceivingCorrection of OleLineItemReceivingAction");
286         LineItemReceivingForm rlForm = (LineItemReceivingForm) form;
287         LineItemReceivingDocument document = (LineItemReceivingDocument) rlForm.getDocument();
288 
289         String operation = "AddCorrectionNote ";
290 
291         ReceivingQuestionCallback callback = new ReceivingQuestionCallback() {
292             public boolean questionComplete = false;
293             protected String correctionDocumentnoteText;
294 
295             @Override
296             public ReceivingDocument doPostQuestion(ReceivingDocument document, String noteText) throws Exception {
297                 //mark question completed
298                 this.setQuestionComplete(true);
299                 this.setCorrectionDocumentCreationNoteText(noteText);
300                 return document;
301             }
302 
303             @Override
304             public boolean isQuestionComplete() {
305                 return this.questionComplete;
306             }
307 
308             @Override
309             public void setQuestionComplete(boolean questionComplete) {
310                 this.questionComplete = questionComplete;
311             }
312 
313             @Override
314             public String getCorrectionDocumentCreationNoteText() {
315                 return correctionDocumentnoteText;
316             }
317 
318             @Override
319             public void setCorrectionDocumentCreationNoteText(String noteText) {
320                 correctionDocumentnoteText = noteText;
321             }
322         };
323 
324         //ask question
325         ActionForward forward = askQuestionWithInput(mapping, form, request, response, CorrectionReceivingDocumentStrings.NOTE_QUESTION, CorrectionReceivingDocumentStrings.NOTE_PREFIX, operation, PurapKeyConstants.MESSAGE_RECEIVING_CORRECTION_NOTE, callback);
326 
327         //if question asked is complete, then route
328         if (callback.isQuestionComplete()) {
329 
330             //set parameters
331             String basePath = getApplicationBaseUrl();
332             String methodToCallDocHandler = "docHandler";
333             String methodToCallReceivingCorrection = "initiate";
334 
335             Properties parameters = new Properties();
336             parameters.put(OLEConstants.DISPATCH_REQUEST_PARAMETER, methodToCallDocHandler);
337             parameters.put(OLEConstants.PARAMETER_COMMAND, methodToCallReceivingCorrection);
338             parameters.put(OLEConstants.DOCUMENT_TYPE_NAME, "OLE_RCVC");
339             parameters.put("receivingLineDocId", document.getDocumentHeader().getDocumentNumber());
340             parameters.put(PurapConstants.CorrectionReceivingDocumentStrings.CORRECTION_RECEIVING_CREATION_NOTE_PARAMETER, callback.getCorrectionDocumentCreationNoteText());
341 
342             //create url
343             String receivingCorrectionUrl = UrlFactory.parameterizeUrl(basePath + "/" + "selectOleCorrectionReceiving.do", parameters);
344             //create forward
345             forward = new ActionForward(receivingCorrectionUrl, true);
346         }
347 
348         LOG.debug("Leaving createReceivingCorrection of OleLineItemReceivingAction");
349 
350         return forward;
351 
352     }
353 
354     /**
355      * This method is overridden to skip intermediate page when creating OleLineItemReceivingDocument from Purchase Order page
356      *
357      * @see org.kuali.ole.module.purap.document.web.struts.LineItemReceivingAction#continueReceivingLine(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
358      */
359     @Override
360     public ActionForward continueReceivingLine(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
361         LOG.debug("Inside continueReceivingLine of OleLineItemReceivingAction");
362         LineItemReceivingForm rlf = (LineItemReceivingForm) form;
363         LineItemReceivingDocument rlDoc = (LineItemReceivingDocument) rlf.getDocument();
364 
365         // Added for OLE-2060 to skip intermediate page when creating Receiving Document from Purchase Order page
366         if (ObjectUtils.isNull(rlDoc.getDocumentHeader()) || ObjectUtils.isNull(rlDoc.getDocumentHeader().getDocumentNumber())) {
367             KualiDocumentFormBase kualiDocumentFormBase = (KualiDocumentFormBase) form;
368             createDocument(kualiDocumentFormBase);
369             rlDoc = (LineItemReceivingDocument) kualiDocumentFormBase.getDocument();
370             rlDoc.setPurchaseOrderIdentifier(rlf.getPurchaseOrderId());
371 
372             DateTimeService dateTimeService = SpringContext.getBean(DateTimeService.class);
373             rlDoc.setShipmentReceivedDate(dateTimeService.getCurrentSqlDate());
374         }
375         // Added for OLE-2060 to skip intermediate page when creating Receiving Document from Purchase Order page Ends
376         getOleLineItemReceivingService().getInitialCollapseSections(rlDoc);
377         GlobalVariables.getMessageMap().clearErrorPath();
378         GlobalVariables.getMessageMap().addToErrorPath(OLEPropertyConstants.DOCUMENT);
379         boolean valid = true;
380         boolean poNotNull = true;
381 
382         //check for a po id
383         if (ObjectUtils.isNull(rlDoc.getPurchaseOrderIdentifier())) {
384             GlobalVariables.getMessageMap().putError(PurapPropertyConstants.PURCHASE_ORDER_IDENTIFIER, OLEKeyConstants.ERROR_REQUIRED, PREQDocumentsStrings.PURCHASE_ORDER_ID);
385             poNotNull = false;
386         }
387 
388         if (ObjectUtils.isNull(rlDoc.getShipmentReceivedDate())) {
389             GlobalVariables.getMessageMap().putError(PurapPropertyConstants.SHIPMENT_RECEIVED_DATE, OLEKeyConstants.ERROR_REQUIRED, PurapConstants.LineItemReceivingDocumentStrings.VENDOR_DATE);
390         }
391 
392         //exit early as the po is null, no need to proceed further until this is taken care of
393         if (poNotNull == false) {
394             return mapping.findForward(OLEConstants.MAPPING_BASIC);
395         }
396 
397         PurchaseOrderDocument po = SpringContext.getBean(PurchaseOrderService.class).getCurrentPurchaseOrder(rlDoc.getPurchaseOrderIdentifier());
398         if (ObjectUtils.isNotNull(po)) {
399             // TODO figure out a more straightforward way to do this.  ailish put this in so the link id would be set and the perm check would work
400             rlDoc.setAccountsPayablePurchasingDocumentLinkIdentifier(po.getAccountsPayablePurchasingDocumentLinkIdentifier());
401 
402             //TODO hjs-check to see if user is allowed to initiate doc based on PO sensitive data (add this to all other docs except acm doc)
403             if (!SpringContext.getBean(DocumentHelperService.class).getDocumentAuthorizer(rlDoc).isAuthorizedByTemplate(rlDoc, KRADConstants.KNS_NAMESPACE, KimConstants.PermissionTemplateNames.OPEN_DOCUMENT, GlobalVariables.getUserSession().getPrincipalId())) {
404                 throw buildAuthorizationException("initiate document", rlDoc);
405             }
406         } else {
407             GlobalVariables.getMessageMap().putError(PurapPropertyConstants.PURCHASE_ORDER_IDENTIFIER, PurapKeyConstants.ERROR_PURCHASE_ORDER_NOT_EXIST);
408             return mapping.findForward(OLEConstants.MAPPING_BASIC);
409         }
410 
411         //perform duplicate check
412         ActionForward forward = performDuplicateReceivingLineCheck(mapping, form, request, response, rlDoc);
413         if (forward != null) {
414             return forward;
415         }
416 
417         if (!SpringContext.getBean(ReceivingService.class).isPurchaseOrderActiveForLineItemReceivingDocumentCreation(rlDoc.getPurchaseOrderIdentifier())) {
418             GlobalVariables.getMessageMap().putError(PurapPropertyConstants.PURCHASE_ORDER_IDENTIFIER, PurapKeyConstants.ERROR_RECEIVING_LINE_DOCUMENT_PO_NOT_ACTIVE, rlDoc.getPurchaseOrderIdentifier().toString());
419             valid &= false;
420         }
421 
422         if (SpringContext.getBean(ReceivingService.class).canCreateLineItemReceivingDocument(rlDoc.getPurchaseOrderIdentifier(), rlDoc.getDocumentNumber()) == false) {
423             String inProcessDocNum = "";
424             List<String> inProcessDocNumbers = SpringContext.getBean(ReceivingService.class).getLineItemReceivingDocumentNumbersInProcessForPurchaseOrder(rlDoc.getPurchaseOrderIdentifier(), rlDoc.getDocumentNumber());
425             if (!inProcessDocNumbers.isEmpty()) {    // should not be empty if we reach this point
426                 inProcessDocNum = inProcessDocNumbers.get(0);
427             }
428             GlobalVariables.getMessageMap().putError(PurapPropertyConstants.PURCHASE_ORDER_IDENTIFIER, PurapKeyConstants.ERROR_RECEIVING_LINE_DOCUMENT_ACTIVE_FOR_PO, inProcessDocNum, rlDoc.getPurchaseOrderIdentifier().toString());
429             valid &= false;
430         }
431 
432         //populate and save Receiving Line Document from Purchase Order, only if we passed all the rules
433         if (valid) {
434             SpringContext.getBean(ReceivingService.class).populateAndSaveLineItemReceivingDocument(rlDoc);
435         }
436 
437         LOG.debug("Leaving continueReceivingLine of OleLineItemReceivingAction");
438 
439         return mapping.findForward(OLEConstants.MAPPING_BASIC);
440     }
441 
442     /**
443      * Add a new item to the document.
444      *
445      * @param mapping  An ActionMapping
446      * @param form     An ActionForm
447      * @param request  The HttpServletRequest
448      * @param response The HttpServletResponse
449      * @return An ActionForward
450      * @throws Exception
451      */
452     @Override
453     public ActionForward addItem(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
454         OleLineItemReceivingForm oleLineItemReceivingForm = (OleLineItemReceivingForm) form;
455         OleLineItemReceivingItem item = (OleLineItemReceivingItem) oleLineItemReceivingForm.getNewLineItemReceivingItemLine();
456         OleLineItemReceivingDocument lineItemReceivingDocument = (OleLineItemReceivingDocument) oleLineItemReceivingForm.getDocument();
457 
458         LOG.debug("Inside addItem >>>>>>>>>>>>>>>>>");
459 
460         String documentTypeName = OLEConstants.FinancialDocumentTypeCodes.LINE_ITEM_RECEIVING;
461         String nameSpaceCode = OLEConstants.OleLineItemReceiving.LINE_ITEM_RECEIVING_NAMESPACE;
462         if (LOG.isDebugEnabled()) {
463             LOG.debug("Inside addItem documentTypeName   >>>>>>>>>>>>>>>>>" + documentTypeName);
464         }
465         LOG.debug("Inside addItem nameSpaceCode  >>>>>>>>>>>>>>>>>" + nameSpaceCode);
466         // LOG.info("Inside addItem permissionDetails >>>>>>>>>>>>>>>>>" + permissionDetails.get(documentTypeName));
467 
468         boolean hasPermission = SpringContext.getBean(IdentityManagementService.class).hasPermission(GlobalVariables.getUserSession().getPerson().getPrincipalId(), nameSpaceCode,
469                 OLEConstants.OleLineItemReceiving.ADD_NEW_LINE_ITEM);
470 
471         if (!hasPermission) {
472             if (LOG.isDebugEnabled()) {
473                 LOG.debug("Inside addItem hasPermission   if>>>>>>>>>>>>>>>>>" + hasPermission);
474             }
475             throw new DocumentAuthorizationException(GlobalVariables.getUserSession().getPerson().getPrincipalName(), "add New Line Items", lineItemReceivingDocument.getDocumentNumber());
476 
477             //  throw new RuntimeException("User " + new String[]{GlobalVariables.getUserSession().getPerson().getPrincipalName() + "is not authorized to add New Line Items" + true});
478         }
479 
480         boolean rulePassed = SpringContext.getBean(KualiRuleService.class).applyRules(new AddReceivingItemEvent(PurapPropertyConstants.NEW_LINE_ITEM_RECEIVING_ITEM_LINE, lineItemReceivingDocument, item));
481         if (rulePassed) {
482             item = (OleLineItemReceivingItem) oleLineItemReceivingForm.getAndResetNewReceivingItemLine();
483             //TODO: we need to set the line number correctly to match up to PO
484 
485             BibInfoWrapperService docStore = SpringContext.getBean(BibInfoWrapperServiceImpl.class);
486             FileProcessingService fileProcessingService = SpringContext.getBean(FileProcessingService.class);
487             String titleId = null;
488             boolean isBibFileExist = false;
489             Iterator itemIterator = lineItemReceivingDocument.getItems().iterator();
490             int itemCounter = 0;
491             while (itemIterator.hasNext()) {
492                 OleLineItemReceivingItem tempItem = (OleLineItemReceivingItem) itemIterator.next();
493                 if (tempItem.getItemTypeCode().equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_ITEM_CODE) || tempItem.getItemTypeCode().equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_UNORDERED_ITEM_CODE)) {
494                     itemCounter++;
495                 }
496             }
497             String itemNo = String.valueOf(itemCounter);
498             //String itemNo = String.valueOf(lineItemReceivingDocument.getItems().size() - 1);
499             HashMap<String, String> dataMap = new HashMap<String, String>();
500             item.setBibInfoBean(new BibInfoBean());
501             if (item.getBibInfoBean().getDocStoreOperation() == null) {
502                 item.getBibInfoBean().setDocStoreOperation(OleSelectConstant.DOCSTORE_OPERATION_STAFF);
503             }
504             String fileName = lineItemReceivingDocument.getDocumentNumber() + "_" + itemNo;
505             // Modified for jira OLE - 2437 starts
506 
507             setItemDescription(item, fileName);
508             item.setStartingCopyNumber(new KualiInteger(1));
509 
510             // Modified for jira OLE - 2437 ends
511 
512             /*dataMap.put(OleSelectConstant.FILEPATH, fileProcessingService.getMarcXMLFileDirLocation());
513             dataMap.put(OleSelectConstant.FILENAME, fileName);
514             if (fileProcessingService.isCreateFileExist(dataMap)) {
515                 isBibFileExist = true;
516             }
517             if (isBibFileExist) {
518                 titleId = docStore.getTitleIdByMarcXMLFileProcessing(item.getBibInfoBean(), dataMap);
519                 item.setItemTitleId(titleId);
520                 BibInfoBean xmlBibInfoBean = new BibInfoBean();
521                 dataMap.put(OleSelectConstant.TITLE_ID, titleId);
522                 dataMap.put(OleSelectConstant.DOC_CATEGORY_TYPE, OleSelectConstant.DOC_CATEGORY_TYPE_ITEMLINKS);
523                 xmlBibInfoBean = docStore.getBibInfo(dataMap);
524                 item.setBibInfoBean(xmlBibInfoBean);
525                 item.setItemDescription((item.getBibInfoBean().getTitle() != null ? item.getBibInfoBean().getTitle() : "") + (item.getBibInfoBean().getAuthor() != null ? "," + item.getBibInfoBean().getAuthor() : "") + (item.getBibInfoBean().getPublisher() != null ? "," + item.getBibInfoBean().getPublisher() : "") + (item.getBibInfoBean().getIsbn() != null ? "," + item.getBibInfoBean().getIsbn() : ""));
526 
527                 HashMap<String,String> queryMap = new HashMap<String,String>();
528                 queryMap.put(OleSelectConstant.DocStoreDetails.ITEMLINKS_KEY, item.getItemTitleId());
529                 List<DocInfoBean> docStoreResult = docStore.searchBibInfo(queryMap);
530                 Iterator bibIdIterator = docStoreResult.iterator();
531 
532                 if(bibIdIterator.hasNext()){
533                     DocInfoBean docInfoBean = (DocInfoBean)bibIdIterator.next();
534                     item.setBibUUID(docInfoBean.getUniqueId());
535                 }
536             }*/
537             boolean ruleFlag = getKualiRuleService().applyRules(new OleLineItemReceivingDescEvent(lineItemReceivingDocument, item));
538             if (ruleFlag) {
539                 lineItemReceivingDocument.addItem(item);
540             }
541         }
542         return mapping.findForward(OLEConstants.MAPPING_BASIC);
543     }
544 
545     @Override
546     public ActionForward route(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
547         // TODO Auto-generated method stub
548         // ActionForward forward=super.route(mapping, form, request, response);
549         OleLineItemReceivingForm oleLineItemReceivingForm = (OleLineItemReceivingForm) form;
550         OleLineItemReceivingDocument lineItemReceivingDocument = (OleLineItemReceivingDocument) oleLineItemReceivingForm.getDocument();
551         List<OleLineItemReceivingItem> items = lineItemReceivingDocument.getItems();
552         for (OleLineItemReceivingItem item : items) {
553             OleLineItemReceivingService oleLineItemReceivingService = SpringContext
554                     .getBean(OleLineItemReceivingServiceImpl.class);
555             OlePurchaseOrderItem olePurchaseOrderItem = oleLineItemReceivingService.getOlePurchaseOrderItem(item.getPurchaseOrderIdentifier());
556             OleLineItemReceivingDoc oleLineItemReceivingItemDoc = new OleLineItemReceivingDoc();
557             oleLineItemReceivingItemDoc.setReceivingLineItemIdentifier(item.getReceivingItemIdentifier());
558             if (item.getItemTitleId() != null) {
559                 oleLineItemReceivingItemDoc.setItemTitleId(item.getItemTitleId());
560             } else {
561 
562                 oleLineItemReceivingItemDoc.setItemTitleId(olePurchaseOrderItem.getItemTitleId());
563             }
564             if (olePurchaseOrderItem != null) {
565                 /*
566                  * if(item.getItemReturnedTotalQuantity().isNonZero() && item.getItemReturnedTotalParts().isNonZero()){ }
567                  */
568                 OleCopyHelperService oleCopyHelperService = SpringContext.getBean(OleCopyHelperService.class);
569                 oleCopyHelperService.updateRequisitionAndPOItems(olePurchaseOrderItem, item, null, lineItemReceivingDocument.getIsATypeOfRCVGDoc());
570                 //  updateReceivingItemReceiptStatus(item);
571             }
572             // oleLineItemReceivingService.saveOleLineItemReceivingItemDoc(oleLineItemReceivingItemDoc);
573         }
574         return super.route(mapping, form, request, response);
575     }
576 
577     @Override
578     public ActionForward save(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
579         ActionForward forward = super.save(mapping, form, request, response);
580         OleLineItemReceivingForm oleLineItemReceivingForm = (OleLineItemReceivingForm) form;
581         OleLineItemReceivingDocument lineItemReceivingDocument = (OleLineItemReceivingDocument) oleLineItemReceivingForm.getDocument();
582         List<OleLineItemReceivingItem> items = lineItemReceivingDocument.getItems();
583         for (OleLineItemReceivingItem item : items) {
584             OleLineItemReceivingService oleLineItemReceivingService = SpringContext.getBean(OleLineItemReceivingServiceImpl.class);
585             ;
586             OleLineItemReceivingDoc oleLineItemReceivingItemDoc = new OleLineItemReceivingDoc();
587             oleLineItemReceivingItemDoc.setReceivingLineItemIdentifier(item.getReceivingItemIdentifier());
588             if (item.getItemTitleId() != null) {
589                 oleLineItemReceivingItemDoc.setItemTitleId(item.getItemTitleId());
590             } else {
591                 OlePurchaseOrderItem olePurchaseOrderItem = oleLineItemReceivingService.getOlePurchaseOrderItem(item.getPurchaseOrderIdentifier());
592                 oleLineItemReceivingItemDoc.setItemTitleId(olePurchaseOrderItem.getItemTitleId());
593             }
594             oleLineItemReceivingService.saveOleLineItemReceivingItemDoc(oleLineItemReceivingItemDoc);
595         }
596         return forward;
597     }
598 
599     private void setItemDescription(OleLineItemReceivingItem item, String fileName) {
600         if (OleDocstoreResponse.getInstance().getEditorResponse() != null) {
601             Map<String, OLEEditorResponse> oleEditorResponses = OleDocstoreResponse.getInstance().getEditorResponse();
602             OLEEditorResponse oleEditorResponse = oleEditorResponses.get(fileName);
603             Bib bib = oleEditorResponse != null ? oleEditorResponse.getBib() : null;
604             bib = (Bib) bib.deserializeContent(bib);
605             if (bib != null) {
606                 String title = (bib.getTitle() != null&& !bib.getTitle().isEmpty()) ? bib.getTitle() + ", " : "";
607                 String author = (bib.getAuthor()!=null && !bib.getAuthor().isEmpty()) ? bib.getAuthor() + ", " : "";
608                 String publisher = (bib.getPublisher()!=null && !bib.getPublisher().isEmpty()) ? bib.getPublisher() + ", " : "";
609                 String isbn = (bib.getIsbn()!=null && !bib.getIsbn().isEmpty()) ? bib.getIsbn() + ", " : "";
610                 String description = title + author + publisher + isbn;
611                 item.setItemDescription(description.substring(0, (description.lastIndexOf(","))));
612             }
613             if (bib != null) {
614                 item.setBibUUID(bib.getId());
615                 item.setItemTitleId(bib.getId());
616                 OleLineItemReceivingDoc oleLineItemReceivingDoc = new OleLineItemReceivingDoc();
617                 oleLineItemReceivingDoc.setItemTitleId(oleEditorResponse.getBib().getId());
618                 item.getOleLineItemReceivingItemDocList().add(oleLineItemReceivingDoc);
619             }
620             OleDocstoreResponse.getInstance().getEditorResponse().remove(oleEditorResponse);
621         }
622     }
623 
624     public boolean checkForCopiesAndLocation(OleLineItemReceivingItem item) {
625         boolean isValid = true;
626         if (null == item.getItemCopies() || null == item.getLocationCopies()) {
627             GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY,
628                     OLEConstants.ITEM_ITEMCOPIES_OR_LOCATIONCOPIES_SHOULDNOT_BE_NULL, new String[]{});
629             isValid = false;
630         }
631         return isValid;
632     }
633 
634     public boolean checkForItemCopiesGreaterThanQuantity(OleLineItemReceivingItem item) {
635         boolean isValid = true;
636         if (item.getItemCopies().isGreaterThan(item.getItemReceivedTotalQuantity())) {
637             GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY,
638                     OLEConstants.ITEM_COPIES_ITEMCOPIES_GREATERTHAN_ITEMCOPIESORDERED, new String[]{});
639             isValid = false;
640         }
641         return isValid;
642     }
643 
644     public boolean checkForTotalCopiesGreaterThanQuantity(OleLineItemReceivingItem item) {
645         boolean isValid = true;
646         int copies = 0;
647         if (item.getCopies().size() > 0) {
648             for (int itemCopies = 0; itemCopies < item.getCopies().size(); itemCopies++) {
649                 copies = copies + item.getCopies().get(itemCopies).getItemCopies().intValue();
650             }
651             if (item.getItemReceivedTotalQuantity().isLessThan(item.getItemCopies().add(new KualiDecimal(copies)))) {
652                 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY,
653                         OLEConstants.TOTAL_OF_ITEM_COPIES_ITEMCOPIES_GREATERTHAN_ITEMCOPIESORDERED, new String[]{});
654                 isValid = false;
655             }
656         }
657         return isValid;
658     }
659 
660     /**
661      * This method takes RequisitionItem as parameter, it will calculate and set partEnumerations and startingCopyNumber for each
662      * lineItem
663      *
664      * @param item
665      * @return OleRequisitionCopies
666      */
667     public OleRequisitionCopies setCopyValues(OleLineItemReceivingItem item) {
668         OleRequisitionCopies itemCopy = new OleRequisitionCopies();
669         int parts = 0;
670         if (null != item.getItemReceivedTotalParts()) {
671             parts = item.getItemReceivedTotalParts().intValue();
672             itemCopy.setParts(new KualiInteger(parts));
673         } else if (null != item.getItemOrderedParts()) {
674             parts = item.getItemOrderedParts().intValue();
675             itemCopy.setParts(new KualiInteger(parts));
676 
677         }
678         itemCopy.setItemCopies(item.getItemCopies());
679         StringBuffer enumeration = new StringBuffer();
680         if (item.getStartingCopyNumber() != null && item.getStartingCopyNumber().isNonZero()) {
681             itemCopy.setStartingCopyNumber(item.getStartingCopyNumber());
682         } else {
683             int startingCopies = 1;
684             for (int copy = 0; copy < item.getCopies().size(); copy++) {
685                 startingCopies = startingCopies + item.getCopies().get(copy).getItemCopies().intValue();
686             }
687             itemCopy.setStartingCopyNumber(new KualiInteger(startingCopies));
688         }
689         String partEnumerationCopy = getConfigurationService().getPropertyValueAsString(
690                 OLEConstants.PART_ENUMERATION_COPY);
691         String partEnumerationVolume = getConfigurationService().getPropertyValueAsString(
692                 OLEConstants.PART_ENUMERATION_VOLUME);
693         int startingCopyNumber = itemCopy.getStartingCopyNumber().intValue();
694         for (int noOfCopies = 0; noOfCopies < item.getItemCopies().intValue(); noOfCopies++) {
695             for (int noOfParts = 0; noOfParts < parts; noOfParts++) {
696                 int newNoOfCopies = startingCopyNumber + noOfCopies;
697                 int newNoOfParts = noOfParts + 1;
698                 if (noOfCopies + 1 == item.getItemCopies().intValue() && newNoOfParts == parts) {
699                     enumeration = enumeration.append(
700                             partEnumerationCopy + newNoOfCopies + OLEConstants.DOT_TO_SEPARATE_COPIES_PARTS).append(
701                             partEnumerationVolume + newNoOfParts);
702                 } else {
703                     enumeration = enumeration.append(
704                             partEnumerationCopy + newNoOfCopies + OLEConstants.DOT_TO_SEPARATE_COPIES_PARTS).append(
705                             partEnumerationVolume + newNoOfParts + OLEConstants.COMMA_TO_SEPARATE_ENUMERATION);
706                 }
707             }
708         }
709         itemCopy.setPartEnumeration(enumeration.toString());
710         itemCopy.setLocationCopies(item.getLocationCopies());
711         return itemCopy;
712     }
713 
714     /**
715      * Receive a Copy for the selected Item .
716      *
717      * @param mapping  An ActionMapping
718      * @param form     An ActionForm
719      * @param request  The HttpServletRequest
720      * @param response The HttpServletResponse
721      * @return An ActionForward
722      * @throws Exception
723      */
724     public ActionForward receiveCopy(ActionMapping mapping, ActionForm form, HttpServletRequest request,
725                                      HttpServletResponse response) throws Exception {
726         LOG.debug("Inside receiveCopy Method of OLELineItemReceivingAction");
727         OleLineItemReceivingForm lineItemReceivingForm = (OleLineItemReceivingForm) form;
728         String[] indexes = getSelectedLineForAccounts(request);
729         int itemIndex = Integer.parseInt(indexes[0]);
730         OleLineItemReceivingItem item = (OleLineItemReceivingItem) ((LineItemReceivingDocument) lineItemReceivingForm
731                 .getDocument()).getItem((itemIndex));
732         OleCopy oleCopy = null;
733         if(item.getCopyList().size()==1){
734              oleCopy =  item.getCopyList().get(0);
735         }else {
736             int copyIndex = Integer.parseInt(indexes[1]);
737             oleCopy = item.getCopyList().get(copyIndex);
738         }
739         oleCopy.setReceiptStatus(OLEConstants.OleLineItemReceiving.RECEIVED_STATUS);
740         LOG.debug("Selected Copy is Received");
741         LOG.debug("Leaving receiveCopy Method of OLELineItemReceivingAction");
742         return mapping.findForward(OLEConstants.MAPPING_BASIC);
743     }
744 
745     public static ConfigurationService getConfigurationService() {
746         if (kualiConfigurationService == null) {
747             kualiConfigurationService = SpringContext.getBean(ConfigurationService.class);
748         }
749         return kualiConfigurationService;
750     }
751 
752     /**
753      * Will return an array of Strings containing 2 indexes, the first String is the item index and the second String is the account
754      * index. These are obtained by parsing the method to call parameter from the request, between the word ".line" and "." The
755      * indexes are separated by a semicolon (:)
756      *
757      * @param request The HttpServletRequest
758      * @return An array of Strings containing pairs of two indices, an item index and a account index
759      */
760     protected String[] getSelectedLineForAccounts(HttpServletRequest request) {
761         String accountString = new String();
762         String parameterName = (String) request.getAttribute(OLEConstants.METHOD_TO_CALL_ATTRIBUTE);
763         if (StringUtils.isNotBlank(parameterName)) {
764             accountString = StringUtils.substringBetween(parameterName, ".line", ".");
765         }
766         String[] result = StringUtils.split(accountString, ":");
767 
768         return result;
769     }
770 
771     @Override
772     public ActionForward blanketApprove(ActionMapping mapping, ActionForm form, HttpServletRequest request,
773                                         HttpServletResponse response) throws Exception {
774         OleLineItemReceivingForm oleLineItemReceivingForm = (OleLineItemReceivingForm) form;
775         OleLineItemReceivingDocument lineItemReceivingDocument = (OleLineItemReceivingDocument) oleLineItemReceivingForm
776                 .getDocument();
777         List<OleLineItemReceivingItem> items = lineItemReceivingDocument.getItems();
778         for (OleLineItemReceivingItem item : items) {
779             OleLineItemReceivingService oleLineItemReceivingService = SpringContext
780                     .getBean(OleLineItemReceivingServiceImpl.class);
781             OlePurchaseOrderItem olePurchaseOrderItem = oleLineItemReceivingService.getOlePurchaseOrderItem(item
782                     .getPurchaseOrderIdentifier());
783             OleLineItemReceivingDoc oleLineItemReceivingItemDoc = new OleLineItemReceivingDoc();
784             oleLineItemReceivingItemDoc.setReceivingLineItemIdentifier(item.getReceivingItemIdentifier());
785             if (item.getItemTitleId() != null) {
786                 oleLineItemReceivingItemDoc.setItemTitleId(item.getItemTitleId());
787             } else {
788 
789                 oleLineItemReceivingItemDoc.setItemTitleId(olePurchaseOrderItem.getItemTitleId());
790             }
791             if (olePurchaseOrderItem != null) {
792 
793                 OleCopyHelperService oleCopyHelperService = SpringContext.getBean(OleCopyHelperService.class);
794                 oleCopyHelperService.updateRequisitionAndPOItems(olePurchaseOrderItem, item, null, lineItemReceivingDocument.getIsATypeOfRCVGDoc());
795                 //   updateReceivingItemReceiptStatus(item);
796             }
797             // oleLineItemReceivingService.saveOleLineItemReceivingItemDoc(oleLineItemReceivingItemDoc);
798         }
799         return super.blanketApprove(mapping, form, request, response);
800     }
801 
802     public static OleLineItemReceivingService getOleLineItemReceivingService() {
803         if (oleLineItemReceivingService == null) {
804             oleLineItemReceivingService = SpringContext.getBean(OleLineItemReceivingService.class);
805         }
806         return oleLineItemReceivingService;
807     }
808 
809     public ActionForward addDonor(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
810         boolean flag = true;
811         OleLineItemReceivingForm oleLineItemReceivingForm = (OleLineItemReceivingForm) form;
812         OleLineItemReceivingDocument receiveDocument = (OleLineItemReceivingDocument) oleLineItemReceivingForm.getDocument();
813         OleLineItemReceivingItem item = (OleLineItemReceivingItem) receiveDocument.getItem(this.getSelectedLine(request));
814         Map map = new HashMap();
815         if (item.getDonorCode() != null) {
816             map.put(OLEConstants.DONOR_CODE, item.getDonorCode());
817             List<OLEDonor> oleDonorList = (List<OLEDonor>) getLookupService().findCollectionBySearch(OLEDonor.class, map);
818             if (oleDonorList != null && oleDonorList.size() > 0) {
819                 OLEDonor oleDonor = oleDonorList.get(0);
820                 if (oleDonor != null) {
821                     for (OLELinkPurapDonor oleLinkPurapDonor : item.getOleDonors()) {
822                         if (oleLinkPurapDonor.getDonorCode().equalsIgnoreCase(item.getDonorCode())) {
823                             flag = false;
824                             GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY,
825                                     OLEConstants.DONOR_CODE_EXISTS, new String[]{});
826                             return mapping.findForward(OLEConstants.MAPPING_BASIC);
827                         }
828                     }
829                     if (flag) {
830                         OLELinkPurapDonor donor = new OLELinkPurapDonor();
831                         donor.setDonorId(oleDonor.getDonorId());
832                         donor.setDonorCode(oleDonor.getDonorCode());
833                         item.getOleDonors().add(donor);
834                         item.setDonorCode(null);
835                     }
836                 }
837             } else {
838                 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY,
839                         OLEConstants.ERROR_DONOR_CODE, new String[]{});
840             }
841         }
842         return mapping.findForward(OLEConstants.MAPPING_BASIC);
843     }
844 
845     private LookupService getLookupService() {
846         return KRADServiceLocatorWeb.getLookupService();
847     }
848 
849     public ActionForward deleteDonor(ActionMapping mapping, ActionForm form, HttpServletRequest request,
850                                      HttpServletResponse response) throws Exception {
851         OleLineItemReceivingForm oleLineItemReceivingForm = (OleLineItemReceivingForm) form;
852         OleLineItemReceivingDocument receiveDocument = (OleLineItemReceivingDocument) oleLineItemReceivingForm.getDocument();
853         String[] indexes = getSelectedLineForAccounts(request);
854         int itemIndex = Integer.parseInt(indexes[0]);
855         int donorIndex = Integer.parseInt(indexes[1]);
856         OleLineItemReceivingItem item = (OleLineItemReceivingItem) receiveDocument.getItem((itemIndex));
857         item.getOleDonors().remove(donorIndex);
858         return mapping.findForward(OLEConstants.MAPPING_BASIC);
859     }
860 }