001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/osp/tags/sakai_2-4-1/matrix/tool/src/java/org/theospi/portfolio/matrix/control/DeleteScaffoldingConfirmationController.java $
003: * $Id: DeleteScaffoldingConfirmationController.java 21847 2007-02-22 20:42:58Z jmpease@syr.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2007 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.matrix.control;
021:
022: import java.util.HashMap;
023: import java.util.Map;
024: import java.util.List;
025: import java.util.Iterator;
026: import java.util.Set;
027:
028: import org.apache.commons.logging.Log;
029: import org.apache.commons.logging.LogFactory;
030: import org.sakaiproject.assignment.taggable.api.TaggableActivity;
031: import org.sakaiproject.assignment.taggable.api.TaggingManager;
032: import org.sakaiproject.assignment.taggable.api.TaggingProvider;
033: import org.sakaiproject.exception.PermissionException;
034: import org.sakaiproject.metaobj.shared.mgt.IdManager;
035: import org.sakaiproject.metaobj.shared.model.Id;
036: import org.sakaiproject.metaobj.utils.mvc.intf.Controller;
037: import org.springframework.validation.Errors;
038: import org.springframework.web.servlet.ModelAndView;
039: import org.theospi.portfolio.matrix.MatrixManager;
040: import org.theospi.portfolio.security.AuthorizationFacade;
041: import org.theospi.portfolio.wizard.taggable.api.WizardActivityProducer;
042: import org.theospi.portfolio.matrix.MatrixFunctionConstants;
043: import org.theospi.portfolio.matrix.model.Matrix;
044: import org.theospi.portfolio.matrix.model.Scaffolding;
045: import org.theospi.portfolio.matrix.model.ScaffoldingCell;
046:
047: /**
048: * Delete scaffolding and associated matrix data if user confirms
049: */
050: public class DeleteScaffoldingConfirmationController implements
051: Controller {
052:
053: private MatrixManager matrixManager = null;
054:
055: private IdManager idManager = null;
056:
057: private AuthorizationFacade authzManager = null;
058:
059: private TaggingManager taggingManager = null;
060:
061: private WizardActivityProducer wizardActivityProducer = null;
062:
063: private final Log logger = LogFactory.getLog(getClass());
064:
065: /*
066: * (non-Javadoc)
067: *
068: * @see org.theospi.utils.mvc.intf.Controller#handleRequest(java.lang.Object,
069: * java.util.Map, java.util.Map, java.util.Map,
070: * org.springframework.validation.Errors)
071: */
072: public ModelAndView handleRequest(Object requestModel, Map request,
073: Map session, Map application, Errors errors) {
074: String viewName = "success";
075: Id id = idManager.getId((String) request.get("scaffolding_id"));
076: Scaffolding scaffolding = getMatrixManager().getScaffolding(id);
077:
078: Map model = new HashMap();
079: model.put("scaffolding_published", scaffolding.isPublished());
080:
081: String cancel = (String) request.get("cancel");
082: String doit = (String) request.get("continue");
083:
084: if (cancel != null)
085: return new ModelAndView("cancel", model);
086: else if (doit == null)
087: return new ModelAndView("delete", model);
088:
089: getAuthzManager().checkPermission(
090: MatrixFunctionConstants.DELETE_SCAFFOLDING, id);
091:
092: if (scaffolding.getExposedPageId() != null
093: && !scaffolding.getExposedPageId().equals("")) {
094: getMatrixManager().removeExposedMatrixTool(scaffolding);
095: }
096:
097: // First delete any associated matrix data (if published scaffolding)
098: List matrices = getMatrixManager().getMatrices(id);
099: for (Iterator matrixIt = matrices.iterator(); matrixIt
100: .hasNext();) {
101: Matrix matrix = (Matrix) matrixIt.next();
102: getMatrixManager().deleteMatrix(matrix.getId());
103: }
104:
105: // if taggable, remove tags for all page defs
106: try {
107: if (getTaggingManager().isTaggable()) {
108: Set<ScaffoldingCell> cells = scaffolding
109: .getScaffoldingCells();
110: for (ScaffoldingCell cell : cells) {
111: for (TaggingProvider provider : getTaggingManager()
112: .getProviders()) {
113: System.out.println(cell.getTitle());
114: TaggableActivity activity = getWizardActivityProducer()
115: .getActivity(
116: cell.getWizardPageDefinition());
117: provider.removeTags(activity);
118: }
119: }
120: }
121: } catch (PermissionException pe) {
122: logger.error(pe.getMessage(), pe);
123: }
124:
125: // Next delete the scaffolding
126: getMatrixManager().deleteScaffolding(id);
127:
128: return new ModelAndView("success", model);
129: }
130:
131: public AuthorizationFacade getAuthzManager() {
132: return authzManager;
133: }
134:
135: public void setAuthzManager(AuthorizationFacade facade) {
136: authzManager = facade;
137: }
138:
139: public IdManager getIdManager() {
140: return idManager;
141: }
142:
143: public void setIdManager(IdManager idManager) {
144: this .idManager = idManager;
145: }
146:
147: public MatrixManager getMatrixManager() {
148: return matrixManager;
149: }
150:
151: public void setMatrixManager(MatrixManager matrixManager) {
152: this .matrixManager = matrixManager;
153: }
154:
155: public TaggingManager getTaggingManager() {
156: return taggingManager;
157: }
158:
159: public void setTaggingManager(TaggingManager taggingManager) {
160: this .taggingManager = taggingManager;
161: }
162:
163: public WizardActivityProducer getWizardActivityProducer() {
164: return wizardActivityProducer;
165: }
166:
167: public void setWizardActivityProducer(
168: WizardActivityProducer wizardActivityProducer) {
169: this.wizardActivityProducer = wizardActivityProducer;
170: }
171: }
|