1 package org.kuali.ole.select.controller;
2
3 import org.apache.commons.lang3.StringUtils;
4 import org.kuali.ole.OLEConstants;
5
6 import org.kuali.ole.select.bo.OLEAccessActivationConfiguration;
7 import org.kuali.ole.select.bo.OLEAccessActivationWorkFlow;
8 import org.kuali.ole.select.service.OLEAccessActivationService;
9 import org.kuali.ole.select.service.impl.OLEAccessActivationServiceImpl;
10 import org.kuali.rice.krad.maintenance.MaintenanceDocument;
11 import org.kuali.rice.krad.uif.UifParameters;
12 import org.kuali.rice.krad.uif.container.CollectionGroup;
13 import org.kuali.rice.krad.uif.util.ObjectPropertyUtils;
14 import org.kuali.rice.krad.uif.view.View;
15 import org.kuali.rice.krad.util.GlobalVariables;
16 import org.kuali.rice.krad.util.KRADConstants;
17 import org.kuali.rice.krad.web.controller.MaintenanceDocumentController;
18 import org.kuali.rice.krad.web.form.MaintenanceDocumentForm;
19 import org.kuali.rice.krad.web.form.UifFormBase;
20 import org.springframework.stereotype.Controller;
21 import org.springframework.validation.BindingResult;
22 import org.springframework.web.bind.annotation.ModelAttribute;
23 import org.springframework.web.bind.annotation.RequestMapping;
24 import org.springframework.web.bind.annotation.RequestMethod;
25 import org.springframework.web.servlet.ModelAndView;
26
27 import javax.servlet.http.HttpServletRequest;
28 import javax.servlet.http.HttpServletResponse;
29
30
31
32
33 @Controller
34 @RequestMapping(value = "/oleAccessActivationConfiguration")
35 public class OLEAccessActivationConfigurationController extends MaintenanceDocumentController {
36
37
38 private OLEAccessActivationService oleAccessActivationService;
39
40 public OLEAccessActivationService getOleAccessActivationService() {
41 if(oleAccessActivationService == null){
42 oleAccessActivationService = new OLEAccessActivationServiceImpl();
43 }
44 return oleAccessActivationService;
45 }
46
47 public void setOleAccessActivationService(OLEAccessActivationService oleAccessActivationService) {
48 this.oleAccessActivationService = oleAccessActivationService;
49 }
50
51 @Override
52 public ModelAndView maintenanceEdit(@ModelAttribute("KualiForm") MaintenanceDocumentForm form, BindingResult result, HttpServletRequest request, HttpServletResponse response) throws Exception {
53 setupMaintenance(form, request, KRADConstants.MAINTENANCE_EDIT_ACTION);
54 OLEAccessActivationConfiguration oleAccessActivationConfiguration = (OLEAccessActivationConfiguration) form.getDocument().getNewMaintainableObject().getDataObject();
55 oleAccessActivationConfiguration = getOleAccessActivationService().setRoleAndPersonName(oleAccessActivationConfiguration);
56 return getUIFModelAndView(form);
57 }
58
59 @Override
60 public ModelAndView maintenanceCopy(@ModelAttribute("KualiForm") MaintenanceDocumentForm form, BindingResult result, HttpServletRequest request, HttpServletResponse response) throws Exception {
61 setupMaintenance(form, request, KRADConstants.MAINTENANCE_COPY_ACTION);
62 OLEAccessActivationConfiguration oleAccessActivationConfiguration = (OLEAccessActivationConfiguration) form.getDocument().getNewMaintainableObject().getDataObject();
63 oleAccessActivationConfiguration = getOleAccessActivationService().setRoleAndPersonName(oleAccessActivationConfiguration);
64 return getUIFModelAndView(form);
65 }
66
67 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addWorkflow")
68 public ModelAndView addWorkflow(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
69 HttpServletRequest request, HttpServletResponse response) {
70 LOG.debug("Initialized addLine method");
71 MaintenanceDocumentForm form = (MaintenanceDocumentForm) uifForm;
72 MaintenanceDocument document = (MaintenanceDocument) form.getDocument();
73 OLEAccessActivationConfiguration accessActivation = (OLEAccessActivationConfiguration) document.getNewMaintainableObject().getDataObject();
74 String selectedCollectionPath = form.getActionParamaterValue(UifParameters.SELLECTED_COLLECTION_PATH);
75 CollectionGroup collectionGroup = form.getPostedView().getViewIndex().getCollectionGroupByPath(selectedCollectionPath);
76 String addLinePath = collectionGroup.getAddLineBindingInfo().getBindingPath();
77 Object eventObject = ObjectPropertyUtils.getPropertyValue(form, addLinePath);
78 OLEAccessActivationWorkFlow accessWorkflow = (OLEAccessActivationWorkFlow) eventObject;
79 if(StringUtils.isNotBlank(accessActivation.getSelector()) && accessActivation.getSelector().equals(OLEConstants.SELECTOR_ROLE)) {
80 accessWorkflow.setPersonName(null);
81 accessWorkflow.setPersonId(null);
82 } else if(StringUtils.isNotBlank(accessActivation.getSelector()) && accessActivation.getSelector().equals(OLEConstants.SELECTOR_PERSON)) {
83 accessWorkflow.setRoleName(null);
84 accessWorkflow.setRoleId(null);
85 }
86 if (!validateEmptyFieldActivationWorkFlow(accessWorkflow, accessActivation.getSelector())) {
87 return getUIFModelAndView(form);
88 }
89 if (!getOleAccessActivationService().validateAccessActivationWorkFlow(accessActivation.getAccessActivationWorkflowList(), accessWorkflow, accessActivation.getSelector())) {
90 return getUIFModelAndView(form);
91 }
92 View view = form.getPostedView();
93 view.getViewHelperService().processCollectionAddLine(view, form, selectedCollectionPath);
94
95 return getUIFModelAndView(form);
96 }
97
98
99
100 private boolean validateEmptyFieldActivationWorkFlow(OLEAccessActivationWorkFlow accessActivationWorkFlow, String selector) {
101 boolean emptyOrderNumber = false;
102 boolean emptyStatus = false;
103 boolean emptyRoleOrPerson = false;
104 if (accessActivationWorkFlow.getOrderNo() == null) {
105 GlobalVariables.getMessageMap().putErrorForSectionId(OLEConstants.OLE_ACCESS_ACTIVATION, OLEConstants.ERROR_EMPTY_ORDER_NO);
106 emptyOrderNumber = true;
107 }
108 if (StringUtils.isBlank(accessActivationWorkFlow.getStatus())) {
109 GlobalVariables.getMessageMap().putErrorForSectionId(OLEConstants.OLE_ACCESS_ACTIVATION, OLEConstants.ERROR_EMPTY_STATUS);
110 emptyStatus = true;
111 }
112 if (StringUtils.isNotBlank(selector) && selector.equals(OLEConstants.SELECTOR_ROLE) && StringUtils.isBlank(accessActivationWorkFlow.getRoleName())) {
113 GlobalVariables.getMessageMap().putErrorForSectionId(OLEConstants.OLE_ACCESS_ACTIVATION, OLEConstants.ERROR_EMPTY_ROLE_NAME);
114 emptyRoleOrPerson = true;
115 }
116 if(StringUtils.isNotBlank(selector) && selector.equals(OLEConstants.SELECTOR_PERSON) && StringUtils.isBlank(accessActivationWorkFlow.getPersonName())) {
117 GlobalVariables.getMessageMap().putErrorForSectionId(OLEConstants.OLE_ACCESS_ACTIVATION, OLEConstants.ERROR_EMPTY_PERSON_NAME);
118 emptyRoleOrPerson = true;
119 }
120 if ((emptyOrderNumber || emptyStatus) || emptyRoleOrPerson) {
121 return false;
122 }
123 return true;
124 }
125
126 }