Search in sources :

Example 1 with CourseDBManager

use of org.olat.course.db.CourseDBManager 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();
}
Also used : CourseDBManager(org.olat.course.db.CourseDBManager) CourseEditorEnv(org.olat.course.editor.CourseEditorEnv) ArgumentParseException(org.olat.course.condition.interpreter.ArgumentParseException) Identity(org.olat.core.id.Identity) CourseDBEntry(org.olat.course.db.CourseDBEntry) ArgumentParseException(org.olat.course.condition.interpreter.ArgumentParseException)

Example 2 with CourseDBManager

use of org.olat.course.db.CourseDBManager in project openolat by klemens.

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();
}
Also used : CourseDBManager(org.olat.course.db.CourseDBManager) CourseEditorEnv(org.olat.course.editor.CourseEditorEnv) ArgumentParseException(org.olat.course.condition.interpreter.ArgumentParseException) Identity(org.olat.core.id.Identity) CourseDBEntry(org.olat.course.db.CourseDBEntry) ArgumentParseException(org.olat.course.condition.interpreter.ArgumentParseException)

Aggregations

Identity (org.olat.core.id.Identity)2 ArgumentParseException (org.olat.course.condition.interpreter.ArgumentParseException)2 CourseDBEntry (org.olat.course.db.CourseDBEntry)2 CourseDBManager (org.olat.course.db.CourseDBManager)2 CourseEditorEnv (org.olat.course.editor.CourseEditorEnv)2