Search in sources :

Example 46 with Property

use of org.olat.properties.Property 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);
    }
}
Also used : CourseEditorEnv(org.olat.course.editor.CourseEditorEnv) ENCourseNode(org.olat.course.nodes.ENCourseNode) CourseNode(org.olat.course.nodes.CourseNode) Identity(org.olat.core.id.Identity) Property(org.olat.properties.Property) CoursePropertyManager(org.olat.course.properties.CoursePropertyManager)

Example 47 with Property

use of org.olat.properties.Property in project OpenOLAT by OpenOLAT.

the class DBTest method testRollbackNonTransactional.

@Test
public void testRollbackNonTransactional() {
    String propertyKey1 = "testNonTransactional-1";
    String testValue1 = "testNonTransactional-1";
    String propertyKey2 = "testNonTransactional-2";
    String testValue2 = "testNonTransactional-2";
    String testValue3 = "testNonTransactional-3";
    try {
        PropertyManager pm = PropertyManager.getInstance();
        Property p1 = pm.createPropertyInstance(null, null, null, null, propertyKey1, null, null, testValue1, null);
        pm.saveProperty(p1);
        Property p2 = pm.createPropertyInstance(null, null, null, null, propertyKey2, null, null, testValue2, null);
        pm.saveProperty(p2);
        // name is null => generated DB error => rollback ?
        Property p3 = pm.createPropertyInstance(null, null, null, null, null, null, null, testValue3, null);
        pm.saveProperty(p3);
        dbInstance.commit();
        fail("Should generate error for rollback.");
        dbInstance.closeSession();
    } catch (Exception ex) {
        dbInstance.closeSession();
    }
    // check if p1 & p2 is NOT rollbacked
    PropertyManager pm = PropertyManager.getInstance();
    Property p_1 = pm.findProperty(null, null, null, null, propertyKey1);
    assertNull("Property1 is NOT rollbacked", p_1);
    Property p_2 = pm.findProperty(null, null, null, null, propertyKey2);
    assertNull("Property2 is NOT rollbacked", p_2);
}
Also used : PropertyManager(org.olat.properties.PropertyManager) Property(org.olat.properties.Property) DBRuntimeException(org.olat.core.logging.DBRuntimeException) Test(org.junit.Test)

Example 48 with Property

use of org.olat.properties.Property in project OpenOLAT by OpenOLAT.

the class DBTest method testMixedNonTransactional_Transactional.

@Test
public void testMixedNonTransactional_Transactional() {
    String propertyKey1 = "testMixed-1";
    String testValue1 = "testMixed-1";
    String propertyKey2 = "testMixed-2";
    String testValue2 = "testMixed-2";
    String testValue3 = "testMixed-3";
    try {
        // outside of transaction
        PropertyManager pm = PropertyManager.getInstance();
        Property p1 = pm.createPropertyInstance(null, null, null, null, propertyKey1, null, null, testValue1, null);
        pm.saveProperty(p1);
        // inside of transaction
        Property p2 = pm.createPropertyInstance(null, null, null, null, propertyKey2, null, null, testValue2, null);
        pm.saveProperty(p2);
        // name is null => generated DB error => rollback
        Property p3 = pm.createPropertyInstance(null, null, null, null, null, null, null, testValue3, null);
        pm.saveProperty(p3);
        dbInstance.commit();
        fail("Should generate error for rollback.");
        dbInstance.closeSession();
    } catch (Exception ex) {
        dbInstance.closeSession();
    }
    // check if p1&p2 is rollbacked
    PropertyManager pm = PropertyManager.getInstance();
    Property p_1 = pm.findProperty(null, null, null, null, propertyKey1);
    assertNull("Property1 is NOT rollbacked", p_1);
    Property p_2 = pm.findProperty(null, null, null, null, propertyKey2);
    assertNull("Property2 is NOT rollbacked", p_2);
}
Also used : PropertyManager(org.olat.properties.PropertyManager) Property(org.olat.properties.Property) DBRuntimeException(org.olat.core.logging.DBRuntimeException) Test(org.junit.Test)

Example 49 with Property

use of org.olat.properties.Property in project OpenOLAT by OpenOLAT.

the class DBTest method testDBUTF8capable.

@Test
public void testDBUTF8capable() {
    PropertyManager pm = PropertyManager.getInstance();
    String uuid = UUID.randomUUID().toString();
    String unicodetest = "a-greek a\u03E2a\u03EAa\u03E8 arab \u0630a\u0631 chinese:\u3150a\u3151a\u3152a\u3153a\u3173a\u3110-z";
    Property p = pm.createPropertyInstance(null, null, null, null, uuid, null, null, unicodetest, null);
    pm.saveProperty(p);
    // forget session cache etc.
    dbInstance.closeSession();
    Property p2 = pm.findProperty(null, null, null, null, uuid);
    String lStr = p2.getStringValue();
    assertEquals(unicodetest, lStr);
}
Also used : PropertyManager(org.olat.properties.PropertyManager) Property(org.olat.properties.Property) Test(org.junit.Test)

Example 50 with Property

use of org.olat.properties.Property in project openolat by klemens.

the class CollaborationTools method lookupFolderAccess.

public Long lookupFolderAccess() {
    NarrowedPropertyManager npm = NarrowedPropertyManager.getInstance(ores);
    Property property = npm.findProperty(null, null, PROP_CAT_BG_COLLABTOOLS, KEY_FOLDER_ACCESS);
    if (property == null) {
        // no entry
        return null;
    }
    // read the long value of the existing property
    return property.getLongValue();
}
Also used : NarrowedPropertyManager(org.olat.properties.NarrowedPropertyManager) Property(org.olat.properties.Property)

Aggregations

Property (org.olat.properties.Property)270 CoursePropertyManager (org.olat.course.properties.CoursePropertyManager)62 PropertyManager (org.olat.properties.PropertyManager)48 Identity (org.olat.core.id.Identity)36 NarrowedPropertyManager (org.olat.properties.NarrowedPropertyManager)36 ArrayList (java.util.ArrayList)24 PersistingCoursePropertyManager (org.olat.course.properties.PersistingCoursePropertyManager)22 BusinessGroup (org.olat.group.BusinessGroup)18 File (java.io.File)16 ICourse (org.olat.course.ICourse)16 Translator (org.olat.core.gui.translator.Translator)14 AssertException (org.olat.core.logging.AssertException)14 CourseNode (org.olat.course.nodes.CourseNode)14 Forum (org.olat.modules.fo.Forum)14 ForumManager (org.olat.modules.fo.manager.ForumManager)14 Test (org.junit.Test)12 SyncerExecutor (org.olat.core.util.coordinate.SyncerExecutor)12 XStream (com.thoughtworks.xstream.XStream)10 HashMap (java.util.HashMap)10 List (java.util.List)10