Package org.olat.course.nodes

Source Code of org.olat.course.nodes.MSCourseNode

/**
* OLAT - Online Learning and Training<br>
* http://www.olat.org
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Copyright (c) since 2004 at Multimedia- & E-Learning Services (MELS),<br>
* University of Zurich, Switzerland.
* <p>
*/

package org.olat.course.nodes;

import java.util.List;
import java.util.Locale;

import org.olat.core.gui.UserRequest;
import org.olat.core.gui.control.Controller;
import org.olat.core.gui.control.WindowControl;
import org.olat.core.gui.control.generic.messages.MessageUIFactory;
import org.olat.core.gui.control.generic.tabbable.TabbableController;
import org.olat.core.gui.translator.PackageTranslator;
import org.olat.core.gui.translator.Translator;
import org.olat.core.id.Identity;
import org.olat.core.id.Roles;
import org.olat.core.logging.OLATRuntimeException;
import org.olat.core.util.Util;
import org.olat.course.ICourse;
import org.olat.course.assessment.AssessmentManager;
import org.olat.course.auditing.UserNodeAuditManager;
import org.olat.course.editor.CourseEditorEnv;
import org.olat.course.editor.NodeEditController;
import org.olat.course.editor.StatusDescription;
import org.olat.course.nodes.ms.MSCourseNodeEditController;
import org.olat.course.nodes.ms.MSCourseNodeRunController;
import org.olat.course.nodes.ms.MSEditFormController;
import org.olat.course.properties.CoursePropertyManager;
import org.olat.course.properties.PersistingCoursePropertyManager;
import org.olat.course.run.navigation.NodeRunConstructionResult;
import org.olat.course.run.scoring.ScoreEvaluation;
import org.olat.course.run.userview.NodeEvaluation;
import org.olat.course.run.userview.UserCourseEnvironment;
import org.olat.modules.ModuleConfiguration;
import org.olat.repository.RepositoryEntry;

/**
* Initial Date: Jun 16, 2004
*
* @author gnaegi
* @author BPS (<a href="http://www.bps-system.de/">BPS Bildungsportal Sachsen GmbH</a>)
*/
public class MSCourseNode extends AbstractAccessableCourseNode implements AssessableCourseNode {
  private static final String PACKAGE_MS = Util.getPackageName(MSCourseNodeRunController.class);

  private static final String PACKAGE = Util.getPackageName(MSCourseNode.class);

  private static final String TYPE = "ms";
  /** configuration: score can be set */
  public static final String CONFIG_KEY_HAS_SCORE_FIELD = "hasScoreField";
  /** configuration: score min value */
  public static final String CONFIG_KEY_SCORE_MIN = "scoreMin";
  /** configuration: score max value */
  public static final String CONFIG_KEY_SCORE_MAX = "scoreMax";
  /** configuration: passed can be set */
  public static final String CONFIG_KEY_HAS_PASSED_FIELD = "hasPassedField";
  /** configuration: passed set to when score higher than cut value */
  public static final String CONFIG_KEY_PASSED_CUT_VALUE = "passedCutValue";
  /** configuration: comment can be set */
  public static final String CONFIG_KEY_HAS_COMMENT_FIELD = "hasCommentField";
  /** configuration: infotext for user */
  public static final String CONFIG_KEY_INFOTEXT_USER = "infoTextUser";
  /** configuration: infotext for coach */
  public static final String CONFIG_KEY_INFOTEXT_COACH = "nfoTextCoach";

  /**
   * Constructor for a course building block of type manual score
   */
  public MSCourseNode() {
    super(TYPE);
    MSCourseNode.initDefaultConfig(getModuleConfiguration());
  }

