use of org.olat.course.condition.interpreter.ConditionErrorMessage 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.ConditionErrorMessage 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;
}
use of org.olat.course.condition.interpreter.ConditionErrorMessage in project openolat by klemens.
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;
}
use of org.olat.course.condition.interpreter.ConditionErrorMessage in project OpenOLAT by OpenOLAT.
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.ConditionErrorMessage in project OpenOLAT by OpenOLAT.
the class EditScoreCalculationExpertForm method validateFormLogic.
@Override
public boolean validateFormLogic(UserRequest ureq) {
String scoreExp = tscoreexpr.getValue().trim();
if (StringHelper.containsNonWhitespace(scoreExp)) {
CourseEditorEnv cev = euce.getCourseEditorEnv();
ConditionExpression ce = new ConditionExpression("score", scoreExp);
ConditionErrorMessage[] cerrmsgs = cev.validateConditionExpression(ce);
if (cerrmsgs != null && cerrmsgs.length > 0) {
setKeys(ureq, tscoreexpr, cerrmsgs);
return false;
}
testElemWithNoResource = getInvalidNodeDescriptions(ce);
}
String passedExp = tpassedexpr.getValue().trim();
if (StringHelper.containsNonWhitespace(passedExp)) {
CourseEditorEnv cev = euce.getCourseEditorEnv();
ConditionExpression ce = new ConditionExpression("passed", passedExp);
ConditionErrorMessage[] cerrmsgs = cev.validateConditionExpression(ce);
if (cerrmsgs != null && cerrmsgs.length > 0) {
setKeys(ureq, tpassedexpr, cerrmsgs);
return false;
}
}
// reset HINTS
tscoreexpr.setExampleKey("rules.example", EXAMPLE_SCORE);
tpassedexpr.setExampleKey("rules.example", EXAMPLE_PASSED);
return true;
}
Aggregations