1 17 package org.apache.forrest.forrestbot.webapp.action; 18 19 import javax.servlet.http.HttpServletRequest ; 20 import javax.servlet.http.HttpServletResponse ; 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 request, HttpServletResponse response) throws Exception { 37 super.execute(mapping, form, request, response); 38 39 ActionErrors errors = new ActionErrors(); 40 41 String project = (String ) PropertyUtils.getSimpleProperty(form, "project"); 42 String build = (String ) PropertyUtils.getSimpleProperty(form, "build"); 43 String deploy = (String ) 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 ) 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 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 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 |