KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > forrest > forrestbot > webapp > action > ExecuteAction


1 /*
2 * Copyright 2002-2004 The Apache Software Foundation or its licensors,
3 * as applicable.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */

17 package org.apache.forrest.forrestbot.webapp.action;
18
19 import javax.servlet.http.HttpServletRequest JavaDoc;
20 import javax.servlet.http.HttpServletResponse JavaDoc;
21
22 import org.apache.commons.beanutils.PropertyUtils;
23 import org.apache.forrest.forrestbot.webapp.Constants;
24 import org.apache.forrest.forrestbot.webapp.util.Project;
25 import org.apache.log4j.Logger;
26 import org.apache.struts.action.ActionError;
27 import org.apache.struts.action.ActionErrors;
28 import org.apache.struts.action.ActionForm;
29 import org.apache.struts.action.ActionForward;
30 import org.apache.struts.action.ActionMapping;
31 import org.apache.forrest.forrestbot.webapp.util.Executor;
32
33 public final class ExecuteAction extends BaseAction {
34     private static Logger log = Logger.getLogger(ExecuteAction.class);
35
36     public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws Exception JavaDoc {
37         super.execute(mapping, form, request, response);
38         
39         ActionErrors errors = new ActionErrors();
40
41         String JavaDoc project = (String JavaDoc) PropertyUtils.getSimpleProperty(form, "project");
42         String JavaDoc build = (String JavaDoc) PropertyUtils.getSimpleProperty(form, "build");
43         String JavaDoc deploy = (String JavaDoc) PropertyUtils.getSimpleProperty(form, "deploy");
44
45         request.setAttribute("project", project);
46
47         if (!checkAuthorized(request, response))
48             return mapping.findForward(Constants.FORWARD_NAME_SUCCESS);
49
50         if (!Project.exists(project)) {
51             log.warn("project doesn't exist: " + project);
52             errors.add("execute", new ActionError("error.project.notfound", project));
53             saveErrors(request, errors);
54             return mapping.findForward(Constants.FORWARD_NAME_SUCCESS);
55         }
56         
57         Project p = new Project();
58         p.asDTO().setName(project);
59         p.loadData();
60         p.loadSecurity((String JavaDoc) request.getSession(true).getAttribute("username"));
61         if (p.asDTO().getStatus() == Constants.STATUS_RUNNING) {
62             log.warn("can't execute " + project + " while still running");
63             errors.add("execute", new ActionError("error.project.stillrunning", project));
64             saveErrors(request, errors);
65             return mapping.findForward(Constants.FORWARD_NAME_SUCCESS);
66         }
67
68         if (build != null && !build.equals("")) {
69             if (p.asDTO().isBuildable()) {
70                 try {
71                     Executor.build(project);
72                 } catch (Exception JavaDoc e) {
73                     log.warn("couldn't build " + project, e);
74                     errors.add("execute", new ActionError("error.build", project));
75                 }
76             } else {
77                 errors.add("execute", new ActionError("error.authorization"));
78             }
79         } else if (deploy != null && !deploy.equals("")) {
80             if (p.asDTO().isDeployable()) {
81                 try {
82                     Executor.deploy(project);
83                 } catch (Exception JavaDoc e) {
84                     log.warn("couldn't deploy " + project, e);
85                     errors.add("execute", new ActionError("error.deploy", project));
86                 }
87             } else {
88                 errors.add("execute", new ActionError("error.authorization"));
89             }
90         }
91         saveErrors(request, errors);
92         return mapping.findForward(Constants.FORWARD_NAME_SUCCESS);
93
94     }
95 }
96
Popular Tags