View Javadoc

1   package org.kuali.ole.deliver.controller;
2   
3   import org.kuali.ole.OLEConstants;
4   import org.kuali.ole.deliver.bo.OleCirculationDesk;
5   import org.kuali.ole.deliver.bo.OleCirculationDeskLocation;
6   import org.kuali.ole.describe.bo.OleLocation;
7   import org.kuali.rice.krad.maintenance.MaintenanceDocument;
8   import org.kuali.rice.krad.service.KRADServiceLocator;
9   import org.kuali.rice.krad.uif.UifParameters;
10  import org.kuali.rice.krad.uif.container.CollectionGroup;
11  import org.kuali.rice.krad.uif.util.ObjectPropertyUtils;
12  import org.kuali.rice.krad.uif.view.View;
13  import org.kuali.rice.krad.util.GlobalVariables;
14  import org.kuali.rice.krad.util.KRADConstants;
15  import org.kuali.rice.krad.web.controller.MaintenanceDocumentController;
16  import org.kuali.rice.krad.web.form.DocumentFormBase;
17  import org.kuali.rice.krad.web.form.MaintenanceDocumentForm;
18  import org.kuali.rice.krad.web.form.UifFormBase;
19  import org.springframework.stereotype.Controller;
20  import org.springframework.validation.BindingResult;
21  import org.springframework.web.bind.annotation.ModelAttribute;
22  import org.springframework.web.bind.annotation.RequestMapping;
23  import org.springframework.web.bind.annotation.RequestMethod;
24  import org.springframework.web.servlet.ModelAndView;
25  
26  import javax.servlet.http.HttpServletRequest;
27  import javax.servlet.http.HttpServletResponse;
28  import java.util.HashMap;
29  import java.util.List;
30  import java.util.Map;
31  
32  /**
33   * Created with IntelliJ IDEA.
34   * User: aurojyotit
35   * Date: 7/6/13
36   * Time: 4:09 PM
37   * To change this template use File | Settings | File Templates.
38   */
39  @Controller
40  @RequestMapping(value = "/oleCirculationDeskMaintenance")
41  public class OleCirculationDeskMaintenanceController extends MaintenanceDocumentController {
42  
43      /**
44       * Default method for controller that setups a new
45       * <code>MaintenanceView</code> with the default new action
46       */
47      @RequestMapping(params = "methodToCall=" + KRADConstants.Maintenance.METHOD_TO_CALL_NEW)
48      @Override
49      public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
50                                HttpServletRequest request, HttpServletResponse response) {
51  
52          return super.start(form, result, request, response);
53      }
54  
55  
56      @Override
57      @RequestMapping(params = "methodToCall=route")
58      public ModelAndView route(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result,
59                                HttpServletRequest request, HttpServletResponse response) {
60          MaintenanceDocumentForm maintenanceForm = (MaintenanceDocumentForm) form;
61          MaintenanceDocument document = (MaintenanceDocument) maintenanceForm.getDocument();
62          OleCirculationDesk oleCirculationDesk = (OleCirculationDesk) document.getNewMaintainableObject().getDataObject();
63          List<OleCirculationDeskLocation> oleCirculationDeskLocationList = oleCirculationDesk.getDeleteoleCirculationDeskLocations();
64          for (OleCirculationDeskLocation oleCirculationDeskLocation : oleCirculationDeskLocationList) {
65              Map<String, String> map = new HashMap<String, String>();
66              map.put("circulationDeskId", oleCirculationDeskLocation.getCirculationDeskId());
67              KRADServiceLocator.getBusinessObjectService().deleteMatching(OleCirculationDeskLocation.class, map);
68          }
69          return super.route(form, result, request, response);
70      }
71  
72      /**
73       * This method populates date of the eventlog object thereby adding to the existing list.
74       *
75       * @param uifForm
76       * @param result
77       * @param request
78       * @param response
79       * @return ModelAndView
80       */
81      @RequestMapping(params = "methodToCall=addCirculationLine")
82      public ModelAndView addCirculationLine(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
83                                             HttpServletRequest request, HttpServletResponse response) throws Exception {
84          MaintenanceDocumentForm form = (MaintenanceDocumentForm) uifForm;
85          MaintenanceDocument document = (MaintenanceDocument) form.getDocument();
86  
87          OleCirculationDesk oleCirculationDesk = (OleCirculationDesk) document.getNewMaintainableObject().getDataObject();
88  
89          List<OleCirculationDeskLocation> oleCirculationDeskLocations = oleCirculationDesk.getOleCirculationDeskLocations();
90          /*OleCirculationDeskLocation oleCirculationDeskLocation=oleCirculationDeskLocations.get(0);
91          if(oleCirculationDeskLocation.getCirculationDeskLocationId()==null || oleCirculationDeskLocation.getCirculationLocationCode()==null){
92              GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, "Invalid Location");
93          }*/
94          oleCirculationDesk.setErrorMessage(null);
95          String selectedCollectionPath = form.getActionParamaterValue(UifParameters.SELLECTED_COLLECTION_PATH);
96          CollectionGroup collectionGroup = form.getPostedView().getViewIndex().getCollectionGroupByPath(selectedCollectionPath);
97          String addLinePath = collectionGroup.getAddLineBindingInfo().getBindingPath();
98  
99          Object eventObject = ObjectPropertyUtils.getPropertyValue(form, addLinePath);
100         OleCirculationDeskLocation oleCirculationDeskLocation = (OleCirculationDeskLocation) eventObject;
101         String fullLocationPath = oleCirculationDeskLocation.getCirculationFullLocationCode();
102         String[] locations = fullLocationPath.split("/");
103         Map<String, String> map = new HashMap<String, String>();
104         if (locations.length > 1) {
105             map.put("locationCode", locations[locations.length - 1]);
106         } else {
107             map.put("locationCode", locations[0]);
108         }
109         List<OleLocation> oleLocations = (List<OleLocation>) KRADServiceLocator.getBusinessObjectService().findMatching(OleLocation.class, map);
110         if (oleLocations.size() == 0) {
111             GlobalVariables.getMessageMap().putErrorForSectionId("OleCirculationDesk-Locations", OLEConstants.OleCirculationDesk.OLE_INVALID_CIRCULATION_DESK_LOCATION);
112             return getUIFModelAndView(form);
113         }
114         OleLocation oleLocation = null;
115         if (oleLocations.size() > 0) {
116             oleLocation = oleLocations.get(0);
117             oleCirculationDeskLocation.setCirculationLocationCode(oleLocation.getLocationCode());
118             oleCirculationDeskLocation.setCirculationDeskLocation(oleLocation.getLocationId());
119             oleCirculationDeskLocation.setOleCirculationDesk(oleCirculationDesk);
120         }
121         for (OleCirculationDeskLocation oleCirculationDeskLocation1 : oleCirculationDeskLocations) {
122             if (oleCirculationDeskLocation1.getCirculationDeskLocation().equalsIgnoreCase(oleCirculationDeskLocation.getCirculationDeskLocation())) {
123                 oleCirculationDeskLocation.setCirculationDeskLocation(null);
124                 oleCirculationDeskLocation.setCirculationLocationCode(null);
125 
126                 GlobalVariables.getMessageMap().putErrorForSectionId("OleCirculationDesk-Locations", OLEConstants.OleCirculationDesk.OLE_CIRCULATION_DESK_LOCATION_DUPLICATE_ERROR);
127                 return getUIFModelAndView(form);
128             }
129         }
130 
131 
132         View view = form.getPostedView();
133         view.getViewHelperService().processCollectionAddLine(view, form, selectedCollectionPath);
134         return getUIFModelAndView(form);
135     }
136 
137     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=deleteCirculationLine")
138     public ModelAndView deleteCirculationLine(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
139                                        HttpServletRequest request, HttpServletResponse response) {
140         LOG.debug("Initialized deleteLine method");
141         MaintenanceDocumentForm form = (MaintenanceDocumentForm) uifForm;
142         String selectedLineIndex = form.getActionParamaterValue("selectedLineIndex");
143         MaintenanceDocument document = (MaintenanceDocument) form.getDocument();
144         OleCirculationDesk oleCirculationDesk = (OleCirculationDesk) document.getNewMaintainableObject().getDataObject();
145         oleCirculationDesk.getDeleteoleCirculationDeskLocations().add(oleCirculationDesk.getOleCirculationDeskLocations().get(Integer.parseInt(selectedLineIndex)));
146         return deleteLine(uifForm, result, request, response);
147     }
148 
149 }
150