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);
}
}
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);
}
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);
}
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);
}
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();
}
Aggregations