001: /**********************************************************************************
002: *
003: * $Id: EditAssignmentBean.java 20001 2006-12-22 19:41:33Z ray@media.berkeley.edu $
004: *
005: ***********************************************************************************
006: *
007: * Copyright (c) 2005 The Regents of the University of California, The MIT Corporation
008: *
009: * Licensed under the Educational Community License, Version 1.0 (the "License");
010: * you may not use this file except in compliance with the License.
011: * You may obtain a copy of the License at
012: *
013: * http://www.opensource.org/licenses/ecl1.php
014: *
015: * Unless required by applicable law or agreed to in writing, software
016: * distributed under the License is distributed on an "AS IS" BASIS,
017: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018: * See the License for the specific language governing permissions and
019: * limitations under the License.
020: *
021: **********************************************************************************/package org.sakaiproject.tool.gradebook.ui;
022:
023: import java.io.Serializable;
024:
025: import org.apache.commons.logging.Log;
026: import org.apache.commons.logging.LogFactory;
027: import org.sakaiproject.service.gradebook.shared.ConflictingAssignmentNameException;
028: import org.sakaiproject.service.gradebook.shared.StaleObjectModificationException;
029: import org.sakaiproject.tool.gradebook.Assignment;
030: import org.sakaiproject.tool.gradebook.jsf.FacesUtil;
031:
032: public class EditAssignmentBean extends GradebookDependentBean
033: implements Serializable {
034: private static final Log logger = LogFactory
035: .getLog(EditAssignmentBean.class);
036:
037: private Long assignmentId;
038: private Assignment assignment;
039:
040: protected void init() {
041: if (logger.isDebugEnabled())
042: logger.debug("init assignment=" + assignment);
043:
044: if (assignment == null) {
045: assignment = getGradebookManager().getAssignment(
046: assignmentId);
047: if (assignment == null) {
048: // The assignment might have been removed since this link was set up.
049: if (logger.isWarnEnabled())
050: logger.warn("No assignmentId=" + assignmentId
051: + " in gradebookUid " + getGradebookUid());
052:
053: // TODO Deliver an appropriate message.
054: }
055: }
056: }
057:
058: public String updateAssignment() {
059: try {
060: getGradebookManager().updateAssignment(assignment);
061: String messageKey = getGradebookManager()
062: .isEnteredAssignmentScores(assignmentId) ? "edit_assignment_save_scored"
063: : "edit_assignment_save";
064: FacesUtil.addRedirectSafeMessage(getLocalizedString(
065: messageKey, new String[] { assignment.getName() }));
066: } catch (ConflictingAssignmentNameException e) {
067: logger.error(e);
068: FacesUtil
069: .addErrorMessage(getLocalizedString("edit_assignment_name_conflict_failure"));
070: return "failure";
071: } catch (StaleObjectModificationException e) {
072: logger.error(e);
073: FacesUtil
074: .addErrorMessage(getLocalizedString("edit_assignment_locking_failure"));
075: return "failure";
076: }
077: return navigateToAssignmentDetails();
078: }
079:
080: public String cancel() {
081: return navigateToAssignmentDetails();
082: }
083:
084: private String navigateToAssignmentDetails() {
085: // Go back to the Assignment Details page for this assignment.
086: AssignmentDetailsBean assignmentDetailsBean = (AssignmentDetailsBean) FacesUtil
087: .resolveVariable("assignmentDetailsBean");
088: assignmentDetailsBean.setAssignmentId(assignmentId);
089: return "assignmentDetails";
090: }
091:
092: /**
093: * View maintenance methods.
094: */
095: public Long getAssignmentId() {
096: if (logger.isDebugEnabled())
097: logger.debug("getAssignmentId " + assignmentId);
098: return assignmentId;
099: }
100:
101: public void setAssignmentId(Long assignmentId) {
102: if (logger.isDebugEnabled())
103: logger.debug("setAssignmentId " + assignmentId);
104: if (assignmentId != null) {
105: this .assignmentId = assignmentId;
106: }
107: }
108:
109: public Assignment getAssignment() {
110: if (logger.isDebugEnabled())
111: logger.debug("getAssignment " + assignment);
112: return assignment;
113: }
114: }
|