1 package org.kuali.ole.describe.controller;
2
3 import org.kuali.ole.OLEConstants;
4 import org.kuali.ole.describe.bo.OleAccessMethod;
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 = "/accessMethodMaintenance")
35 public class OleAccessMethodController 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
40 MaintenanceDocumentForm maintenanceForm = (MaintenanceDocumentForm) form;
41 MaintenanceDocument maintenanceDocument = (MaintenanceDocument) form.getDocument();
42 OleAccessMethod oleAccessMethod = (OleAccessMethod) maintenanceDocument.getDocumentDataObject();
43 String accessMethodName = oleAccessMethod.getAccessMethodName();
44 OleAccessMethod oleAccessMethodOld = (OleAccessMethod) maintenanceDocument.getOldMaintainableObject().getDataObject();
45 String newAccessMethodCode = oleAccessMethodOld.getAccessMethodCode();
46 Map<String, String> accessMethodMap = new HashMap<String, String>();
47 accessMethodMap.put(OLEConstants.OleAccessMethod.ACCESS_METHOD_CD, oleAccessMethod.getAccessMethodCode());
48 List<OleAccessMethod> accessMethodInDatabase = (List<OleAccessMethod>) KRADServiceLocator.getBusinessObjectService().findMatching(OleAccessMethod.class, accessMethodMap);
49 if ("Edit".equals(maintenanceDocument.getNewMaintainableObject().getMaintenanceAction())) {
50 Document document = form.getDocument();
51 String successMessageKey = null;
52 if (oleAccessMethod.getAccessMethodCode().equals(newAccessMethodCode) || accessMethodInDatabase.size() == 0) {
53 getDocumentService().blanketApproveDocument(document, form.getAnnotation(), combineAdHocRecipients(
54 form));
55 successMessageKey = RiceKeyConstants.MESSAGE_ROUTE_APPROVED;
56 GlobalVariables.getMessageMap().putInfo(OLEConstants.OleAccessMethod.ACCESS_METHOD_CODE, "message.route.approved");
57 return getUIFModelAndView(form);
58
59 } else {
60 if (accessMethodInDatabase.size() > 0) {
61 for (OleAccessMethod accessMehtodObj : accessMethodInDatabase) {
62 String accessMethodId = accessMehtodObj.getAccessMethodId().toString();
63
64 if (null == oleAccessMethod.getAccessMethodId() ||
65 !(oleAccessMethod.getAccessMethodId().equals(accessMethodId))) {
66 GlobalVariables.getMessageMap().putError(OLEConstants.OleAccessMethod.ACCESS_METHOD_CODE, "error.duplicate.code.access");
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.OleAccessMethod.ACCESS_METHOD_CODE, "message.route.approved");
73 return getUIFModelAndView(form);
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 (accessMethodInDatabase.size() == 0) {
84 getDocumentService().blanketApproveDocument(document, form.getAnnotation(), combineAdHocRecipients(
85 form));
86 successMessageKey = RiceKeyConstants.MESSAGE_ROUTE_APPROVED;
87 GlobalVariables.getMessageMap().putInfo(OLEConstants.OleAccessMethod.ACCESS_METHOD_CODE, "message.route.approved");
88 return getUIFModelAndView(form);
89 } else if ((accessMethodInDatabase.size() > 0)) {
90
91 for (OleAccessMethod accessMehtodObj : accessMethodInDatabase) {
92 String accessMethodId = accessMehtodObj.getAccessMethodId().toString();
93 if (null == oleAccessMethod.getAccessMethodId() ||
94 !(oleAccessMethod.getAccessMethodId().equals(accessMethodId))) {
95 GlobalVariables.getMessageMap().putError(OLEConstants.OleAccessMethod.ACCESS_METHOD_CODE, "error.duplicate.code.access");
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 (accessMethodInDatabase.size() == 0) {
105 getDocumentService().blanketApproveDocument(document, form.getAnnotation(), combineAdHocRecipients(
106 form));
107 successMessageKey = RiceKeyConstants.MESSAGE_ROUTE_APPROVED;
108 GlobalVariables.getMessageMap().putInfo(OLEConstants.OleAccessMethod.ACCESS_METHOD_CODE, "message.route.approved");
109 return getUIFModelAndView(form);
110 } else if ((accessMethodInDatabase.size() > 0)) {
111
112 for (OleAccessMethod accessMehtodObj : accessMethodInDatabase) {
113 String accessMethodId = accessMehtodObj.getAccessMethodId().toString();
114 if (null == oleAccessMethod.getAccessMethodId() ||
115 !(oleAccessMethod.getAccessMethodId().equals(accessMethodId))) {
116 GlobalVariables.getMessageMap().putError(OLEConstants.OleAccessMethod.ACCESS_METHOD_CODE, "error.duplicate.code.access");
117 return getUIFModelAndView(form);
118 }
119 }
120
121 }
122 }
123
124
125
126
127
128
129
130
131
132
133
134
135
136 performWorkflowAction(form, UifConstants.WorkflowAction.BLANKETAPPROVE, true);
137 return returnToPrevious(form);
138 }
139 }