PageRenderTime 38ms CodeModel.GetById 27ms app.highlight 4ms RepoModel.GetById 5ms app.codeStats 0ms

/actions/src/main/java/org/ala/spatial/services/web/ApplicationController.java

http://alageospatialportal.googlecode.com/
Java | 107 lines | 63 code | 25 blank | 19 comment | 2 complexity | ce08487a0fb190e29373987aec44c5e2 MD5 | raw file
  1/**************************************************************************
  2 *  Copyright (C) 2010 Atlas of Living Australia
  3 *  All Rights Reserved.
  4 *
  5 *  The contents of this file are subject to the Mozilla Public
  6 *  License Version 1.1 (the "License"); you may not use this file
  7 *  except in compliance with the License. You may obtain a copy of
  8 *  the License at http://www.mozilla.org/MPL/
  9 *
 10 *  Software distributed under the License is distributed on an "AS
 11 *  IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 12 *  implied. See the License for the specific language governing
 13 *  rights and limitations under the License.
 14 ***************************************************************************/
 15
 16package org.ala.spatial.services.web;
 17
 18import java.util.List;
 19import javax.annotation.Resource;
 20import javax.servlet.http.HttpServletRequest;
 21
 22import org.ala.spatial.services.dao.ApplicationDAO;
 23import org.ala.spatial.services.dto.Application;
 24import org.apache.log4j.Logger;
 25import org.springframework.stereotype.Controller;
 26import org.springframework.web.bind.annotation.ModelAttribute;
 27import org.springframework.web.bind.annotation.PathVariable;
 28import org.springframework.web.bind.annotation.RequestMapping;
 29import org.springframework.web.bind.annotation.RequestMethod;
 30import org.springframework.web.bind.annotation.ResponseBody;
 31import org.springframework.web.servlet.ModelAndView;
 32
 33/**
 34 * @author ajay
 35 */
 36@Controller
 37public class ApplicationController {
 38
 39    private static final Logger logger = Logger.getLogger(ApplicationController.class);
 40
 41    private final String APP_LIST = "/apps/";
 42    private final String APP_VIEW = "/app/{appid}";
 43    private final String APP_NEW = "/app/new";
 44
 45    @Resource(name = "applicationDao")
 46    private ApplicationDAO applicationDao;
 47
 48    @RequestMapping(value = APP_LIST)
 49    public ModelAndView viewApplications() {
 50        List<Application> apps = applicationDao.findApplications();
 51
 52        System.out.println("Got " + apps.size() + " items");
 53
 54        ModelAndView m = new ModelAndView("apps/list");
 55        m.addObject("apps", apps);
 56
 57        return m;
 58    }
 59
 60    @RequestMapping(value = APP_VIEW)
 61    public ModelAndView appInfo(@PathVariable String appid) {
 62        Application app = applicationDao.findApplicationByAppId(appid);
 63
 64        ModelAndView m = new ModelAndView("apps/view");
 65        m.addObject("app", app);
 66
 67        return m;
 68    }
 69
 70
 71    @RequestMapping(method = RequestMethod.GET, value = APP_NEW)
 72    public String newApplicationForm() {
 73        return "apps/new";
 74    }
 75
 76    @RequestMapping(method = RequestMethod.POST, value = APP_NEW)
 77    public ModelAndView newApplication(@ModelAttribute("application") Application app, HttpServletRequest req) {
 78
 79        logger.info("Adding application: \n" + app.toString());
 80
 81        List<Application> apps = applicationDao.findApplicationsByEmail(app.getEmail());
 82        ModelAndView m = new ModelAndView("message");
 83
 84        if (apps.size() > 0) {
 85            m.addObject("msg", "An application with the email has already been registered. Would you like to register yet another application?");
 86            //return "Application with the email has already been registered.";
 87        } else {
 88            applicationDao.addApplication(app);
 89
 90            logger.info("now application is: \n" + app.toString());
 91            String html = "";
 92            html += "Thank you for registering your application.";
 93            html += "Please keep your AppID secure and use it as part of your client application.";
 94            html += "<br />";
 95            html += "<strong>" + apps.get(0).getAppid() + "</strong>";
 96            html += "<br /><br />";
 97
 98            m.addObject("msg", html);
 99            m.addObject("isnew", true);
100
101            //return "application successfully created. Your appid is '" + app.getAppid() + "', please keep this safe.";
102        }
103
104        return m;
105
106    }
107}