001package org.kuali.ole.select.controller; 002 003import org.apache.commons.lang3.StringUtils; 004import org.kuali.ole.OLEConstants; 005 006import org.kuali.ole.select.bo.OLEAccessActivationConfiguration; 007import org.kuali.ole.select.bo.OLEAccessActivationWorkFlow; 008import org.kuali.ole.select.service.OLEAccessActivationService; 009import org.kuali.ole.select.service.impl.OLEAccessActivationServiceImpl; 010import org.kuali.rice.krad.maintenance.MaintenanceDocument; 011import org.kuali.rice.krad.uif.UifParameters; 012import org.kuali.rice.krad.uif.container.CollectionGroup; 013import org.kuali.rice.krad.uif.util.ObjectPropertyUtils; 014import org.kuali.rice.krad.uif.view.View; 015import org.kuali.rice.krad.util.GlobalVariables; 016import org.kuali.rice.krad.util.KRADConstants; 017import org.kuali.rice.krad.web.controller.MaintenanceDocumentController; 018import org.kuali.rice.krad.web.form.MaintenanceDocumentForm; 019import org.kuali.rice.krad.web.form.UifFormBase; 020import org.springframework.stereotype.Controller; 021import org.springframework.validation.BindingResult; 022import org.springframework.web.bind.annotation.ModelAttribute; 023import org.springframework.web.bind.annotation.RequestMapping; 024import org.springframework.web.bind.annotation.RequestMethod; 025import org.springframework.web.servlet.ModelAndView; 026 027import javax.servlet.http.HttpServletRequest; 028import javax.servlet.http.HttpServletResponse; 029 030/** 031 * Created by hemalathas on 12/22/14. 032 */ 033@Controller 034@RequestMapping(value = "/oleAccessActivationConfiguration") 035public class OLEAccessActivationConfigurationController extends MaintenanceDocumentController { 036 037 038 private OLEAccessActivationService oleAccessActivationService; 039 040 public OLEAccessActivationService getOleAccessActivationService() { 041 if(oleAccessActivationService == null){ 042 oleAccessActivationService = new OLEAccessActivationServiceImpl(); 043 } 044 return oleAccessActivationService; 045 } 046 047 public void setOleAccessActivationService(OLEAccessActivationService oleAccessActivationService) { 048 this.oleAccessActivationService = oleAccessActivationService; 049 } 050 051 @Override 052 public ModelAndView maintenanceEdit(@ModelAttribute("KualiForm") MaintenanceDocumentForm form, BindingResult result, HttpServletRequest request, HttpServletResponse response) throws Exception { 053 setupMaintenance(form, request, KRADConstants.MAINTENANCE_EDIT_ACTION); 054 OLEAccessActivationConfiguration oleAccessActivationConfiguration = (OLEAccessActivationConfiguration) form.getDocument().getNewMaintainableObject().getDataObject(); 055 oleAccessActivationConfiguration = getOleAccessActivationService().setRoleAndPersonName(oleAccessActivationConfiguration); 056 return getUIFModelAndView(form); 057 } 058 059 @Override 060 public ModelAndView maintenanceCopy(@ModelAttribute("KualiForm") MaintenanceDocumentForm form, BindingResult result, HttpServletRequest request, HttpServletResponse response) throws Exception { 061 setupMaintenance(form, request, KRADConstants.MAINTENANCE_COPY_ACTION); 062 OLEAccessActivationConfiguration oleAccessActivationConfiguration = (OLEAccessActivationConfiguration) form.getDocument().getNewMaintainableObject().getDataObject(); 063 oleAccessActivationConfiguration = getOleAccessActivationService().setRoleAndPersonName(oleAccessActivationConfiguration); 064 return getUIFModelAndView(form); 065 } 066 067 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addWorkflow") 068 public ModelAndView addWorkflow(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result, 069 HttpServletRequest request, HttpServletResponse response) { 070 LOG.debug("Initialized addLine method"); 071 MaintenanceDocumentForm form = (MaintenanceDocumentForm) uifForm; 072 MaintenanceDocument document = (MaintenanceDocument) form.getDocument(); 073 OLEAccessActivationConfiguration accessActivation = (OLEAccessActivationConfiguration) document.getNewMaintainableObject().getDataObject(); 074 String selectedCollectionPath = form.getActionParamaterValue(UifParameters.SELLECTED_COLLECTION_PATH); 075 CollectionGroup collectionGroup = form.getPostedView().getViewIndex().getCollectionGroupByPath(selectedCollectionPath); 076 String addLinePath = collectionGroup.getAddLineBindingInfo().getBindingPath(); 077 Object eventObject = ObjectPropertyUtils.getPropertyValue(form, addLinePath); 078 OLEAccessActivationWorkFlow accessWorkflow = (OLEAccessActivationWorkFlow) eventObject; 079 if(StringUtils.isNotBlank(accessActivation.getSelector()) && accessActivation.getSelector().equals(OLEConstants.SELECTOR_ROLE)) { 080 accessWorkflow.setPersonName(null); 081 accessWorkflow.setPersonId(null); 082 } else if(StringUtils.isNotBlank(accessActivation.getSelector()) && accessActivation.getSelector().equals(OLEConstants.SELECTOR_PERSON)) { 083 accessWorkflow.setRoleName(null); 084 accessWorkflow.setRoleId(null); 085 } 086 if (!validateEmptyFieldActivationWorkFlow(accessWorkflow, accessActivation.getSelector())) { 087 return getUIFModelAndView(form); 088 } 089 if (!getOleAccessActivationService().validateAccessActivationWorkFlow(accessActivation.getAccessActivationWorkflowList(), accessWorkflow, accessActivation.getSelector())) { 090 return getUIFModelAndView(form); 091 } 092 View view = form.getPostedView(); 093 view.getViewHelperService().processCollectionAddLine(view, form, selectedCollectionPath); 094 // accessActivation.getAccessActivationWorkflowList().add(accessWorkflow); 095 return getUIFModelAndView(form); 096 } 097 098 099 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}