001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/sections/tags/sakai_2-4-1/sections-app/src/java/org/sakaiproject/tool/section/jsf/backingbean/OptionsBean.java $
003: * $Id: OptionsBean.java 20230 2007-01-10 01:13:02Z jholtzman@berkeley.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2005, 2006 The Regents of the University of California and The Regents of the University of Michigan
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.sakaiproject.tool.section.jsf.backingbean;
021:
022: import java.io.Serializable;
023:
024: import org.apache.commons.logging.Log;
025: import org.apache.commons.logging.LogFactory;
026: import org.sakaiproject.section.api.SectionManager;
027: import org.sakaiproject.section.api.SectionManager.ExternalIntegrationConfig;
028: import org.sakaiproject.tool.section.jsf.JsfUtil;
029:
030: /**
031: * Controls the options page.
032: *
033: * @author <a href="mailto:jholtzman@berkeley.edu">Josh Holtzman</a>
034: *
035: */
036: public class OptionsBean extends CourseDependentBean implements
037: Serializable {
038:
039: private static final long serialVersionUID = 1L;
040: private static final String EXTERNAL = "external";
041: private static final String INTERNAL = "internal";
042:
043: private static final Log log = LogFactory.getLog(OptionsBean.class);
044:
045: private boolean selfRegister;
046: private boolean selfSwitch;
047: private String management;
048: private boolean confirmMode;
049: private boolean managementToggleEnabled;
050:
051: public void init() {
052: // We don't need to initialize the bean when we're in confirm mode
053: if (confirmMode) {
054: return;
055: }
056:
057: // The management toggle is not available in mandatory configurations
058: ExternalIntegrationConfig config = getApplicationConfiguration();
059: if (config == ExternalIntegrationConfig.AUTOMATIC_DEFAULT
060: || config == ExternalIntegrationConfig.MANUAL_DEFAULT) {
061: managementToggleEnabled = true;
062: }
063:
064: if (log.isDebugEnabled())
065: log.debug("OptionsBean.init()");
066: String courseUuid = getCourse().getUuid();
067: SectionManager sm = getSectionManager();
068: this .selfRegister = sm.isSelfRegistrationAllowed(courseUuid);
069: this .selfSwitch = sm.isSelfSwitchingAllowed(courseUuid);
070: if (sm.isExternallyManaged(courseUuid)) {
071: management = EXTERNAL;
072: } else {
073: management = INTERNAL;
074: }
075: }
076:
077: public String confirmExternallyManaged() {
078: return update(false);
079: }
080:
081: public String update() {
082: return update(true);
083: }
084:
085: public String update(boolean checkForConfirmation) {
086: if (!isSectionOptionsManagementEnabled()) {
087: // This should never happen
088: log.warn("Updating section options not permitted for user "
089: + getUserUid());
090: return "overview";
091: }
092:
093: String courseUuid = getCourse().getUuid();
094:
095: if (checkForConfirmation) {
096: boolean oldExternallyManagedSetting = getSectionManager()
097: .isExternallyManaged(courseUuid);
098: if (EXTERNAL.equals(management)
099: && !oldExternallyManagedSetting) {
100: // The user is switching from manual to automatic. Switch to confirm mode.
101: confirmMode = true;
102: return null;
103: }
104: }
105: if (log.isInfoEnabled())
106: log.info("*** Persisting externallyManaged as "
107: + management);
108: getSectionManager().setExternallyManaged(courseUuid,
109: EXTERNAL.equals(management));
110: // If we're externally managed, these will automatically be set to false
111: if (INTERNAL.equals(management)) {
112: getSectionManager().setJoinOptions(courseUuid,
113: selfRegister, selfSwitch);
114: }
115:
116: // TODO Customize the message depending on the action taken
117: JsfUtil.addRedirectSafeInfoMessage(JsfUtil
118: .getLocalizedMessage("options_update_successful"));
119: return "overview";
120: }
121:
122: public boolean isSelfRegister() {
123: return selfRegister;
124: }
125:
126: public void setSelfRegister(boolean selfRegister) {
127: this .selfRegister = selfRegister;
128: }
129:
130: public boolean isSelfSwitch() {
131: return selfSwitch;
132: }
133:
134: public void setSelfSwitch(boolean selfSwitch) {
135: this .selfSwitch = selfSwitch;
136: }
137:
138: /**
139: * See http://issues.apache.org/jira/browse/MYFACES-570 for the reason for this boolean/String hack
140: * @return
141: */
142: public String getManagement() {
143: if (log.isDebugEnabled())
144: log.debug("---- management = " + management);
145: return management;
146: }
147:
148: /**
149: * See http://issues.apache.org/jira/browse/MYFACES-570 for the reason for this boolean/String hack
150: * @return
151: */
152: public void setManagement(String management) {
153: if (log.isDebugEnabled())
154: log.debug("---- setting management to " + management);
155: this .management = management;
156: }
157:
158: public boolean isConfirmMode() {
159: return confirmMode;
160: }
161:
162: public void setConfirmMode(boolean confirmMode) {
163: this .confirmMode = confirmMode;
164: }
165:
166: public boolean isManagementToggleEnabled() {
167: return managementToggleEnabled;
168: }
169:
170: }
|