001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/osp/tags/sakai_2-4-1/presentation/api-impl/src/java/org/theospi/portfolio/presentation/model/impl/PresentationListGenerator.java $
003: * $Id: PresentationListGenerator.java 21614 2007-02-15 17:16:23Z chmaurer@iupui.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2005, 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.theospi.portfolio.presentation.model.impl;
021:
022: import java.util.ArrayList;
023: import java.util.HashMap;
024: import java.util.Iterator;
025: import java.util.List;
026: import java.util.Map;
027:
028: import org.sakaiproject.exception.IdUnusedException;
029: import org.sakaiproject.metaobj.security.AuthenticationManager;
030: import org.sakaiproject.metaobj.shared.model.Agent;
031: import org.sakaiproject.metaobj.worksite.mgt.WorksiteManager;
032: import org.sakaiproject.site.api.Site;
033: import org.sakaiproject.site.api.ToolConfiguration;
034: import org.sakaiproject.site.cover.SiteService;
035: import org.sakaiproject.user.api.UserNotDefinedException;
036: import org.theospi.portfolio.list.impl.BaseListGenerator;
037: import org.theospi.portfolio.list.intf.ActionableListGenerator;
038: import org.theospi.portfolio.list.intf.CustomLinkListGenerator;
039: import org.theospi.portfolio.presentation.PresentationFunctionConstants;
040: import org.theospi.portfolio.presentation.PresentationManager;
041: import org.theospi.portfolio.presentation.model.Presentation;
042: import org.theospi.portfolio.presentation.model.PresentationTemplate;
043: import org.theospi.portfolio.security.AuthorizationFacade;
044:
045: public class PresentationListGenerator extends BaseListGenerator
046: implements ActionableListGenerator, CustomLinkListGenerator {
047: private PresentationManager presentationManager;
048: private static final String TOOL_ID_PARAM = "toolId";
049: private static final String PRESENTATION_ID_PARAM = "presentationId";
050:
051: private WorksiteManager worksiteManager;
052: private AuthenticationManager authnManager;
053: private AuthorizationFacade authzManager;
054:
055: public void init() {
056: logger.info("init()");
057: super .init();
058: }
059:
060: public WorksiteManager getWorksiteManager() {
061: return worksiteManager;
062: }
063:
064: public AuthenticationManager getAuthnManager() {
065: return authnManager;
066: }
067:
068: public void setAuthnManager(AuthenticationManager authnManager) {
069: this .authnManager = authnManager;
070: }
071:
072: public void setWorksiteManager(WorksiteManager worksiteManager) {
073: this .worksiteManager = worksiteManager;
074: }
075:
076: public PresentationManager getPresentationManager() {
077: return presentationManager;
078: }
079:
080: public void setPresentationManager(
081: PresentationManager presentationManager) {
082: this .presentationManager = presentationManager;
083: }
084:
085: public List getObjects() {
086:
087: List<DecoratedPresentation> presentations = new ArrayList<DecoratedPresentation>();
088: Agent viewer = getAuthnManager().getAgent();
089: List tempPresentationList = new ArrayList(
090: getPresentationManager().findPresentationsByViewer(
091: viewer));
092: {
093: if (tempPresentationList.size() > 0) {
094: Iterator iter = tempPresentationList.iterator();
095:
096: while (iter.hasNext()) {
097: Presentation pres = (Presentation) iter.next();
098:
099: try {
100: if (!getAuthzManager()
101: .isAuthorized(
102: viewer,
103: PresentationFunctionConstants.HIDE_PRESENTATION,
104: pres.getId())) {
105: Site site = SiteService.getSite(pres
106: .getSiteId());
107: DecoratedPresentation decoPres = new DecoratedPresentation(
108: pres, site);
109: presentations.add(decoPres);
110: }
111: } catch (IdUnusedException e) {
112: logger.warn("Site with id " + pres.getSiteId()
113: + " does not exist.");
114: } catch (UserNotDefinedException e) {
115: logger.warn("User with id "
116: + pres.getOwner().getId()
117: + " does not exist.");
118: }
119: }
120: }
121: }
122: return presentations;
123:
124: // return new ArrayList(getPresentationManager().findPresentationsByViewer(getAuthnManager().getAgent()));
125: }
126:
127: public boolean isNewWindow(Object entry) {
128: return !internalWindow((DecoratedPresentation) entry);
129: }
130:
131: /**
132: * Create a custom link for enty if it needs
133: * to customize, otherwise, null to use the usual entry
134: *
135: * @param entry
136: * @return link to use or null to use normal redirect link
137: */
138: public String getCustomLink(Object entry) {
139: DecoratedPresentation decoPres = (DecoratedPresentation) entry;
140: if (!internalWindow(decoPres)) {
141: return decoPres.getPresentation().getExternalUri();
142: }
143: return null;
144: }
145:
146: protected boolean internalWindow(DecoratedPresentation pres) {
147: PresentationTemplate template = pres.getPresentation()
148: .getTemplate();
149:
150: if (!template.isIncludeHeaderAndFooter()) {
151: return false;
152: }
153:
154: WorksiteManager manager = getWorksiteManager();
155:
156: return manager.isUserInSite(pres.getPresentation()
157: .getTemplate().getSiteId());
158: }
159:
160: public Map getToolParams(Object entry) {
161: Map<String, Object> params = new HashMap<String, Object>();
162: DecoratedPresentation presentation = (DecoratedPresentation) entry;
163: params.put(PRESENTATION_ID_PARAM, presentation.getId());
164: params.put(TOOL_ID_PARAM, presentation.getPresentation()
165: .getToolId());
166: return params;
167: }
168:
169: public ToolConfiguration getToolInfo(Map request) {
170: return null; //To change body of implemented methods use File | Settings | File Templates.
171: }
172:
173: public void setToolState(String toolId, Map request) {
174: //To change body of implemented methods use File | Settings | File Templates.
175: }
176:
177: /**
178: * @return the authzManager
179: */
180: public AuthorizationFacade getAuthzManager() {
181: return authzManager;
182: }
183:
184: /**
185: * @param authzManager the authzManager to set
186: */
187: public void setAuthzManager(AuthorizationFacade authzManager) {
188: this.authzManager = authzManager;
189: }
190: }
|