001: /**********************************************************************************
002: * $URL:https://source.sakaiproject.org/svn/osp/trunk/matrix/tool/src/java/org/theospi/portfolio/matrix/control/WizardPageDefinitionController.java $
003: * $Id:WizardPageDefinitionController.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.ArrayList;
023: import java.util.HashSet;
024: import java.util.List;
025: import java.util.Map;
026: import java.util.Iterator;
027:
028: import org.sakaiproject.metaobj.utils.mvc.intf.CancelableController;
029: import org.sakaiproject.tool.cover.ToolManager;
030: import org.springframework.validation.Errors;
031: import org.springframework.web.servlet.ModelAndView;
032: import org.theospi.portfolio.matrix.WizardPageHelper;
033: import org.theospi.portfolio.matrix.model.ScaffoldingCell;
034: import org.theospi.portfolio.matrix.model.WizardPage;
035: import org.theospi.portfolio.matrix.model.WizardPageDefinition;
036: import org.theospi.portfolio.wizard.WizardFunctionConstants;
037: import org.theospi.portfolio.wizard.model.WizardPageSequence;
038:
039: /**
040: * Created by IntelliJ IDEA.
041: * User: John Ellis
042: * Date: Jan 18, 2006
043: * Time: 3:18:48 PM
044: * To change this template use File | Settings | File Templates.
045: */
046: public class WizardPageDefinitionController extends
047: EditScaffoldingCellController implements CancelableController {
048:
049: private List pageList = null;
050:
051: /* (non-Javadoc)
052: * @see org.theospi.utils.mvc.intf.FormController#referenceData(java.util.Map, java.lang.Object, org.springframework.validation.Errors)
053: */
054: public Map referenceData(Map request, Object command, Errors errors) {
055: Map model = super .referenceData(request, command, errors);
056:
057: ScaffoldingCell sCell = (ScaffoldingCell) command;
058:
059: boolean wizardPublished = false;
060:
061: if (sCell.getWizardPageDefinition() != null
062: && getWizardManager() != null)
063: if (sCell.getWizardPageDefinition().getId() != null) {
064: WizardPageSequence wps = getWizardManager()
065: .getWizardPageSeqByDef(
066: sCell.getWizardPageDefinition().getId());
067: if (wps.getCategory() != null)
068: if (wps.getCategory().getWizard() != null)
069: wizardPublished = wps.getCategory().getWizard()
070: .isPublished();
071: }
072:
073: model.put("wizardPublished", new Boolean(wizardPublished));
074: model.put("isPageUsed", wizardPublished
075: && isPageUsed(sCell.getWizardPageDefinition()));
076: model.put("helperPage", "true");
077: model.put("isWizard", "true");
078: model.put("pageTitleKey", "title_editWizardPage");
079: model.put("pageInstructionsKey",
080: "instructions_wizardPageSettings");
081: return model;
082: }
083:
084: public Object fillBackingObject(Object incomingModel, Map request,
085: Map session, Map application) throws Exception {
086: Object pages = session.get(WizardPageHelper.WIZARD_PAGE);
087:
088: WizardPageDefinition page = null;
089: if (pages instanceof WizardPageDefinition) {
090: pageList = new ArrayList();
091: pageList.add(pages);
092: }
093: if (pages instanceof List) {
094: pageList = (List) pages;
095: }
096:
097: page = (WizardPageDefinition) pageList.get(0);
098:
099: session.remove(WizardPageHelper.CANCELED);
100: page.setSiteId(ToolManager.getCurrentPlacement().getContext());
101: ScaffoldingCell cell = new ScaffoldingCell();
102: cell.setWizardPageDefinition(page);
103: if (page.getId() == null) {
104: cell.setId(page.getNewId());
105: } else {
106: cell.setId(page.getId());
107: }
108: EditedScaffoldingStorage sessionBean = new EditedScaffoldingStorage(
109: cell);
110: session
111: .put(
112: EditedScaffoldingStorage.EDITED_SCAFFOLDING_STORAGE_SESSION_KEY,
113: sessionBean);
114: checkForGuidance(session, cell);
115: return cell;
116: }
117:
118: public ModelAndView handleRequest(Object requestModel, Map request,
119: Map session, Map application, Errors errors) {
120: return super .handleRequest(requestModel, request, session,
121: application, errors); //To change body of overridden methods use File | Settings | File Templates.
122: }
123:
124: protected boolean isPublished(ScaffoldingCell scaffoldingCell) {
125: return false;
126: }
127:
128: /**
129: ** Determine if any completed wizard page has been 'used'
130: ** (containing reflections,feedback,evaluations and/or added form items)
131: */
132: protected boolean isPageUsed(WizardPageDefinition pagedef) {
133: if (pagedef == null)
134: return false;
135:
136: List pageList = getMatrixManager().getPagesByPageDef(
137: pagedef.getId());
138: for (Iterator pageIt = pageList.iterator(); pageIt.hasNext();) {
139: WizardPage wizardPage = (WizardPage) pageIt.next();
140: String pageId = wizardPage.getId().getValue();
141:
142: if (wizardPage.getReflections() != null
143: && wizardPage.getReflections().size() > 0)
144: return true;
145: if (wizardPage.getPageForms() != null
146: && wizardPage.getPageForms().size() > 0)
147: return true;
148: if (wizardPage.getFeedback() != null
149: && wizardPage.getFeedback().size() > 0)
150: return true;
151: if (wizardPage.getAttachments() != null
152: && wizardPage.getAttachments().size() > 0)
153: return true;
154: if (getReviewManager().getReviewsByParent(pageId) != null
155: && getReviewManager().getReviewsByParent(pageId)
156: .size() > 0)
157: return true;
158: }
159: return false;
160: }
161:
162: protected void saveScaffoldingCell(Map request,
163: ScaffoldingCell scaffoldingCell) {
164: // do nothing... let caller deal with it...
165: scaffoldingCell.getWizardPageDefinition().setEvalWorkflows(
166: new HashSet(super .createEvalWorkflows(scaffoldingCell
167: .getWizardPageDefinition())));
168: }
169:
170: protected void prepareModelWithScaffoldingId(Map model,
171: ScaffoldingCell scaffoldingCell) {
172: // do nothing... don't care about scaffolding id
173: }
174:
175: public boolean isCancel(Map request) {
176: Object cancel = request.get("canceling");
177: if (cancel == null) {
178: return false;
179: }
180: return cancel.equals("true");
181: }
182:
183: public ModelAndView processCancel(Map request, Map session,
184: Map application, Object command, Errors errors)
185: throws Exception {
186: if (getTaggingManager().isTaggable()) {
187: session.remove(PROVIDERS_PARAM);
188: }
189: return new ModelAndView("return", WizardPageHelper.CANCELED,
190: "true");
191: }
192:
193: protected String getGuidanceViewPermission() {
194: return WizardFunctionConstants.VIEW_WIZARDPAGE_GUIDANCE;
195: }
196:
197: protected String getGuidanceEditPermission() {
198: return WizardFunctionConstants.EDIT_WIZARDPAGE_GUIDANCE;
199: }
200:
201: protected String getGuidanceTitle() {
202: return "Guidance for Wizard Page";
203: }
204:
205: protected String getStyleReturnView() {
206: return "page";
207: }
208: }
|