View Javadoc
1   package org.kuali.ole.select.controller;
2   
3   import org.apache.commons.lang.StringUtils;
4   import org.apache.commons.lang.time.DateUtils;
5   import org.kuali.ole.DocumentUniqueIDPrefix;
6   import org.kuali.ole.OLEConstants;
7   import org.kuali.ole.OLEKeyConstants;
8   import org.kuali.ole.describe.keyvalue.LocationValuesBuilder;
9   import org.kuali.ole.docstore.common.client.DocstoreClientLocator;
10  import org.kuali.ole.docstore.common.document.*;
11  import org.kuali.ole.docstore.common.document.content.instance.OleHoldings;
12  import org.kuali.ole.docstore.common.document.content.instance.xstream.HoldingOlemlRecordProcessor;
13  import org.kuali.ole.select.bo.OLESerialReceivingDocument;
14  import org.kuali.ole.select.bo.OLESerialReceivingHistory;
15  import org.kuali.ole.select.bo.OLESerialReceivingType;
16  import org.kuali.ole.select.bo.OLESerialRelatedPODocument;
17  import org.kuali.ole.select.document.OlePurchaseOrderDocument;
18  import org.kuali.ole.select.form.OLESerialReceivingForm;
19  import org.kuali.ole.service.impl.OLESerialReceivingService;
20  import org.kuali.ole.service.impl.OLESerialReceivingServiceImpl;
21  import org.kuali.ole.sys.context.SpringContext;
22  import org.kuali.ole.util.DocstoreUtil;
23  import org.kuali.rice.core.api.config.property.ConfigContext;
24  import org.kuali.rice.core.api.datetime.DateTimeService;
25  import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
26  import org.kuali.rice.kew.actionitem.ActionItem;
27  import org.kuali.rice.kew.actionlist.service.ActionListService;
28  import org.kuali.rice.kew.actionrequest.ActionRequestValue;
29  import org.kuali.rice.kew.actionrequest.service.ActionRequestService;
30  import org.kuali.rice.kew.api.KewApiConstants;
31  import org.kuali.rice.kew.api.document.DocumentStatus;
32  import org.kuali.rice.kew.service.KEWServiceLocator;
33  import org.kuali.rice.kim.api.identity.Person;
34  import org.kuali.rice.kim.api.identity.PersonService;
35  import org.kuali.rice.krad.UserSession;
36  import org.kuali.rice.krad.bo.Note;
37  import org.kuali.rice.krad.service.BusinessObjectService;
38  import org.kuali.rice.krad.service.DocumentService;
39  import org.kuali.rice.krad.util.GlobalVariables;
40  import org.kuali.rice.krad.web.controller.TransactionalDocumentControllerBase;
41  import org.kuali.rice.krad.web.form.DocumentFormBase;
42  import org.kuali.rice.krad.web.form.UifFormBase;
43  import org.springframework.stereotype.Controller;
44  import org.springframework.validation.BindingResult;
45  import org.springframework.web.bind.annotation.ModelAttribute;
46  import org.springframework.web.bind.annotation.RequestMapping;
47  import org.springframework.web.servlet.ModelAndView;
48  
49  import javax.servlet.http.HttpServletRequest;
50  import javax.servlet.http.HttpServletResponse;
51  import java.sql.Timestamp;
52  import java.util.*;
53  
54  /**
55   * Created with IntelliJ IDEA.
56   * User: vivekb
57   * Date: 6/28/13
58   * Time: 5:42 PM
59   * To change this template use File | Settings | File Templates.
60   */
61  @Controller
62  @RequestMapping(value = "/serialReceiving")
63  public class OLESerialReceivingController extends TransactionalDocumentControllerBase {
64      @Override
65      protected OLESerialReceivingForm createInitialForm(HttpServletRequest request) {
66          return new OLESerialReceivingForm();
67      }
68  
69      private DocstoreClientLocator docstoreClientLocator;
70  
71      DocumentService documentService = SpringContext.getBean(DocumentService.class);
72  
73      public DocstoreClientLocator getDocstoreClientLocator() {
74  
75          if (docstoreClientLocator == null) {
76              docstoreClientLocator = SpringContext.getBean(DocstoreClientLocator.class);
77  
78          }
79          return docstoreClientLocator;
80      }
81  
82      BusinessObjectService businessObject = SpringContext.getBean(BusinessObjectService.class);
83  
84      @RequestMapping(params = "methodToCall=receive")
85      public ModelAndView receive(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
86                                  HttpServletRequest request, HttpServletResponse response) {
87          OLESerialReceivingForm oleSerialReceivingForm = (OLESerialReceivingForm) form;
88          OLESerialReceivingDocument oleSerialReceivingDocument = (OLESerialReceivingDocument) oleSerialReceivingForm.getDocument();
89          try {
90              String statusCode = oleSerialReceivingDocument.getDocumentHeader().getWorkflowDocument().getStatus().getCode();
91              if (statusCode.equalsIgnoreCase(DocumentStatus.INITIATED.getCode()) || statusCode.equalsIgnoreCase(DocumentStatus.SAVED.getCode())) {
92                  Date date = new Date(System.currentTimeMillis());
93                  String interval = oleSerialReceivingDocument.getActionInterval();
94                  if (StringUtils.isNotBlank(interval)) {
95                      boolean actIntvlFlag = isNumber(interval);
96                      if (actIntvlFlag) {
97                          Integer actIntvl = Integer.parseInt(oleSerialReceivingDocument.getActionInterval());
98                          Date actDate = DateUtils.addDays(date, actIntvl);
99                          oleSerialReceivingDocument.setActionDate(new Timestamp(actDate.getTime()));
100                     }
101                 }
102                 if (oleSerialReceivingDocument.getUnboundLocation() != null && !isValidLocation(oleSerialReceivingDocument.getUnboundLocation())) {
103                     GlobalVariables.getMessageMap().putError(OLEKeyConstants.SERIAL_UNBOUND_LOCATION_FIELD, OLEKeyConstants.SERIAL_UNBOUND_LOCATION);
104                 }
105                 OLESerialReceivingService oleSerialReceivingService = new OLESerialReceivingServiceImpl();
106                 if (oleSerialReceivingDocument.isClaim()) {
107                     oleSerialReceivingService.validateClaim(oleSerialReceivingDocument);
108                 }
109                 if (GlobalVariables.getMessageMap().getErrorCount() > 0) {
110                     return getUIFModelAndView(oleSerialReceivingForm);
111                 }
112                 String treatmentNote = oleSerialReceivingDocument.getTreatmentInstructionNote();
113                 if (StringUtils.isBlank(treatmentNote)) {
114                     oleSerialReceivingDocument.setTreatmentNoteFlag(false);
115                     oleSerialReceivingService.updateEnumValues(oleSerialReceivingDocument);
116                     oleSerialReceivingService.createOrUpdateReceivingRecordType(oleSerialReceivingDocument);
117                     oleSerialReceivingService.updateEnumCaptionValues(oleSerialReceivingDocument, null);
118                     oleSerialReceivingService.validateSerialReceivingDocument(oleSerialReceivingDocument);
119                     if (GlobalVariables.getMessageMap().getErrorCount() > 0) {
120                         oleSerialReceivingDocument.setItemCheckFlag(false);
121                         return getUIFModelAndView(oleSerialReceivingForm);
122                     } else {
123                         oleSerialReceivingDocument.setItemCheckFlag(true);
124                     }
125                     oleSerialReceivingService.receiveRecord(oleSerialReceivingDocument, OLEConstants.RECEIVED);
126                     save(oleSerialReceivingForm, result, request, response);
127                 } else {
128                     oleSerialReceivingDocument.setTreatmentNoteFlag(true);
129                     oleSerialReceivingDocument.setTreatmentDialogNote(treatmentNote);
130                 }
131             } else {
132                 oleSerialReceivingDocument.setItemCheckFlag(false);
133                 GlobalVariables.getMessageMap().putError(OLEKeyConstants.SERIAL_RECEIVE_EN_ROUTE, OLEKeyConstants.SERIAL_RECEIVE_EN_ROUTE);
134             }
135         } catch (Exception ex) {
136             ex.printStackTrace();
137             throw new RuntimeException(ex);
138         }
139         return getUIFModelAndView(oleSerialReceivingForm);
140     }
141     @Override
142     @RequestMapping(params = "methodToCall=route")
143     public ModelAndView route(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result,
144                                    HttpServletRequest request, HttpServletResponse response){
145         OLESerialReceivingForm oleSerialReceivingForm = (OLESerialReceivingForm) form;
146         OLESerialReceivingDocument oleSerialReceivingDocument = (OLESerialReceivingDocument) oleSerialReceivingForm.getDocument();
147         Note note = documentService.createNoteFromDocument(oleSerialReceivingDocument, OLEConstants.SRR_ROUTE_NOTES);;
148         oleSerialReceivingDocument.addNote(note);
149         ModelAndView modelAndView = super.route(oleSerialReceivingForm, result, request, response);
150         return modelAndView;
151     }
152 
153     @Override
154     @RequestMapping(params = "methodToCall=docHandler")
155     public ModelAndView docHandler(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result,
156                                    HttpServletRequest request, HttpServletResponse response) throws Exception {
157         long begin = System.currentTimeMillis();
158         OLESerialReceivingForm oleSerialReceivingForm = (OLESerialReceivingForm) form;
159         ModelAndView modelAndView = super.docHandler(oleSerialReceivingForm, result, request, response);
160         OLESerialReceivingDocument oleSerialReceivingDocument = (OLESerialReceivingDocument) oleSerialReceivingForm.getDocument();
161         String vendorId = oleSerialReceivingDocument.getVendorId();
162         oleSerialReceivingDocument.getDocumentHeader().setDocumentDescription(OLEConstants.SERIAL_REC_DESC + oleSerialReceivingForm.getDocument().getDocumentNumber());
163         if (oleSerialReceivingDocument.getUrgentNote() != null) {
164             oleSerialReceivingDocument.setUrgentNoteFlag(true);
165             oleSerialReceivingDocument.setUrgentDialogNote(oleSerialReceivingDocument.getUrgentNote());
166         } else {
167             oleSerialReceivingDocument.setUrgentNoteFlag(false);
168         }
169         if (StringUtils.isBlank(oleSerialReceivingDocument.getSerialReceivingRecordId())) {
170             oleSerialReceivingDocument.setPublicDisplay(true);
171         }
172         OLESerialReceivingService oleSerialReceivingService = new OLESerialReceivingServiceImpl();
173         oleSerialReceivingService.readReceivingRecordType(oleSerialReceivingDocument);
174         oleSerialReceivingService.updateEnumCaptionValues(oleSerialReceivingDocument, null);
175         String statusCode = oleSerialReceivingDocument.getDocumentHeader().getWorkflowDocument().getStatus().getCode();
176         oleSerialReceivingDocument.setStatusCode(statusCode);
177         //if (statusCode.equalsIgnoreCase(DocumentStatus.INITIATED.getCode())||statusCode.equalsIgnoreCase(DocumentStatus.SAVED.getCode())) {
178         String bibId;
179         String instanceId;
180         String holdingsId;
181         if (request.getParameter(OLEConstants.BIB_ID) != null) {
182             bibId = request.getParameter(OLEConstants.BIB_ID);
183         } else {
184             bibId = oleSerialReceivingDocument.getBibId();
185         }
186         if (request.getParameter(OLEConstants.INSTANCE_ID) != null) {
187             instanceId = request.getParameter(OLEConstants.INSTANCE_ID);
188             holdingsId = request.getParameter(OLEConstants.INSTANCE_ID);
189         } else {
190             instanceId = oleSerialReceivingDocument.getInstanceId();
191             holdingsId = oleSerialReceivingDocument.getInstanceId();
192         }
193         if (bibId != null) {
194             oleSerialReceivingDocument.setBibId(bibId);
195             oleSerialReceivingDocument.setLocalId(DocumentUniqueIDPrefix.getDocumentId(bibId));
196         } else if (oleSerialReceivingDocument.getBibId() != null) {
197 
198             oleSerialReceivingDocument.setLocalId(DocumentUniqueIDPrefix.getDocumentId(oleSerialReceivingDocument.getBibId()));
199         }
200         // LinkedHashMap<String, String> bibIdList = new LinkedHashMap<String, String>();
201         //bibIdList.put(DocType.BIB.getDescription(), bibId);
202         // List<WorkBibDocument> workBibDocuments = getWorkBibDocuments(bibIdList);
203         BibTree bibTree = getDocstoreClientLocator().getDocstoreClient().retrieveBibTree(bibId);
204 
205 
206         DocstoreUtil docstoreUtil = new DocstoreUtil();
207         // WorkBibDocument workBibDocument = workBibDocuments != null && workBibDocuments.size() > 0 ? workBibDocuments.get(0) : null;
208         String locationName = null;
209         String copyNumber = null;
210         String callNumber = null;
211         String holdingId = null;
212         if (bibTree != null) {
213             if (bibTree.getHoldingsTrees() != null) {
214                 for (HoldingsTree holdingsTree : bibTree.getHoldingsTrees()) {
215                     if (holdingsTree.getHoldings().getId().equals(holdingsId)) {
216                         OleHoldings oleHoldings = new HoldingOlemlRecordProcessor().fromXML(holdingsTree.getHoldings().getContent());
217                         //locationName = workInstanceDocument.getHoldingsDocument().getLocationName();
218                         locationName = docstoreUtil.getLocation(oleHoldings.getLocation(), new StringBuffer(""));
219                         //copyNumber = workInstanceDocument.getHoldingsDocument().getCopyNumber();
220                         //copyNumber=holdingsTree.getHoldings().getCopyNumber();
221                         //callNumber = workInstanceDocument.getHoldingsDocument().getCallNumber();
222                         callNumber = oleHoldings != null && oleHoldings.getCallNumber() != null && oleHoldings.getCallNumber().getNumber() != null ? oleHoldings.getCallNumber().getNumber() : "";
223                         copyNumber = oleHoldings != null && oleHoldings.getCopyNumber() != null ? oleHoldings.getCopyNumber() : "";
224                         holdingId = holdingsTree.getHoldings().getId();
225                     }
226                 }
227             }
228             oleSerialReceivingDocument.setBoundLocation(locationName != null ? locationName : "");
229             //oleSerialReceivingDocument.setCorporateAuthor(workBibDocument.getAuthor() != null ? workBibDocument.getAuthor() : "");
230             oleSerialReceivingDocument.setCorporateAuthor(bibTree.getBib() != null ? bibTree.getBib().getAuthor() : "");
231 
232             //oleSerialReceivingDocument.setTitle(workBibDocument.getTitle() != null ? workBibDocument.getTitle() : "");
233             String title = "";
234             if(bibTree.getBib() != null && bibTree.getBib().getTitle() != null){
235                 title = bibTree.getBib().getTitle();
236                 title = title.replaceAll("<","&lt;");
237                 title = title.replaceAll(">","&gt;");
238             }
239             oleSerialReceivingDocument.setTitle(title);
240             //oleSerialReceivingDocument.setTitle(bibTree.getBib() != null ? bibTree.getBib().getTitle() : "");
241             //oleSerialReceivingDocument.setIssn(workBibDocument.getIssn() != null ? workBibDocument.getIssn() : "");
242             oleSerialReceivingDocument.setIssn(bibTree.getBib() != null ? bibTree.getBib().getIssn() : "");
243             // oleSerialReceivingDocument.setPublisher(workBibDocument.getPublisher() != null ? workBibDocument.getPublisher() : "");
244             oleSerialReceivingDocument.setPublisher(bibTree.getBib() != null ? bibTree.getBib().getPublisher() : "");
245             oleSerialReceivingDocument.setCopyNumber(copyNumber != null ? copyNumber : "");
246             oleSerialReceivingDocument.setCallNumber(callNumber != null ? callNumber : "");
247             if (StringUtils.isNotBlank(instanceId)) {
248                 //oleSerialReceivingDocument.setInstanceId(instanceId);
249                 oleSerialReceivingDocument.setInstanceId(holdingsId);
250 
251             } else {
252                 //oleSerialReceivingDocument.setInstanceId(workBibDocument.getInstanceDocument().getInstanceIdentifier() != null ? workBibDocument.getInstanceDocument().getInstanceIdentifier() : "");
253                 oleSerialReceivingDocument.setInstanceId(holdingId);
254             }
255             oleSerialReceivingDocument.setTempInstanceId(oleSerialReceivingDocument.getInstanceId());
256         }
257         if ((oleSerialReceivingDocument.getPoId() == null || oleSerialReceivingDocument.getPoId().isEmpty())) {
258             oleSerialReceivingService.updatePOVendorDetail(oleSerialReceivingDocument);
259         } else {
260             Map<String, String> parentCriterial = new HashMap<>();
261             String poDocNum = oleSerialReceivingDocument.getPoId();
262 
263             parentCriterial.put("purapDocumentIdentifier", poDocNum);
264             List<OlePurchaseOrderDocument> olePurchaseOrderDocument = (List<OlePurchaseOrderDocument>) getBusinessObjectService().findMatching(OlePurchaseOrderDocument.class, parentCriterial);
265             if (olePurchaseOrderDocument != null)
266                 oleSerialReceivingDocument.setPoIdLink(oleSerialReceivingDocument.formPoIdLinkUsingPoDocumentNumber(olePurchaseOrderDocument.get(0).getDocumentNumber()));
267         }
268         String principalName = GlobalVariables.getUserSession().getPrincipalName();
269         oleSerialReceivingDocument.setOperatorId(principalName);
270         if (oleSerialReceivingDocument.getSerialReceivingRecord() == null || oleSerialReceivingDocument.getSerialReceivingRecord().isEmpty()) {
271             oleSerialReceivingDocument.setSerialReceivingRecord(oleSerialReceivingDocument.getSerialReceivingRecordId());
272         }
273             /*if (oleSerialReceivingDocument.getOleSerialReceivingTypes() != null && oleSerialReceivingDocument.getOleSerialReceivingTypes().size() > 0) {
274                 for(OLESerialReceivingType oleSerialReceivingType : oleSerialReceivingDocument.getOleSerialReceivingTypes()) {
275                     oleSerialReceivingService.populateEnumerationAndChronologyValues(oleSerialReceivingDocument, oleSerialReceivingType);
276                 }
277             }*/
278         // }
279         if (vendorId != null && vendorId.length() > 0) {
280             oleSerialReceivingService.populateVendorNameFromVendorId(vendorId, oleSerialReceivingDocument);
281         }
282         List<OLESerialReceivingHistory> oleSerialReceivingHistoryList = oleSerialReceivingDocument.getOleSerialReceivingHistoryList() != null ?
283                 oleSerialReceivingDocument.getOleSerialReceivingHistoryList() : new ArrayList<OLESerialReceivingHistory>();
284         oleSerialReceivingService.sortById(oleSerialReceivingHistoryList);
285         oleSerialReceivingService.listOutHistoryBasedOnReceivingRecord(oleSerialReceivingDocument);
286         if (oleSerialReceivingDocument.getOleSerialReceivingHistoryList() != null && oleSerialReceivingDocument.getOleSerialReceivingHistoryList().size() > 0) {
287             for (int serialReceivingHistoryList = 0; serialReceivingHistoryList < oleSerialReceivingDocument.getOleSerialReceivingHistoryList().size(); serialReceivingHistoryList++) {
288                 oleSerialReceivingService.setEnumerationAndChronologyValues(oleSerialReceivingDocument.getOleSerialReceivingHistoryList().get(serialReceivingHistoryList));
289             }
290         }
291         long end = System.currentTimeMillis();
292         long total = end - begin;
293         LOG.info("Time taken Inside docHandler"+total);
294         return modelAndView;
295     }
296 
297 
298 //    private List<WorkBibDocument> getWorkBibDocuments(LinkedHashMap<String, String> bibIdList) {
299 //        List<LinkedHashMap<String, String>> bibIdMapList = new ArrayList<LinkedHashMap<String, String>>();
300 //        bibIdMapList.add(bibIdList);
301 //        QueryService queryService = QueryServiceImpl.getInstance();
302 //        List<WorkBibDocument> workBibDocuments = new ArrayList<WorkBibDocument>();
303 //        try {
304 //            workBibDocuments = queryService.getWorkBibRecords(bibIdMapList);
305 //
306 //
307 //
308 //        } catch (Exception ex) {
309 //            ex.printStackTrace();
310 //        }
311 //        return workBibDocuments;
312 //    }
313 
314     @RequestMapping(params = "methodToCall=returnToSearch")
315     public ModelAndView returnToSearch(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
316                                        HttpServletRequest request, HttpServletResponse response) {
317         OLESerialReceivingForm oleSerialReceivingForm = (OLESerialReceivingForm) form;
318         OLESerialReceivingDocument oleSerialReceivingDocument = (OLESerialReceivingDocument) oleSerialReceivingForm.getDocument();
319         return getUIFModelAndView(oleSerialReceivingForm);
320     }
321 
322     @RequestMapping(params = "methodToCall=confirmReturnToSearch")
323     public ModelAndView confirmReturnToSearch(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
324                                               HttpServletRequest request, HttpServletResponse response) {
325         OLESerialReceivingForm oleSerialReceivingForm = (OLESerialReceivingForm) form;
326         OLESerialReceivingDocument oleSerialReceivingDocument = (OLESerialReceivingDocument) oleSerialReceivingForm.getDocument();
327         oleSerialReceivingDocument.setConfirmMessage(OLEConstants.CONFIRM_MSG_RETURN_TO_SEARCH);
328         oleSerialReceivingDocument.setReturnToSearch(true);
329         return getUIFModelAndView(oleSerialReceivingForm);
330     }
331 
332 
333     @RequestMapping(params = "methodToCall=specialIssue")
334     public ModelAndView specialIssue(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
335                                      HttpServletRequest request, HttpServletResponse response) {
336         OLESerialReceivingForm oleSerialReceivingForm = (OLESerialReceivingForm) form;
337         OLESerialReceivingDocument oleSerialReceivingDocument = (OLESerialReceivingDocument) oleSerialReceivingForm.getDocument();
338         String statusCode = oleSerialReceivingDocument.getDocumentHeader().getWorkflowDocument().getStatus().getCode();
339         if (oleSerialReceivingDocument.getUnboundLocation() != null && !isValidLocation(oleSerialReceivingDocument.getUnboundLocation())) {
340             GlobalVariables.getMessageMap().putError(OLEKeyConstants.SERIAL_UNBOUND_LOCATION_FIELD, OLEKeyConstants.SERIAL_UNBOUND_LOCATION);
341             return getUIFModelAndView(oleSerialReceivingForm);
342         }
343         if (statusCode.equalsIgnoreCase(DocumentStatus.INITIATED.getCode()) || statusCode.equalsIgnoreCase(DocumentStatus.SAVED.getCode())) {
344             oleSerialReceivingDocument.setSpecialIssueFlag(true);
345         } else {
346             oleSerialReceivingDocument.setItemCheckFlag(false);
347             GlobalVariables.getMessageMap().putError(OLEKeyConstants.SERIAL_RECEIVE_EN_ROUTE, OLEKeyConstants.SERIAL_RECEIVE_EN_ROUTE);
348         }
349         return getUIFModelAndView(oleSerialReceivingForm);
350     }
351 
352     @RequestMapping(params = "methodToCall=claim")
353     public ModelAndView claim(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
354                               HttpServletRequest request, HttpServletResponse response) {
355         OLESerialReceivingForm oleSerialReceivingForm = (OLESerialReceivingForm) form;
356         OLESerialReceivingDocument oleSerialReceivingDocument = (OLESerialReceivingDocument) oleSerialReceivingForm.getDocument();
357         try {
358             String statusCode = oleSerialReceivingDocument.getDocumentHeader().getWorkflowDocument().getStatus().getCode();
359             if (statusCode.equalsIgnoreCase(DocumentStatus.INITIATED.getCode()) || statusCode.equalsIgnoreCase(DocumentStatus.SAVED.getCode())) {
360                 OLESerialReceivingService oleSerialReceivingService = new OLESerialReceivingServiceImpl();
361                 oleSerialReceivingService.updateEnumValues(oleSerialReceivingDocument);
362                 oleSerialReceivingService.createOrUpdateReceivingRecordType(oleSerialReceivingDocument);
363                 oleSerialReceivingDocument.setClaimIntervalInformation(oleSerialReceivingDocument.getClaimDialogNote());
364                 oleSerialReceivingService.receiveRecord(oleSerialReceivingDocument, OLEConstants.CLAIMED);
365                 save(oleSerialReceivingForm, result, request, response);
366             } else {
367                 oleSerialReceivingDocument.setItemCheckFlag(false);
368                 GlobalVariables.getMessageMap().putError(OLEKeyConstants.SERIAL_RECEIVE_EN_ROUTE, OLEKeyConstants.SERIAL_RECEIVE_EN_ROUTE);
369             }
370         } catch (Exception ex) {
371             ex.printStackTrace();
372             throw new RuntimeException(ex);
373         }
374         return getUIFModelAndView(oleSerialReceivingForm);
375     }
376 
377     @Override
378     @RequestMapping(params = "methodToCall=save")
379     public ModelAndView save(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result,
380                              HttpServletRequest request, HttpServletResponse response) throws Exception {
381         OLESerialReceivingForm oleSerialReceivingForm = (OLESerialReceivingForm) form;
382         OLESerialReceivingDocument oleSerialReceivingDocument = (OLESerialReceivingDocument) oleSerialReceivingForm.getDocument();
383         List<OLESerialReceivingHistory> oleSerialReceivingHistoryLists = oleSerialReceivingDocument.getOleSerialReceivingHistoryList();
384         if (oleSerialReceivingHistoryLists != null) {
385             for(int serialReceivingHistory=0; serialReceivingHistory<oleSerialReceivingHistoryLists.size(); serialReceivingHistory++) {
386                 if (StringUtils.isBlank(oleSerialReceivingHistoryLists.get(serialReceivingHistory).getEnumerationCaption())
387                         && StringUtils.isBlank(oleSerialReceivingHistoryLists.get(serialReceivingHistory).getChronologyCaption())) {
388                     GlobalVariables.getMessageMap().putError(OLEKeyConstants.SERIAL_RECEIVE_ENUM_OR_CHRON_REQUIRED, OLEKeyConstants.SERIAL_RECEIVE_ENUM_OR_CHRON_REQUIRED);
389                     oleSerialReceivingForm.setJumpToId(OLEConstants.SERIAL_RECEIVING_MAIN_PAGE);
390                     return getUIFModelAndView(form);
391                 }
392             }
393         }
394         OLESerialReceivingService oleSerialReceivingService = new OLESerialReceivingServiceImpl();
395         String statusCode = oleSerialReceivingDocument.getDocumentHeader().getWorkflowDocument().getStatus().getCode();
396         if (statusCode.equalsIgnoreCase(DocumentStatus.INITIATED.getCode()) || statusCode.equalsIgnoreCase(DocumentStatus.SAVED.getCode())) {
397             Date date = new Date(System.currentTimeMillis());
398             String interval = oleSerialReceivingDocument.getActionInterval();
399             if (StringUtils.isNotBlank(interval)) {
400                 boolean actIntvlFlag = isNumber(interval);
401                 if (actIntvlFlag && oleSerialReceivingDocument.getActionDate() == null) {
402                     Integer actIntvl = Integer.parseInt(oleSerialReceivingDocument.getActionInterval());
403                     Date actDate = DateUtils.addDays(date, actIntvl);
404                     oleSerialReceivingDocument.setActionDate(new Timestamp(actDate.getTime()));
405                 }
406             }
407             ModelAndView modelAndView;
408             if (oleSerialReceivingDocument.isClaim()) {
409                 if (StringUtils.isBlank(interval)) {
410                     GlobalVariables.getMessageMap().putError(OLEKeyConstants.SERIAL_RECEIVE_ACTIONINTERVAL, OLEKeyConstants.SERIAL_RECEIVE_ACTIONINTERVAL);
411                 }
412                 if (oleSerialReceivingDocument.getActionDate() == null) {
413                     GlobalVariables.getMessageMap().putError(OLEKeyConstants.SERIAL_RECEIVE_ACTIONDATE, OLEKeyConstants.SERIAL_RECEIVE_ACTIONDATE);
414                 }
415                 if (StringUtils.isBlank(oleSerialReceivingDocument.getVendorId())) {
416                     GlobalVariables.getMessageMap().putError(OLEKeyConstants.SERIAL_RECEIVE_VENDOR_ID, OLEKeyConstants.SERIAL_RECEIVE_VENDOR_ID);
417                 }
418             }
419             if (oleSerialReceivingDocument.getUnboundLocation() != null && !isValidLocation(oleSerialReceivingDocument.getUnboundLocation())) {
420                 GlobalVariables.getMessageMap().putError(OLEKeyConstants.SERIAL_UNBOUND_LOCATION_FIELD, OLEKeyConstants.SERIAL_UNBOUND_LOCATION);
421             }
422             if (GlobalVariables.getMessageMap().getErrorCount() > 0) {
423                 return getUIFModelAndView(oleSerialReceivingForm);
424             }
425             if (oleSerialReceivingDocument.getVendorAliasName() != null && oleSerialReceivingDocument.getVendorAliasName().length() > 0) {
426                 oleSerialReceivingService.validateVendorDetailsForSave(oleSerialReceivingDocument);
427             }
428             oleSerialReceivingService.updateEnumValues(oleSerialReceivingDocument);
429             oleSerialReceivingService.createOrUpdateReceivingRecordType(oleSerialReceivingDocument);
430             modelAndView = super.save(oleSerialReceivingForm, result, request, response);
431             if (oleSerialReceivingDocument.getSerialReceivingRecord() == null || oleSerialReceivingDocument.getSerialReceivingRecord().isEmpty()) {
432                 oleSerialReceivingDocument.setSerialReceivingRecord(oleSerialReceivingDocument.getSerialReceivingRecordId());
433             }
434             oleSerialReceivingService.updateSerialIdInCopy(oleSerialReceivingDocument);
435             oleSerialReceivingDocument.setTempInstanceId(oleSerialReceivingDocument.getInstanceId());
436             List<OLESerialReceivingHistory> oleSerialReceivingHistoryList = oleSerialReceivingDocument.getOleSerialReceivingHistoryList() != null ?
437                     oleSerialReceivingDocument.getOleSerialReceivingHistoryList() : new ArrayList<OLESerialReceivingHistory>();
438             oleSerialReceivingService.sortById(oleSerialReceivingHistoryList);
439             oleSerialReceivingService.listOutHistoryBasedOnReceivingRecord(oleSerialReceivingDocument);
440             assignActionRequests(oleSerialReceivingDocument.getDocumentHeader().getWorkflowDocument().getDocumentId());
441             return modelAndView;
442         } else {
443             oleSerialReceivingDocument.setItemCheckFlag(false);
444             GlobalVariables.getMessageMap().putError(OLEKeyConstants.SERIAL_RECEIVE_EN_ROUTE, OLEKeyConstants.SERIAL_RECEIVE_EN_ROUTE);
445             return getUIFModelAndView(form);
446         }
447     }
448 
449     public static boolean isNumber(String actionInterval) {
450         String actStr = actionInterval;
451         for (int i = 0; i < actStr.length(); i++) {
452             if (!Character.isDigit(actStr.charAt(i)))
453                 return false;
454         }
455         return true;
456     }
457 
458     @RequestMapping(params = "methodToCall=saveNote")
459     public ModelAndView saveNote(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result,
460                                  HttpServletRequest request, HttpServletResponse response) throws Exception {
461         OLESerialReceivingForm oleSerialReceivingForm = (OLESerialReceivingForm) form;
462         OLESerialReceivingDocument oleSerialReceivingDocument = (OLESerialReceivingDocument) oleSerialReceivingForm.getDocument();
463         String spclIssueNote = oleSerialReceivingDocument.getSpecialIssueNote();
464         if (spclIssueNote != null && !spclIssueNote.isEmpty()) {
465             oleSerialReceivingDocument.setEnumerationCaptionLevel1(spclIssueNote);
466         }
467         OLESerialReceivingService oleSerialReceivingService = new OLESerialReceivingServiceImpl();
468         oleSerialReceivingService.receiveRecord(oleSerialReceivingDocument, OLEConstants.RECEIVED);
469         save(form, result, request, response);
470         oleSerialReceivingDocument.setSpecialIssueFlag(false);
471         return getUIFModelAndView(oleSerialReceivingForm);
472     }
473 
474     @RequestMapping(params = "methodToCall=claimNote")
475     public ModelAndView claimNote(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result,
476                                   HttpServletRequest request, HttpServletResponse response) throws Exception {
477         OLESerialReceivingForm oleSerialReceivingForm = (OLESerialReceivingForm) form;
478         OLESerialReceivingDocument oleSerialReceivingDocument = (OLESerialReceivingDocument) oleSerialReceivingForm.getDocument();
479         try {
480             String statusCode = oleSerialReceivingDocument.getDocumentHeader().getWorkflowDocument().getStatus().getCode();
481             if (statusCode.equalsIgnoreCase(DocumentStatus.INITIATED.getCode()) || statusCode.equalsIgnoreCase(DocumentStatus.SAVED.getCode())) {
482                 Date date = new Date(System.currentTimeMillis());
483                 String interval = oleSerialReceivingDocument.getActionInterval();
484                 if (StringUtils.isNotBlank(interval)) {
485                     boolean actIntvlFlag = isNumber(interval);
486                     if (actIntvlFlag && oleSerialReceivingDocument.getActionDate() == null) {
487                         Integer actIntvl = Integer.parseInt(oleSerialReceivingDocument.getActionInterval());
488                         Date actDate = DateUtils.addDays(date, actIntvl);
489                         oleSerialReceivingDocument.setActionDate(new Timestamp(actDate.getTime()));
490                     }
491                 }
492                 /*if (StringUtils.isBlank(interval)) {
493                     GlobalVariables.getMessageMap().putError(OLEKeyConstants.SERIAL_RECEIVE_ACTIONINTERVAL, OLEKeyConstants.SERIAL_RECEIVE_ACTIONINTERVAL);
494                 }
495                 if (oleSerialReceivingDocument.getActionDate() == null) {
496                     GlobalVariables.getMessageMap().putError(OLEKeyConstants.SERIAL_RECEIVE_ACTIONDATE, OLEKeyConstants.SERIAL_RECEIVE_ACTIONDATE);
497                 }
498                 if (StringUtils.isBlank(oleSerialReceivingDocument.getVendorId())) {
499                     GlobalVariables.getMessageMap().putError(OLEKeyConstants.SERIAL_RECEIVE_VENDOR_ID, OLEKeyConstants.SERIAL_RECEIVE_VENDOR_ID);
500                 }*/
501                 OLESerialReceivingService oleSerialReceivingService = new OLESerialReceivingServiceImpl();
502                 oleSerialReceivingService.validateClaim(oleSerialReceivingDocument);
503                 if (GlobalVariables.getMessageMap().getErrorCount() > 0) {
504                     return getUIFModelAndView(oleSerialReceivingForm);
505                 }
506                 oleSerialReceivingDocument.setClaimNoteFlag(true);
507                 oleSerialReceivingDocument.setClaimAgainNoteFlag(false);
508                 oleSerialReceivingDocument.setClaimDialogNote(oleSerialReceivingDocument.getClaimIntervalInformation());
509             } else {
510                 oleSerialReceivingDocument.setItemCheckFlag(false);
511                 GlobalVariables.getMessageMap().putError(OLEKeyConstants.SERIAL_RECEIVE_EN_ROUTE, OLEKeyConstants.SERIAL_RECEIVE_EN_ROUTE);
512             }
513         } catch (Exception ex) {
514             ex.printStackTrace();
515             throw new RuntimeException(ex);
516         }
517         return getUIFModelAndView(oleSerialReceivingForm);
518     }
519 
520 
521     @RequestMapping(params = "methodToCall=acknowledgeNote")
522     public ModelAndView acknowledgeNote(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
523                                         HttpServletRequest request, HttpServletResponse response) {
524         OLESerialReceivingForm oleSerialReceivingForm = (OLESerialReceivingForm) form;
525         OLESerialReceivingDocument oleSerialReceivingDocument = (OLESerialReceivingDocument) oleSerialReceivingForm.getDocument();
526         try {
527             OLESerialReceivingService oleSerialReceivingService = new OLESerialReceivingServiceImpl();
528             oleSerialReceivingService.updateEnumValues(oleSerialReceivingDocument);
529             oleSerialReceivingService.createOrUpdateReceivingRecordType(oleSerialReceivingDocument);
530             oleSerialReceivingService.validateSerialReceivingDocument(oleSerialReceivingDocument);
531             if (GlobalVariables.getMessageMap().getErrorCount() > 0) {
532                 oleSerialReceivingDocument.setItemCheckFlag(false);
533                 return getUIFModelAndView(oleSerialReceivingForm);
534             }
535 
536             oleSerialReceivingService.receiveRecord(oleSerialReceivingDocument, OLEConstants.RECEIVED);
537             save(oleSerialReceivingForm, result, request, response);
538         } catch (Exception ex) {
539             ex.printStackTrace();
540             throw new RuntimeException(ex);
541         }
542         return getUIFModelAndView(oleSerialReceivingForm);
543     }
544 
545 
546     @RequestMapping(params = "methodToCall=acknowledgeUrgentNote")
547     public ModelAndView acknowledgeUrgentNote(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
548                                               HttpServletRequest request, HttpServletResponse response) {
549         OLESerialReceivingForm oleSerialReceivingForm = (OLESerialReceivingForm) form;
550         OLESerialReceivingDocument oleSerialReceivingDocument = (OLESerialReceivingDocument) oleSerialReceivingForm.getDocument();
551         oleSerialReceivingDocument.setUrgentNote(oleSerialReceivingDocument.getUrgentDialogNote());
552         return getUIFModelAndView(oleSerialReceivingForm);
553     }
554 
555     @RequestMapping(params = "methodToCall=receiveHistory")
556     public ModelAndView receiveHistory(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
557                                        HttpServletRequest request, HttpServletResponse response) {
558         OLESerialReceivingForm oleSerialReceivingForm = (OLESerialReceivingForm) form;
559         try {
560             OLESerialReceivingDocument oleSerialReceivingDocument = (OLESerialReceivingDocument) oleSerialReceivingForm.getDocument();
561             String statusCode = oleSerialReceivingDocument.getDocumentHeader().getWorkflowDocument().getStatus().getCode();
562             if (statusCode.equalsIgnoreCase(DocumentStatus.SAVED.getCode())) {
563                 Date date = new Date(System.currentTimeMillis());
564                 for (OLESerialReceivingHistory oleSerialReceivingHistory : oleSerialReceivingDocument.getOleSerialReceivingHistoryList()) {
565                     if (oleSerialReceivingHistory.getSerialReceivingRecordHistoryId().equalsIgnoreCase(oleSerialReceivingDocument.getSerialReceiptHistoryId())) {
566                         oleSerialReceivingHistory.setReceiptStatus(OLEConstants.RECEIVED);
567                         oleSerialReceivingHistory.setReceiptDate(new Timestamp(date.getTime()));
568                     }
569                 }
570                 save(oleSerialReceivingForm, result, request, response);
571             } else {
572                 oleSerialReceivingDocument.setItemCheckFlag(false);
573                 GlobalVariables.getMessageMap().putError(OLEKeyConstants.SERIAL_RECEIVE_EN_ROUTE, OLEKeyConstants.SERIAL_RECEIVE_EN_ROUTE);
574             }
575         } catch (Exception ex) {
576             ex.printStackTrace();
577             throw new RuntimeException(ex);
578         }
579         return getUIFModelAndView(oleSerialReceivingForm);
580     }
581 
582 
583     @RequestMapping(params = "methodToCall=claimHistory")
584     public ModelAndView claimHistory(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
585                                      HttpServletRequest request, HttpServletResponse response) {
586         OLESerialReceivingForm oleSerialReceivingForm = (OLESerialReceivingForm) form;
587         try {
588             Date date = new Date(System.currentTimeMillis());
589             OLESerialReceivingDocument oleSerialReceivingDocument = (OLESerialReceivingDocument) oleSerialReceivingForm.getDocument();
590             String statusCode = oleSerialReceivingDocument.getDocumentHeader().getWorkflowDocument().getStatus().getCode();
591             if (statusCode.equalsIgnoreCase(DocumentStatus.SAVED.getCode())) {
592                 for (OLESerialReceivingHistory oleSerialReceivingHistory : oleSerialReceivingDocument.getOleSerialReceivingHistoryList()) {
593                     if (oleSerialReceivingHistory.getSerialReceivingRecordHistoryId().equalsIgnoreCase(oleSerialReceivingDocument.getSerialReceiptHistoryId())) {
594                         oleSerialReceivingHistory.setReceiptStatus(OLEConstants.CLAIMED);
595                         oleSerialReceivingHistory.setClaimDate(new Timestamp(date.getTime()));
596                         oleSerialReceivingHistory.setClaimType(oleSerialReceivingDocument.getClaimType());
597                         oleSerialReceivingHistory.setClaimNote(oleSerialReceivingDocument.getClaimDialogNote());
598                         if (oleSerialReceivingHistory.getClaimCount() != null && !oleSerialReceivingHistory.getClaimCount().isEmpty()) {
599                             Integer count = Integer.parseInt(oleSerialReceivingHistory.getClaimCount());
600                             count++;
601                             oleSerialReceivingHistory.setClaimCount(count.toString());
602                         } else {
603                             oleSerialReceivingHistory.setClaimCount("1");
604                         }
605 
606                     }
607                 }
608                 save(oleSerialReceivingForm, result, request, response);
609             } else {
610                 oleSerialReceivingDocument.setItemCheckFlag(false);
611                 GlobalVariables.getMessageMap().putError(OLEKeyConstants.SERIAL_RECEIVE_EN_ROUTE, OLEKeyConstants.SERIAL_RECEIVE_EN_ROUTE);
612             }
613         } catch (Exception ex) {
614             ex.printStackTrace();
615             throw new RuntimeException(ex);
616         }
617         return getUIFModelAndView(oleSerialReceivingForm);
618     }
619 
620     @RequestMapping(params = "methodToCall=claimAgainNote")
621     public ModelAndView claimAgainNote(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result,
622                                        HttpServletRequest request, HttpServletResponse response) throws Exception {
623         OLESerialReceivingForm oleSerialReceivingForm = (OLESerialReceivingForm) form;
624         try {
625             OLESerialReceivingDocument oleSerialReceivingDocument = (OLESerialReceivingDocument) oleSerialReceivingForm.getDocument();
626             String statusCode = oleSerialReceivingDocument.getDocumentHeader().getWorkflowDocument().getStatus().getCode();
627             if (statusCode.equalsIgnoreCase(DocumentStatus.SAVED.getCode())) {
628                 for (OLESerialReceivingHistory oleSerialReceivingHistory : oleSerialReceivingDocument.getOleSerialReceivingHistoryList()) {
629                     if (oleSerialReceivingHistory.getSerialReceivingRecordHistoryId().equalsIgnoreCase(oleSerialReceivingDocument.getSerialReceiptHistoryId())) {
630                         oleSerialReceivingDocument.setClaimAgainNoteFlag(true);
631                         oleSerialReceivingDocument.setClaimNoteFlag(false);
632                         oleSerialReceivingDocument.setClaimType(oleSerialReceivingHistory.getClaimType());
633                         oleSerialReceivingDocument.setClaimDialogNote(oleSerialReceivingHistory.getClaimNote());
634                     }
635                 }
636             } else {
637                 oleSerialReceivingDocument.setItemCheckFlag(false);
638                 GlobalVariables.getMessageMap().putError(OLEKeyConstants.SERIAL_RECEIVE_EN_ROUTE, OLEKeyConstants.SERIAL_RECEIVE_EN_ROUTE);
639             }
640         } catch (Exception ex) {
641             ex.printStackTrace();
642             throw new RuntimeException(ex);
643         }
644         return getUIFModelAndView(oleSerialReceivingForm);
645     }
646 
647     @RequestMapping(params = "methodToCall=unReceiveHistory")
648     public ModelAndView unReceiveHistory(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
649                                          HttpServletRequest request, HttpServletResponse response) {
650         OLESerialReceivingForm oleSerialReceivingForm = (OLESerialReceivingForm) form;
651         try {
652             OLESerialReceivingDocument oleSerialReceivingDocument = (OLESerialReceivingDocument) oleSerialReceivingForm.getDocument();
653             String statusCode = oleSerialReceivingDocument.getDocumentHeader().getWorkflowDocument().getStatus().getCode();
654             if (statusCode.equalsIgnoreCase(DocumentStatus.SAVED.getCode())) {
655                 for (OLESerialReceivingHistory oleSerialReceivingHistory : oleSerialReceivingDocument.getOleSerialReceivingHistoryList()) {
656                     if (oleSerialReceivingHistory.getSerialReceivingRecordHistoryId().equalsIgnoreCase(oleSerialReceivingDocument.getSerialReceiptHistoryId())) {
657                         getBusinessObjectService().delete(oleSerialReceivingHistory);
658                         oleSerialReceivingDocument.getOleSerialReceivingHistoryList().remove(oleSerialReceivingHistory);
659                         break;
660                     }
661                 }
662                 OLESerialReceivingService oleSerialReceivingService = new OLESerialReceivingServiceImpl();
663                 oleSerialReceivingService.listOutHistoryBasedOnReceivingRecord(oleSerialReceivingDocument);
664             } else {
665                 oleSerialReceivingDocument.setItemCheckFlag(false);
666                 GlobalVariables.getMessageMap().putError(OLEKeyConstants.SERIAL_RECEIVE_EN_ROUTE, OLEKeyConstants.SERIAL_RECEIVE_EN_ROUTE);
667             }
668         } catch (Exception ex) {
669             ex.printStackTrace();
670             throw new RuntimeException(ex);
671         }
672         return getUIFModelAndView(oleSerialReceivingForm);
673     }
674 
675     @RequestMapping(params = "methodToCall=cancelClaim")
676     public ModelAndView cancelClaim(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
677                                     HttpServletRequest request, HttpServletResponse response) {
678         OLESerialReceivingForm oleSerialReceivingForm = (OLESerialReceivingForm) form;
679         try {
680             OLESerialReceivingDocument oleSerialReceivingDocument = (OLESerialReceivingDocument) oleSerialReceivingForm.getDocument();
681             String statusCode = oleSerialReceivingDocument.getDocumentHeader().getWorkflowDocument().getStatus().getCode();
682             if (statusCode.equalsIgnoreCase(DocumentStatus.SAVED.getCode())) {
683                 for (OLESerialReceivingHistory oleSerialReceivingHistory : oleSerialReceivingDocument.getOleSerialReceivingHistoryList()) {
684                     if (oleSerialReceivingHistory.getSerialReceivingRecordHistoryId().equalsIgnoreCase(oleSerialReceivingDocument.getSerialReceiptHistoryId())) {
685                         oleSerialReceivingHistory.setReceiptStatus(OLEConstants.RCV_CANCELLED);
686                         break;
687                     }
688                 }
689             } else {
690                 oleSerialReceivingDocument.setItemCheckFlag(false);
691                 GlobalVariables.getMessageMap().putError(OLEKeyConstants.SERIAL_RECEIVE_EN_ROUTE, OLEKeyConstants.SERIAL_RECEIVE_EN_ROUTE);
692             }
693         } catch (Exception ex) {
694             ex.printStackTrace();
695             throw new RuntimeException(ex);
696         }
697         return getUIFModelAndView(oleSerialReceivingForm);
698     }
699 
700 
701     @RequestMapping(params = "methodToCall=selectVendor")
702     public ModelAndView selectVendor(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
703                                      HttpServletRequest request, HttpServletResponse response) {
704         OLESerialReceivingForm oleSerialReceivingForm = (OLESerialReceivingForm) form;
705         OLESerialReceivingDocument oleSerialReceivingDocument = (OLESerialReceivingDocument) oleSerialReceivingForm.getDocument();
706         if (oleSerialReceivingDocument.getVendorAliasName() != null && oleSerialReceivingDocument.getVendorAliasName().length() > 0) {
707             OLESerialReceivingService oleSerialReceivingService = new OLESerialReceivingServiceImpl();
708             oleSerialReceivingService.validateVendorDetailsForSelect(oleSerialReceivingDocument);
709         } else {
710             oleSerialReceivingDocument.setVendorId(null);
711             GlobalVariables.getMessageMap().putError(OLEKeyConstants.SERIAL_RECEIVE_VENDOR_ALIAS_NOT_FOUND, OLEKeyConstants.SERIAL_RECEIVE_VENDOR_ALIAS_NOT_FOUND);
712         }
713         return getUIFModelAndView(oleSerialReceivingForm);
714     }
715 
716     @RequestMapping(params = "methodToCall=searchVendor")
717     public ModelAndView searchVendor(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
718                                      HttpServletRequest request, HttpServletResponse response) {
719         OLESerialReceivingForm oleSerialReceivingForm = (OLESerialReceivingForm) form;
720         OLESerialReceivingDocument oleSerialReceivingDocument = (OLESerialReceivingDocument) oleSerialReceivingForm.getDocument();
721         OLESerialReceivingService oleSerialReceivingService = new OLESerialReceivingServiceImpl();
722         oleSerialReceivingService.populateVendorAliasNameFromVendorName(oleSerialReceivingDocument);
723         return getUIFModelAndView(oleSerialReceivingForm);
724     }
725 
726 
727     /**
728      * Performs the disapprove workflow action on the form document instance
729      *
730      * @param form - document form base containing the document instance that will be disapproved
731      * @return ModelAndView
732      */
733     @RequestMapping(params = "methodToCall=disapprove")
734     public ModelAndView disapprove(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result,
735                                    HttpServletRequest request, HttpServletResponse response) throws Exception {
736         OLESerialReceivingForm oleSerialReceivingForm = (OLESerialReceivingForm) form;
737         OLESerialReceivingDocument oldSerialReceivingDocument = (OLESerialReceivingDocument) oleSerialReceivingForm.getDocument();
738         ModelAndView modelAndView = super.disapprove(form, result, request, response);
739         form.setDocId(null);
740         form.setCommand(KewApiConstants.INITIATE_COMMAND);
741         super.docHandler(form, result, request, response);
742         OLESerialReceivingService oleSerialReceivingService = new OLESerialReceivingServiceImpl();
743         String user = oldSerialReceivingDocument.getDocumentHeader().getWorkflowDocument().getInitiatorPrincipalId();
744         Person person = SpringContext.getBean(PersonService.class).getPerson(user);
745         GlobalVariables.setUserSession(new UserSession(person.getPrincipalName()));
746         DocumentService documentService = GlobalResourceLoader.getService(OLEConstants.DOCUMENT_HEADER_SERVICE);
747         OLESerialReceivingDocument newDocument = (OLESerialReceivingDocument) documentService.getNewDocument("OLE_SER_RECV_REC");
748         newDocument.getDocumentHeader().setDocumentDescription(OLEConstants.SERIAL_REC_DESC + form.getDocument().getDocumentNumber());
749         oleSerialReceivingService.disapproveCreateNewWithExisting(newDocument, oldSerialReceivingDocument);
750         documentService.saveDocument(newDocument);
751         form.setDocument(newDocument);
752         return modelAndView;
753     }
754 
755     @RequestMapping(params = "methodToCall=linkPO")
756     public ModelAndView linkPO(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
757                                HttpServletRequest request, HttpServletResponse response) {
758         OLESerialReceivingForm oleSerialReceivingForm = (OLESerialReceivingForm) form;
759         OLESerialReceivingDocument oleSerialReceivingDocument = (OLESerialReceivingDocument) oleSerialReceivingForm.getDocument();
760         List<OLESerialRelatedPODocument> oleSerialRelatedPODocuments = oleSerialReceivingDocument.getOleSerialRelatedPODocuments();
761         for (OLESerialRelatedPODocument oleSerialRelatedPODocument : oleSerialRelatedPODocuments) {
762             if (oleSerialRelatedPODocument.isSelectPO()) {
763                 oleSerialReceivingDocument.setPoId(oleSerialRelatedPODocument.getPoId());
764                 oleSerialReceivingDocument.setPoIdLink(oleSerialRelatedPODocument.getPoIdLink());
765                 oleSerialReceivingDocument.setVendorId(oleSerialRelatedPODocument.getVendorId());
766                 oleSerialReceivingDocument.setVendorAliasName(oleSerialRelatedPODocument.getVendorAliasName());
767                 oleSerialReceivingDocument.setVendorName(oleSerialRelatedPODocument.getVendorName());
768                 oleSerialReceivingDocument.setActionInterval(oleSerialRelatedPODocument.getActionInterval());
769                 break;
770             }
771         }
772         return getUIFModelAndView(oleSerialReceivingForm);
773     }
774 
775     @RequestMapping(params = "methodToCall=noLinkPO")
776     public ModelAndView noLinkPO(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
777                                  HttpServletRequest request, HttpServletResponse response) {
778         OLESerialReceivingForm oleSerialReceivingForm = (OLESerialReceivingForm) form;
779         OLESerialReceivingDocument oleSerialReceivingDocument = (OLESerialReceivingDocument) oleSerialReceivingForm.getDocument();
780         return getUIFModelAndView(oleSerialReceivingForm);
781     }
782 
783     @RequestMapping(params = "methodToCall=linkPOErrMsg")
784     public ModelAndView linkPOErrMsg(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
785                                      HttpServletRequest request, HttpServletResponse response) {
786         OLESerialReceivingForm oleSerialReceivingForm = (OLESerialReceivingForm) form;
787         OLESerialReceivingDocument oleSerialReceivingDocument = (OLESerialReceivingDocument) oleSerialReceivingForm.getDocument();
788         oleSerialReceivingDocument.setSerialPOErrMsg("Select At least One PO");
789         return getUIFModelAndView(oleSerialReceivingForm);
790     }
791 
792     @RequestMapping(params = "methodToCall=refreshReceivingRecordType")
793     public ModelAndView refreshReceivingRecordType(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
794                                                    HttpServletRequest request, HttpServletResponse response) {
795         OLESerialReceivingForm oleSerialReceivingForm = (OLESerialReceivingForm) form;
796         OLESerialReceivingDocument oleSerialReceivingDocument = (OLESerialReceivingDocument) oleSerialReceivingForm.getDocument();
797         OLESerialReceivingService oleSerialReceivingService = new OLESerialReceivingServiceImpl();
798         oleSerialReceivingService.readReceivingRecordType(oleSerialReceivingDocument);
799         oleSerialReceivingService.updateEnumCaptionValues(oleSerialReceivingDocument, null);
800         return getUIFModelAndView(oleSerialReceivingForm);
801     }
802 
803 
804     /**
805      * This method assigns specified document to the selector.
806      */
807     private void assignActionRequests(String routeHeaderId) {
808         LOG.debug("Inside assignActionRequests");
809         Timestamp currentTime = SpringContext.getBean(DateTimeService.class).getCurrentTimestamp();
810         OLESerialReceivingService oleSerialReceivingService = new OLESerialReceivingServiceImpl();
811         String principalId = oleSerialReceivingService.getParameter("SAVE_ACTION_USR");
812         // TODO Need to check principalId from DB.
813         if (principalId == null || principalId.isEmpty()) {
814             principalId = ConfigContext.getCurrentContextConfig().getProperty("save.action.usr");
815         }
816         ActionListService actionListSrv = KEWServiceLocator.getActionListService();
817         ActionRequestService actionReqSrv = KEWServiceLocator.getActionRequestService();
818         List<ActionRequestValue> actionReqValues = actionReqSrv.findAllPendingRequests(routeHeaderId);
819         for (ActionRequestValue actionRequest : actionReqValues) {
820             List<ActionItem> actionItems = actionRequest.getActionItems();
821             for (ActionItem actionItem : actionItems) {
822                 actionItem.setPrincipalId(principalId);
823                 actionItem.setDateAssigned(currentTime);
824                 actionListSrv.saveActionItem(actionItem);
825             }
826             actionRequest.setPrincipalId(principalId);
827             actionRequest.setCreateDate(currentTime);
828             actionReqSrv.saveActionRequest(actionRequest);
829         }
830         LOG.debug("Leaving assignActionRequests");
831     }
832 
833     @RequestMapping(params = "methodToCall=saveEnumerationChronology")
834     public ModelAndView saveEnumerationChronology(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
835                                                       HttpServletRequest request, HttpServletResponse response) {
836         OLESerialReceivingForm oleSerialReceivingForm = (OLESerialReceivingForm) form;
837         OLESerialReceivingService oleSerialReceivingService = new OLESerialReceivingServiceImpl();
838         OLESerialReceivingDocument oleSerialReceivingDocument = (OLESerialReceivingDocument) oleSerialReceivingForm.getDocument();
839         for (OLESerialReceivingHistory oleSerialReceivingHistory : oleSerialReceivingDocument.getOleSerialReceivingHistoryList()) {
840             if (StringUtils.isNotBlank(oleSerialReceivingHistory.getSerialReceivingRecordHistoryId())
841                     && StringUtils.isNotBlank(oleSerialReceivingDocument.getSerialReceiptHistoryId()) ) {
842                 if (oleSerialReceivingHistory.getSerialReceivingRecordHistoryId().equalsIgnoreCase(oleSerialReceivingDocument.getSerialReceiptHistoryId())) {
843                     oleSerialReceivingService.updateEnumerationAndChronologyValues(oleSerialReceivingDocument,oleSerialReceivingHistory);
844                     oleSerialReceivingService.setEnumerationAndChronologyValues(oleSerialReceivingHistory);
845                 }
846             }
847         }
848         return getUIFModelAndView(oleSerialReceivingForm);
849     }
850 
851     @RequestMapping(params = "methodToCall=resetEnumerationAndChronology")
852     public ModelAndView resetEnumerationAndChronology(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
853                                         HttpServletRequest request, HttpServletResponse response) {
854         return getUIFModelAndView(form);
855     }
856 
857     @RequestMapping(params = "methodToCall=setEnumerationChronology")
858     public ModelAndView setEnumerationChronology(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
859                                                   HttpServletRequest request, HttpServletResponse response) {
860         OLESerialReceivingForm oleSerialReceivingForm = (OLESerialReceivingForm) form;
861         OLESerialReceivingService oleSerialReceivingService = new OLESerialReceivingServiceImpl();
862         OLESerialReceivingDocument oleSerialReceivingDocument = (OLESerialReceivingDocument) oleSerialReceivingForm.getDocument();
863         for (OLESerialReceivingHistory oleSerialReceivingHistory : oleSerialReceivingDocument.getOleSerialReceivingHistoryList()) {
864             if (StringUtils.isNotBlank(oleSerialReceivingHistory.getSerialReceivingRecordHistoryId())
865                     && StringUtils.isNotBlank(oleSerialReceivingDocument.getSerialReceiptHistoryId()) ) {
866                 if (oleSerialReceivingHistory.getSerialReceivingRecordHistoryId().equalsIgnoreCase(oleSerialReceivingDocument.getSerialReceiptHistoryId())) {
867                     oleSerialReceivingService.setEnumerationAndChronologyValues(oleSerialReceivingDocument,oleSerialReceivingHistory);
868                 }
869             }
870         }
871         return getUIFModelAndView(oleSerialReceivingForm);
872     }
873     private boolean isValidLocation(String location) {
874         List<String> locationList = LocationValuesBuilder.retrieveLocationDetailsForSuggest(location);
875         if (locationList != null && locationList.size() > 0) {
876             for (String locationValue : locationList) {
877                 if (locationValue.equalsIgnoreCase(location)) {
878                     return true;
879                 }
880             }
881         }
882         return false;
883     }
884 
885     @RequestMapping(params = "methodToCall=loadHistoryRecords")
886     public ModelAndView loadHistoryRecords(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
887                                                 HttpServletRequest request, HttpServletResponse response) {
888         OLESerialReceivingForm oleSerialReceivingForm = (OLESerialReceivingForm) form;
889         return getUIFModelAndView(oleSerialReceivingForm);
890     }
891 
892 }