Search in sources :

Example 31 with DBCheckbox

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

Example 32 with DBCheckbox

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

Example 33 with DBCheckbox

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

Example 34 with DBCheckbox

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);
}
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 35 with DBCheckbox

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

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