001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/osp/tags/sakai_2-4-1/matrix/tool/src/java/org/theospi/portfolio/matrix/control/BaseListObjectController.java $
003: * $Id: BaseListObjectController.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.Map;
024:
025: import org.sakaiproject.metaobj.utils.mvc.intf.CustomCommandController;
026: import org.sakaiproject.metaobj.utils.mvc.intf.FormController;
027: import org.sakaiproject.metaobj.utils.mvc.intf.LoadObjectController;
028: import org.springframework.validation.Errors;
029: import org.springframework.web.servlet.ModelAndView;
030: import org.theospi.portfolio.matrix.model.Criterion;
031: import org.theospi.portfolio.matrix.model.CriterionTransport;
032: import org.theospi.portfolio.matrix.model.Level;
033: import org.theospi.portfolio.matrix.model.LevelTransport;
034: import org.theospi.portfolio.matrix.model.Scaffolding;
035:
036: /**
037: * @author chmaurer
038: */
039: public abstract class BaseListObjectController implements
040: FormController, LoadObjectController, CustomCommandController {
041:
042: /* (non-Javadoc)
043: * @see org.theospi.utils.mvc.intf.FormController#referenceData(java.util.Map, java.lang.Object, org.springframework.validation.Errors)
044: */
045: public Map referenceData(Map request, Object command, Errors errors) {
046: Map model = new HashMap();
047: model.put("isInSession",
048: EditedScaffoldingStorage.STORED_SCAFFOLDING_FLAG);
049: return model;
050: }
051:
052: public Object fillBackingObject(Object incomingModel, Map request,
053: Map session, Map application) throws Exception {
054: String index = (String) request.get("index");
055: if (index != null) {
056: EditedScaffoldingStorage sessionBean = (EditedScaffoldingStorage) session
057: .get(EditedScaffoldingStorage.EDITED_SCAFFOLDING_STORAGE_SESSION_KEY);
058: Object obj = null;
059: if (incomingModel instanceof CriterionTransport) {
060: obj = new CriterionTransport((Criterion) sessionBean
061: .getScaffolding().getCriteria().get(
062: Integer.parseInt(index)));
063: } else if (incomingModel instanceof LevelTransport) {
064: obj = new LevelTransport((Level) sessionBean
065: .getScaffolding().getLevels().get(
066: Integer.parseInt(index)));
067: }
068:
069: return obj;
070: }
071: return incomingModel;
072: }
073:
074: public ModelAndView handleRequest(Object requestModel, Map request,
075: Map session, Map application, Errors errors) {
076: EditedScaffoldingStorage sessionBean = (EditedScaffoldingStorage) session
077: .get(EditedScaffoldingStorage.EDITED_SCAFFOLDING_STORAGE_SESSION_KEY);
078: Scaffolding scaffolding = sessionBean.getScaffolding();
079: Map model = new HashMap();
080:
081: String action = (String) request.get("updateAction");
082: if (action != null) {
083: String index = (String) request.get("index");
084: if (requestModel instanceof CriterionTransport) {
085: CriterionTransport obj = (CriterionTransport) requestModel;
086: if (index == null) {
087: scaffolding.getCriteria().add(new Criterion(obj));
088: } else {
089: int idx = Integer.parseInt(index);
090: Criterion criterion = (Criterion) scaffolding
091: .getCriteria().get(idx);
092: criterion.copy(obj);
093: scaffolding.getCriteria().set(idx, criterion);
094: }
095: sessionBean.setScaffolding(scaffolding);
096: } else if (requestModel instanceof LevelTransport) {
097: LevelTransport obj = (LevelTransport) requestModel;
098: if (index == null) {
099: scaffolding.add(new Level(obj));
100: } else {
101: int idx = Integer.parseInt(index);
102: Level level = (Level) scaffolding.getLevels().get(
103: idx);
104: level.copy(obj);
105: scaffolding.getLevels().set(idx, level);
106: }
107: sessionBean.setScaffolding(scaffolding);
108: }
109:
110: session
111: .put(
112: EditedScaffoldingStorage.EDITED_SCAFFOLDING_STORAGE_SESSION_KEY,
113: sessionBean);
114: }
115:
116: model.put(EditedScaffoldingStorage.STORED_SCAFFOLDING_FLAG,
117: "true");
118:
119: return new ModelAndView("success", model);
120: }
121: }
|