001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/metaobj/tags/sakai_2-4-1/metaobj-util/tool-lib/src/java/org/sakaiproject/metaobj/shared/control/AbstractStructuredArtifactDefinitionController.java $
003: * $Id: AbstractStructuredArtifactDefinitionController.java 27794 2007-03-26 05:10:41Z 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.shared.control;
021:
022: import java.util.ArrayList;
023: import java.util.Collection;
024: import java.util.Collections;
025: import java.util.HashMap;
026: import java.util.Iterator;
027: import java.util.List;
028: import java.util.Map;
029:
030: import org.apache.commons.logging.Log;
031: import org.apache.commons.logging.LogFactory;
032: import org.sakaiproject.metaobj.security.AuthenticationManager;
033: import org.sakaiproject.metaobj.security.AuthorizationFacade;
034: import org.sakaiproject.metaobj.security.AuthorizationFailedException;
035: import org.sakaiproject.metaobj.shared.mgt.HomeFactory;
036: import org.sakaiproject.metaobj.shared.mgt.IdManager;
037: import org.sakaiproject.metaobj.shared.mgt.StructuredArtifactDefinitionManager;
038: import org.sakaiproject.metaobj.shared.model.StructuredArtifactDefinitionBean;
039: import org.sakaiproject.metaobj.utils.mvc.impl.servlet.AbstractFormController;
040: import org.sakaiproject.metaobj.utils.mvc.intf.ListScroll;
041: import org.sakaiproject.metaobj.utils.mvc.intf.ListScrollIndexer;
042: import org.sakaiproject.metaobj.worksite.mgt.WorksiteManager;
043: import org.sakaiproject.site.api.Site;
044: import org.sakaiproject.site.api.ToolConfiguration;
045: import org.sakaiproject.tool.cover.ToolManager;
046: import org.springframework.web.servlet.ModelAndView;
047:
048: abstract public class AbstractStructuredArtifactDefinitionController
049: extends AbstractFormController {
050: protected final Log logger = LogFactory.getLog(getClass());
051: private HomeFactory homeFactory;
052: private AuthenticationManager authManager;
053: //private FileArtifactFinder fileArtifactFinder;
054: private StructuredArtifactDefinitionManager structuredArtifactDefinitionManager;
055: //private RepositoryManager repositoryManager;
056: private IdManager idManager;
057: private AuthorizationFacade authzManager = null;
058: private WorksiteManager worksiteManager = null;
059: private String toolId;
060: private ListScrollIndexer listScrollIndexer;
061:
062: //TODO removed references to repositoryManager and fileArtifactFinder
063:
064: public void checkPermission(String function)
065: throws AuthorizationFailedException {
066: if (getStructuredArtifactDefinitionManager().isGlobal()) {
067: getAuthzManager()
068: .checkPermission(
069: function,
070: getIdManager()
071: .getId(
072: StructuredArtifactDefinitionManager.GLOBAL_SAD_QUALIFIER));
073: } else {
074: getAuthzManager().checkPermission(
075: function,
076: getIdManager().getId(
077: ToolManager.getCurrentPlacement().getId()));
078: }
079:
080: }
081:
082: protected Boolean isMaintainer() {
083: return new Boolean(getAuthzManager()
084: .isAuthorized(
085: WorksiteManager.WORKSITE_MAINTAIN,
086: getIdManager().getId(
087: ToolManager.getCurrentPlacement()
088: .getContext())));
089: }
090:
091: protected ModelAndView prepareListView(Map request, String recentId) {
092: Map model = new HashMap();
093: String worksiteId = getWorksiteManager().getCurrentWorksiteId()
094: .getValue();
095: model.put("isMaintainer", isMaintainer());
096: model.put("worksite", getWorksiteManager().getSite(worksiteId));
097: model.put("sites", getUserSites());
098: ToolConfiguration tool = getWorksiteManager().getTool(
099: ToolManager.getCurrentPlacement().getId());
100: model.put("tool", tool);
101:
102: boolean global = getStructuredArtifactDefinitionManager()
103: .isGlobal();
104: model.put("isGlobal", new Boolean(global));
105:
106: if (global) {
107: model
108: .put(
109: "authZqualifier",
110: getIdManager()
111: .getId(
112: StructuredArtifactDefinitionManager.GLOBAL_SAD_QUALIFIER));
113: } else {
114: if (tool != null) {
115: model.put("authZqualifier", getIdManager().getId(
116: tool.getId()));
117: } else {
118: model.put("authZqualifier", getIdManager().getId(
119: ToolManager.getCurrentPlacement().getId()));
120: }
121: }
122:
123: List types;
124: if (getStructuredArtifactDefinitionManager().isGlobal()) {
125: types = getStructuredArtifactDefinitionManager()
126: .findGlobalHomes();
127: } else {
128: types = getStructuredArtifactDefinitionManager().findHomes(
129: getWorksiteManager().getCurrentWorksiteId(), true,
130: false);
131: }
132:
133: Collections.sort(types);
134: List typesList = new ArrayList(types);
135: if (recentId != null) {
136: request.put(ListScroll.ENSURE_VISIBLE_TAG, ""
137: + getTypeIndex(typesList, recentId));
138: model.put("newFormId", recentId);
139: }
140:
141: types = getListScrollIndexer().indexList(request, model,
142: typesList);
143:
144: model.put("types", types);
145:
146: return new ModelAndView("success", model);
147: }
148:
149: protected int getTypeIndex(List typesList, String recentId) {
150: for (int i = 0; i < typesList.size(); i++) {
151: StructuredArtifactDefinitionBean home = (StructuredArtifactDefinitionBean) typesList
152: .get(i);
153: if (home.getType().getId().getValue().equals(recentId)) {
154: return i;
155: }
156: }
157:
158: return 0;
159: }
160:
161: /**
162: * @return collection of site ids user belongs to, as Strings
163: */
164: protected Map getUserSites() {
165: Collection sites = getWorksiteManager().getUserSites();
166: Map userSites = new HashMap();
167: for (Iterator i = sites.iterator(); i.hasNext();) {
168: Site site = (Site) i.next();
169: userSites.put(site.getId(), site);
170: }
171: return userSites;
172: }
173:
174: /**
175: * @return Returns the authManager.
176: */
177: public AuthenticationManager getAuthManager() {
178: return authManager;
179: }
180:
181: /**
182: * @param authManager The authManager to set.
183: */
184: public void setAuthManager(AuthenticationManager authManager) {
185: this .authManager = authManager;
186: }
187:
188: /**
189: * @return Returns the homeFactory.
190: */
191: public HomeFactory getHomeFactory() {
192: return homeFactory;
193: }
194:
195: /**
196: * @param homeFactory The homeFactory to set.
197: */
198: public void setHomeFactory(HomeFactory homeFactory) {
199: this .homeFactory = homeFactory;
200: }
201:
202: /**
203: * @return Returns the fileArtifactFinder.
204: */
205: //public FileArtifactFinder getFileArtifactFinder() {
206: // return fileArtifactFinder;
207: //}
208: /**
209: * @param fileArtifactFinder The fileArtifactFinder to set.
210: */
211: //public void setFileArtifactFinder(FileArtifactFinder fileArtifactFinder) {
212: // this.fileArtifactFinder = fileArtifactFinder;
213: //}
214: public StructuredArtifactDefinitionManager getStructuredArtifactDefinitionManager() {
215: return structuredArtifactDefinitionManager;
216: }
217:
218: public void setStructuredArtifactDefinitionManager(
219: StructuredArtifactDefinitionManager structuredArtifactDefinitionManager) {
220: this .structuredArtifactDefinitionManager = structuredArtifactDefinitionManager;
221: }
222:
223: /**
224: * @return Returns the repositoryManager.
225: */
226: //public RepositoryManager getRepositoryManager() {
227: // return repositoryManager;
228: //}
229: /**
230: * @param repositoryManager The repositoryManager to set.
231: */
232: //public void setRepositoryManager(RepositoryManager repositoryManager) {
233: // this.repositoryManager = repositoryManager;
234: //}
235: /**
236: * @return Returns the idManager.
237: */
238: public IdManager getIdManager() {
239: return idManager;
240: }
241:
242: /**
243: * @param idManager The idManager to set.
244: */
245: public void setIdManager(IdManager idManager) {
246: this .idManager = idManager;
247: }
248:
249: public AuthorizationFacade getAuthzManager() {
250: return authzManager;
251: }
252:
253: public void setAuthzManager(AuthorizationFacade authzManager) {
254: this .authzManager = authzManager;
255: }
256:
257: public WorksiteManager getWorksiteManager() {
258: return worksiteManager;
259: }
260:
261: public void setWorksiteManager(WorksiteManager worksiteManager) {
262: this .worksiteManager = worksiteManager;
263: }
264:
265: public void setToolId(String toolId) {
266: this .toolId = toolId;
267: }
268:
269: public String getToolId() {
270: return toolId;
271: }
272:
273: public ListScrollIndexer getListScrollIndexer() {
274: return listScrollIndexer;
275: }
276:
277: public void setListScrollIndexer(ListScrollIndexer listScrollIndexer) {
278: this.listScrollIndexer = listScrollIndexer;
279: }
280: }
|