001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/osp/tags/sakai_2-4-1/matrix/tool/src/java/org/theospi/portfolio/matrix/control/ManageCellStatusController.java $
003: * $Id: ManageCellStatusController.java 21731 2007-02-19 14:43:12Z 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.Iterator;
024: import java.util.List;
025: import java.util.Map;
026:
027: import org.sakaiproject.content.api.LockManager;
028: import org.sakaiproject.metaobj.shared.mgt.IdManager;
029: import org.sakaiproject.metaobj.shared.model.Id;
030: import org.sakaiproject.metaobj.utils.mvc.intf.Controller;
031: import org.springframework.validation.Errors;
032: import org.springframework.web.servlet.ModelAndView;
033: import org.theospi.portfolio.matrix.MatrixFunctionConstants;
034: import org.theospi.portfolio.matrix.MatrixManager;
035: import org.theospi.portfolio.matrix.WizardPageHelper;
036: import org.theospi.portfolio.matrix.model.Attachment;
037: import org.theospi.portfolio.matrix.model.WizardPage;
038: import org.theospi.portfolio.matrix.model.WizardPageForm;
039: import org.theospi.portfolio.matrix.model.impl.MatrixContentEntityProducer;
040: import org.theospi.portfolio.review.mgt.ReviewManager;
041: import org.theospi.portfolio.review.model.Review;
042:
043: public class ManageCellStatusController implements Controller {
044:
045: private MatrixManager matrixManager = null;
046: private IdManager idManager = null;
047: private LockManager lockManager = null;
048: private ReviewManager reviewManager = null;
049:
050: /* (non-Javadoc)
051: * @see org.theospi.utils.mvc.intf.Controller#handleRequest(java.lang.Object, java.util.Map, java.util.Map, java.util.Map, org.springframework.validation.Errors)
052: */
053:
054: public ModelAndView handleRequest(Object requestModel, Map request,
055: Map session, Map application, Errors errors) {
056: String viewName = "success";
057: Id id = idManager.getId((String) request.get("page_id"));
058:
059: Map<String, Object> model = new HashMap<String, Object>();
060: model.put("page_id", id);
061: //Cell cell = getMatrixManager().getCellFromPage(id);
062: WizardPage page = getMatrixManager().getWizardPage(id);
063: String newStatus = getNewPageStatus(page);
064: model.put("newStatus", newStatus);
065: model.put("readOnlyMatrix", (String) request
066: .get("readOnlyMatrix"));
067:
068: String cancel = (String) request.get("cancel");
069: String next = (String) request.get("continue");
070: String setSingle = (String) request.get("changeUserOnly");
071: String setAll = (String) request.get("changeAll");
072:
073: if (cancel != null) {
074: viewName = "done";
075: } else if (next != null && setSingle != null) {
076: viewName = "done";
077: setPageStatus(page, newStatus);
078: } else if (next != null && setAll != null) {
079: //Set allCells = cell.getScaffoldingCell().getCells();
080: List allPages = getMatrixManager().getPagesByPageDef(
081: page.getPageDefinition().getId());
082: //cell.getWizardPage().getPageDefinition().get
083: viewName = "done";
084: for (Iterator iter = allPages.iterator(); iter.hasNext();) {
085: WizardPage iterPage = (WizardPage) iter.next();
086: setPageStatus(iterPage, newStatus);
087: }
088: }
089:
090: session.put(WizardPageHelper.WIZARD_OWNER, page.getOwner());
091: return new ModelAndView(viewName, model);
092: }
093:
094: protected void setPageStatus(WizardPage page, String status) {
095: //Set the status only if it needs to be changed
096: if (!page.getStatus().equals(status)) {
097: page.setStatus(status);
098: getMatrixManager().storePage(page);
099: if (status.equals(MatrixFunctionConstants.READY_STATUS)) {
100: //Unlock page's content
101: for (Iterator iter = page.getAttachments().iterator(); iter
102: .hasNext();) {
103: Attachment att = (Attachment) iter.next();
104: getLockManager().removeLock(
105: att.getArtifactId().getValue(),
106: page.getId().getValue());
107: }
108: for (Iterator iter2 = page.getPageForms().iterator(); iter2
109: .hasNext();) {
110: WizardPageForm form = (WizardPageForm) iter2.next();
111: getLockManager().removeLock(
112: form.getArtifactId().getValue(),
113: page.getId().getValue());
114: }
115: //unlock reflection form too
116: List reflections = getReviewManager()
117: .getReviewsByParentAndType(
118: page.getId().getValue(),
119: Review.REFLECTION_TYPE,
120: page.getPageDefinition().getSiteId(),
121: MatrixContentEntityProducer.MATRIX_PRODUCER);
122: for (Iterator iter3 = reflections.iterator(); iter3
123: .hasNext();) {
124: Review review = (Review) iter3.next();
125: getLockManager().removeLock(
126: review.getReviewContent().getValue(),
127: page.getId().getValue());
128: }
129: }
130: }
131: }
132:
133: protected String getNewPageStatus(WizardPage page) {
134: //TODO setting to READY for now no matter what the previous status is
135: String status = page.getStatus();
136: /*
137: if (cell.getStatus().equals(MatrixFunctionConstants.LOCKED_STATUS))
138: status = MatrixFunctionConstants.READY_STATUS;
139: else if (cell.getStatus().equals(MatrixFunctionConstants.READY_STATUS))
140: status = MatrixFunctionConstants.LOCKED_STATUS;
141: */
142: status = MatrixFunctionConstants.READY_STATUS;
143: return status;
144: }
145:
146: public IdManager getIdManager() {
147: return idManager;
148: }
149:
150: public void setIdManager(IdManager idManager) {
151: this .idManager = idManager;
152: }
153:
154: public MatrixManager getMatrixManager() {
155: return matrixManager;
156: }
157:
158: public void setMatrixManager(MatrixManager matrixManager) {
159: this .matrixManager = matrixManager;
160: }
161:
162: public LockManager getLockManager() {
163: return lockManager;
164: }
165:
166: public void setLockManager(LockManager lockManager) {
167: this .lockManager = lockManager;
168: }
169:
170: /**
171: * @return the reviewManager
172: */
173: public ReviewManager getReviewManager() {
174: return reviewManager;
175: }
176:
177: /**
178: * @param reviewManager the reviewManager to set
179: */
180: public void setReviewManager(ReviewManager reviewManager) {
181: this.reviewManager = reviewManager;
182: }
183: }
|