use of org.olat.course.nodes.cl.model.DBCheckbox in project OpenOLAT by OpenOLAT.
the class CheckListRunController method doCheck.
private boolean doCheck(UserRequest ureq, CheckboxWrapper wrapper, boolean checked) {
DBCheckbox theOne;
if (wrapper.getDbCheckbox() == null) {
String uuid = wrapper.getCheckbox().getCheckboxId();
theOne = checkboxManager.loadCheckbox(courseOres, courseNode.getIdent(), uuid);
} else {
theOne = wrapper.getDbCheckbox();
}
if (theOne == null) {
// only warning because this happen in course preview
logWarn("A checkbox is missing: " + courseOres + " / " + courseNode.getIdent(), null);
} else {
Float score;
if (checked) {
score = wrapper.getCheckbox().getPoints();
} else {
score = 0f;
}
checkboxManager.check(theOne, getIdentity(), score, Boolean.valueOf(checked));
// make sure all results is on the database before calculating some scores
// manager commit already
courseNode.updateScoreEvaluation(getIdentity(), userCourseEnv, getIdentity(), Role.user);
Checkbox checkbox = wrapper.getCheckbox();
logUpdateCheck(checkbox.getCheckboxId(), checkbox.getTitle());
}
exposeUserDataToVC(ureq, flc);
return courseNode.hasScoreConfigured() || courseNode.hasPassedConfigured();
}
use of org.olat.course.nodes.cl.model.DBCheckbox in project OpenOLAT by OpenOLAT.
the class CheckboxManagerImpl method syncCheckbox.
@Override
public void syncCheckbox(CheckboxList checkboxList, OLATResourceable ores, String resSubPath) {
List<DBCheckbox> dbCheckboxList = loadCheckbox(ores, resSubPath);
Map<String, DBCheckbox> uuids = new HashMap<String, DBCheckbox>();
for (DBCheckbox dbCheckbox : dbCheckboxList) {
uuids.put(dbCheckbox.getCheckboxId(), dbCheckbox);
}
if (checkboxList != null && checkboxList.getList() != null) {
List<Checkbox> resCheckboxList = checkboxList.getList();
for (Checkbox resCheckbox : resCheckboxList) {
String resUuid = resCheckbox.getCheckboxId();
if (uuids.containsKey(resUuid)) {
// already synched
uuids.remove(resUuid);
} else {
createDBCheckbox(resUuid, ores, resSubPath);
}
}
}
for (DBCheckbox dbCheckbox : uuids.values()) {
System.out.println("Remove them??? " + dbCheckbox.getCheckboxId());
}
}
use of org.olat.course.nodes.cl.model.DBCheckbox in project OpenOLAT by OpenOLAT.
the class CheckboxManagerImpl method check.
@Override
public void check(DBCheckbox checkbox, Identity owner, Float score, Boolean checked) {
DBCheck currentCheck = loadCheck(checkbox, owner);
if (currentCheck == null) {
DBCheckbox lockedCheckbox = loadForUpdate(checkbox);
if (lockedCheckbox != null) {
// locked -> reload to make sure nobody create it
DBCheck reloadedCheck = loadCheck(checkbox, owner);
if (reloadedCheck == null) {
createCheck(lockedCheckbox, owner, score, checked);
} else {
currentCheck = reloadedCheck;
}
}
}
if (currentCheck != null) {
currentCheck.setScore(score);
currentCheck.setChecked(checked);
}
dbInstance.commit();
}
use of org.olat.course.nodes.cl.model.DBCheckbox in project openolat by klemens.
the class CheckboxManagerTest method createCheck.
@Test
public void createCheck() {
Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("check-1");
OLATResourceable ores = OresHelper.createOLATResourceableInstance("checkbox-5", 2349l);
String resSubPath = UUID.randomUUID().toString();
String checkboxId = UUID.randomUUID().toString();
DBCheckbox checkbox = checkboxManager.createDBCheckbox(checkboxId, ores, resSubPath);
// create a check
DBCheck check = checkboxManager.createCheck(checkbox, id, new Float(1.0), Boolean.TRUE);
dbInstance.commitAndCloseSession();
// paranoia check
Assert.assertNotNull(check);
Assert.assertNotNull(check.getKey());
Assert.assertNotNull(check.getCreationDate());
Assert.assertNotNull(check.getLastModified());
Assert.assertEquals(id, check.getIdentity());
Assert.assertEquals(checkbox, check.getCheckbox());
Assert.assertEquals(Boolean.TRUE, check.getChecked());
Assert.assertEquals(1.0f, check.getScore().floatValue(), 0.00001);
}
use of org.olat.course.nodes.cl.model.DBCheckbox in project openolat by klemens.
the class CheckboxManagerTest method testCheck.
@Test
public void testCheck() {
Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("check-2");
OLATResourceable ores = OresHelper.createOLATResourceableInstance("checkbox-6", 2350l);
String resSubPath = UUID.randomUUID().toString();
String checkboxId = UUID.randomUUID().toString();
DBCheckbox checkbox = checkboxManager.createDBCheckbox(checkboxId, ores, resSubPath);
dbInstance.commitAndCloseSession();
// check
checkboxManager.check(checkbox, id, new Float(1.515), Boolean.FALSE);
dbInstance.commitAndCloseSession();
// load the check
DBCheck loadedCheck = checkboxManager.loadCheck(checkbox, id);
// paranoia check
Assert.assertNotNull(loadedCheck);
Assert.assertEquals(id, loadedCheck.getIdentity());
Assert.assertEquals(checkbox, loadedCheck.getCheckbox());
Assert.assertEquals(Boolean.FALSE, loadedCheck.getChecked());
Assert.assertEquals(1.515f, loadedCheck.getScore().floatValue(), 0.00001);
}
Aggregations