001: /*
002: * $Header: /export/home/cvsroot/MyPersonalizerRepository/MyPersonalizer/Subsystems/Portal/Sources/es/udc/mypersonalizer/portal/controller/actions/content/SelectWorkspaceAction.java,v 1.1.1.1 2004/03/25 12:08:40 fbellas Exp $
003: * $Revision: 1.1.1.1 $
004: * $Date: 2004/03/25 12:08:40 $
005: *
006: * =============================================================================
007: *
008: * Copyright (c) 2003, The MyPersonalizer Development Group
009: * (http://www.tic.udc.es/~fbellas/mypersonalizer/index.html) at
010: * University Of A Coruna
011: * All rights reserved.
012: *
013: * Redistribution and use in source and binary forms, with or without
014: * modification, are permitted provided that the following conditions are met:
015: *
016: * - Redistributions of source code must retain the above copyright notice,
017: * this list of conditions and the following disclaimer.
018: *
019: * - Redistributions in binary form must reproduce the above copyright notice,
020: * this list of conditions and the following disclaimer in the documentation
021: * and/or other materials provided with the distribution.
022: *
023: * - Neither the name of the University Of A Coruna nor the names of its
024: * contributors may be used to endorse or promote products derived from
025: * this software without specific prior written permission.
026: *
027: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
028: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
029: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
030: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
031: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
032: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
033: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
034: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
035: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
036: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
037: * POSSIBILITY OF SUCH DAMAGE.
038: *
039: */
040:
041: package es.udc.mypersonalizer.portal.controller.actions.content;
042:
043: import es.udc.mypersonalizer.portal.conventions.RequestParameterConventions;
044: import es.udc.mypersonalizer.kernel.model.actions.ActionProcessorSingleton;
045: import es.udc.mypersonalizer.kernel.model.editors.DesktopLayoutEditor;
046: import es.udc.mypersonalizer.kernel.model.editors.EditorFactory;
047: import es.udc.mypersonalizer.kernel.model.repository.interfaces.DesktopLayout;
048: import es.udc.mypersonalizer.kernel.model.repository.interfaces.WorkspaceLayout;
049: import es.udc.mypersonalizer.kernel.util.exceptions.InstanceNotFoundException;
050: import es.udc.mypersonalizer.kernel.controller.actions.DefaultAction;
051: import es.udc.mypersonalizer.portal.controller.session.KeyChecker;
052: import es.udc.mypersonalizer.portal.controller.session.SessionIdentifierCookieManagerSingleton;
053: import es.udc.mypersonalizer.portal.controller.session.SessionManager;
054: import es.udc.mypersonalizer.portal.model.permissions.UserCredentials;
055: import es.udc.mypersonalizer.portal.model.types.content.ContentResult;
056: import es.udc.mypersonalizer.portal.model.types.content.WorkspaceEvent;
057: import java.util.*;
058: import javax.servlet.http.HttpServletRequest;
059: import javax.servlet.http.HttpServletResponse;
060: import org.apache.commons.beanutils.PropertyUtils;
061: import org.apache.struts.action.ActionErrors;
062: import org.apache.struts.action.ActionForm;
063: import org.apache.struts.action.ActionForward;
064: import org.apache.struts.action.ActionMapping;
065:
066: /**
067: * This action lets the user change workspace to another of those he or she
068: * has permission for. It calls the model action <tt>SelectWorkspaceAction</tt>,
069: * which must be registered in configuration. It also sets the adequate
070: * information in the session about the new workspace.<p>
071: *
072: * It receives as a parameter a struts action form which must have been
073: * populated with the following data:
074: * <ul>
075: * <li><tt>workspaceIdentifier</tt>: The identifier for the workspace to switch
076: * to.</li>
077: * </ul>
078: *
079: * This action requires a <tt>Success</tt> forward, which will usually point
080: * to the portal main page.<p>
081: *
082: *
083: * @author Daniel Fernandez
084: * @since 1.0
085: */
086: public class SelectWorkspaceAction extends DefaultAction {
087:
088: /**
089: * Name of the model action for selecting a different workspace.
090: * This is "SelectWorkspaceAction".
091: */
092: private static final String SELECT_WORKSPACE_ACTION = "SelectWorkspaceAction";
093:
094: protected ActionForward doExecute(ActionMapping mapping,
095: ActionForm form, HttpServletRequest request,
096: HttpServletResponse response) throws Exception {
097:
098: ActionErrors errors = new ActionErrors();
099:
100: /*
101: * If there are no workspaces, this action cannot be executed.
102: */
103: if (!SessionManager.getUserHasWorkspaces(request)) {
104: throw new NoActiveWorkspacesException(
105: "Cannot select workspace");
106: }
107:
108: ActionProcessorSingleton actionProcessorSingleton = ActionProcessorSingleton
109: .getInstance();
110:
111: UserCredentials userCredentials = SessionManager
112: .getUserCredentials(request);
113:
114: /* We get the action parameters from the action form */
115: String workspaceIdentifierStr = (String) PropertyUtils
116: .getSimpleProperty(
117: form,
118: RequestParameterConventions.WORKSPACE_IDENTIFIER);
119:
120: Long workspaceIdentifier = new Long(workspaceIdentifierStr);
121:
122: /*
123: * We have to check whether the required workspace is one of the
124: * valid ones for the user's desktop.
125: */
126: if (KeyChecker.isValidWorkspaceLayoutIdentifier(request,
127: workspaceIdentifier)) {
128:
129: /*
130: * Maybe it already is cached at the session (we could have
131: * accessed it before.
132: */
133: WorkspaceLayout newCurrentWorkspaceLayout = SessionManager
134: .getWorkspaceLayout(request, workspaceIdentifier);
135:
136: if (newCurrentWorkspaceLayout == null) {
137:
138: /*
139: * We get the desktopLayout from the Session, as we need its
140: * timeStamp and identifier.
141: */
142: DesktopLayout desktopLayout = SessionManager
143: .getDesktopLayout(request);
144: EditorFactory editorFactory = EditorFactory
145: .getInstance();
146: DesktopLayoutEditor desktopLayoutEditor = editorFactory
147: .createDesktopLayoutEditor(desktopLayout
148: .getProperty());
149:
150: Long desktopLayoutIdentifier = desktopLayout
151: .getIdentifier();
152: Long timeStamp = desktopLayoutEditor.getTimeStamp();
153:
154: WorkspaceEvent selectWorkspaceEvent = new WorkspaceEvent(
155: userCredentials, desktopLayoutIdentifier,
156: workspaceIdentifier, timeStamp);
157:
158: ContentResult contentResult = (ContentResult) actionProcessorSingleton
159: .execute(SELECT_WORKSPACE_ACTION,
160: selectWorkspaceEvent);
161:
162: newCurrentWorkspaceLayout = contentResult
163: .getCurrentWorkspaceLayout();
164:
165: Collection newServiceButtonsStates = contentResult
166: .getServiceButtonsStates();
167:
168: /* We push the new info into the session */
169: SessionManager.setCurrentWorkspace(request,
170: newCurrentWorkspaceLayout,
171: newServiceButtonsStates);
172:
173: } else {
174: /* If it already is in the session, just select it */
175: SessionManager.setCurrentWorkspaceLayout(request,
176: workspaceIdentifier);
177: }
178:
179: /*
180: * The session cookie, which contains the current workspace
181: * identifier, is updated.
182: */
183: SessionIdentifierCookieManagerSingleton sessionIdentifierCookieManagerSingleton = SessionIdentifierCookieManagerSingleton
184: .getInstance();
185:
186: sessionIdentifierCookieManagerSingleton
187: .updateCookieWorkspace(request, response,
188: userCredentials.getLoginName(),
189: newCurrentWorkspaceLayout.getIdentifier());
190:
191: } else {
192: throw new InstanceNotFoundException(workspaceIdentifier,
193: "WorkspaceLayout");
194: }
195:
196: return mapping
197: .findForward(DefaultAction.ACTION_SUCCESS_FORWARD);
198: }
199:
200: }
|