Search in sources :

Example 11 with DBCheck

use of org.olat.course.nodes.cl.model.DBCheck in project openolat by klemens.

the class CheckboxManagerTest method loadAssessmentDatas_inGroup.

@Test
public void loadAssessmentDatas_inGroup() {
    RepositoryEntry entry = JunitTestHelper.createAndPersistRepositoryEntry();
    Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("check-19");
    BusinessGroup group = businessGroupDao.createAndPersist(null, "gcheck", "gcheck-desc", 0, 10, true, true, false, false, false);
    businessGroupRelationDao.addRole(id, group, GroupRoles.participant.name());
    dbInstance.commitAndCloseSession();
    String checkboxId = UUID.randomUUID().toString();
    String resSubPath = UUID.randomUUID().toString();
    DBCheckbox checkbox = checkboxManager.createDBCheckbox(checkboxId, entry.getOlatResource(), resSubPath);
    DBCheck check = checkboxManager.createCheck(checkbox, id, null, Boolean.TRUE);
    dbInstance.commitAndCloseSession();
    List<BusinessGroup> groups = Collections.singletonList(group);
    List<AssessmentData> loadedChecks = checkboxManager.getAssessmentDatas(entry.getOlatResource(), resSubPath, null, groups);
    Assert.assertNotNull(loadedChecks);
    Assert.assertEquals(1, loadedChecks.size());
    AssessmentData data = loadedChecks.get(0);
    Assert.assertNotNull(data);
    Assert.assertNotNull(data.getChecks());
    Assert.assertEquals(1, data.getChecks().size());
    Assert.assertEquals(check, data.getChecks().get(0));
    Assert.assertEquals(id, data.getIdentity());
}
Also used : AssessmentData(org.olat.course.nodes.cl.model.AssessmentData) DBCheck(org.olat.course.nodes.cl.model.DBCheck) BusinessGroup(org.olat.group.BusinessGroup) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) DBCheckbox(org.olat.course.nodes.cl.model.DBCheckbox) Test(org.junit.Test)

Example 12 with DBCheck

use of org.olat.course.nodes.cl.model.DBCheck in project openolat by klemens.

the class CheckboxManagerTest method calculateResource.

@Test
public void calculateResource() {
    // create checkbox to delete
    Identity id1 = JunitTestHelper.createAndPersistIdentityAsRndUser("check-13");
    Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("check-14");
    Identity id3 = JunitTestHelper.createAndPersistIdentityAsRndUser("check-15");
    OLATResourceable ores = OresHelper.createOLATResourceableInstance("checkbox-11", 2356l);
    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);
    // 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(checkbox3, id3, 1.0f, Boolean.FALSE);
    dbInstance.commitAndCloseSession();
    // create a reference which must stay
    OLATResourceable oresRef = OresHelper.createOLATResourceableInstance("checkbox-12", 2357l);
    String resSubPathRef = UUID.randomUUID().toString();
    String checkboxIdRef = UUID.randomUUID().toString();
    DBCheckbox checkboxRef = checkboxManager.createDBCheckbox(checkboxIdRef, oresRef, resSubPathRef);
    checkboxManager.createCheck(checkboxRef, id1, 3.0f, Boolean.TRUE);
    checkboxManager.createCheck(checkboxRef, id3, 2.0f, Boolean.TRUE);
    dbInstance.commitAndCloseSession();
    // delete all checks and checklist of the resource
    checkboxManager.deleteCheckbox(ores, resSubPath);
    dbInstance.commitAndCloseSession();
    // verify id1
    List<DBCheck> checksId1 = checkboxManager.loadCheck(id1, ores, resSubPath);
    Assert.assertNotNull(checksId1);
    Assert.assertEquals(0, checksId1.size());
    List<DBCheck> checksId1Ref = checkboxManager.loadCheck(id1, oresRef, resSubPathRef);
    Assert.assertNotNull(checksId1Ref);
    Assert.assertEquals(1, checksId1Ref.size());
    // verify id2
    List<DBCheck> checksId2 = checkboxManager.loadCheck(id2, ores, resSubPath);
    Assert.assertNotNull(checksId2);
    Assert.assertEquals(0, checksId2.size());
    List<DBCheck> checksId2Ref = checkboxManager.loadCheck(id2, oresRef, resSubPathRef);
    Assert.assertNotNull(checksId2Ref);
    Assert.assertEquals(0, checksId2Ref.size());
    // verify id3
    List<DBCheck> checksId3 = checkboxManager.loadCheck(id3, ores, resSubPath);
    Assert.assertNotNull(checksId3);
    Assert.assertEquals(0, checksId3.size());
    List<DBCheck> checksId3Ref = checkboxManager.loadCheck(id3, oresRef, resSubPathRef);
    Assert.assertNotNull(checksId3Ref);
    Assert.assertEquals(1, checksId3Ref.size());
}
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 13 with DBCheck

