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