  /**
   * Adds to the given module configuration the default configuration for the
   * manual scoring
   *
   * @param moduleConfiguration
   */
  public static void initDefaultConfig(ModuleConfiguration moduleConfiguration) {
    moduleConfiguration.set(CONFIG_KEY_HAS_SCORE_FIELD, Boolean.FALSE);
    moduleConfiguration.set(CONFIG_KEY_SCORE_MIN, new Float(0));
    moduleConfiguration.set(CONFIG_KEY_SCORE_MAX, new Float(0));
    moduleConfiguration.set(CONFIG_KEY_HAS_PASSED_FIELD, Boolean.TRUE);
    // no preset for passed cut value -> manual setting of passed
    moduleConfiguration.set(CONFIG_KEY_HAS_COMMENT_FIELD, Boolean.TRUE);
    moduleConfiguration.set(CONFIG_KEY_INFOTEXT_USER, "");
    moduleConfiguration.set(CONFIG_KEY_INFOTEXT_COACH, "");
  }

  /**
   * @see org.olat.course.nodes.CourseNode#createEditController(org.olat.core.gui.UserRequest,
   *      org.olat.core.gui.control.WindowControl, org.olat.course.ICourse)
   */
  @Override
  public TabbableController createEditController(UserRequest ureq, WindowControl wControl, ICourse course, UserCourseEnvironment euce) {
    MSCourseNodeEditController childTabCntrllr = new MSCourseNodeEditController(ureq, wControl, this, course, euce);
    CourseNode chosenNode = course.getEditorTreeModel().getCourseNode(euce.getCourseEditorEnv().getCurrentCourseNodeId());
    return new NodeEditController(ureq, wControl, course.getEditorTreeModel(), course, chosenNode, course.getCourseEnvironment()
        .getCourseGroupManager(), euce, childTabCntrllr);
  }

  /**
   * @see org.olat.course.nodes.CourseNode#createNodeRunConstructionResult(org.olat.core.gui.UserRequest,
   *      org.olat.core.gui.control.WindowControl,
   *      org.olat.course.run.userview.UserCourseEnvironment,
   *      org.olat.course.run.userview.NodeEvaluation)
   */
  @Override
  public NodeRunConstructionResult createNodeRunConstructionResult(UserRequest ureq, WindowControl wControl,
      UserCourseEnvironment userCourseEnv, NodeEvaluation ne, String nodecmd) {
    Controller controller;
    // Do not allow guests to have manual scoring
    Roles roles = ureq.getUserSession().getRoles();
    if (roles.isGuestOnly()) {
      Translator trans = new PackageTranslator(PACKAGE, ureq.getLocale());
      String title = trans.translate("guestnoaccess.title");
      String message = trans.translate("guestnoaccess.message");
      controller = MessageUIFactory.createInfoMessage(ureq, wControl, title, message);
    } else {
      controller = new MSCourseNodeRunController(ureq, wControl, userCourseEnv, this, true);
    }
   
    Controller wrappedCtrl = TitledWrapperHelper.getWrapper(ureq, wControl, controller, this, "o_ms_icon");
    return new NodeRunConstructionResult(wrappedCtrl);
  }

  /**
   * @see org.olat.course.nodes.CourseNode#getReferencedRepositoryEntry()
   */
  public RepositoryEntry getReferencedRepositoryEntry() {
    return null;
  }

  /**
   * @see org.olat.course.nodes.CourseNode#needsReferenceToARepositoryEntry()
   */
  public boolean needsReferenceToARepositoryEntry() {
    return false;
  }

  /**
   * @see org.olat.course.nodes.CourseNode#isConfigValid()
   */
  public StatusDescription isConfigValid() {
    /*
     * first check the one click cache
     */
    if (oneClickStatusCache != null) { return oneClickStatusCache[0]; }

    boolean isValid = MSEditFormController.isConfigValid(getModuleConfiguration());
    StatusDescription sd = StatusDescription.NOERROR;
    if (!isValid) {
      // FIXME: refine statusdescriptions by moving the statusdescription
      // generation to the MSEditForm
      String shortKey = "error.missingconfig.short";
      String longKey = "error.missingconfig.long";
      String[] params = new String[] { this.getShortTitle() };
      String translPackage = Util.getPackageName(MSEditFormController.class);
      sd = new StatusDescription(StatusDescription.ERROR, shortKey, longKey, params, translPackage);
      sd.setDescriptionForUnit(getIdent());
      // set which pane is affected by error
      sd.setActivateableViewIdentifier(MSCourseNodeEditController.PANE_TAB_CONFIGURATION);
    }
    return sd;
  }

