001: /**********************************************************************************
002: * $URL:https://source.sakaiproject.org/svn/osp/trunk/matrix/tool/src/java/org/theospi/portfolio/matrix/control/DeleteLevelController.java $
003: * $Id:DeleteLevelController.java 9134 2006-05-08 20:28:42Z 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.matrix.control;
021:
022: import java.util.HashMap;
023: import java.util.Iterator;
024: import java.util.Map;
025: import java.util.Set;
026:
027: import org.apache.commons.logging.Log;
028: import org.apache.commons.logging.LogFactory;
029: import org.sakaiproject.content.api.LockManager;
030: import org.sakaiproject.metaobj.utils.mvc.intf.Controller;
031: import org.springframework.validation.Errors;
032: import org.springframework.web.servlet.ModelAndView;
033: import org.theospi.portfolio.matrix.model.Cell;
034: import org.theospi.portfolio.matrix.model.Scaffolding;
035: import org.theospi.portfolio.matrix.model.ScaffoldingCell;
036:
037: /**
038: * @author chmaurer
039: */
040: public class DeleteLevelController implements Controller {
041:
042: protected final Log logger = LogFactory.getLog(getClass());
043:
044: private LockManager lockManager;
045:
046: /* (non-Javadoc)
047: * @see org.theospi.utils.mvc.intf.Controller#handleRequest(java.lang.Object, java.util.Map, java.util.Map, java.util.Map, org.springframework.validation.Errors)
048: */
049: public ModelAndView handleRequest(Object requestModel, Map request,
050: Map session, Map application, Errors errors) {
051: EditedScaffoldingStorage sessionBean = (EditedScaffoldingStorage) session
052: .get(EditedScaffoldingStorage.EDITED_SCAFFOLDING_STORAGE_SESSION_KEY);
053: Scaffolding scaffolding = sessionBean.getScaffolding();
054: Map model = new HashMap();
055:
056: String levelId = (String) request.get("level_id");
057: String levelIndex = (String) request.get("index");
058:
059: if (levelIndex != null) {
060: scaffolding.getLevels()
061: .remove(Integer.parseInt(levelIndex));
062: }
063:
064: if (levelId != null && !levelId.equals("")) {
065: Set scaffoldingCells = scaffolding.getScaffoldingCells();
066: for (Iterator iter = scaffoldingCells.iterator(); iter
067: .hasNext();) {
068: ScaffoldingCell sCell = (ScaffoldingCell) iter.next();
069: if (sCell.getLevel().getId().getValue().equals(levelId)) {
070: Set cells = sCell.getCells();
071: for (Iterator i = cells.iterator(); i.hasNext();) {
072: Cell cell = (Cell) i.next();
073: lockManager.removeAllLocks(cell.getId()
074: .getValue());
075: i.remove();
076: }
077:
078: iter.remove();
079: }
080: }
081: }
082:
083: sessionBean.setScaffolding(scaffolding);
084: session
085: .put(
086: EditedScaffoldingStorage.EDITED_SCAFFOLDING_STORAGE_SESSION_KEY,
087: sessionBean);
088:
089: model.put(EditedScaffoldingStorage.STORED_SCAFFOLDING_FLAG,
090: "true");
091: return new ModelAndView("success", model);
092: }
093:
094: public LockManager getLockManager() {
095: return lockManager;
096: }
097:
098: public void setLockManager(LockManager lockManager) {
099: this.lockManager = lockManager;
100: }
101: }
|