use of org.olat.course.editor.CourseEditorEnv in project OpenOLAT by OpenOLAT.
the class GetUserCourseDBFunction method call.
/**
* @see org.olat.course.condition.interpreter.AbstractFunction#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 < 1) {
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"));
}
CourseEditorEnv cev = getUserCourseEnv().getCourseEditorEnv();
if (cev != null) {
// return emtyp string to continue with condition evaluation test
return defaultValue();
}
CourseDBManager courseDbManager = CoreSpringFactory.getImpl(CourseDBManager.class);
Identity ident = getUserCourseEnv().getIdentityEnvironment().getIdentity();
String category = null;
String key = null;
if (inStack.length == 1) {
category = null;
key = (String) inStack[1];
} else if (inStack.length == 2) {
category = (String) inStack[0];
key = (String) inStack[1];
}
Long courseId = getUserCourseEnv().getCourseEnvironment().getCourseResourceableId();
Object value;
try {
CourseDBEntry entry = courseDbManager.getValue(courseId, ident, category, key);
if (entry == null) {
return defaultValue();
}
value = entry.getValue();
if (value == null) {
return defaultValue();
}
} catch (Exception e) {
log.error("", e);
return defaultValue();
}
return value.toString();
}
use of org.olat.course.editor.CourseEditorEnv in project OpenOLAT by OpenOLAT.
the class GetCourseBeginDateFunction method call.
/**
* @see com.neemsoft.jmep.FunctionCB#call(java.lang.Object[])
*/
@Override
public Object call(Object[] inStack) {
CourseEditorEnv cev = getUserCourseEnv().getCourseEditorEnv();
if (cev != null) {
return defaultValue();
}
RepositoryEntryLifecycle lifecycle = getUserCourseEnv().getLifecycle();
if (lifecycle != null && lifecycle.getValidFrom() != null) {
return Double.valueOf(lifecycle.getValidFrom().getTime());
} else {
// what to do in case of no date available??? -> return date in the future
return new Double(Double.POSITIVE_INFINITY);
}
}
use of org.olat.course.editor.CourseEditorEnv in project OpenOLAT by OpenOLAT.
the class GetInitialCourseLaunchDateFunction method call.
/**
* @see com.neemsoft.jmep.FunctionCB#call(java.lang.Object[])
*/
public Object call(Object[] inStack) {
CourseEditorEnv cev = getUserCourseEnv().getCourseEditorEnv();
if (cev != null) {
return defaultValue();
}
// the real function evaluation which is used during run time
UserCourseInformationsManager mgr = CoreSpringFactory.getImpl(UserCourseInformationsManager.class);
UserCourseInformations infos = mgr.getUserCourseInformations(getUserCourseEnv().getCourseEnvironment().getCourseGroupManager().getCourseResource(), getUserCourseEnv().getIdentityEnvironment().getIdentity());
if (infos != null) {
return Double.valueOf(infos.getInitialLaunch().getTime());
} else {
// what to do in case of no date available??? -> return date in the future
return new Double(Double.POSITIVE_INFINITY);
}
}
use of org.olat.course.editor.CourseEditorEnv in project OpenOLAT by OpenOLAT.
the class GetRecentEnrollmentDateFunction 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.nodereference"));
} else if (inStack.length < 1) {
return handleException(new ArgumentParseException(ArgumentParseException.NEEDS_MORE_ARGUMENTS, name, "", "error.moreargs", "solution.provideone.nodereference"));
}
/*
* argument type check
*/
if (!(inStack[0] instanceof String))
return handleException(new ArgumentParseException(ArgumentParseException.WRONG_ARGUMENT_FORMAT, name, "", "error.argtype.coursnodeidexpeted", "solution.example.node.infunction"));
String nodeId = (String) inStack[0];
/*
* check reference integrity
*/
CourseEditorEnv cev = getUserCourseEnv().getCourseEditorEnv();
if (cev != null) {
if (!cev.existsNode(nodeId)) {
return handleException(new ArgumentParseException(ArgumentParseException.REFERENCE_NOT_FOUND, name, nodeId, "error.notfound.coursenodeid", "solution.copypastenodeid"));
}
if (!cev.isEnrollmentNode(nodeId)) {
return handleException(new ArgumentParseException(ArgumentParseException.REFERENCE_NOT_FOUND, name, nodeId, "error.notenrollment.coursenodeid", "solution.chooseenrollment"));
}
// Allow self-referencing but do not allow dependencies to parents as they create cycles.
if (!nodeId.equals(cev.getCurrentCourseNodeId())) {
cev.addSoftReference("courseNodeId", nodeId, false);
}
// return a valid value to continue with condition evaluation test
return defaultValue();
}
/*
* the real function evaluation which is used during run time
*/
CourseNode node = getUserCourseEnv().getCourseEnvironment().getRunStructure().getNode(nodeId);
// invalid node id's return still a valid double
// TODO fg: check with editor tree model DONE: above checks ensure correct node references
// if (node == null) return new Double(Double.NEGATIVE_INFINITY);
CoursePropertyManager pm = getUserCourseEnv().getCourseEnvironment().getCoursePropertyManager();
Identity identity = getUserCourseEnv().getIdentityEnvironment().getIdentity();
Property recentTime = pm.findCourseNodeProperty(node, identity, null, ENCourseNode.PROPERTY_RECENT_ENROLLMENT_DATE);
if (recentTime != null) {
String firstTimeMillis = recentTime.getStringValue();
return Double.valueOf(firstTimeMillis);
} else {
// what to do in case of no date available??? -> return date in the future
return new Double(Double.POSITIVE_INFINITY);
}
}
use of org.olat.course.editor.CourseEditorEnv in project OpenOLAT by OpenOLAT.
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;
}
Aggregations