use of org.olat.course.editor.CourseEditorEnv in project OpenOLAT by OpenOLAT.
the class GetScoreWithCourseIdFunction method call.
/**
* @see com.neemsoft.jmep.FunctionCB#call(java.lang.Object[])
*/
public Object call(Object[] inStack) {
if (inStack.length > 2) {
// need > 2 for compatibility reason
return handleException(new ArgumentParseException(ArgumentParseException.NEEDS_FEWER_ARGUMENTS, name, "", "error.fewerargs", "solution.provideone.nodereference"));
} else if (inStack.length < 1) {
return handleException(new ArgumentParseException(ArgumentParseException.NEEDS_MORE_ARGUMENTS, name, "", "error.moreargs", "solution.provideone.nodereference"));
}
Long courseRepoEntryKey;
try {
courseRepoEntryKey = Long.decode((String) inStack[0]);
} catch (NumberFormatException nfe) {
return handleException(new ArgumentParseException(ArgumentParseException.WRONG_ARGUMENT_FORMAT, name, "", "error.argtype.coursnodeidexpeted", "solution.example.node.infunction"));
}
// no integrity check can be done - other course might not exist anymore
CourseEditorEnv cev = getUserCourseEnv().getCourseEditorEnv();
if (cev != null) {
return defaultValue();
}
// the real function evaluation which is used during run time
EfficiencyStatementManager esm = CoreSpringFactory.getImpl(EfficiencyStatementManager.class);
RepositoryEntryRef courseRef = new RepositoryEntryRefImpl(courseRepoEntryKey);
UserEfficiencyStatement es = esm.getUserEfficiencyStatementLightByRepositoryEntry(courseRef, getUserCourseEnv().getIdentityEnvironment().getIdentity());
if (es == null)
return defaultValue();
Float score = es.getScore();
if (score == null)
return defaultValue();
// finally check existing value
return new Double(score.doubleValue());
}
use of org.olat.course.editor.CourseEditorEnv in project openolat by klemens.
the class EvalAttributeFunction method call.
/**
* @see com.neemsoft.jmep.FunctionCB#call(java.lang.Object[])
*/
@Override
public Object call(Object[] inStack) {
/*
* argument check
*/
if (inStack.length > 2) {
return handleException(new ArgumentParseException(ArgumentParseException.NEEDS_FEWER_ARGUMENTS, name, "", "error.fewerargs", "solution.providetwo.attrvalue"));
} else if (inStack.length < 2) {
return handleException(new ArgumentParseException(ArgumentParseException.NEEDS_MORE_ARGUMENTS, name, "", "error.moreargs", "solution.providetwo.attrvalue"));
}
/*
* argument type check
*/
if (!(inStack[0] instanceof String))
return handleException(new ArgumentParseException(ArgumentParseException.WRONG_ARGUMENT_FORMAT, name, "", "error.argtype.attributename", "solution.example.name.infunction"));
if (!(inStack[1] instanceof String))
return handleException(new ArgumentParseException(ArgumentParseException.WRONG_ARGUMENT_FORMAT, name, "", "error.argtype.attribvalue", "solution.example.name.infunction"));
String attributeId = (String) inStack[0];
/*
* check reference integrity
*/
CourseEditorEnv cev = getUserCourseEnv().getCourseEditorEnv();
if (cev != null) {
// remember the reference to the attribute for this condtion
cev.addSoftReference("attribute", attributeId, false);
// return a valid value to continue with condition evaluation test
return defaultValue();
}
/*
* the real function evaluation which is used during run time
*/
String attName = (String) inStack[0];
String attValue = (String) inStack[1];
IdentityEnvironment ienv = getUserCourseEnv().getIdentityEnvironment();
Identity ident = ienv.getIdentity();
Map<String, String> attributes = ienv.getAttributes();
if (attributes == null)
return ConditionInterpreter.INT_FALSE;
String value = attributes.get(attName);
boolean match = false;
boolean debug = log.isDebug();
if (debug) {
log.debug("value : " + value);
log.debug("attrValue: " + attValue);
log.debug("fT : " + functionType);
}
if (value != null) {
if (functionType <= FUNCTION_TYPE_IS_NOT_IN_ATTRIBUTE) {
match = findExpressionInMultiValue(attValue, value, functionType);
} else if (functionType == FUNCTION_TYPE_HAS_NOT_ATTRIBUTE) {
match = !findExpressionInMultiValue(attValue, value, FUNCTION_TYPE_HAS_ATTRIBUTE);
}
}
if (debug) {
log.debug("identity '" + ident.getName() + "' tested on attribute '" + attName + "' to have value '" + attValue + "' user's value was '" + value + "', match=" + match);
}
return match ? ConditionInterpreter.INT_TRUE : ConditionInterpreter.INT_FALSE;
}
use of org.olat.course.editor.CourseEditorEnv in project openolat by klemens.
the class EvalUserPropertyFunction method call.
/**
* @see com.neemsoft.jmep.FunctionCB#call(java.lang.Object[])
*/
public Object call(Object[] inStack) {
/*
* argument check
*/
if (inStack.length > 2) {
String name = getFunctionName(functionType);
return handleException(new ArgumentParseException(ArgumentParseException.NEEDS_FEWER_ARGUMENTS, name, "", "error.fewerargs", "solution.providetwo.attrvalue"));
} else if (inStack.length < 2) {
String name = getFunctionName(functionType);
return handleException(new ArgumentParseException(ArgumentParseException.NEEDS_MORE_ARGUMENTS, name, "", "error.moreargs", "solution.providetwo.attrvalue"));
}
/*
* argument type check
*/
if (!(inStack[0] instanceof String)) {
String name = getFunctionName(functionType);
return handleException(new ArgumentParseException(ArgumentParseException.WRONG_ARGUMENT_FORMAT, name, "", "error.argtype.attributename", "solution.example.name.infunction"));
}
if (!(inStack[1] instanceof String)) {
String name = getFunctionName(functionType);
return handleException(new ArgumentParseException(ArgumentParseException.WRONG_ARGUMENT_FORMAT, name, "", "error.argtype.attribvalue", "solution.example.name.infunction"));
} else {
String propValue = (String) inStack[1];
if (!StringHelper.containsNonWhitespace(propValue)) {
String name = getFunctionName(functionType);
return handleException(new ArgumentParseException(ArgumentParseException.WRONG_ARGUMENT_FORMAT, name, "", "error.argtype.attribvalue", "solution.example.whiteSpace"));
}
}
/*
* check reference integrity
*/
CourseEditorEnv cev = getUserCourseEnv().getCourseEditorEnv();
if (cev != null) {
// return a valid value to continue with condition evaluation test
return defaultValue();
}
/*
* the real function evaluation which is used during run time
*/
String propName = (String) inStack[0];
String searchValue = (String) inStack[1];
Identity ident = getUserCourseEnv().getIdentityEnvironment().getIdentity();
if (ident == null) {
return defaultValue();
}
User user = ident.getUser();
String userValue = user.getPropertyOrIdentityEnvAttribute(propName, null);
boolean match = false;
boolean debug = log.isDebug();
if (debug) {
log.debug("value : " + userValue);
log.debug("searchValue: " + searchValue);
log.debug("fT : " + functionType);
}
if (StringHelper.containsNonWhitespace(userValue)) {
match = checkPropertyValue(searchValue, userValue);
}
if (debug) {
log.debug("identity '" + ident.getName() + "' tested on properties '" + propName + "' to have value '" + searchValue + "' user's value was '" + userValue + "', match=" + match);
}
return match ? ConditionInterpreter.INT_TRUE : ConditionInterpreter.INT_FALSE;
}
use of org.olat.course.editor.CourseEditorEnv in project openolat by klemens.
the class InInstitutionFunction method call.
/**
* @see com.neemsoft.jmep.FunctionCB#call(java.lang.Object[])
*/
public Object call(Object[] inStack) {
/*
* argument check
*/
if (inStack.length > 1) {
return handleException(new ArgumentParseException(ArgumentParseException.NEEDS_FEWER_ARGUMENTS, name, "", "error.fewerargs", "solution.provideone.institutionalname"));
} else if (inStack.length < 1) {
return handleException(new ArgumentParseException(ArgumentParseException.NEEDS_MORE_ARGUMENTS, name, "", "error.moreargs", "solution.provideone.institutionalname"));
}
/*
* argument type check
*/
if (!(inStack[0] instanceof String))
return handleException(new ArgumentParseException(ArgumentParseException.WRONG_ARGUMENT_FORMAT, name, "", "error.argtype.institutionalname", "solution.example.institutionalname.infunction"));
String configInstname = (String) inStack[0];
/*
* expression check only if cev != null
*/
CourseEditorEnv cev = getUserCourseEnv().getCourseEditorEnv();
if (cev != null) {
// return a valid value to continue with condition evaluation test
return defaultValue();
}
Identity ident = getUserCourseEnv().getIdentityEnvironment().getIdentity();
String instName = ident.getUser().getProperty(UserConstants.INSTITUTIONALNAME, getUserCourseEnv().getIdentityEnvironment().getLocale());
return instName.equals(configInstname) ? ConditionInterpreter.INT_TRUE : ConditionInterpreter.INT_FALSE;
}
use of org.olat.course.editor.CourseEditorEnv in project openolat by klemens.
the class InLearningGroupFunction method call.
/**
* @see com.neemsoft.jmep.FunctionCB#call(java.lang.Object[])
*/
@Override
public Object call(Object[] inStack) {
/*
* argument check
*/
if (inStack.length > 1) {
return handleException(new ArgumentParseException(ArgumentParseException.NEEDS_FEWER_ARGUMENTS, name, "", "error.fewerargs", "solution.provideone.groupname"));
} else if (inStack.length < 1) {
return handleException(new ArgumentParseException(ArgumentParseException.NEEDS_MORE_ARGUMENTS, name, "", "error.moreargs", "solution.provideone.groupname"));
}
/*
* argument type check
*/
if (!(inStack[0] instanceof String))
return handleException(new ArgumentParseException(ArgumentParseException.WRONG_ARGUMENT_FORMAT, name, "", "error.argtype.groupnameexpected", "solution.example.name.infunction"));
String groupName = (String) inStack[0];
groupName = groupName != null ? groupName.trim() : null;
/*
* check reference integrity
*/
CourseEditorEnv cev = getUserCourseEnv().getCourseEditorEnv();
if (cev != null) {
if (!cev.existsGroup(groupName)) {
return handleException(new ArgumentParseException(ArgumentParseException.REFERENCE_NOT_FOUND, name, groupName, "error.notfound.name", "solution.checkgroupmanagement"));
}
// remember the reference to the node id for this condtion
cev.addSoftReference("groupId", groupName, false);
// return a valid value to continue with condition evaluation test
return defaultValue();
}
// the real function evaluation which is used during run time
if (StringHelper.isLong(groupName)) {
try {
Long groupKey = Long.parseLong(groupName);
return getUserCourseEnv().isIdentityInCourseGroup(groupKey) ? ConditionInterpreter.INT_TRUE : ConditionInterpreter.INT_FALSE;
} catch (NumberFormatException e) {
log.error("" + groupName, e);
}
}
CourseGroupManager cgm = getUserCourseEnv().getCourseEnvironment().getCourseGroupManager();
List<Long> groupKeys = CoreSpringFactory.getImpl(BusinessGroupService.class).toGroupKeys(groupName, cgm.getCourseEntry());
if (!groupKeys.isEmpty()) {
Identity ident = getUserCourseEnv().getIdentityEnvironment().getIdentity();
return cgm.isIdentityInGroup(ident, groupKeys.get(0)) ? ConditionInterpreter.INT_TRUE : ConditionInterpreter.INT_FALSE;
}
return ConditionInterpreter.INT_FALSE;
}
Aggregations