1 /**
2 * Copyright 2005-2006 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.ComponentForm;
19 import org.figure8.join.businessobjects.commons.Release;
20 import org.figure8.join.businessobjects.artifact.Component;
21 import org.figure8.join.businessobjects.artifact.ComponentType;
22 import org.figure8.join.businessfacades.artifact.ArtifactManager;
23 import org.figure8.join.businessfacades.commons.IntegrationProcessManager;
24 import org.figure8.join.util.LogUtil;
25
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.beanutils.PropertyUtils;
28 import org.apache.struts.action.ActionForm;
29 import org.apache.struts.action.ActionForward;
30 import org.apache.struts.action.ActionMapping;
31
32 import javax.servlet.http.HttpServletRequest;
33 import javax.servlet.http.HttpServletResponse;
34
35 import java.util.List;
36 /**
37 * This is a Struts action for managing all the components within Join.
38 * @author <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
39 * @version $Revision: 1.1 $
40 *
41 * @struts.action path="/component" name="componentForm"
42 * scope="request" parameter="op" validate="true"
43 * input="/pages/mainpage.jsp?body=/jsp/artifact/components.jsp"
44 * @struts.action-forward name="Component" path="/jsp/artifact/component.jsp"
45 * @struts.action-forward name="Components" path="/jsp/artifact/components.jsp"
46 */
47 public class ComponentActions extends JoinAction{
48
49
50
51 /** Get a commons logger. */
52 private static final Log log = LogUtil.getLog(ComponentActions.class);
53
54 /** Operation code for searching components using type and release */
55 public static final String SEARCH_OP = "search";
56 /** Operation code for getting details on a specific Component */
57 public static final String DETAILS_OP = "details";
58
59 /** The request scope attribute under which the Component is stored. */
60 public static final String COMPONENT_KEY = "component";
61 /** The request scope attribute under which the Components are stored. */
62 public static final String COMPONENTS_KEY = "components";
63
64
65
66
67 /** Join artifact manager instance. */
68 protected ArtifactManager artifactManager = null;
69 /** The integration process manager implementation to use. */
70 protected IntegrationProcessManager processManager = null;
71
72
73
74
75 /** Creates a new instance of ComponentActions. */
76 public ComponentActions(){
77 }
78
79
80
81
82 /** @param manager <code>ArtifactManager</code> implementation instance */
83 public void setArtifactManager(ArtifactManager manager){
84 this.artifactManager = manager;
85 }
86 /** @param manager The integration process manager implementation to use */
87 public void setIntegrationProcessManager(IntegrationProcessManager manager){
88 this.processManager = manager;
89 }
90
91
92
93
94 /**
95 *
96 * @param operation String representing the operation to invoke on Action
97 * @param mapping Mapping between forwards name and path for this action
98 * @param form The form object containing request parameters
99 * @param request The servlet container request wrapper
100 * @param response The servlet container response wrapper
101 * @return A forward to the next view to render and display
102 * @throws Exception such as InfraStructureExceptions ...
103 */
104 public ActionForward doExecute(String operation, ActionMapping mapping, ActionForm form,
105 HttpServletRequest request, HttpServletResponse response) throws Exception{
106
107 log.debug("doExecute() called for '" + operation + "' operation");
108
109 if (SEARCH_OP.equals(operation)){
110 return searchComponents(mapping, form, request, response);
111 }
112 else if (DETAILS_OP.equals(operation)){
113 return getComponentDetails(mapping, form, request, response);
114 }
115 else{
116
117 request.setAttribute(ComponentTypeActions.COMPONENT_TYPES_KEY, artifactManager.getComponentTypes());
118 return mapping.findForward("Components");
119 }
120 }
121
122
123
124
125 /**
126 * Serch all the components using the type and the bound release criteria.
127 * @return A forward to the next view to render and display
128 */
129 protected ActionForward searchComponents(ActionMapping mapping, ActionForm form,
130 HttpServletRequest request, HttpServletResponse response) throws Exception{
131 if (form instanceof ComponentForm){
132
133 ComponentForm cForm = (ComponentForm)form;
134
135
136 Release release = processManager.getRelease(cForm.getReleaseName());
137 ComponentType type = artifactManager.getComponentType(cForm.getTypeKey());
138
139
140 List components = artifactManager.getContainedComponents(type, release);
141 request.setAttribute(COMPONENTS_KEY, components);
142 request.setAttribute(ReleaseActions.RELEASE_KEY, release);
143 request.setAttribute(ComponentTypeActions.COMPONENT_TYPE_KEY, type);
144 request.setAttribute(ComponentTypeActions.COMPONENT_TYPES_KEY, artifactManager.getComponentTypes());
145
146 return mapping.findForward("Components");
147 }
148
149 return null;
150 }
151
152 /**
153 * Get all the details onto an existing Component.
154 * @return A forward to the next view to render and display
155 */
156 protected ActionForward getComponentDetails(ActionMapping mapping, ActionForm form,
157 HttpServletRequest request, HttpServletResponse response)
158 throws Exception{
159
160 if (form instanceof ComponentForm){
161
162 ComponentForm cForm = (ComponentForm)form;
163 Component component = artifactManager.getComponent(cForm.getKey());
164
165
166 request.setAttribute(COMPONENT_KEY, component);
167
168 PropertyUtils.copyProperties(cForm, component);
169
170 cForm.setReleaseName(component.getRelease().getName());
171 cForm.setTypeKey(component.getComponentType().getKey());
172
173 return mapping.findForward("Component");
174 }
175
176 return null;
177 }
178 }
179