View Javadoc
1   package org.kuali.ole.describe.controller;
2   
3   import org.kuali.ole.OLEConstants;
4   import org.kuali.ole.describe.bo.OleStatisticalSearchingCodes;
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   * Created with IntelliJ IDEA.
28   * User: ?
29   * Date: 1/24/13
30   * Time: 2:47 PM
31   * To change this template use File | Settings | File Templates.
32   */
33  @Controller
34  @RequestMapping(value = "/statisticalSearchingCodesMaintenance")
35  public class OleStatisticalSearchingCodesController 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          MaintenanceDocumentForm maintenanceForm = (MaintenanceDocumentForm) form;
40          MaintenanceDocument maintenanceDocument = (MaintenanceDocument) form.getDocument();
41          OleStatisticalSearchingCodes oleStatisticalSearchingCodes = (OleStatisticalSearchingCodes) maintenanceDocument.getDocumentDataObject();
42          OleStatisticalSearchingCodes oleStatisticalSearchingOld = (OleStatisticalSearchingCodes) maintenanceDocument.getOldMaintainableObject().getDataObject();
43          String statisticalSearchingCodeOld = oleStatisticalSearchingOld.getStatisticalSearchingCode();
44          Map<String, String> statisticalSearchingCodesMap = new HashMap<String, String>();
45          statisticalSearchingCodesMap.put(OLEConstants.OleStatisticalSearchingCodes.STATISTICAL_SEARCHING_CD, oleStatisticalSearchingCodes.getStatisticalSearchingCode());
46          List<OleStatisticalSearchingCodes> statisticalSearchingCodesInDatabase = (List<OleStatisticalSearchingCodes>) KRADServiceLocator.getBusinessObjectService().findMatching(OleStatisticalSearchingCodes.class, statisticalSearchingCodesMap);
47          if ("Edit".equals(maintenanceDocument.getNewMaintainableObject().getMaintenanceAction())) {
48              Document document = form.getDocument();
49              String successMessageKey = null;
50              if (oleStatisticalSearchingCodes.getStatisticalSearchingCode().equals(statisticalSearchingCodeOld) || statisticalSearchingCodesInDatabase.size() == 0) {
51                  getDocumentService().blanketApproveDocument(document, form.getAnnotation(), combineAdHocRecipients(
52                          form));
53                  successMessageKey = RiceKeyConstants.MESSAGE_ROUTE_APPROVED;
54                  GlobalVariables.getMessageMap().putInfo(OLEConstants.OleStatisticalSearchingCodes.STATISTICAL_SEARCHING_CODE, "message.route.approved");
55                  return getUIFModelAndView(form);
56  
57              } else {
58                  if ((statisticalSearchingCodesInDatabase.size() > 0)) {
59                      for (OleStatisticalSearchingCodes statisticalSearchingCodesOjb : statisticalSearchingCodesInDatabase) {
60                          String statisticalSearchingCodesId = statisticalSearchingCodesOjb.getStatisticalSearchingCodeId().toString();
61                          if (null == oleStatisticalSearchingCodes.getStatisticalSearchingCodeId() ||
62                                  !(oleStatisticalSearchingCodes.getStatisticalSearchingCodeId().equals(statisticalSearchingCodesId))) {
63                              GlobalVariables.getMessageMap().putError(OLEConstants.OleStatisticalSearchingCodes.STATISTICAL_SEARCHING_CODE, "error.duplicate.code.statistical");
64                              return getUIFModelAndView(form);
65                          }
66                          getDocumentService().blanketApproveDocument(document, form.getAnnotation(), combineAdHocRecipients(
67                                  form));
68                          successMessageKey = RiceKeyConstants.MESSAGE_ROUTE_APPROVED;
69                          GlobalVariables.getMessageMap().putInfo(OLEConstants.OleStatisticalSearchingCodes.STATISTICAL_SEARCHING_CODE, "message.route.approved");
70                          return getUIFModelAndView(form);
71                      }
72                  }
73              }
74          } else if ("Copy".equals(maintenanceDocument.getNewMaintainableObject().getMaintenanceAction())) {
75              String successMessageKey = null;
76              Document document = form.getDocument();
77              if (statisticalSearchingCodesInDatabase.size() == 0) {
78                  getDocumentService().blanketApproveDocument(document, form.getAnnotation(), combineAdHocRecipients(
79                          form));
80                  successMessageKey = RiceKeyConstants.MESSAGE_ROUTE_APPROVED;
81                  GlobalVariables.getMessageMap().putInfo(OLEConstants.OleStatisticalSearchingCodes.STATISTICAL_SEARCHING_CODE, "message.route.approved");
82                  return getUIFModelAndView(form);
83              } else if ((statisticalSearchingCodesInDatabase.size() > 0)) {
84  
85                  for (OleStatisticalSearchingCodes statisticalSearchingCodesOjb : statisticalSearchingCodesInDatabase) {
86                      String statisticalSearchingCodesId = statisticalSearchingCodesOjb.getStatisticalSearchingCodeId().toString();
87                      if (null == oleStatisticalSearchingCodes.getStatisticalSearchingCodeId() ||
88                              !(oleStatisticalSearchingCodes.getStatisticalSearchingCodeId().equals(statisticalSearchingCodesId))) {
89                          GlobalVariables.getMessageMap().putError(OLEConstants.OleStatisticalSearchingCodes.STATISTICAL_SEARCHING_CODE, "error.duplicate.code.statistical");
90                          return getUIFModelAndView(form);
91                      }
92                  }
93  
94              }
95          } else if ("New".equals(maintenanceDocument.getNewMaintainableObject().getMaintenanceAction())) {
96              String successMessageKey = null;
97              Document document = form.getDocument();
98              if (statisticalSearchingCodesInDatabase.size() == 0) {
99                  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