001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/osp/tags/sakai_2-4-1/matrix/tool/src/java/org/theospi/portfolio/matrix/control/ViewScaffoldingController.java $
003: * $Id: ViewScaffoldingController.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.HashMap;
024: import java.util.Iterator;
025: import java.util.List;
026: import java.util.Map;
027: import java.util.Set;
028:
029: import org.apache.commons.logging.Log;
030: import org.apache.commons.logging.LogFactory;
031: import org.sakaiproject.metaobj.shared.mgt.IdManager;
032: import org.sakaiproject.metaobj.shared.model.Id;
033: import org.sakaiproject.metaobj.utils.mvc.intf.FormController;
034: import org.sakaiproject.metaobj.utils.mvc.intf.LoadObjectController;
035: import org.sakaiproject.metaobj.worksite.mgt.WorksiteManager;
036: import org.sakaiproject.tool.api.ToolManager;
037: import org.springframework.validation.Errors;
038: import org.springframework.web.servlet.ModelAndView;
039: import org.theospi.portfolio.matrix.MatrixManager;
040: import org.theospi.portfolio.matrix.model.Criterion;
041: import org.theospi.portfolio.matrix.model.Level;
042: import org.theospi.portfolio.matrix.model.Scaffolding;
043: import org.theospi.portfolio.matrix.model.ScaffoldingCell;
044: import org.theospi.portfolio.security.AuthorizationFacade;
045: import org.theospi.portfolio.workflow.mgt.WorkflowManager;
046:
047: /**
048: * @author chmaurer
049: */
050: public class ViewScaffoldingController implements FormController,
051: LoadObjectController {
052:
053: protected final Log logger = LogFactory.getLog(getClass());
054: private MatrixManager matrixManager;
055: private IdManager idManager;
056: private WorksiteManager worksiteManager = null;
057: private AuthorizationFacade authzManager;
058: private ToolManager toolManager;
059: private WorkflowManager workflowManager;
060:
061: /* (non-Javadoc)
062: * @see org.theospi.utils.mvc.intf.LoadObjectController#fillBackingObject(java.lang.Object, java.util.Map, java.util.Map, java.util.Map)
063: */
064: public Object fillBackingObject(Object incomingModel, Map request,
065: Map session, Map application) throws Exception {
066:
067: MatrixGridBean grid = (MatrixGridBean) incomingModel;
068:
069: Id sId = getIdManager().getId(
070: (String) request.get("scaffolding_id"));
071: Scaffolding scaffolding = getMatrixManager()
072: .getScaffolding(sId);
073:
074: List levels = scaffolding.getLevels();
075: List criteria = scaffolding.getCriteria();
076: List matrixContents = new ArrayList();
077: Criterion criterion = new Criterion();
078: Level level = new Level();
079: List row = new ArrayList();
080:
081: Set cells = scaffolding.getScaffoldingCells();
082:
083: for (Iterator criteriaIterator = criteria.iterator(); criteriaIterator
084: .hasNext();) {
085: row = new ArrayList();
086: criterion = (Criterion) criteriaIterator.next();
087: for (Iterator levelsIterator = levels.iterator(); levelsIterator
088: .hasNext();) {
089: level = (Level) levelsIterator.next();
090: ScaffoldingCell scaffoldingCell = getScaffoldingCell(
091: cells, criterion, level);
092:
093: row.add(scaffoldingCell);
094: }
095: matrixContents.add(row);
096: }
097:
098: grid.setScaffolding(scaffolding);
099: grid.setColumnLabels(levels);
100: grid.setRowLabels(criteria);
101: grid.setMatrixContents(matrixContents);
102:
103: //Make sure these are not in session.
104: session
105: .remove(EditedScaffoldingStorage.STORED_SCAFFOLDING_FLAG);
106: session
107: .remove(EditedScaffoldingStorage.EDITED_SCAFFOLDING_STORAGE_SESSION_KEY);
108:
109: return incomingModel;
110: }
111:
112: /* (non-Javadoc)
113: * @see org.theospi.utils.mvc.intf.FormController#referenceData(java.util.Map, java.lang.Object, org.springframework.validation.Errors)
114: */
115: public Map referenceData(Map request, Object command, Errors errors) {
116: Map model = new HashMap();
117: String worksiteId = getWorksiteManager().getCurrentWorksiteId()
118: .getValue();
119: model.put("worksite", getWorksiteManager().getSite(worksiteId));
120: model.put("tool", getToolManager().getCurrentPlacement());
121:
122: return model;
123: }
124:
125: /* (non-Javadoc)
126: * @see org.theospi.utils.mvc.intf.Controller#handleRequest(java.lang.Object, java.util.Map, java.util.Map, java.util.Map, org.springframework.validation.Errors)
127: */
128: public ModelAndView handleRequest(Object requestModel, Map request,
129: Map session, Map application, Errors errors) {
130: Map model = new HashMap();
131: model.put(EditedScaffoldingStorage.STORED_SCAFFOLDING_FLAG,
132: "false");
133: return new ModelAndView("success", model);
134: }
135:
136: private ScaffoldingCell getScaffoldingCell(Set cells,
137: Criterion criterion, Level level) {
138: for (Iterator iter = cells.iterator(); iter.hasNext();) {
139: ScaffoldingCell scaffoldingCell = (ScaffoldingCell) iter
140: .next();
141: if (scaffoldingCell.getRootCriterion().getId().getValue()
142: .equals(criterion.getId().getValue())
143: && scaffoldingCell.getLevel().getId().getValue()
144: .equals(level.getId().getValue())) {
145: return scaffoldingCell;
146: }
147: }
148: return null;
149: }
150:
151: /**
152: * @return Returns the matrixManager.
153: */
154: public MatrixManager getMatrixManager() {
155: return matrixManager;
156: }
157:
158: /**
159: * @param matrixManager The matrixManager to set.
160: */
161: public void setMatrixManager(MatrixManager matrixManager) {
162: this .matrixManager = matrixManager;
163: }
164:
165: /**
166: * @return Returns the idManager.
167: */
168: public IdManager getIdManager() {
169: return idManager;
170: }
171:
172: /**
173: * @param idManager The idManager to set.
174: */
175: public void setIdManager(IdManager idManager) {
176: this .idManager = idManager;
177: }
178:
179: /**
180: * @return Returns the worksiteManager.
181: */
182: public WorksiteManager getWorksiteManager() {
183: return worksiteManager;
184: }
185:
186: /**
187: * @param worksiteManager The worksiteManager to set.
188: */
189: public void setWorksiteManager(WorksiteManager worksiteManager) {
190: this .worksiteManager = worksiteManager;
191: }
192:
193: /**
194: * @return Returns the authzManager.
195: */
196: public AuthorizationFacade getAuthzManager() {
197: return authzManager;
198: }
199:
200: /**
201: * @param authzManager The authzManager to set.
202: */
203: public void setAuthzManager(AuthorizationFacade authzManager) {
204: this .authzManager = authzManager;
205: }
206:
207: public ToolManager getToolManager() {
208: return toolManager;
209: }
210:
211: public void setToolManager(ToolManager toolManager) {
212: this .toolManager = toolManager;
213: }
214:
215: /**
216: * @return Returns the workflowManager.
217: */
218: public WorkflowManager getWorkflowManager() {
219: return workflowManager;
220: }
221:
222: /**
223: * @param workflowManager The workflowManager to set.
224: */
225: public void setWorkflowManager(WorkflowManager workflowManager) {
226: this.workflowManager = workflowManager;
227: }
228: }
|