use of org.olat.course.nodes.cl.model.DBCheck in project openolat by klemens.

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 14 with DBCheck

use of org.olat.course.nodes.cl.model.DBCheck in project openolat by klemens.

the class CheckboxManagerTest method loadAssessmentDatas_inGroupAndCourse.

@Test
public void loadAssessmentDatas_inGroupAndCourse() {
    RepositoryEntry entry = JunitTestHelper.createAndPersistRepositoryEntry();
    Identity groupParticipant = JunitTestHelper.createAndPersistIdentityAsRndUser("check-20");
    BusinessGroup group = businessGroupDao.createAndPersist(null, "gcheck", "gcheck-desc", 0, 10, true, true, false, false, false);
    businessGroupRelationDao.addRole(groupParticipant, group, GroupRoles.participant.name());
    Identity courseParticipant = JunitTestHelper.createAndPersistIdentityAsRndUser("check-21");
    repositoryEntryRelationDao.addRole(courseParticipant, entry, GroupRoles.participant.name());
    dbInstance.commitAndCloseSession();
    // add some noise
    Identity courseOwner = JunitTestHelper.createAndPersistIdentityAsRndUser("check-22");
    repositoryEntryRelationDao.addRole(courseOwner, entry, GroupRoles.owner.name());
    Identity groupWaiting = JunitTestHelper.createAndPersistIdentityAsRndUser("check-23");
    businessGroupRelationDao.addRole(groupWaiting, group, GroupRoles.waiting.name());
    dbInstance.commitAndCloseSession();
    String checkboxId = UUID.randomUUID().toString();
    String resSubPath = UUID.randomUUID().toString();
    DBCheckbox checkbox = checkboxManager.createDBCheckbox(checkboxId, entry.getOlatResource(), resSubPath);
    DBCheck checkGroup = checkboxManager.createCheck(checkbox, groupParticipant, null, Boolean.TRUE);
    DBCheck checkCourse = checkboxManager.createCheck(checkbox, courseParticipant, null, Boolean.TRUE);
    DBCheck checkNotVisible1 = checkboxManager.createCheck(checkbox, groupWaiting, null, Boolean.FALSE);
    DBCheck checkNotVisible2 = checkboxManager.createCheck(checkbox, courseOwner, null, Boolean.FALSE);
    dbInstance.commitAndCloseSession();
    List<BusinessGroup> groups = Collections.singletonList(group);
    List<AssessmentData> loadedChecks = checkboxManager.getAssessmentDatas(entry.getOlatResource(), resSubPath, entry, groups);
    Assert.assertNotNull(loadedChecks);
    Assert.assertEquals(2, loadedChecks.size());
    List<DBCheck> collectedChecks = new ArrayList<>();
    for (AssessmentData loadedCheck : loadedChecks) {
        for (DBCheck loaded : loadedCheck.getChecks()) {
            collectedChecks.add(loaded);
        }
    }
    Assert.assertEquals(2, collectedChecks.size());
    Assert.assertTrue(collectedChecks.contains(checkGroup));
    Assert.assertTrue(collectedChecks.contains(checkCourse));
    Assert.assertFalse(collectedChecks.contains(checkNotVisible1));
    Assert.assertFalse(collectedChecks.contains(checkNotVisible2));
}
Also used : AssessmentData(org.olat.course.nodes.cl.model.AssessmentData) DBCheck(org.olat.course.nodes.cl.model.DBCheck) BusinessGroup(org.olat.group.BusinessGroup) ArrayList(java.util.ArrayList) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) DBCheckbox(org.olat.course.nodes.cl.model.DBCheckbox) Test(org.junit.Test)

Example 15 with DBCheck

use of org.olat.course.nodes.cl.model.DBCheck in project OpenOLAT by OpenOLAT.

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

Aggregations

DBCheck (org.olat.course.nodes.cl.model.DBCheck)34 DBCheckbox (org.olat.course.nodes.cl.model.DBCheckbox)26 Identity (org.olat.core.id.Identity)22 Test (org.junit.Test)18 AssessmentData (org.olat.course.nodes.cl.model.AssessmentData)14 HashMap (java.util.HashMap)12 OLATResourceable (org.olat.core.id.OLATResourceable)12 ArrayList (java.util.ArrayList)10 Checkbox (org.olat.course.nodes.cl.model.Checkbox)6 BusinessGroup (org.olat.group.BusinessGroup)6 RepositoryEntry (org.olat.repository.RepositoryEntry)6 Date (java.util.Date)4 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)3 IOException (java.io.IOException)2 OutputStream (java.io.OutputStream)2 Collections (java.util.Collections)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Locale (java.util.Locale)2 Map (java.util.Map)2