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