use of org.olat.course.condition.interpreter.ConditionExpression in project OpenOLAT by OpenOLAT.
the class CourseElementWebService method getTaskConfiguration.
/**
* Retrieves configuration of the task course node
* @response.representation.200.qname {http://www.example.com}surveyConfigVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The course node configuration
* @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_COURSENODEVO}
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @response.representation.404.doc The course or task node not found
* @param courseId
* @param nodeId
* @return the task course node configuration
*/
@GET
@Path("task/{nodeId}/configuration")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getTaskConfiguration(@PathParam("courseId") Long courseId, @PathParam("nodeId") String nodeId, @Context HttpServletRequest httpRequest) {
if (!isAuthor(httpRequest)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
TaskConfigVO config = new TaskConfigVO();
ICourse course = CoursesWebService.loadCourse(courseId);
CourseNode courseNode = getParentNode(course, nodeId);
ModuleConfiguration moduleConfig = courseNode.getModuleConfiguration();
// build configuration with fallback to default values
Boolean isAssignmentEnabled = (Boolean) moduleConfig.get(TACourseNode.CONF_TASK_ENABLED);
config.setIsAssignmentEnabled(isAssignmentEnabled == null ? Boolean.TRUE : isAssignmentEnabled);
String taskAssignmentType = moduleConfig.getStringValue(TACourseNode.CONF_TASK_TYPE);
config.setTaskAssignmentType(taskAssignmentType == null ? TaskController.TYPE_MANUAL : taskAssignmentType);
String taskAssignmentText = moduleConfig.getStringValue(TACourseNode.CONF_TASK_TEXT);
config.setTaskAssignmentText(taskAssignmentText == null ? "" : taskAssignmentText);
Boolean isTaskPreviewEnabled = moduleConfig.get(TACourseNode.CONF_TASK_PREVIEW) == null ? Boolean.FALSE : moduleConfig.getBooleanEntry(TACourseNode.CONF_TASK_PREVIEW);
config.setIsTaskPreviewEnabled(isTaskPreviewEnabled);
Boolean isTaskDeselectEnabled = moduleConfig.getBooleanEntry(TACourseNode.CONF_TASK_DESELECT);
config.setIsTaskDeselectEnabled(isTaskDeselectEnabled == null ? Boolean.FALSE : isTaskDeselectEnabled);
Boolean onlyOneUserPerTask = (Boolean) moduleConfig.get(TACourseNode.CONF_TASK_SAMPLING_WITH_REPLACEMENT);
config.setOnlyOneUserPerTask(onlyOneUserPerTask == null ? Boolean.TRUE : onlyOneUserPerTask);
Boolean isDropboxEnabled = (Boolean) moduleConfig.get(TACourseNode.CONF_DROPBOX_ENABLED);
config.setIsDropboxEnabled(isDropboxEnabled == null ? Boolean.TRUE : isDropboxEnabled);
Boolean isDropboxConfirmationMailEnabled = (Boolean) moduleConfig.get(TACourseNode.CONF_DROPBOX_ENABLEMAIL);
config.setIsDropboxConfirmationMailEnabled(isDropboxConfirmationMailEnabled == null ? Boolean.FALSE : isDropboxConfirmationMailEnabled);
String dropboxConfirmationText = moduleConfig.getStringValue(TACourseNode.CONF_DROPBOX_CONFIRMATION);
config.setDropboxConfirmationText(dropboxConfirmationText == null ? "" : dropboxConfirmationText);
Boolean isReturnboxEnabled = (Boolean) moduleConfig.get(TACourseNode.CONF_RETURNBOX_ENABLED);
config.setIsReturnboxEnabled(isReturnboxEnabled == null ? Boolean.TRUE : isReturnboxEnabled);
Boolean isScoringEnabled = (Boolean) moduleConfig.get(TACourseNode.CONF_SCORING_ENABLED);
config.setIsScoringEnabled(isScoringEnabled == null ? Boolean.TRUE : isScoringEnabled);
Boolean isScoringGranted = (Boolean) moduleConfig.get(MSCourseNode.CONFIG_KEY_HAS_SCORE_FIELD);
config.setIsScoringGranted(isScoringGranted == null ? Boolean.FALSE : isScoringGranted);
Float minScore = (Float) moduleConfig.get(MSCourseNode.CONFIG_KEY_SCORE_MIN);
config.setMinScore(minScore);
Float maxScore = (Float) moduleConfig.get(MSCourseNode.CONFIG_KEY_SCORE_MAX);
config.setMaxScore(maxScore);
Boolean isPassingGranted = (Boolean) moduleConfig.get(MSCourseNode.CONFIG_KEY_HAS_PASSED_FIELD);
config.setIsPassingGranted(isPassingGranted == null ? Boolean.FALSE : isPassingGranted);
Float passingScoreThreshold = (Float) moduleConfig.get(MSCourseNode.CONFIG_KEY_PASSED_CUT_VALUE);
config.setPassingScoreThreshold(passingScoreThreshold);
Boolean hasCommentField = (Boolean) moduleConfig.get(MSCourseNode.CONFIG_KEY_HAS_COMMENT_FIELD);
config.setHasCommentField(hasCommentField == null ? Boolean.FALSE : hasCommentField);
String commentForUser = moduleConfig.getStringValue(MSCourseNode.CONFIG_KEY_INFOTEXT_USER);
config.setCommentForUser(commentForUser == null ? "" : commentForUser);
String commentForCoaches = moduleConfig.getStringValue(MSCourseNode.CONFIG_KEY_INFOTEXT_COACH);
config.setCommentForCoaches(commentForCoaches == null ? "" : commentForCoaches);
Boolean isSolutionEnabled = (Boolean) moduleConfig.get(TACourseNode.CONF_SOLUTION_ENABLED);
config.setIsSolutionEnabled(isSolutionEnabled == null ? Boolean.TRUE : isSolutionEnabled);
// get the conditions
List<ConditionExpression> lstConditions = courseNode.getConditionExpressions();
for (ConditionExpression cond : lstConditions) {
String id = cond.getId();
String expression = cond.getExptressionString();
if (id.equals(TACourseNode.ACCESS_TASK))
config.setConditionTask(expression);
else if (// TACourseNode uses "drop" instead the static ACCESS_DROPBOX, very bad!
id.equals("drop"))
config.setConditionDropbox(expression);
else if (id.equals(TACourseNode.ACCESS_RETURNBOX))
config.setConditionReturnbox(expression);
else if (id.equals(TACourseNode.ACCESS_SCORING))
config.setConditionScoring(expression);
else if (id.equals(TACourseNode.ACCESS_SOLUTION))
config.setConditionSolution(expression);
}
return Response.ok(config).build();
}
use of org.olat.course.condition.interpreter.ConditionExpression in project OpenOLAT by OpenOLAT.
the class AbstractAccessableCourseNode method getConditionExpressions.
/**
* @see org.olat.course.nodes.GenericCourseNode#getConditionExpression()
*/
@Override
public List<ConditionExpression> getConditionExpressions() {
ArrayList<ConditionExpression> retVal;
List<ConditionExpression> parentsConditions = super.getConditionExpressions();
if (parentsConditions.size() > 0) {
retVal = new ArrayList<>(parentsConditions);
} else {
retVal = new ArrayList<>();
}
//
String coS = getPreConditionAccess().getConditionExpression();
if (coS != null && !coS.equals("")) {
// an active condition is defined
ConditionExpression ce = new ConditionExpression(getPreConditionAccess().getConditionId());
ce.setExpressionString(getPreConditionAccess().getConditionExpression());
retVal.add(ce);
}
//
return retVal;
}
use of org.olat.course.condition.interpreter.ConditionExpression in project OpenOLAT by OpenOLAT.
the class BCCourseNode method getConditionExpressions.
/**
* @see org.olat.course.nodes.GenericCourseNode#getConditionExpressions()
*/
public List<ConditionExpression> getConditionExpressions() {
List<ConditionExpression> retVal;
List<ConditionExpression> parentsConditions = super.getConditionExpressions();
if (parentsConditions.size() > 0) {
retVal = new ArrayList<ConditionExpression>(parentsConditions);
} else {
retVal = new ArrayList<ConditionExpression>();
}
//
String coS = getPreConditionDownloaders().getConditionExpression();
if (coS != null && !coS.equals("")) {
// an active condition is defined
ConditionExpression ce = new ConditionExpression(getPreConditionDownloaders().getConditionId());
ce.setExpressionString(getPreConditionDownloaders().getConditionExpression());
retVal.add(ce);
}
//
coS = getPreConditionUploaders().getConditionExpression();
if (coS != null && !coS.equals("")) {
// an active condition is defined
ConditionExpression ce = new ConditionExpression(getPreConditionUploaders().getConditionId());
ce.setExpressionString(getPreConditionUploaders().getConditionExpression());
retVal.add(ce);
}
//
return retVal;
}
use of org.olat.course.condition.interpreter.ConditionExpression in project OpenOLAT by OpenOLAT.
the class GenericCourseNode method isConfigValidWithTranslator.
/**
* @param userCourseEnv
* @param translatorStr
* @return
*/
// for StatusDescription.WARNING
protected List<StatusDescription> isConfigValidWithTranslator(CourseEditorEnv cev, String translatorStr, List<ConditionExpression> condExprs) {
List<StatusDescription> condExprsStatusDescs = new ArrayList<>();
// check valid configuration without course environment
StatusDescription first = isConfigValid();
// check valid configuration within the course environment
if (cev == null) {
// course environment not configured!??
condExprsStatusDescs.add(first);
return condExprsStatusDescs;
}
/*
* there is course editor environment, we can check further. Iterate over
* all conditions of this course node, validate the condition expression and
* transform the condition error message into a status description
*/
for (int i = 0; i < condExprs.size(); i++) {
ConditionExpression ce = condExprs.get(i);
ConditionErrorMessage[] cems = cev.validateConditionExpression(ce);
if (cems != null && cems.length > 0) {
for (int j = 0; j < cems.length; j++) {
StatusDescription sd = new StatusDescription(StatusDescription.WARNING, cems[j].errorKey, cems[j].solutionMsgKey, cems[j].errorKeyParams, translatorStr);
sd.setDescriptionForUnit(getIdent());
condExprsStatusDescs.add(sd);
}
}
}
condExprsStatusDescs.add(first);
return condExprsStatusDescs;
}
use of org.olat.course.condition.interpreter.ConditionExpression in project OpenOLAT by OpenOLAT.
the class ConditionConfigExpertForm method validateFormLogic.
@Override
public boolean validateFormLogic(UserRequest ureq) {
if (tprecond.isEmpty()) {
// the precondition
return true;
}
/*
* not empty, nowOLAT - Demo Course_1264602504362 test precondition syntax and for existing soft references
*/
CourseEditorEnv cev = euce.getCourseEditorEnv();
ConditionExpression ce = new ConditionExpression(conditionId, tprecond.getValue());
ConditionErrorMessage[] cerrmsg = cev.validateConditionExpression(ce);
/*
* display any error detected in the condition expression testing.
*/
if (cerrmsg != null && cerrmsg.length > 0) {
// the error messOLAT - Demo Course_1264602504362age
tprecond.setErrorKey(cerrmsg[0].errorKey, cerrmsg[0].errorKeyParams);
if (cerrmsg[0].solutionMsgKey != null && !"".equals(cerrmsg[0].solutionMsgKey)) {
// and a hint or example to clarify the error message
tprecond.setExampleKey(cerrmsg[0].solutionMsgKey, cerrmsg[0].errorKeyParams);
}
return false;
}
// reset HINTS
tprecond.setExampleKey("xx", new String[] { "" });
return true;
}
Aggregations