Search in sources :

Example 16 with CourseEditorEnv

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());
}
Also used : CourseEditorEnv(org.olat.course.editor.CourseEditorEnv) EfficiencyStatementManager(org.olat.course.assessment.manager.EfficiencyStatementManager) UserEfficiencyStatement(org.olat.course.assessment.UserEfficiencyStatement) RepositoryEntryRefImpl(org.olat.repository.model.RepositoryEntryRefImpl) ArgumentParseException(org.olat.course.condition.interpreter.ArgumentParseException) RepositoryEntryRef(org.olat.repository.RepositoryEntryRef)

Example 17 with CourseEditorEnv

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;
}
Also used : CourseEditorEnv(org.olat.course.editor.CourseEditorEnv) Identity(org.olat.core.id.Identity) IdentityEnvironment(org.olat.core.id.IdentityEnvironment)

Example 18 with CourseEditorEnv

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;
}
Also used : User(org.olat.core.id.User) CourseEditorEnv(org.olat.course.editor.CourseEditorEnv) Identity(org.olat.core.id.Identity)

Example 19 with CourseEditorEnv

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

Example 20 with CourseEditorEnv

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;
}
Also used : CourseGroupManager(org.olat.course.groupsandrights.CourseGroupManager) BusinessGroupService(org.olat.group.BusinessGroupService) CourseEditorEnv(org.olat.course.editor.CourseEditorEnv) Identity(org.olat.core.id.Identity)

Aggregations

CourseEditorEnv (org.olat.course.editor.CourseEditorEnv)68 Identity (org.olat.core.id.Identity)32 ArgumentParseException (org.olat.course.condition.interpreter.ArgumentParseException)10 CourseGroupManager (org.olat.course.groupsandrights.CourseGroupManager)8 CourseNode (org.olat.course.nodes.CourseNode)8 Date (java.util.Date)6 BusinessGroupService (org.olat.group.BusinessGroupService)6 IdentityEnvironment (org.olat.core.id.IdentityEnvironment)4 User (org.olat.core.id.User)4 AssessmentManager (org.olat.course.assessment.AssessmentManager)4 UserCourseInformations (org.olat.course.assessment.UserCourseInformations)4 UserEfficiencyStatement (org.olat.course.assessment.UserEfficiencyStatement)4 EfficiencyStatementManager (org.olat.course.assessment.manager.EfficiencyStatementManager)4 UserCourseInformationsManager (org.olat.course.assessment.manager.UserCourseInformationsManager)4 ConditionErrorMessage (org.olat.course.condition.interpreter.ConditionErrorMessage)4 ConditionExpression (org.olat.course.condition.interpreter.ConditionExpression)4 ENCourseNode (org.olat.course.nodes.ENCourseNode)4 STCourseNode (org.olat.course.nodes.STCourseNode)4 CoursePropertyManager (org.olat.course.properties.CoursePropertyManager)4 CourseEnvironment (org.olat.course.run.environment.CourseEnvironment)4