1 /**
2 * Copyright 2005-2007 the original author or authors.
3 *
4 * Licensed under the Gnu General Pubic License, Version 2.0 (the
5 * "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.opensource.org/licenses/gpl-license.php
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the Gnu General Public License for more details.
14 */
15 package org.figure8.join.control.action;
16
17 import org.figure8.join.control.JoinAction;
18 import org.figure8.join.control.form.DeploymentsForm;
19 import org.figure8.join.businessfacades.environment.EnvironmentManager;
20 import org.figure8.join.businessobjects.environment.EnvironmentMapping;
21 import org.figure8.join.businessobjects.environment.LogicalEnvironment;
22 import org.figure8.join.businessobjects.environment.PhysicalEnvironment;
23 import org.figure8.join.util.LogUtil;
24
25 import org.apache.commons.logging.Log;
26 import org.apache.struts.action.ActionForm;
27 import org.apache.struts.action.ActionForward;
28 import org.apache.struts.action.ActionMapping;
29
30 import javax.servlet.http.HttpServletRequest;
31 import javax.servlet.http.HttpServletResponse;
32
33 import java.util.List;
34 /**
35 * This is a Struts action controller for managing Deployments retrieval related operations.
36 * @author <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
37 * @version $Revision: 1.1 $
38 * @struts.action path="/deployments" name="DeploymentsForm"
39 * scope="request" parameter="op" validate="true"
40 * input="/pages/mainpage.jsp?body=/jsp/environment/deploymentshistory.jsp"
41 * @struts.action-forward name="History" path="/jsp/environment/deploymentshistory.jsp"
42 */
43 public class DeploymentsActions extends JoinAction{
44
45
46
47 /** Get a commons logger */
48 private static final Log log = LogUtil.getLog(DeploymentsActions.class);
49
50 /** Operation code for retrieving deployments for a logical environment. */
51 public static final String LOGICALENV_OP = "getByLogical";
52 /** Operation code for retrieving deployments for a physical environment. */
53 public static final String PHYSICALENV_OP = "getByPhysical";
54 /** Operation code for retrieving deployments for an environment mapping. */
55 public static final String ENVMAPPING_OP = "getByEnvMapping";
56
57 /** The request scope for specifying the title of the screen (used by view) */
58 public static final String TITLE_KEY = "title";
59
60 /**
61 * The request scope attribute under which the retrivied deployments
62 * list is stored.
63 */
64 public static final String DEPLOYMENTS_KEY = "deployments";
65
66
67
68
69 /** The EnvironmentManager implementation to use */
70 protected EnvironmentManager environmentManager = null;
71
72
73
74
75 /** Creates a new instance of DeploymentsActions. */
76 public DeploymentsActions(){
77 }
78
79
80
81
82 /** @param environmentManager The EnvironmentManager implementation to use */
83 public void setEnvironmentManager(EnvironmentManager environmentManager){
84 this.environmentManager = environmentManager;
85 }
86
87
88
89
90 /**
91 * @param operation String representing the operation to invoke on Action
92 * @param mapping Mapping between forwards name and path for this action
93 * @param form The form object containing request parameters
94 * @param request The servlet container request wrapper
95 * @param response The servlet container response wrapper
96 * @return A forward to the next view to render and display
97 * @throws Exception such as InfraStructureExceptions ...
98 */
99 public ActionForward doExecute(String operation, ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
100 throws Exception{
101
102 log.debug("doExecute() called for '" + operation + "' operation");
103
104 if (form instanceof DeploymentsForm){
105
106 DeploymentsForm dForm = (DeploymentsForm)form;
107
108 if (LOGICALENV_OP.equals(operation)){
109 return getDeploymentsForLogicalEnvironment(mapping, dForm, request, response);
110 }
111 else if (PHYSICALENV_OP.equals(operation)){
112 return getDeploymentsForPhysicalEnvironment(mapping, dForm, request, response);
113 }
114 else if (ENVMAPPING_OP.equals(operation)){
115 return getDeploymentsForEnvironmentMapping(mapping, dForm, request, response);
116 }
117 }
118
119
120 return null;
121 }
122
123
124
125
126 /**
127 * Retrieve deployments for a specified logical environment.
128 * @return A forward to the next view to render and display
129 */
130 protected ActionForward getDeploymentsForLogicalEnvironment(ActionMapping mapping, DeploymentsForm form,
131 HttpServletRequest request, HttpServletResponse response)
132 throws Exception{
133
134 LogicalEnvironment environment = environmentManager.getLogicalEnvironment(form.getLogicalEnvKey());
135 List deployments = environmentManager.getDeployments(environment);
136
137 request.setAttribute(LogicalEnvironmentActions.ENVIRONMENT_KEY, environment);
138 request.setAttribute(DEPLOYMENTS_KEY, deployments);
139 request.setAttribute(TITLE_KEY, "title.deployments.bylogicalenv");
140 request.setAttribute("criterion", "logicalenv");
141
142 return mapping.findForward("History");
143 }
144
145 /**
146 * Retrieve deployments for a specified physical environment.
147 * @return A forward to the next view to render and display
148 */
149 protected ActionForward getDeploymentsForPhysicalEnvironment(ActionMapping mapping, DeploymentsForm form,
150 HttpServletRequest request, HttpServletResponse response)
151 throws Exception{
152
153 PhysicalEnvironment environment = environmentManager.getPhysicalEnvironment(form.getPhysicalEnvKey());
154 List deployments = environmentManager.getDeployments(environment);
155
156 request.setAttribute(PhysicalEnvironmentActions.ENVIRONMENT_KEY, environment);
157 request.setAttribute(DEPLOYMENTS_KEY, deployments);
158 request.setAttribute(TITLE_KEY, "title.deployments.byphysicalenv");
159 request.setAttribute("criterion", "physicalenv");
160
161 return mapping.findForward("History");
162 }
163
164 /**
165 * Retrieve deployments for a specified environment mapping.
166 * @return A forward to the next view to render and display
167 */
168 protected ActionForward getDeploymentsForEnvironmentMapping(ActionMapping mapping, DeploymentsForm form,
169 HttpServletRequest request, HttpServletResponse response)
170 throws Exception{
171
172 EnvironmentMapping envMapping = environmentManager.getEnvironmentMapping(form.getId());
173
174 request.setAttribute(EnvironmentMappingActions.MAPPING_KEY, envMapping);
175 request.setAttribute(DEPLOYMENTS_KEY, envMapping.getDeployments());
176 request.setAttribute(TITLE_KEY, "title.deployments.byenvmapping");
177 request.setAttribute("criterion", "envmapping");
178
179 return mapping.findForward("History");
180 }
181 }