001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/metaobj/tags/sakai_2-4-1/metaobj-impl/api-impl/src/java/org/sakaiproject/metaobj/worksite/mgt/impl/WorksiteManagerImpl.java $
003: * $Id: WorksiteManagerImpl.java 18591 2006-12-01 16:24:01Z john.ellis@rsmart.com $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2004, 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.sakaiproject.metaobj.worksite.mgt.impl;
021:
022: import org.apache.commons.logging.Log;
023: import org.apache.commons.logging.LogFactory;
024: import org.sakaiproject.authz.api.AuthzGroup;
025: import org.sakaiproject.authz.api.GroupNotDefinedException;
026: import org.sakaiproject.authz.cover.AuthzGroupService;
027: import org.sakaiproject.exception.IdUnusedException;
028: import org.sakaiproject.metaobj.shared.mgt.IdManager;
029: import org.sakaiproject.metaobj.shared.model.Id;
030: import org.sakaiproject.metaobj.shared.model.OspException;
031: import org.sakaiproject.metaobj.worksite.mgt.WorksiteManager;
032: import org.sakaiproject.site.api.Site;
033: import org.sakaiproject.site.api.SitePage;
034: import org.sakaiproject.site.api.ToolConfiguration;
035: import org.sakaiproject.site.cover.SiteService;
036: import org.sakaiproject.tool.api.Placement;
037: import org.sakaiproject.tool.api.ToolSession;
038: import org.sakaiproject.tool.cover.SessionManager;
039: import org.sakaiproject.tool.cover.ToolManager;
040:
041: import java.util.*;
042:
043: public class WorksiteManagerImpl implements WorksiteManager {
044: protected final transient Log logger = LogFactory
045: .getLog(getClass());
046:
047: private IdManager idManager = null;
048:
049: public List getUserSites() {
050: return getUserSites(null);
051: }
052:
053: public List getUserSites(Map properties) {
054: // process all the sites
055: return getUserSites(properties, null);
056: }
057:
058: public List getUserSites(Map properties, List siteTypes) {
059: List mySites = SiteService
060: .getSites(
061: org.sakaiproject.site.api.SiteService.SelectionType.ACCESS,
062: siteTypes,
063: null,
064: properties,
065: org.sakaiproject.site.api.SiteService.SortType.NONE,
066: null);
067:
068: if (mySites.size() > 0) {
069: Collections.sort(mySites);
070: }
071:
072: return mySites;
073: }
074:
075: public Id getCurrentWorksiteId() {
076: Placement currentPlacement = ToolManager.getCurrentPlacement();
077:
078: if (currentPlacement == null) {
079: currentPlacement = getToolSessionPlacement();
080:
081: if (currentPlacement == null) {
082: return null;
083: }
084: }
085:
086: String id = currentPlacement.getContext();
087:
088: if (id != null) {
089: return getIdManager().getId(id);
090: }
091: return null;
092: }
093:
094: protected Placement getToolSessionPlacement() {
095: ToolSession session = SessionManager.getCurrentToolSession();
096:
097: if (session == null) {
098: return null;
099: }
100:
101: String placementId = session.getPlacementId();
102: return getTool(placementId);
103: }
104:
105: public List getSiteTools(String toolId, Site site) {
106: List tools = new ArrayList();
107:
108: List pages = site.getPages();
109:
110: for (Iterator i = pages.iterator(); i.hasNext();) {
111: SitePage page = (SitePage) i.next();
112:
113: for (Iterator j = page.getTools().iterator(); j.hasNext();) {
114: ToolConfiguration tool = (ToolConfiguration) j.next();
115: if (toolId == null) {
116: tools.add(tool);
117: } else if (toolId.equals(tool.getToolId())) {
118: tools.add(tool);
119: }
120: }
121: }
122:
123: return tools;
124: }
125:
126: public Site getSite(String siteId) {
127: try {
128: return SiteService.getSite(siteId);
129: } catch (IdUnusedException e) {
130: logger.error("", e);
131: throw new OspException(e);
132: }
133: }
134:
135: public AuthzGroup getSiteRealm(String siteId) {
136: AuthzGroup siteRealm = null;
137: try {
138: siteRealm = AuthzGroupService.getAuthzGroup("/site/"
139: + siteId);
140: } catch (GroupNotDefinedException e) {
141: logger.error("", e);
142: throw new OspException(e);
143: }
144:
145: return siteRealm;
146: }
147:
148: public ToolConfiguration getTool(String id) {
149: return SiteService.findTool(id);
150: }
151:
152: public boolean isUserInSite(String siteId) {
153: return SiteService.allowAccessSite(siteId);
154: }
155:
156: public IdManager getIdManager() {
157: return idManager;
158: }
159:
160: public void setIdManager(IdManager idManager) {
161: this.idManager = idManager;
162: }
163: }
|