Search in sources :

Example 1 with DBCheckbox

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());
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) DBCheckbox(org.olat.course.nodes.cl.model.DBCheckbox) Test(org.junit.Test)

Example 2 with DBCheckbox

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);
}
Also used : DBCheck(org.olat.course.nodes.cl.model.DBCheck) OLATResourceable(org.olat.core.id.OLATResourceable) Identity(org.olat.core.id.Identity) DBCheckbox(org.olat.course.nodes.cl.model.DBCheckbox) Test(org.junit.Test)

Example 3 with DBCheckbox

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);
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) Identity(org.olat.core.id.Identity) DBCheckbox(org.olat.course.nodes.cl.model.DBCheckbox) Test(org.junit.Test)

Example 4 with DBCheckbox

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);
}
Also used : DBCheckbox(org.olat.course.nodes.cl.model.DBCheckbox)

Example 5 with DBCheckbox

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;
}
Also used : DBCheckbox(org.olat.course.nodes.cl.model.DBCheckbox) Date(java.util.Date)

Aggregations

DBCheckbox (org.olat.course.nodes.cl.model.DBCheckbox)46 Test (org.junit.Test)34 OLATResourceable (org.olat.core.id.OLATResourceable)28 Identity (org.olat.core.id.Identity)26 DBCheck (org.olat.course.nodes.cl.model.DBCheck)22 AssessmentData (org.olat.course.nodes.cl.model.AssessmentData)8 Checkbox (org.olat.course.nodes.cl.model.Checkbox)6 RepositoryEntry (org.olat.repository.RepositoryEntry)6 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 BusinessGroup (org.olat.group.BusinessGroup)4 Date (java.util.Date)2 HashSet (java.util.HashSet)2 EntityManager (javax.persistence.EntityManager)2 IdentityImpl (org.olat.basesecurity.IdentityImpl)2 AssessmentBatch (org.olat.course.nodes.cl.model.AssessmentBatch)2 CheckboxList (org.olat.course.nodes.cl.model.CheckboxList)2