  /**
   * @see org.olat.course.nodes.CourseNode#isConfigValid(org.olat.course.run.userview.UserCourseEnvironment)
   */
  @Override
  public StatusDescription[] isConfigValid(CourseEditorEnv cev) {
    oneClickStatusCache = null;
    // only here we know which translator to take for translating condition
    // error messages
    String translatorStr = Util.getPackageName(MSEditFormController.class);
    List sds = isConfigValidWithTranslator(cev, translatorStr, getConditionExpressions());
    oneClickStatusCache = StatusDescriptionHelper.sort(sds);
    return oneClickStatusCache;
  }

  /**
   * @see org.olat.course.nodes.AssessableCourseNode#getUserScoreEvaluation(org.olat.course.run.userview.UserCourseEnvironment)
   */
  public ScoreEvaluation getUserScoreEvaluation(UserCourseEnvironment userCourseEnvironment) {
    // read score from properties
    AssessmentManager am = userCourseEnvironment.getCourseEnvironment().getAssessmentManager();
    Identity mySelf = userCourseEnvironment.getIdentityEnvironment().getIdentity();
    Boolean passed = null;
    Float score = null;
    // only db lookup if configured, else return null
    if (hasPassedConfigured()) passed = am.getNodePassed(this, mySelf);
    if (hasScoreConfigured()) score = am.getNodeScore(this, mySelf);

    ScoreEvaluation se = new ScoreEvaluation(score, passed);
    return se;
  }

  /**
   * @see org.olat.course.nodes.CourseNode#informOnDelete(org.olat.core.gui.UserRequest,
   *      org.olat.course.ICourse)
   */
  @Override
  public String informOnDelete(Locale locale, ICourse course) {
    CoursePropertyManager cpm = PersistingCoursePropertyManager.getInstance(course);
    List list = cpm.listCourseNodeProperties(this, null, null, null);
    if (list.size() == 0) return null; // no properties created yet
    Translator trans = new PackageTranslator(PACKAGE_MS, locale);
    return trans.translate("warn.nodedelete");
  }

  /**
   * @see org.olat.course.nodes.CourseNode#cleanupOnDelete(
   *      org.olat.course.ICourse)
   */
  @Override
  public void cleanupOnDelete(ICourse course) {
    CoursePropertyManager pm = course.getCourseEnvironment().getCoursePropertyManager();
    // Delete all properties: score, passed, log, comment, coach_comment
    pm.deleteNodeProperties(this, null);
  }

  /**
   * @see org.olat.course.nodes.AssessableCourseNode#hasCommentConfigured()
   */
  public boolean hasCommentConfigured() {
    ModuleConfiguration config = getModuleConfiguration();
    Boolean comment = (Boolean) config.get(CONFIG_KEY_HAS_COMMENT_FIELD);
    if (comment == null) return false;
    return comment.booleanValue();
  }

  /**
   * @see org.olat.course.nodes.AssessableCourseNode#hasPassedConfigured()
   */
  public boolean hasPassedConfigured() {
    ModuleConfiguration config = getModuleConfiguration();
    Boolean passed = (Boolean) config.get(CONFIG_KEY_HAS_PASSED_FIELD);
    if (passed == null) return false;
    return passed.booleanValue();
  }

  /**
   * @see org.olat.course.nodes.AssessableCourseNode#hasScoreConfigured()
   */
  public boolean hasScoreConfigured() {
    ModuleConfiguration config = getModuleConfiguration();
    Boolean score = (Boolean) config.get(CONFIG_KEY_HAS_SCORE_FIELD);
    if (score == null) return false;
    return score.booleanValue();
  }
 
  /**
   * @see org.olat.course.nodes.AssessableCourseNode#hasStatusConfigured()
   */
  public boolean hasStatusConfigured() {
    return false;
  }

