use of org.olat.course.nodes.cl.model.DBCheckbox in project OpenOLAT by OpenOLAT.
the class CheckboxManagerTest method createCheckBox.
@Test
public void createCheckBox() {
OLATResourceable ores = OresHelper.createOLATResourceableInstance("checkbox-1", 2345l);
String resSubPath = UUID.randomUUID().toString();
String checkboxId = UUID.randomUUID().toString();
DBCheckbox checkbox = checkboxManager.createDBCheckbox(checkboxId, ores, resSubPath);
dbInstance.commit();
Assert.assertNotNull(checkbox);
Assert.assertNotNull(checkbox.getKey());
Assert.assertNotNull(checkbox.getCreationDate());
Assert.assertEquals(checkboxId, checkbox.getCheckboxId());
Assert.assertEquals("checkbox-1", checkbox.getResName());
Assert.assertEquals(new Long(2345l), checkbox.getResId());
Assert.assertEquals(resSubPath, checkbox.getResSubPath());
}
use of org.olat.course.nodes.cl.model.DBCheckbox in project OpenOLAT by OpenOLAT.
the class CheckboxManagerTest method loadCheck.
@Test
public void loadCheck() {
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);
// create a check
DBCheck check = checkboxManager.createCheck(checkbox, id, new Float(1.0), Boolean.TRUE);
dbInstance.commitAndCloseSession();
// load the check
DBCheck loadedCheck = checkboxManager.loadCheck(checkbox, id);
// paranoia check
Assert.assertNotNull(loadedCheck);
Assert.assertEquals(check, loadedCheck);
Assert.assertEquals(id, loadedCheck.getIdentity());
Assert.assertEquals(checkbox, loadedCheck.getCheckbox());
Assert.assertEquals(Boolean.TRUE, loadedCheck.getChecked());
Assert.assertEquals(1.0f, loadedCheck.getScore().floatValue(), 0.00001);
}
use of org.olat.course.nodes.cl.model.DBCheckbox in project OpenOLAT by OpenOLAT.
the class CheckboxManagerTest method countChecked_withIdentity.
@Test
public void countChecked_withIdentity() {
Identity id1 = JunitTestHelper.createAndPersistIdentityAsRndUser("check-7");
Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("check-8");
Identity id3 = JunitTestHelper.createAndPersistIdentityAsRndUser("check-12");
OLATResourceable ores = OresHelper.createOLATResourceableInstance("checkbox-10", 2354l);
String resSubPath = UUID.randomUUID().toString();
String checkboxId1 = UUID.randomUUID().toString();
DBCheckbox checkbox1 = checkboxManager.createDBCheckbox(checkboxId1, ores, resSubPath);
String checkboxId2 = UUID.randomUUID().toString();
DBCheckbox checkbox2 = checkboxManager.createDBCheckbox(checkboxId2, ores, resSubPath);
String checkboxId3 = UUID.randomUUID().toString();
DBCheckbox checkbox3 = checkboxManager.createDBCheckbox(checkboxId3, ores, resSubPath);
String checkboxId4 = UUID.randomUUID().toString();
DBCheckbox checkbox4 = checkboxManager.createDBCheckbox(checkboxId4, ores, resSubPath);
// create a check
checkboxManager.createCheck(checkbox1, id1, null, Boolean.TRUE);
checkboxManager.createCheck(checkbox2, id1, null, Boolean.TRUE);
checkboxManager.createCheck(checkbox1, id2, null, Boolean.TRUE);
checkboxManager.createCheck(checkbox3, id2, null, Boolean.FALSE);
checkboxManager.createCheck(checkbox4, id2, null, Boolean.TRUE);
dbInstance.commitAndCloseSession();
// count the checks
int id1Checked = checkboxManager.countChecked(id1, ores, resSubPath);
Assert.assertEquals(2, id1Checked);
int id2Checked = checkboxManager.countChecked(id2, ores, resSubPath);
Assert.assertEquals(2, id2Checked);
int id3Checked = checkboxManager.countChecked(id3, ores, resSubPath);
Assert.assertEquals(0, id3Checked);
}
use of org.olat.course.nodes.cl.model.DBCheckbox in project OpenOLAT by OpenOLAT.
the class CheckboxManagerImpl method removeCheckbox.
@Override
public void removeCheckbox(DBCheckbox checkbox) {
DBCheckbox ref = dbInstance.getCurrentEntityManager().getReference(DBCheckbox.class, checkbox.getKey());
dbInstance.getCurrentEntityManager().remove(ref);
}
use of org.olat.course.nodes.cl.model.DBCheckbox in project OpenOLAT by OpenOLAT.
the class CheckboxManagerImpl method createDBCheckbox.
@Override
public DBCheckbox createDBCheckbox(String checkboxId, OLATResourceable ores, String resSubPath) {
DBCheckbox checkbox = new DBCheckbox();
checkbox.setCreationDate(new Date());
checkbox.setLastModified(new Date());
checkbox.setCheckboxId(checkboxId);
checkbox.setResName(ores.getResourceableTypeName());
checkbox.setResId(ores.getResourceableId());
checkbox.setResSubPath(resSubPath);
dbInstance.getCurrentEntityManager().persist(checkbox);
return checkbox;
}
Aggregations