View Javadoc
1   /**
2    * Copyright 2005-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krad.labs.fileUploads;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.rice.krad.labs.KradLabsController;
20  import org.kuali.rice.krad.util.GlobalVariables;
21  import org.kuali.rice.krad.util.KRADConstants;
22  import org.kuali.rice.krad.web.form.UifFormBase;
23  import org.springframework.stereotype.Controller;
24  import org.springframework.validation.BindingResult;
25  import org.springframework.web.bind.annotation.ModelAttribute;
26  import org.springframework.web.bind.annotation.RequestMapping;
27  import org.springframework.web.servlet.ModelAndView;
28  
29  import javax.servlet.http.HttpServletRequest;
30  import javax.servlet.http.HttpServletResponse;
31  
32  /**
33   * Controller class for the file uploads lab view
34   *
35   * @author Kuali Rice Team (rice.collab@kuali.org)
36   */
37  @Controller
38  @RequestMapping(value = "/fileUploads")
39  public class LabsFileUploadsController extends KradLabsController {
40  
41      @Override
42      protected LabsFileUploadsForm createInitialForm() {
43          return new LabsFileUploadsForm();
44      }
45  
46      @RequestMapping(params = "methodToCall=uploadOne")
47      public ModelAndView uploadOne(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
48              HttpServletRequest request, HttpServletResponse response) {
49          LabsFileUploadsForm uploadForm = (LabsFileUploadsForm) form;
50  
51          if ((uploadForm.getUploadOne() == null) || StringUtils.isBlank(uploadForm.getUploadOne().getName())) {
52              GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, "labs.fileUpload", "one");
53          }
54  
55          return getModelAndView(form);
56      }
57  
58      @RequestMapping(params = "methodToCall=uploadTwo")
59      public ModelAndView uploadTwo(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
60              HttpServletRequest request, HttpServletResponse response) {
61          LabsFileUploadsForm uploadForm = (LabsFileUploadsForm) form;
62  
63          if ((uploadForm.getUploadTwo() == null) || StringUtils.isBlank(uploadForm.getUploadTwo().getName())) {
64              GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, "labs.fileUpload", "two");
65          }
66  
67          return getModelAndView(form);
68      }
69  }