001: /**********************************************************************************
002: * $URL:https://source.sakaiproject.org/svn/osp/trunk/matrix/tool/src/java/org/theospi/portfolio/matrix/control/DeleteCriterionController.java $
003: * $Id:DeleteCriterionController.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 DeleteCriterionController 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 criterionId = (String) request.get("criterion_id");
057: String criterionIndex = (String) request.get("index");
058: if (criterionIndex != null) {
059: scaffolding.getCriteria().remove(
060: Integer.parseInt(criterionIndex));
061: }
062: if (criterionId != null && !criterionId.equals("")) {
063: Set scaffoldingCells = scaffolding.getScaffoldingCells();
064: for (Iterator iter = scaffoldingCells.iterator(); iter
065: .hasNext();) {
066: ScaffoldingCell sCell = (ScaffoldingCell) iter.next();
067: if (sCell.getRootCriterion().getId().getValue().equals(
068: criterionId)) {
069: Set cells = sCell.getCells();
070: for (Iterator i = cells.iterator(); i.hasNext();) {
071: Cell cell = (Cell) i.next();
072: lockManager.removeAllLocks(cell.getId()
073: .getValue());
074: i.remove();
075: }
076:
077: iter.remove();
078: }
079: }
080: }
081:
082: sessionBean.setScaffolding(scaffolding);
083: session
084: .put(
085: EditedScaffoldingStorage.EDITED_SCAFFOLDING_STORAGE_SESSION_KEY,
086: sessionBean);
087:
088: model.put(EditedScaffoldingStorage.STORED_SCAFFOLDING_FLAG,
089: "true");
090: return new ModelAndView("success", model);
091: }
092:
093: public LockManager getLockManager() {
094: return lockManager;
095: }
096:
097: public void setLockManager(LockManager lockManager) {
098: this.lockManager = lockManager;
099: }
100: }
|