001 package org.kuali.ole.catalog.controller; 002 003 import org.kuali.ole.OLEConstants; 004 import org.kuali.ole.catalog.bo.OleAccessMethod; 005 import org.kuali.rice.core.api.util.RiceKeyConstants; 006 import org.kuali.rice.krad.document.Document; 007 import org.kuali.rice.krad.maintenance.MaintenanceDocument; 008 import org.kuali.rice.krad.service.KRADServiceLocator; 009 import org.kuali.rice.krad.uif.UifConstants; 010 import org.kuali.rice.krad.util.GlobalVariables; 011 import org.kuali.rice.krad.util.KRADConstants; 012 import org.kuali.rice.krad.web.controller.MaintenanceDocumentController; 013 import org.kuali.rice.krad.web.form.DocumentFormBase; 014 import org.kuali.rice.krad.web.form.MaintenanceDocumentForm; 015 import org.springframework.stereotype.Controller; 016 import org.springframework.validation.BindingResult; 017 import org.springframework.web.bind.annotation.ModelAttribute; 018 import org.springframework.web.bind.annotation.RequestMapping; 019 import org.springframework.web.servlet.ModelAndView; 020 021 import javax.servlet.http.HttpServletRequest; 022 import javax.servlet.http.HttpServletResponse; 023 import java.util.HashMap; 024 import java.util.List; 025 import java.util.Map; 026 027 /** 028 * Created with IntelliJ IDEA. 029 * User: ? 030 * Date: 1/23/13 031 * Time: 12:36 PM 032 * To change this template use File | Settings | File Templates. 033 */ 034 @Controller 035 @RequestMapping(value = "/accessMethodMaintenance") 036 public class OleAccessMethodController extends MaintenanceDocumentController { 037 @RequestMapping(params = "methodToCall=blanketApprove") 038 public ModelAndView blanketApprove(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result, 039 HttpServletRequest request, HttpServletResponse response) throws Exception { 040 041 MaintenanceDocumentForm maintenanceForm = (MaintenanceDocumentForm) form; 042 MaintenanceDocument maintenanceDocument = (MaintenanceDocument)form.getDocument(); 043 OleAccessMethod oleAccessMethod = (OleAccessMethod)maintenanceDocument.getDocumentDataObject(); 044 String accessMethodName=oleAccessMethod.getAccessMethodName(); 045 OleAccessMethod oleAccessMethodOld=(OleAccessMethod)maintenanceDocument.getOldMaintainableObject().getDataObject(); 046 String newAccessMethodCode=oleAccessMethodOld.getAccessMethodCode(); 047 Map<String,String> accessMethodMap = new HashMap<String,String>(); 048 accessMethodMap.put(OLEConstants.OleAccessMethod.ACCESS_METHOD_CD, oleAccessMethod.getAccessMethodCode()); 049 List<OleAccessMethod> accessMethodInDatabase = (List<OleAccessMethod>) KRADServiceLocator.getBusinessObjectService().findMatching(OleAccessMethod.class, accessMethodMap); 050 if("Edit".equals(maintenanceDocument.getNewMaintainableObject().getMaintenanceAction())){ 051 Document document = form.getDocument(); 052 String successMessageKey = null; 053 if(oleAccessMethod.getAccessMethodCode().equals(newAccessMethodCode) || accessMethodInDatabase.size()==0) { 054 getDocumentService().blanketApproveDocument(document, form.getAnnotation(), combineAdHocRecipients( 055 form)); 056 successMessageKey = RiceKeyConstants.MESSAGE_ROUTE_APPROVED; 057 GlobalVariables.getMessageMap().putInfo(OLEConstants.OleAccessMethod.ACCESS_METHOD_CODE,"message.route.approved"); 058 return getUIFModelAndView(form); 059 060 } 061 else { 062 if(accessMethodInDatabase.size()>0){ 063 for(OleAccessMethod accessMehtodObj : accessMethodInDatabase){ 064 String accessMethodId = accessMehtodObj.getAccessMethodId().toString(); 065 //String accessMethodCode=accessMehtodObj.getAccessMethodCode(); 066 if (null == oleAccessMethod.getAccessMethodId() || 067 !(oleAccessMethod.getAccessMethodId().equals(accessMethodId))) { 068 GlobalVariables.getMessageMap().putError(OLEConstants.OleAccessMethod.ACCESS_METHOD_CODE, "error.duplicate.code.access"); 069 return getUIFModelAndView(form); 070 } 071 getDocumentService().blanketApproveDocument(document, form.getAnnotation(), combineAdHocRecipients( 072 form)); 073 successMessageKey = RiceKeyConstants.MESSAGE_ROUTE_APPROVED; 074 GlobalVariables.getMessageMap().putInfo(OLEConstants.OleAccessMethod.ACCESS_METHOD_CODE,"message.route.approved"); 075 return getUIFModelAndView(form); 076 077 } 078 } 079 080 } 081 082 } else if("Copy".equals(maintenanceDocument.getNewMaintainableObject().getMaintenanceAction())){ 083 String successMessageKey = null; 084 Document document = form.getDocument(); 085 if(accessMethodInDatabase.size()==0){ 086 getDocumentService().blanketApproveDocument(document, form.getAnnotation(), combineAdHocRecipients( 087 form)); 088 successMessageKey = RiceKeyConstants.MESSAGE_ROUTE_APPROVED; 089 GlobalVariables.getMessageMap().putInfo(OLEConstants.OleAccessMethod.ACCESS_METHOD_CODE,"message.route.approved"); 090 return getUIFModelAndView(form); 091 } else if((accessMethodInDatabase.size() > 0)) { 092 093 for(OleAccessMethod accessMehtodObj : accessMethodInDatabase){ 094 String accessMethodId = accessMehtodObj.getAccessMethodId().toString(); 095 if (null == oleAccessMethod.getAccessMethodId() || 096 !(oleAccessMethod.getAccessMethodId().equals(accessMethodId))) { 097 GlobalVariables.getMessageMap().putError(OLEConstants.OleAccessMethod.ACCESS_METHOD_CODE, "error.duplicate.code.access"); 098 return getUIFModelAndView(form); 099 } 100 } 101 102 } 103 } else if("New".equals(maintenanceDocument.getNewMaintainableObject().getMaintenanceAction())){ 104 String successMessageKey = null; 105 Document document = form.getDocument(); 106 if(accessMethodInDatabase.size()==0){ 107 getDocumentService().blanketApproveDocument(document, form.getAnnotation(), combineAdHocRecipients( 108 form)); 109 successMessageKey = RiceKeyConstants.MESSAGE_ROUTE_APPROVED; 110 GlobalVariables.getMessageMap().putInfo(OLEConstants.OleAccessMethod.ACCESS_METHOD_CODE,"message.route.approved"); 111 return getUIFModelAndView(form); 112 } else if((accessMethodInDatabase.size() > 0)) { 113 114 for(OleAccessMethod accessMehtodObj : accessMethodInDatabase){ 115 String accessMethodId = accessMehtodObj.getAccessMethodId().toString(); 116 if (null == oleAccessMethod.getAccessMethodId() || 117 !(oleAccessMethod.getAccessMethodId().equals(accessMethodId))) { 118 GlobalVariables.getMessageMap().putError(OLEConstants.OleAccessMethod.ACCESS_METHOD_CODE, "error.duplicate.code.access"); 119 return getUIFModelAndView(form); 120 } 121 } 122 123 } 124 } 125 126 /*else if((accessMethodInDatabase.size() > 0)) { 127 128 for(OleAccessMethod accessMehtodObj : accessMethodInDatabase){ 129 String accessMethodId = accessMehtodObj.getAccessMethodId().toString(); 130 if (null == oleAccessMethod.getAccessMethodId() || 131 !(oleAccessMethod.getAccessMethodId().equals(accessMethodId))) { 132 GlobalVariables.getMessageMap().putError(OLEConstants.OleAccessMethod.ACCESS_METHOD_CODE, "error.duplicate.code"); 133 return getUIFModelAndView(form); 134 } 135 } 136 137 }*/ 138 performWorkflowAction(form, UifConstants.WorkflowAction.BLANKETAPPROVE, true); 139 return returnToPrevious(form); 140 } 141 }