use of org.olat.course.nodes.cl.model.DBCheckbox in project openolat by klemens.
the class CheckboxManagerTest method calculateScore.
@Test
public void calculateScore() {
Identity id1 = JunitTestHelper.createAndPersistIdentityAsRndUser("check-9");
Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("check-10");
Identity id3 = JunitTestHelper.createAndPersistIdentityAsRndUser("check-11");
OLATResourceable ores = OresHelper.createOLATResourceableInstance("checkbox-10", 2355l);
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, 3.0f, Boolean.TRUE);
checkboxManager.createCheck(checkbox2, id1, 2.0f, Boolean.TRUE);
checkboxManager.createCheck(checkbox1, id2, 4.0f, Boolean.TRUE);
checkboxManager.createCheck(checkbox3, id2, 5.5f, Boolean.TRUE);
checkboxManager.createCheck(checkbox4, id2, 1.0f, Boolean.FALSE);
dbInstance.commitAndCloseSession();
// count the checks
float score1 = checkboxManager.calculateScore(id1, ores, resSubPath);
Assert.assertEquals(5.0f, score1, 0.0001);
float score2 = checkboxManager.calculateScore(id2, ores, resSubPath);
Assert.assertEquals(9.5f, score2, 0.0001);
float score3 = checkboxManager.calculateScore(id3, ores, resSubPath);
Assert.assertEquals(0.0f, score3, 0.0001);
}
use of org.olat.course.nodes.cl.model.DBCheckbox in project openolat by klemens.
the class CheckboxManagerTest method loadAssessmentDatas.
@Test
public void loadAssessmentDatas() {
Identity id1 = JunitTestHelper.createAndPersistIdentityAsRndUser("check-4");
Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("check-5");
Identity id3 = JunitTestHelper.createAndPersistIdentityAsRndUser("check-6");
OLATResourceable ores = OresHelper.createOLATResourceableInstance("checkbox-9", 2353l);
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);
// create a check
DBCheck check1_1 = checkboxManager.createCheck(checkbox1, id1, null, Boolean.TRUE);
DBCheck check1_2 = checkboxManager.createCheck(checkbox2, id1, null, Boolean.TRUE);
DBCheck check2_1 = checkboxManager.createCheck(checkbox1, id2, null, Boolean.TRUE);
DBCheck check3_1 = checkboxManager.createCheck(checkbox1, id3, null, Boolean.TRUE);
DBCheck check3_2 = checkboxManager.createCheck(checkbox2, id3, null, Boolean.FALSE);
dbInstance.commitAndCloseSession();
// load the check
List<AssessmentData> loadedChecks = checkboxManager.getAssessmentDatas(ores, resSubPath, null, null);
Assert.assertNotNull(loadedChecks);
Assert.assertEquals(3, loadedChecks.size());
List<DBCheck> collectedChecks = new ArrayList<>();
for (AssessmentData loadedCheck : loadedChecks) {
for (DBCheck loaded : loadedCheck.getChecks()) {
collectedChecks.add(loaded);
}
}
Assert.assertEquals(5, collectedChecks.size());
Assert.assertTrue(collectedChecks.contains(check1_1));
Assert.assertTrue(collectedChecks.contains(check1_2));
Assert.assertTrue(collectedChecks.contains(check2_1));
Assert.assertTrue(collectedChecks.contains(check3_1));
Assert.assertTrue(collectedChecks.contains(check3_2));
}
use of org.olat.course.nodes.cl.model.DBCheckbox in project openolat by klemens.
the class CheckboxManagerTest method loadCheckBox_withcheckboxId.
@Test
public void loadCheckBox_withcheckboxId() {
OLATResourceable ores = OresHelper.createOLATResourceableInstance("checkbox-7", 2351l);
String resSubPath = UUID.randomUUID().toString();
String checkboxId = UUID.randomUUID().toString();
DBCheckbox checkbox = checkboxManager.createDBCheckbox(checkboxId, ores, resSubPath);
dbInstance.commit();
// load it
DBCheckbox loadedBox = checkboxManager.loadCheckbox(ores, resSubPath, checkboxId);
Assert.assertNotNull(loadedBox);
Assert.assertEquals(checkbox, loadedBox);
}
use of org.olat.course.nodes.cl.model.DBCheckbox in project openolat by klemens.
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 klemens.
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