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