View Javadoc
1   package org.kuali.ole.describe.controller;
2   
3   import org.kuali.ole.OLEConstants;
4   import org.kuali.ole.describe.bo.OleShelvingScheme;
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: 6:00 PM
31   * To change this template use File | Settings | File Templates.
32   */
33  @Controller
34  @RequestMapping(value = "/shelvingSchemeMaintenance")
35  public class OleShelvingSchemeController 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          OleShelvingScheme oleShelvingScheme = (OleShelvingScheme) maintenanceDocument.getDocumentDataObject();
42          OleShelvingScheme oleShelvingSchemeOld = (OleShelvingScheme) maintenanceDocument.getOldMaintainableObject().getDataObject();
43          String shelvingSchemeCodeOld = oleShelvingSchemeOld.getShelvingSchemeCode();
44          Map<String, String> shelvingSchemeMap = new HashMap<String, String>();
45          shelvingSchemeMap.put(OLEConstants.OleShelvingScheme.SHELVING_SCHEME_CD, oleShelvingScheme.getShelvingSchemeCode());
46          List<OleShelvingScheme> shelvingSchemeInDatabase = (List<OleShelvingScheme>) KRADServiceLocator.getBusinessObjectService().findMatching(OleShelvingScheme.class, shelvingSchemeMap);
47  
48          if ("Edit".equals(maintenanceDocument.getNewMaintainableObject().getMaintenanceAction())) {
49              Document document = form.getDocument();
50              String successMessageKey = null;
51              if (oleShelvingScheme.getShelvingSchemeCode().equals(shelvingSchemeCodeOld) || shelvingSchemeInDatabase.size() == 0) {
52                  getDocumentService().blanketApproveDocument(document, form.getAnnotation(), combineAdHocRecipients(
53                          form));
54                  successMessageKey = RiceKeyConstants.MESSAGE_ROUTE_APPROVED;
55                  GlobalVariables.getMessageMap().putInfo(OLEConstants.OleAccessMethod.ACCESS_METHOD_CODE, "message.route.approved");
56                  return getUIFModelAndView(form);
57  
58              } else {
59                  if (shelvingSchemeInDatabase.size() > 0) {
60                      for (OleShelvingScheme shelvingSchemeObj : shelvingSchemeInDatabase) {
61                          String shelvingSchemeId = shelvingSchemeObj.getShelvingSchemeId().toString();
62                          //String accessMethodCode=accessMehtodObj.getAccessMethodCode();
63                          if (null == oleShelvingScheme.getShelvingSchemeId() ||
64                                  !(oleShelvingScheme.getShelvingSchemeId().equals(shelvingSchemeId))) {
65                              GlobalVariables.getMessageMap().putError(OLEConstants.OleShelvingScheme.SHELVING_SCHEME_CODE, "error.duplicate.code.shelving");
66                              return getUIFModelAndView(form);
67                          }
68                          getDocumentService().blanketApproveDocument(document, form.getAnnotation(), combineAdHocRecipients(
69                                  form));
70                          successMessageKey = RiceKeyConstants.MESSAGE_ROUTE_APPROVED;
71                          GlobalVariables.getMessageMap().putInfo(OLEConstants.OleShelvingScheme.SHELVING_SCHEME_CODE, "message.route.approved");
72                          return getUIFModelAndView(form);
73  
74                      }
75                  }
76  
77              }
78  
79          } else if ("Copy".equals(maintenanceDocument.getNewMaintainableObject().getMaintenanceAction())) {
80              String successMessageKey = null;
81              Document document = form.getDocument();
82              if (shelvingSchemeInDatabase.size() == 0) {
83                  getDocumentService().blanketApproveDocument(document, form.getAnnotation(), combineAdHocRecipients(
84                          form));
85                  successMessageKey = RiceKeyConstants.MESSAGE_ROUTE_APPROVED;
86                  GlobalVariables.getMessageMap().putInfo(OLEConstants.OleShelvingScheme.SHELVING_SCHEME_CODE, "message.route.approved");
87                  return getUIFModelAndView(form);
88              } else if ((shelvingSchemeInDatabase.size() > 0)) {
89  
90                  for (OleShelvingScheme shelvingSchemeObj : shelvingSchemeInDatabase) {
91                      String shelvingSchemeId = shelvingSchemeObj.getShelvingSchemeId().toString();
92                      if (null == oleShelvingScheme.getShelvingSchemeId() ||
93                              !(oleShelvingScheme.getShelvingSchemeId().equals(shelvingSchemeId))) {
94                          GlobalVariables.getMessageMap().putError(OLEConstants.OleShelvingScheme.SHELVING_SCHEME_CODE, "error.duplicate.code.shelving");
95                          return getUIFModelAndView(form);
96                      }
97                  }
98  
99              }
100         } else if ("New".equals(maintenanceDocument.getNewMaintainableObject().getMaintenanceAction())) {
101             String successMessageKey = null;
102             Document document = form.getDocument();
103             if (shelvingSchemeInDatabase.size() == 0) {
104                 getDocumentService().blanketApproveDocument(document, form.getAnnotation(), combineAdHocRecipients(
105                         form));
106                 successMessageKey = RiceKeyConstants.MESSAGE_ROUTE_APPROVED;
107                 GlobalVariables.getMessageMap().putInfo(OLEConstants.OleShelvingScheme.SHELVING_SCHEME_CODE, "message.route.approved");
108                 return getUIFModelAndView(form);
109             } else if ((shelvingSchemeInDatabase.size() > 0)) {
110 
111                 for (OleShelvingScheme shelvingSchemeObj : shelvingSchemeInDatabase) {
112                     String shelvingSchemeId = shelvingSchemeObj.getShelvingSchemeId().toString();
113                     if (null == oleShelvingScheme.getShelvingSchemeId() ||
114                             !(oleShelvingScheme.getShelvingSchemeId().equals(shelvingSchemeId))) {
115                         GlobalVariables.getMessageMap().putError(OLEConstants.OleShelvingScheme.SHELVING_SCHEME_CODE, "error.duplicate.code.shelving");
116                         return getUIFModelAndView(form);
117                     }
118                 }
119 
120             }
121         }
122 
123 
124         /* if((shelvingSchemeInDatabase.size() > 0)) {
125 
126             for(OleShelvingScheme shelvingSchemeObj : shelvingSchemeInDatabase){
127                 String shelvingSchemeId =  shelvingSchemeObj.getShelvingSchemeId().toString();
128                 if (null == oleShelvingScheme.getShelvingSchemeId()  ||
129                         !(oleShelvingScheme.getShelvingSchemeId().equals(shelvingSchemeId))) {
130                     GlobalVariables.getMessageMap().putError(OLEConstants.OleShelvingScheme.SHELVING_SCHEME_CODE, "error.duplicate.code");
131                     return getUIFModelAndView(form);
132                 }
133             }
134 
135         }*/
136         performWorkflowAction(form, UifConstants.WorkflowAction.BLANKETAPPROVE, true);
137         return returnToPrevious(form);
138     }
139 }
140