1 package org.kuali.ole.catalog.controller;
2
3 import org.kuali.ole.OLEConstants;
4
5 import org.kuali.ole.catalog.bo.OleItemAvailableStatus;
6 import org.kuali.rice.core.api.util.RiceKeyConstants;
7 import org.kuali.rice.krad.document.Document;
8 import org.kuali.rice.krad.maintenance.MaintenanceDocument;
9 import org.kuali.rice.krad.service.KRADServiceLocator;
10 import org.kuali.rice.krad.uif.UifConstants;
11 import org.kuali.rice.krad.util.GlobalVariables;
12 import org.kuali.rice.krad.web.controller.MaintenanceDocumentController;
13 import org.kuali.rice.krad.web.form.DocumentFormBase;
14 import org.kuali.rice.krad.web.form.MaintenanceDocumentForm;
15 import org.springframework.stereotype.Controller;
16 import org.springframework.validation.BindingResult;
17 import org.springframework.web.bind.annotation.ModelAttribute;
18 import org.springframework.web.bind.annotation.RequestMapping;
19 import org.springframework.web.servlet.ModelAndView;
20
21 import javax.servlet.http.HttpServletRequest;
22 import javax.servlet.http.HttpServletResponse;
23 import java.util.HashMap;
24 import java.util.List;
25 import java.util.Map;
26
27
28
29
30
31
32
33
34 @Controller
35 @RequestMapping(value = "/itemAvailableStatusMaintenance")
36 public class OleItemAvailableStatusController extends MaintenanceDocumentController {
37 @RequestMapping(params = "methodToCall=blanketApprove")
38 public ModelAndView blanketApprove(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result,
39 HttpServletRequest request, HttpServletResponse response) throws Exception {
40 MaintenanceDocumentForm maintenanceForm = (MaintenanceDocumentForm) form;
41 MaintenanceDocument maintenanceDocument = (MaintenanceDocument)form.getDocument();
42 OleItemAvailableStatus oleItemAvailableStatus = (OleItemAvailableStatus)maintenanceDocument.getDocumentDataObject();
43 OleItemAvailableStatus oleItemAvailableStatusOld=(OleItemAvailableStatus)maintenanceDocument.getOldMaintainableObject().getDataObject();
44 String oleItemAvailableStatusCode=oleItemAvailableStatusOld.getItemAvailableStatusCode();
45 Map<String,String> itemAvailableStatusMap = new HashMap<String,String>();
46 itemAvailableStatusMap.put(OLEConstants.OleItemAvailableStatus.ITEM_AVAILABLE_STATUS_CD, oleItemAvailableStatus.getItemAvailableStatusCode());
47 List<OleItemAvailableStatus> itemAvailableStatusInDatabase = (List<OleItemAvailableStatus>) KRADServiceLocator.getBusinessObjectService().findMatching(OleItemAvailableStatus.class, itemAvailableStatusMap);
48
49 if("Edit".equals(maintenanceDocument.getNewMaintainableObject().getMaintenanceAction())){
50 Document document = form.getDocument();
51 String successMessageKey = null;
52 if(oleItemAvailableStatus.getItemAvailableStatusCode().equals(oleItemAvailableStatusOld) || itemAvailableStatusInDatabase.size()==0) {
53 getDocumentService().blanketApproveDocument(document, form.getAnnotation(), combineAdHocRecipients(
54 form));
55 successMessageKey = RiceKeyConstants.MESSAGE_ROUTE_APPROVED;
56 GlobalVariables.getMessageMap().putInfo(OLEConstants.OleItemAvailableStatus.ITEM_AVAILABLE_STATUS_CODE,"message.route.approved");
57 return getUIFModelAndView(form);
58
59 } else {
60 if((itemAvailableStatusInDatabase.size() > 0)) {
61
62 for(OleItemAvailableStatus itemAvailableStatusObj : itemAvailableStatusInDatabase){
63 String instanceItemTypeId = itemAvailableStatusObj.getItemAvailableStatusId().toString();
64 if (null == oleItemAvailableStatus.getItemAvailableStatusId() ||
65 !(oleItemAvailableStatus.getItemAvailableStatusId().equals(instanceItemTypeId))) {
66 GlobalVariables.getMessageMap().putError(OLEConstants.OleItemAvailableStatus.ITEM_AVAILABLE_STATUS_CODE, "error.duplicate.code.itemavailable");
67 return getUIFModelAndView(form);
68 }
69 getDocumentService().blanketApproveDocument(document, form.getAnnotation(), combineAdHocRecipients(
70 form));
71 successMessageKey = RiceKeyConstants.MESSAGE_ROUTE_APPROVED;
72 GlobalVariables.getMessageMap().putInfo(OLEConstants.OleItemAvailableStatus.ITEM_AVAILABLE_STATUS_CODE,"message.route.approved");
73 return getUIFModelAndView(form);
74 }
75
76 }
77
78
79 }
80
81 } else if("Copy".equals(maintenanceDocument.getNewMaintainableObject().getMaintenanceAction())){
82 String successMessageKey = null;
83 Document document = form.getDocument();
84 if(itemAvailableStatusInDatabase.size()==0){
85 getDocumentService().blanketApproveDocument(document, form.getAnnotation(), combineAdHocRecipients(
86 form));
87 successMessageKey = RiceKeyConstants.MESSAGE_ROUTE_APPROVED;
88 GlobalVariables.getMessageMap().putInfo(OLEConstants.OleItemAvailableStatus.ITEM_AVAILABLE_STATUS_CODE,"message.route.approved");
89 return getUIFModelAndView(form);
90 } else if((itemAvailableStatusInDatabase.size() > 0)) {
91
92 for(OleItemAvailableStatus itemAvailableStatusObj : itemAvailableStatusInDatabase){
93 String instanceItemTypeId = itemAvailableStatusObj.getItemAvailableStatusId().toString();
94 if (null == oleItemAvailableStatus.getItemAvailableStatusId() ||
95 !(oleItemAvailableStatus.getItemAvailableStatusId().equals(instanceItemTypeId))) {
96 GlobalVariables.getMessageMap().putError(OLEConstants.OleItemAvailableStatus.ITEM_AVAILABLE_STATUS_CODE, "error.duplicate.code.itemavailable");
97 return getUIFModelAndView(form);
98 }
99 }
100
101 }
102 } else if("New".equals(maintenanceDocument.getNewMaintainableObject().getMaintenanceAction())){
103 String successMessageKey = null;
104 Document document = form.getDocument();
105 if(itemAvailableStatusInDatabase.size()==0){
106 getDocumentService().blanketApproveDocument(document, form.getAnnotation(), combineAdHocRecipients(
107 form));
108 successMessageKey = RiceKeyConstants.MESSAGE_ROUTE_APPROVED;
109 GlobalVariables.getMessageMap().putInfo(OLEConstants.OleItemAvailableStatus.ITEM_AVAILABLE_STATUS_CODE,"message.route.approved");
110 return getUIFModelAndView(form);
111 } else if((itemAvailableStatusInDatabase.size() > 0)) {
112
113 for(OleItemAvailableStatus itemAvailableStatusObj : itemAvailableStatusInDatabase){
114 String instanceItemTypeId = itemAvailableStatusObj.getItemAvailableStatusId().toString();
115 if (null == oleItemAvailableStatus.getItemAvailableStatusId() ||
116 !(oleItemAvailableStatus.getItemAvailableStatusId().equals(instanceItemTypeId))) {
117 GlobalVariables.getMessageMap().putError(OLEConstants.OleItemAvailableStatus.ITEM_AVAILABLE_STATUS_CODE, "error.duplicate.code.itemavailable");
118 return getUIFModelAndView(form);
119 }
120 }
121
122 }
123 }
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138 performWorkflowAction(form, UifConstants.WorkflowAction.BLANKETAPPROVE, true);
139 return returnToPrevious(form);
140 }
141 }
142