use of org.olat.course.condition.interpreter.ConditionExpression in project OpenOLAT by OpenOLAT.
the class TACourseNode method getConditionExpressions.
/**
* @see org.olat.course.nodes.GenericCourseNode#getConditionExpressions()
*/
@Override
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 = getConditionDrop().getConditionExpression();
if (coS != null && !coS.equals("")) {
// an active condition is defined
ConditionExpression ce = new ConditionExpression(getConditionDrop().getConditionId());
ce.setExpressionString(getConditionDrop().getConditionExpression());
retVal.add(ce);
}
coS = getConditionReturnbox().getConditionExpression();
if (coS != null && !coS.equals("")) {
// an active condition is defined
ConditionExpression ce = new ConditionExpression(getConditionReturnbox().getConditionId());
ce.setExpressionString(getConditionReturnbox().getConditionExpression());
retVal.add(ce);
} else if (coS == null && getConditionDrop().getConditionExpression() != null && !getConditionDrop().getConditionExpression().equals("")) {
// old courses that had dropbox but no returnbox: use for returnbox the conditionExpression from dropbox
ConditionExpression ce = new ConditionExpression(getConditionReturnbox().getConditionId());
ce.setExpressionString(getConditionDrop().getConditionExpression());
retVal.add(ce);
}
coS = getConditionScoring().getConditionExpression();
if (coS != null && !coS.equals("")) {
// an active condition is defined
ConditionExpression ce = new ConditionExpression(getConditionScoring().getConditionId());
ce.setExpressionString(getConditionScoring().getConditionExpression());
retVal.add(ce);
}
coS = getConditionTask().getConditionExpression();
if (coS != null && !coS.equals("")) {
// an active condition is defined
ConditionExpression ce = new ConditionExpression(getConditionTask().getConditionId());
ce.setExpressionString(getConditionTask().getConditionExpression());
retVal.add(ce);
}
//
return retVal;
}
use of org.olat.course.condition.interpreter.ConditionExpression in project openolat by klemens.
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 klemens.
the class CourseEditorEnvImpl method validateConditionExpression.
/**
* @see org.olat.course.editor.CourseEditorEnv#validateConditionExpression(org.olat.course.condition.interpreter.ConditionExpression)
*/
public ConditionErrorMessage[] validateConditionExpression(ConditionExpression condExpr) {
// first set the active condition expression, which will be accessed from
// the conditions functions inserting soft references
currentConditionExpression = condExpr;
if (condExpr.getExptressionString() == null) {
return null;
}
// evaluate expression
ConditionErrorMessage[] cems = ci.syntaxTestExpression(condExpr);
if (softRefs.containsKey(this.currentCourseNodeId)) {
List<ConditionExpression> condExprs = softRefs.get(this.currentCourseNodeId);
for (Iterator<ConditionExpression> iter = condExprs.iterator(); iter.hasNext(); ) {
ConditionExpression element = iter.next();
if (element.getId().equals(currentConditionExpression.getId())) {
condExprs.remove(element);
break;
}
}
condExprs.add(currentConditionExpression);
} else {
List<ConditionExpression> condExprs = new ArrayList<ConditionExpression>();
condExprs.add(currentConditionExpression);
softRefs.put(currentCourseNodeId, condExprs);
}
return cems;
}
use of org.olat.course.condition.interpreter.ConditionExpression in project openolat by klemens.
the class CourseEditorEnvImpl method listCycles.
/**
* @see org.olat.course.editor.CourseEditorEnv#listCycles()
*/
@Override
public Set<String> listCycles() {
/*
* convert nodeRefs datastructure to a directed graph
*/
DirectedGraph dg = new DefaultDirectedGraph();
DirectedEdgeFactory def = new EdgeFactories.DirectedEdgeFactory();
/*
* add the course structure as directed graph, where
*/
Visitor v = new Convert2DGVisitor(dg);
(new TreeVisitor(v, cetm.getRootNode(), true)).visitAll();
/*
* iterate over nodeRefs, add each not existing node id as vertex, for each
* key - child relation add an edge to the directed graph.
*/
Map<String, Set<String>> nodeSoftRefs = new HashMap<>();
for (Iterator<String> iter = softRefs.keySet().iterator(); iter.hasNext(); ) {
String nodeId = iter.next();
List<ConditionExpression> conditionExprs = softRefs.get(nodeId);
for (int i = 0; i < conditionExprs.size(); i++) {
ConditionExpression ce = conditionExprs.get(i);
Set<String> refs = ce.getSoftReferencesForCycleDetectorOf("courseNodeId");
if (refs != null && refs.size() > 0) {
if (nodeSoftRefs.containsKey(nodeId)) {
nodeSoftRefs.get(nodeId).addAll(refs);
} else {
nodeSoftRefs.put(nodeId, refs);
}
}
}
}
for (Iterator<String> keys = nodeSoftRefs.keySet().iterator(); keys.hasNext(); ) {
// a node
String key = keys.next();
if (!dg.containsVertex(key)) {
dg.addVertex(key);
}
// and its children
Set<String> children = nodeSoftRefs.get(key);
for (Iterator<String> childrenIt = children.iterator(); childrenIt.hasNext(); ) {
String child = childrenIt.next();
if (!dg.containsVertex(child)) {
dg.addVertex(child);
}
// add edge, precondition: vertex key - child are already added to the graph
Edge de = def.createEdge(key, child);
dg.addEdge(de);
}
}
/*
* find the id's participating in the cycle, and return the intersection
* with set of id's which actually produce references.
*/
CycleDetector cd = new CycleDetector(dg);
Set<String> cycleIds = cd.findCycles();
cycleIds.retainAll(nodeSoftRefs.keySet());
return cycleIds;
}
use of org.olat.course.condition.interpreter.ConditionExpression in project openolat by klemens.
the class CalCourseNode method getConditionExpressions.
@Override
public List<ConditionExpression> getConditionExpressions() {
List<ConditionExpression> parentConditions = super.getConditionExpressions();
List<ConditionExpression> conditions = new ArrayList<>();
if (parentConditions != null && parentConditions.size() > 0) {
conditions.addAll(parentConditions);
}
Condition editCondition = getPreConditionEdit();
if (editCondition != null && StringHelper.containsNonWhitespace(editCondition.getConditionExpression())) {
ConditionExpression ce = new ConditionExpression(editCondition.getConditionId());
ce.setExpressionString(editCondition.getConditionExpression());
conditions.add(ce);
}
return conditions;
}
Aggregations