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.form.ResourceForm;
18 import org.figure8.join.businessfacades.environment.ResourceManager;
19 import org.figure8.join.view.GatewayTrackingView;
20 import org.figure8.join.util.LogUtil;
21 import org.figure8.join.businessobjects.environment.Gateway;
22
23 import org.apache.commons.logging.Log;
24 import org.apache.struts.action.ActionForm;
25 import org.apache.struts.action.ActionForward;
26 import org.apache.struts.action.ActionMapping;
27
28 import javax.servlet.http.HttpServletRequest;
29 import javax.servlet.http.HttpServletResponse;
30 /**
31 * This is a Struts action for managing all specific operations related to Gateway entities.
32 * @author <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
33 * @version $Revision: 1.1 $
34 *
35 * @struts.action path="/gateway" name="resourceForm"
36 * scope="request" parameter="op" validate="true"
37 * input="/pages/mainpage.jsp?body=/jsp/environment/resources.jsp"
38 * @struts.action-forward name="GatewayView" path="/jsp/environment/gatewayview.jsp"
39 * @struts.action-forward name="GatewayTrackingView" path="/jsp/environment/gatewaytrackingview.jsp"
40 */
41 public class GatewayActions extends ResourceActions{
42
43
44
45 /** Get a comons logger */
46 private static final Log log = LogUtil.getLog(GatewayActions.class);
47
48 /** Operation code for getting details on a specified Gateway view */
49 public static final String DETAILS_OP = "details";
50
51 /**
52 * The request scope attribute under which the Gateway object
53 * currently selected by our logged-in User is stored.
54 */
55 public static final String GATEWAY_KEY = "gateway";
56 /**
57 * The request scope attribute under which the configuration changes view
58 * for a tracking period is stored.
59 */
60 public static final String TRACKING_VIEW_KEY = "trackingView";
61
62
63
64
65 /** The ResourceManager to use */
66 private ResourceManager resourceManager = null;
67
68
69
70
71 /** Creates a new instance of GatewayActions. */
72 public GatewayActions(){
73 }
74
75
76
77
78 /** @param manager The ResourceManager implementation to use */
79 public void setResourceManager(ResourceManager manager){
80 this.resourceManager = manager;
81 }
82
83
84
85
86 /**
87 *
88 * @param operation String representing the operation to invoke on Action
89 * @param mapping Mapping between forwards name and path for this action
90 * @param form The form object containing request parameters
91 * @param request The servlet container request wrapper
92 * @param response The servlet container response wrapper
93 * @return A forward to the next view to render and display
94 * @throws Exception such as InfraStructureExceptions ...
95 */
96 public ActionForward doExecute(String operation, ActionMapping mapping, ActionForm form,
97 HttpServletRequest request, HttpServletResponse response) throws Exception{
98
99 log.debug("doExecute() called for '" + operation + "' operation");
100
101 if (DETAILS_OP.equals(operation)){
102 return getGatewayDetails(mapping, form, request, response);
103 }
104 else if (CONFIG_OP.equals(operation)){
105 return null;
106 }
107 else if (CHANGES_OP.equals(operation)){
108 return getGatewayChanges(mapping, form, request, response);
109 }
110
111 return null;
112 }
113
114
115
116
117 /**
118 * Load a specified gateway from datastore.
119 * @return A forward to the next view to render and display
120 */
121 protected ActionForward getGatewayDetails(ActionMapping mapping, ActionForm form,
122 HttpServletRequest request, HttpServletResponse response) throws Exception{
123
124 if (form instanceof ResourceForm){
125
126 ResourceForm resForm = (ResourceForm)form;
127 Gateway gateway = (Gateway)request.getAttribute(GATEWAY_KEY);
128
129 if (gateway == null)
130 gateway = (Gateway)resourceManager.getResource(resForm.getName());
131
132
133 request.setAttribute(GATEWAY_KEY, gateway);
134 return mapping.findForward("GatewayView");
135 }
136
137 return null;
138 }
139
140 /**
141 * Load a specified gateway from datastore and get its configuration
142 * changes during specified period (use startDate and endDate from form).
143 * @return A forward to the next view to render and display
144 */
145 protected ActionForward getGatewayChanges(ActionMapping mapping, ActionForm form,
146 HttpServletRequest request, HttpServletResponse response) throws Exception{
147
148 if (form instanceof ResourceForm){
149
150 ResourceForm resForm = (ResourceForm)form;
151 GatewayTrackingView view = resourceManager.getGatewayTrackingView(resForm.getName(),
152 resForm.getStartDate(), resForm.getEndDate());
153
154 request.setAttribute(TRACKING_VIEW_KEY, view);
155 return mapping.findForward("GatewayTrackingView");
156 }
157
158 return null;
159 }
160 }