001: /**********************************************************************************
002: * $URL:https://source.sakaiproject.org/svn/osp/trunk/matrix/tool/src/java/org/theospi/portfolio/matrix/control/BaseScaffoldingCellController.java $
003: * $Id:BaseScaffoldingCellController.java 9134 2006-05-08 20:28:42Z chmaurer@iupui.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2005, 2006, 2007 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.HashSet;
023: import java.util.Iterator;
024: import java.util.List;
025: import java.util.Map;
026: import java.util.Set;
027:
028: import org.sakaiproject.assignment.taggable.api.TaggingManager;
029: import org.sakaiproject.metaobj.shared.mgt.IdManager;
030: import org.sakaiproject.metaobj.shared.model.Id;
031: import org.sakaiproject.tool.api.SessionManager;
032: import org.theospi.portfolio.guidance.mgt.GuidanceManager;
033: import org.theospi.portfolio.guidance.model.Guidance;
034: import org.theospi.portfolio.matrix.MatrixFunctionConstants;
035: import org.theospi.portfolio.matrix.MatrixManager;
036: import org.theospi.portfolio.matrix.model.Cell;
037: import org.theospi.portfolio.matrix.model.ScaffoldingCell;
038: import org.theospi.portfolio.matrix.model.WizardPageDefinition;
039: import org.theospi.portfolio.security.AuthorizationFacade;
040: import org.theospi.portfolio.workflow.mgt.WorkflowManager;
041: import org.theospi.portfolio.workflow.model.Workflow;
042:
043: public class BaseScaffoldingCellController {
044:
045: private AuthorizationFacade authzManager;
046:
047: private MatrixManager matrixManager;
048:
049: private IdManager idManager;
050:
051: private GuidanceManager guidanceManager;
052:
053: private WorkflowManager workflowManager;
054:
055: private TaggingManager taggingManager;
056:
057: private SessionManager sessionManager;
058:
059: protected static final String PROVIDERS_PARAM = "providers";
060:
061: public Object fillBackingObject(Object incomingModel, Map request,
062: Map session, Map application) throws Exception {
063: ScaffoldingCell scaffoldingCell = (ScaffoldingCell) incomingModel;
064: if (request
065: .get(EditedScaffoldingStorage.STORED_SCAFFOLDING_FLAG) == null
066: && session
067: .get(EditedScaffoldingStorage.STORED_SCAFFOLDING_FLAG) == null) {
068: Id sCellId = ((ScaffoldingCell) incomingModel).getId();
069: if (sCellId == null) {
070: sCellId = getIdManager().getId(
071: (String) request.get("scaffoldingCell_id"));
072: }
073:
074: scaffoldingCell = getMatrixManager().getScaffoldingCell(
075: sCellId);
076: EditedScaffoldingStorage sessionBean = new EditedScaffoldingStorage(
077: scaffoldingCell);
078: session
079: .put(
080: EditedScaffoldingStorage.EDITED_SCAFFOLDING_STORAGE_SESSION_KEY,
081: sessionBean);
082: } else {
083: EditedScaffoldingStorage sessionBean = (EditedScaffoldingStorage) session
084: .get(EditedScaffoldingStorage.EDITED_SCAFFOLDING_STORAGE_SESSION_KEY);
085: scaffoldingCell = sessionBean.getScaffoldingCell();
086: }
087: // Check for guidance
088: checkForGuidance(session, scaffoldingCell);
089: // Traversing the collection to un-lazily load
090: scaffoldingCell.getWizardPageDefinition().getEvalWorkflows()
091: .size();
092: for (Iterator i = scaffoldingCell.getWizardPageDefinition()
093: .getEvalWorkflows().iterator(); i.hasNext();) {
094: Workflow w = (Workflow) i.next();
095: w.getItems().size();
096: }
097:
098: getMatrixManager().removeFromSession(scaffoldingCell);
099: scaffoldingCell.getScaffolding().isPublished();
100: return scaffoldingCell;
101: }
102:
103: protected void checkForGuidance(Map session,
104: ScaffoldingCell scaffoldingCell) {
105: if (session.get(GuidanceManager.CURRENT_GUIDANCE) != null) {
106: Guidance guidance = (Guidance) session
107: .get(GuidanceManager.CURRENT_GUIDANCE);
108: scaffoldingCell.setGuidanceId(guidance.getId());
109:
110: session.remove(GuidanceManager.CURRENT_GUIDANCE);
111: }
112: if (scaffoldingCell.getGuidanceId() != null
113: && scaffoldingCell.getGuidance() == null) {
114: scaffoldingCell.setGuidance(getGuidanceManager()
115: .getGuidance(scaffoldingCell.getGuidanceId()));
116: scaffoldingCell.setGuidanceId(null);
117: }
118: }
119:
120: protected void saveScaffoldingCell(Map request,
121: ScaffoldingCell scaffoldingCell) {
122:
123: getMatrixManager().removeFromSession(scaffoldingCell);
124: ScaffoldingCell oldScaffoldingCell = getMatrixManager()
125: .getScaffoldingCell(scaffoldingCell.getRootCriterion(),
126: scaffoldingCell.getLevel());
127: // String oldStatus =
128: // matrixManager.getScaffoldingCellsStatus(scaffoldingCell.getId());
129: getMatrixManager().removeFromSession(oldScaffoldingCell);
130:
131: String oldStatus = oldScaffoldingCell.getInitialStatus();
132: scaffoldingCell.getWizardPageDefinition().setEvalWorkflows(
133: new HashSet(createEvalWorkflows(scaffoldingCell
134: .getWizardPageDefinition())));
135: getMatrixManager().storeScaffoldingCell(scaffoldingCell);
136: List cells = getMatrixManager().getCellsByScaffoldingCell(
137: scaffoldingCell.getId());
138: for (Iterator iter = cells.iterator(); iter.hasNext();) {
139: Cell cell = (Cell) iter.next();
140: if (!oldStatus.equals(scaffoldingCell.getInitialStatus())
141: && (cell.getStatus().equals(
142: MatrixFunctionConstants.LOCKED_STATUS) || cell
143: .getStatus()
144: .equals(
145: MatrixFunctionConstants.READY_STATUS))) {
146: cell.setStatus(scaffoldingCell.getInitialStatus());
147: getMatrixManager().storeCell(cell);
148: }
149: }
150: if (scaffoldingCell.getDeleteGuidanceId() != null) {
151: Guidance guidance = getGuidanceManager().getGuidance(
152: scaffoldingCell.getDeleteGuidanceId());
153: getGuidanceManager().deleteGuidance(guidance);
154: }
155: }
156:
157: protected Set createEvalWorkflows(WizardPageDefinition wpd) {
158: return getWorkflowManager().createEvalWorkflows(wpd);
159: }
160:
161: public AuthorizationFacade getAuthzManager() {
162: return authzManager;
163: }
164:
165: public void setAuthzManager(AuthorizationFacade authzManager) {
166: this .authzManager = authzManager;
167: }
168:
169: public MatrixManager getMatrixManager() {
170: return matrixManager;
171: }
172:
173: public void setMatrixManager(MatrixManager matrixManager) {
174: this .matrixManager = matrixManager;
175: }
176:
177: public IdManager getIdManager() {
178: return idManager;
179: }
180:
181: public void setIdManager(IdManager idManager) {
182: this .idManager = idManager;
183: }
184:
185: /**
186: * @return Returns the guidanceManager.
187: */
188: public GuidanceManager getGuidanceManager() {
189: return guidanceManager;
190: }
191:
192: /**
193: * @param guidanceManager
194: * The guidanceManager to set.
195: */
196: public void setGuidanceManager(GuidanceManager guidanceManager) {
197: this .guidanceManager = guidanceManager;
198: }
199:
200: /**
201: * @return Returns the workflowManager.
202: */
203: public WorkflowManager getWorkflowManager() {
204: return workflowManager;
205: }
206:
207: /**
208: * @param workflowManager
209: * The workflowManager to set.
210: */
211: public void setWorkflowManager(WorkflowManager workflowManager) {
212: this .workflowManager = workflowManager;
213: }
214:
215: public TaggingManager getTaggingManager() {
216: return taggingManager;
217: }
218:
219: public void setTaggingManager(TaggingManager taggingManager) {
220: this .taggingManager = taggingManager;
221: }
222:
223: public SessionManager getSessionManager() {
224: return sessionManager;
225: }
226:
227: public void setSessionManager(SessionManager sessionManager) {
228: this.sessionManager = sessionManager;
229: }
230: }
|