View Javadoc
1   package org.kuali.ole.describe.controller;
2   
3   import org.kuali.ole.OLEConstants;
4   import org.kuali.ole.describe.bo.OleCountryCodes;
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: 5:40 PM
31   * To change this template use File | Settings | File Templates.
32   */
33  @Controller
34  @RequestMapping(value = "/countryCodesMaintenance")
35  public class OleCountryCodesController 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          OleCountryCodes oleCountryCodes = (OleCountryCodes) maintenanceDocument.getDocumentDataObject();
42          OleCountryCodes oleCountryCodesOld = (OleCountryCodes) maintenanceDocument.getOldMaintainableObject().getDataObject();
43          String oleCountryCodeOldCode = oleCountryCodesOld.getCountryCode();
44          Map<String, String> countryCodesMap = new HashMap<String, String>();
45          countryCodesMap.put(OLEConstants.OleCountryCodes.COUNTRY_CD, oleCountryCodes.getCountryCode());
46          List<OleCountryCodes> countryCodesInDatabase = (List<OleCountryCodes>) KRADServiceLocator.getBusinessObjectService().findMatching(OleCountryCodes.class, countryCodesMap);
47          if ("Edit".equals(maintenanceDocument.getNewMaintainableObject().getMaintenanceAction())) {
48              Document document = form.getDocument();
49              String successMessageKey = null;
50              if (oleCountryCodes.getCountryCode().equals(oleCountryCodeOldCode) || countryCodesInDatabase.size() == 0) {
51                  getDocumentService().blanketApproveDocument(document, form.getAnnotation(), combineAdHocRecipients(
52                          form));
53                  successMessageKey = RiceKeyConstants.MESSAGE_ROUTE_APPROVED;
54                  GlobalVariables.getMessageMap().putInfo(OLEConstants.OleCountryCodes.COUNTRY_CODE, "message.route.approved");
55                  return getUIFModelAndView(form);
56              } else {
57                  if (countryCodesInDatabase.size() > 0) {
58                      for (OleCountryCodes countryCodesObj : countryCodesInDatabase) {
59                          String countryCodeTypeId = countryCodesObj.getCountryCodeId().toString();
60                          String countryCodeCode = countryCodesObj.getCountryCode();
61                          if (null == oleCountryCodes.getCountryCodeId() ||
62                                  !(oleCountryCodes.getCountryCodeId().equals(countryCodeTypeId))) {
63                              GlobalVariables.getMessageMap().putError(OLEConstants.OleCountryCodes.COUNTRY_CODE, "error.duplicate.code.country");
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.OleCountryCodes.COUNTRY_CODE, "message.route.approved");
70                          return getUIFModelAndView(form);
71  
72  
73                      }
74                  }
75              }
76          } else if ("Copy".equals(maintenanceDocument.getNewMaintainableObject().getMaintenanceAction())) {
77              String successMessageKey = null;
78              Document document = form.getDocument();
79              if (countryCodesInDatabase.size() == 0) {
80                  getDocumentService().blanketApproveDocument(document, form.getAnnotation(), combineAdHocRecipients(
81                          form));
82                  successMessageKey = RiceKeyConstants.MESSAGE_ROUTE_APPROVED;
83                  GlobalVariables.getMessageMap().putInfo(OLEConstants.OleCountryCodes.COUNTRY_CODE, "message.route.approved");
84                  return getUIFModelAndView(form);
85              } else if ((countryCodesInDatabase.size() > 0)) {
86                  for (OleCountryCodes countryCodesObj : countryCodesInDatabase) {
87                      String instanceItemTypeId = countryCodesObj.getCountryCodeId().toString();
88                      if (null == oleCountryCodes.getCountryCodeId() ||
89                              !(oleCountryCodes.getCountryCodeId().equals(instanceItemTypeId))) {
90                          GlobalVariables.getMessageMap().putError(OLEConstants.OleCountryCodes.COUNTRY_CODE, "error.duplicate.code.country");
91                          return getUIFModelAndView(form);
92                      }
93                  }
94              }
95  
96          } else if ("New".equals(maintenanceDocument.getNewMaintainableObject().getMaintenanceAction())) {
97              String successMessageKey = null;
98              Document document = form.getDocument();
99              if ((countryCodesInDatabase.size() == 0)) {
100                 getDocumentService().blanketApproveDocument(document, form.getAnnotation(), combineAdHocRecipients(
101                         form));
102                 successMessageKey = RiceKeyConstants.MESSAGE_ROUTE_APPROVED;
103                 GlobalVariables.getMessageMap().putInfo(OLEConstants.OleCountryCodes.COUNTRY_CODE, "message.route.approved");
104                 return getUIFModelAndView(form);
105             } else if ((countryCodesInDatabase.size() > 0)) {
106                 for (OleCountryCodes countryCodesObj : countryCodesInDatabase) {
107                     String instanceItemTypeId = countryCodesObj.getCountryCodeId().toString();
108                     if (null == oleCountryCodes.getCountryCodeId() ||
109                             !(oleCountryCodes.getCountryCodeId().equals(instanceItemTypeId))) {
110                         GlobalVariables.getMessageMap().putError(OLEConstants.OleCountryCodes.COUNTRY_CODE, "error.duplicate.code.country");
111                         return getUIFModelAndView(form);
112                     }
113                 }
114             }
115         }
116 
117         /*else if((countryCodesInDatabase.size() > 0)) {
118 
119             for(OleCountryCodes countryCodesObj : countryCodesInDatabase){
120                 String instanceItemTypeId =  countryCodesObj.getCountryCodeId().toString();
121                 if (null == oleCountryCodes.getCountryCodeId()  ||
122                         !(oleCountryCodes.getCountryCodeId().equals(instanceItemTypeId))) {
123                     GlobalVariables.getMessageMap().putError(OLEConstants.OleCountryCodes.COUNTRY_CODE, "error.duplicate.code");
124                     return getUIFModelAndView(form);
125                 }
126             }
127 
128         }*/
129         performWorkflowAction(form, UifConstants.WorkflowAction.BLANKETAPPROVE, true);
130         return returnToPrevious(form);
131     }
132 }
133