001: /*
002: * $Header: /export/home/cvsroot/MyPersonalizerRepository/MyPersonalizer/Subsystems/Portal/Sources/es/udc/mypersonalizer/portal/controller/actions/content/FindDesktopContentAction.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.kernel.controller.actions.DefaultAction;
044: import es.udc.mypersonalizer.kernel.conventions.UserAndGroupConventions;
045: import es.udc.mypersonalizer.kernel.model.actions.ActionProcessorSingleton;
046: import es.udc.mypersonalizer.kernel.model.editors.DesktopLayoutEditor;
047: import es.udc.mypersonalizer.kernel.model.editors.EditorFactory;
048: import es.udc.mypersonalizer.kernel.model.repository.interfaces.DesktopLayout;
049: import es.udc.mypersonalizer.portal.controller.session.SessionManager;
050: import es.udc.mypersonalizer.portal.conventions.RequestAttributeNames;
051: import es.udc.mypersonalizer.portal.model.permissions.PermissionCheckerSingleton;
052: import es.udc.mypersonalizer.portal.model.permissions.UserCredentials;
053: import es.udc.mypersonalizer.portal.model.types.content.FindDesktopContentEvent;
054: import es.udc.mypersonalizer.portal.model.types.content.FindDesktopContentResult;
055: import es.udc.mypersonalizer.portal.view.content.DefaultWorkspaceView;
056: import es.udc.mypersonalizer.portal.view.content.DesktopContentView;
057: import java.util.*;
058: import javax.servlet.http.HttpServletRequest;
059: import javax.servlet.http.HttpServletResponse;
060: import org.apache.struts.action.ActionErrors;
061: import org.apache.struts.action.ActionForm;
062: import org.apache.struts.action.ActionForward;
063: import org.apache.struts.action.ActionMapping;
064: import org.apache.struts.util.LabelValueBean;
065:
066: /**
067: * This action performs a lookup for the contents of the user's desktop.
068: * It gathers information about which pages (workspaceLayouts) could be added,
069: * which ones removed and which is the default page. It calls the model action
070: * called <tt>FindDesktopContentAction</tt>, which must be registered in
071: * configuration.<p>
072: *
073: * This action requires a <tt>Success</tt> forward, which will usually point
074: * to the jsp page where the data is presented to the user.<p>
075: *
076: * When successful, this action populates the request (before performing
077: * any <i>forward</i> operation) with an object of class {@link
078: * es.udc.mypersonalizer.portal.view.content.DesktopContentView}, containing
079: * all the needed data to show the contents of the desktop to the user.
080: *
081: * @author Daniel Fernandez
082: * @since 1.0
083: */
084: public class FindDesktopContentAction extends DefaultAction {
085:
086: /**
087: * Name of the model action for looking all the desktop data up.
088: * This is <tt>FindDesktopContentAction</tt>.
089: */
090: private static final String FIND_DESKTOP_CONTENT_ACTION = "FindDesktopContentAction";
091:
092: protected ActionForward doExecute(ActionMapping mapping,
093: ActionForm form, HttpServletRequest request,
094: HttpServletResponse response) throws Exception {
095:
096: ActionErrors errors = new ActionErrors();
097:
098: UserCredentials userCredentials = SessionManager
099: .getUserCredentials(request);
100: PermissionCheckerSingleton permissionCheckerSingleton = PermissionCheckerSingleton
101: .getInstance();
102:
103: /*
104: * We get the List of active workspaces from the session. And convert
105: * its elements, from Maps to LabelValues.
106: */
107: List activeWorkspacesAsMaps = SessionManager
108: .getAvailableWorkspaces(request);
109: List activeWorkspaces = getLabelValueList(
110: activeWorkspacesAsMaps, "workspaceName",
111: "workspaceLayoutIdentifier");
112:
113: /*
114: * Now we get the user's desktop layout and its timestamp, needed
115: * as parameters for the model action.
116: */
117: DesktopLayout desktopLayout = SessionManager
118: .getDesktopLayout(request);
119: EditorFactory editorFactory = EditorFactory.getInstance();
120: DesktopLayoutEditor desktopLayoutEditor = editorFactory
121: .createDesktopLayoutEditor(desktopLayout.getProperty());
122: Long desktopLayoutIdentifier = desktopLayout.getIdentifier();
123: Long timeStamp = desktopLayoutEditor.getTimeStamp();
124:
125: FindDesktopContentEvent findDesktopContentEvent = new FindDesktopContentEvent(
126: userCredentials, desktopLayoutIdentifier, timeStamp);
127:
128: ActionProcessorSingleton actionProcessorSingleton = ActionProcessorSingleton
129: .getInstance();
130:
131: FindDesktopContentResult findDesktopContentResult = (FindDesktopContentResult) actionProcessorSingleton
132: .execute(FIND_DESKTOP_CONTENT_ACTION,
133: findDesktopContentEvent);
134:
135: /*
136: * We create the List of available workspaces (to be added)
137: */
138: List availableWorkspacesAsMaps = findDesktopContentResult
139: .getAllowedNewWorkspaces();
140: List availableWorkspaces = null;
141: if (userCredentials.getLoginName().equals(
142: UserAndGroupConventions.MYPERSONALIZER_LOGIN_NAME)) {
143: availableWorkspaces = getLabelValueList(
144: availableWorkspacesAsMaps, "workspaceName",
145: "workspaceType");
146: } else {
147: availableWorkspaces = getLabelValueList(
148: availableWorkspacesAsMaps, "workspaceName",
149: "workspaceLayoutIdentifier");
150: }
151:
152: /*
153: * We create the List of removable workspaces
154: */
155: List removableWorkspacesAsMaps = findDesktopContentResult
156: .getRemovableWorkspaces();
157: List removableWorkspaces = getLabelValueList(
158: removableWorkspacesAsMaps, "workspaceName",
159: "workspaceLayoutIdentifier");
160:
161: /*
162: * We get the default workspace view
163: */
164: Long defaultWorkspaceLayoutIdentifier = findDesktopContentResult
165: .getDefaultWorkspaceLayoutIdentifier();
166: String defaultWorkspaceName = findDesktopContentResult
167: .getDefaultWorkspaceName();
168: DefaultWorkspaceView defaultWorkspaceView = new DefaultWorkspaceView(
169: defaultWorkspaceLayoutIdentifier, defaultWorkspaceName);
170:
171: /*
172: * Finally, we create the view object
173: */
174: DesktopContentView desktopContentView = new DesktopContentView(
175: defaultWorkspaceView, activeWorkspaces,
176: availableWorkspaces, removableWorkspaces);
177:
178: /* The desktop content view get into the request */
179: request
180: .setAttribute(
181: RequestAttributeNames.DESKTOP_CONTENT_VIEW_ATTRIBUTE_NAME,
182: desktopContentView);
183:
184: return mapping
185: .findForward(DefaultAction.ACTION_SUCCESS_FORWARD);
186: }
187:
188: private List getLabelValueList(List mapsList, String labelEntries,
189: String valueEntries) {
190:
191: List result = new ArrayList();
192: Iterator mapsListIter = mapsList.iterator();
193: while (mapsListIter.hasNext()) {
194: Map currentMap = (Map) mapsListIter.next();
195: LabelValueBean currentResult = new LabelValueBean(
196: currentMap.get(labelEntries).toString(), currentMap
197: .get(valueEntries).toString());
198: result.add(currentResult);
199: }
200:
201: return result;
202: }
203:
204: }
|