  /**
   * @see org.olat.course.nodes.AssessableCourseNode#getMaxScoreConfiguration()
   */
  public Float getMaxScoreConfiguration() {
    if (!hasScoreConfigured()) { throw new OLATRuntimeException(MSCourseNode.class, "getMaxScore not defined when hasScore set to false", null); }
    ModuleConfiguration config = getModuleConfiguration();
    Float max = (Float) config.get(CONFIG_KEY_SCORE_MAX);
    return max;
  }

  /**
   * @see org.olat.course.nodes.AssessableCourseNode#getMinScoreConfiguration()
   */
  public Float getMinScoreConfiguration() {
    if (!hasScoreConfigured()) { throw new OLATRuntimeException(MSCourseNode.class, "getMinScore not defined when hasScore set to false", null); }
    ModuleConfiguration config = getModuleConfiguration();
    Float min = (Float) config.get(CONFIG_KEY_SCORE_MIN);
    return min;
  }

  /**
   * @see org.olat.course.nodes.AssessableCourseNode#getCutValueConfiguration()
   */
  public Float getCutValueConfiguration() {
    if (!hasPassedConfigured()) { throw new OLATRuntimeException(MSCourseNode.class, "getCutValue not defined when hasPassed set to false", null); }
    ModuleConfiguration config = getModuleConfiguration();
    Float cut = (Float) config.get(CONFIG_KEY_PASSED_CUT_VALUE);
    return cut;
  }

  /**
   * @see org.olat.course.nodes.AssessableCourseNode#getUserCoachComment(org.olat.course.run.userview.UserCourseEnvironment)
   */
  public String getUserCoachComment(UserCourseEnvironment userCourseEnvironment) {
    AssessmentManager am = userCourseEnvironment.getCourseEnvironment().getAssessmentManager();
    String coachCommentValue = am.getNodeCoachComment(this, userCourseEnvironment.getIdentityEnvironment().getIdentity());
    return coachCommentValue;
  }

  /**
   * @see org.olat.course.nodes.AssessableCourseNode#getUserUserComment(org.olat.course.run.userview.UserCourseEnvironment)
   */
  public String getUserUserComment(UserCourseEnvironment userCourseEnvironment) {
    AssessmentManager am = userCourseEnvironment.getCourseEnvironment().getAssessmentManager();
    String userCommentValue = am.getNodeComment(this, userCourseEnvironment.getIdentityEnvironment().getIdentity());
    return userCommentValue;
  }

  /**
   * @see org.olat.course.nodes.AssessableCourseNode#getUserLog(org.olat.course.run.userview.UserCourseEnvironment)
   */
  public String getUserLog(UserCourseEnvironment userCourseEnvironment) {
    UserNodeAuditManager am = userCourseEnvironment.getCourseEnvironment().getAuditManager();
    String logValue = am.getUserNodeLog(this, userCourseEnvironment.getIdentityEnvironment().getIdentity());
    return logValue;
  }

  /**
   * @see org.olat.course.nodes.AssessableCourseNode#isEditableConfigured()
   */
  public boolean isEditableConfigured() {
    // manual scoring fields can be edited manually
    return true;
  }

  /**
   * @see org.olat.course.nodes.AssessableCourseNode#updateUserCoachComment(java.lang.String,
   *      org.olat.course.run.userview.UserCourseEnvironment)
   */
  public void updateUserCoachComment(String coachComment, UserCourseEnvironment userCourseEnvironment) {
    AssessmentManager am = userCourseEnvironment.getCourseEnvironment().getAssessmentManager();
    Identity mySelf = userCourseEnvironment.getIdentityEnvironment().getIdentity();
    if (coachComment != null) {
      am.saveNodeCoachComment(this, mySelf, coachComment);
    }
  }

