001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/osp/tags/sakai_2-4-1/matrix/tool/src/java/org/theospi/portfolio/matrix/control/SubmitCellConfirmationController.java $
003: * $Id: SubmitCellConfirmationController.java 18535 2006-11-29 18:32:53Z 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.shared.mgt.IdManager;
026: import org.sakaiproject.metaobj.shared.model.Id;
027: import org.sakaiproject.metaobj.utils.mvc.intf.CustomCommandController;
028: import org.sakaiproject.metaobj.utils.mvc.intf.LoadObjectController;
029: import org.springframework.validation.Errors;
030: import org.springframework.web.servlet.ModelAndView;
031: import org.theospi.portfolio.matrix.MatrixManager;
032: import org.theospi.portfolio.matrix.WizardPageHelper;
033: import org.theospi.portfolio.matrix.model.Cell;
034: import org.theospi.portfolio.matrix.model.WizardPage;
035: import org.theospi.portfolio.wizard.WizardFunctionConstants;
036: import org.theospi.portfolio.wizard.mgt.WizardManager;
037: import org.theospi.portfolio.wizard.model.WizardPageSequence;
038: import org.theospi.portfolio.wizard.model.Wizard;
039:
040: /**
041: * @author chmaurer
042: */
043: public class SubmitCellConfirmationController implements
044: LoadObjectController, CustomCommandController {
045:
046: IdManager idManager = null;
047: MatrixManager matrixManager = null;
048: WizardManager wizardManager = null;
049:
050: /* (non-Javadoc)
051: * @see org.theospi.utils.mvc.intf.CustomCommandController#formBackingObject(java.util.Map, java.util.Map, java.util.Map)
052: */
053: public Object formBackingObject(Map request, Map session,
054: Map application) {
055: return new HashMap();
056: }
057:
058: /* (non-Javadoc)
059: * @see org.theospi.utils.mvc.intf.LoadObjectController#fillBackingObject(java.lang.Object, java.util.Map, java.util.Map, java.util.Map)
060: */
061: public Object fillBackingObject(Object incomingModel, Map request,
062: Map session, Map application) throws Exception {
063: return incomingModel;
064: }
065:
066: /* (non-Javadoc)
067: * @see org.theospi.utils.mvc.intf.Controller#handleRequest(java.lang.Object, java.util.Map, java.util.Map, java.util.Map, org.springframework.validation.Errors)
068: */
069: public ModelAndView handleRequest(Object requestModel, Map request,
070: Map session, Map application, Errors errors) {
071: boolean isCellPage = false;
072: String view = "continueSeq";
073:
074: WizardPage page = (WizardPage) session
075: .get(WizardPageHelper.WIZARD_PAGE);
076:
077: Cell cell = null;
078: if (page == null) {
079: Id pageId = idManager
080: .getId((String) request.get("page_id"));
081: cell = getMatrixManager().getCellFromPage(pageId);
082: page = cell.getWizardPage();
083: isCellPage = true;
084: } else {
085: WizardPageSequence seq = wizardManager
086: .getWizardPageSeqByDef(page.getPageDefinition()
087: .getId());
088:
089: if (seq.getCategory().getWizard().getType().equals(
090: WizardFunctionConstants.WIZARD_TYPE_HIERARCHICAL))
091: view = "continueHier";
092: }
093: String submitAction = (String) request.get("submit");
094: String cancelAction = (String) request.get("cancel");
095: if (submitAction != null) {
096: if (!isCellPage) {
097: getMatrixManager().submitPageForEvaluation(page);
098: session.put("altDoneURL", "submitWizardPage");
099: session.put("submittedPage", page);
100:
101: if (isLast(session)) {
102: view = "done";
103: }
104:
105: return new ModelAndView(view, "page_id", page.getId()
106: .getValue());
107: } else {
108: getMatrixManager().submitCellForEvaluation(cell);
109: }
110: return new ModelAndView(view, "page_id", page.getId()
111: .getValue());
112: }
113: if (cancelAction != null) {
114: // the current page is set to the next page after the submitted page for confirmation.
115: // So the current step needs to be rolled back
116: Object stepObj = (Object) session
117: .get(WizardPageHelper.SEQUENTIAL_WIZARD_CURRENT_STEP);
118: if (stepObj != null && stepObj instanceof Integer
119: && !isLast(session)) {
120: session
121: .put(
122: WizardPageHelper.SEQUENTIAL_WIZARD_CURRENT_STEP,
123: new Integer(((Integer) stepObj)
124: .intValue() - 1));
125: }
126: return new ModelAndView(view, "page_id", page.getId()
127: .getValue());
128: }
129: return new ModelAndView("success", "page", page);
130: }
131:
132: protected boolean isLast(Map session) {
133: return session.get(WizardPageHelper.IS_LAST_STEP) != null;
134: }
135:
136: /**
137: * @return Returns the idManager.
138: */
139: public IdManager getIdManager() {
140: return idManager;
141: }
142:
143: /**
144: * @param idManager The idManager to set.
145: */
146: public void setIdManager(IdManager idManager) {
147: this .idManager = idManager;
148: }
149:
150: /**
151: * @return Returns the matrixManager.
152: */
153: public MatrixManager getMatrixManager() {
154: return matrixManager;
155: }
156:
157: /**
158: * @param matrixManager The matrixManager to set.
159: */
160: public void setMatrixManager(MatrixManager matrixManager) {
161: this .matrixManager = matrixManager;
162: }
163:
164: public WizardManager getWizardManager() {
165: return wizardManager;
166: }
167:
168: public void setWizardManager(WizardManager wizardManager) {
169: this.wizardManager = wizardManager;
170: }
171: }
|