  /**
   * @see org.olat.course.nodes.AssessableCourseNode#updateUserScoreEvaluation(org.olat.course.run.scoring.ScoreEvaluation,
   *      org.olat.course.run.userview.UserCourseEnvironment,
   *      org.olat.core.id.Identity)
   */
  public void updateUserScoreEvaluation(ScoreEvaluation scoreEvaluation, UserCourseEnvironment userCourseEnvironment,
      Identity coachingIdentity, boolean incrementAttempts) {
    AssessmentManager am = userCourseEnvironment.getCourseEnvironment().getAssessmentManager();
    Identity mySelf = userCourseEnvironment.getIdentityEnvironment().getIdentity();
    am.saveScoreEvaluation(this, coachingIdentity, mySelf, new ScoreEvaluation(scoreEvaluation.getScore(), scoreEvaluation.getPassed()), userCourseEnvironment, incrementAttempts);   
  }

  /**
   * @see org.olat.course.nodes.AssessableCourseNode#updateUserUserComment(java.lang.String,
   *      org.olat.course.run.userview.UserCourseEnvironment,
   *      org.olat.core.id.Identity)
   */
  public void updateUserUserComment(String userComment, UserCourseEnvironment userCourseEnvironment, Identity coachingIdentity) {
    AssessmentManager am = userCourseEnvironment.getCourseEnvironment().getAssessmentManager();
    Identity mySelf = userCourseEnvironment.getIdentityEnvironment().getIdentity();
    if (userComment != null) {
      am.saveNodeComment(this, coachingIdentity, mySelf, userComment);
    }
  }

  /**
   * @see org.olat.course.nodes.AssessableCourseNode#getUserAttempts(org.olat.course.run.userview.UserCourseEnvironment)
   */
  public Integer getUserAttempts(UserCourseEnvironment userCourseEnvironment) {
    throw new OLATRuntimeException(MSCourseNode.class, "No attempts available in MS nodes", null);

  }

  /**
   * @see org.olat.course.nodes.AssessableCourseNode#hasAttemptsConfigured()
   */
  public boolean hasAttemptsConfigured() {
    return false;
  }

  /**
   * @see org.olat.course.nodes.AssessableCourseNode#updateUserAttempts(java.lang.Integer,
   *      org.olat.course.run.userview.UserCourseEnvironment,
   *      org.olat.core.id.Identity)
   */
  public void updateUserAttempts(Integer userAttempts, UserCourseEnvironment userCourseEnvironment, Identity coachingIdentity) {
    throw new OLATRuntimeException(MSCourseNode.class, "Attempts variable can't be updated in MS nodes", null);
  }

  /**
   * @see org.olat.course.nodes.AssessableCourseNode#incrementUserAttempts(org.olat.course.run.userview.UserCourseEnvironment)
   */
  public void incrementUserAttempts(UserCourseEnvironment userCourseEnvironment) {
    throw new OLATRuntimeException(MSCourseNode.class, "Attempts variable can't be updated in MS nodes", null);
  }

  /**
   * @see org.olat.course.nodes.AssessableCourseNode#getDetailsEditController(org.olat.core.gui.UserRequest,
   *      org.olat.core.gui.control.WindowControl,
   *      org.olat.course.run.userview.UserCourseEnvironment)
   */
  public Controller getDetailsEditController(UserRequest ureq, WindowControl wControl, UserCourseEnvironment userCourseEnvironment) {
    throw new OLATRuntimeException(MSCourseNode.class, "Details controler not available in MS nodes", null);
  }

  /**
   * @see org.olat.course.nodes.AssessableCourseNode#getDetailsListView(org.olat.course.run.userview.UserCourseEnvironment)
   */
  public String getDetailsListView(UserCourseEnvironment userCourseEnvironment) {
    throw new OLATRuntimeException(MSCourseNode.class, "Details not available in MS nodes", null);
  }

  /**
   * @see org.olat.course.nodes.AssessableCourseNode#getDetailsListViewHeaderKey()
   */
  public String getDetailsListViewHeaderKey() {
    throw new OLATRuntimeException(MSCourseNode.class, "Details not available in MS nodes", null);
  }

  /**
   * @see org.olat.course.nodes.AssessableCourseNode#hasDetails()
   */
  public boolean hasDetails() {
    return false;
  }

}
TOP

Related Classes of org.olat.course.nodes.MSCourseNode

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.