Search in sources :

Example 6 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(OLATResourceable ores, String resSubPath, List<AssessmentBatch> batch) {
    Collections.sort(batch, new BatchComparator());
    EntityManager em = dbInstance.getCurrentEntityManager();
    Set<String> dbBoxUuids = new HashSet<>();
    for (AssessmentBatch row : batch) {
        dbBoxUuids.add(row.getCheckboxId());
    }
    List<DBCheckbox> boxes = loadCheckbox(ores, resSubPath, dbBoxUuids);
    Map<String, DBCheckbox> uuidToBox = new HashMap<>();
    for (DBCheckbox box : boxes) {
        uuidToBox.put(box.getCheckboxId(), box);
    }
    Identity currentIdentity = null;
    for (AssessmentBatch row : batch) {
        Long identityKey = row.getIdentityKey();
        if (currentIdentity == null || !identityKey.equals(currentIdentity.getKey())) {
            currentIdentity = em.getReference(IdentityImpl.class, identityKey);
        }
        boolean check = row.getCheck();
        DBCheckbox checkbox = uuidToBox.get(row.getCheckboxId());
        DBCheck currentCheck = loadCheck(checkbox, currentIdentity);
        if (check) {
            if (currentCheck == null) {
                DBCheckbox lockedCheckbox = loadForUpdate(checkbox);
                if (lockedCheckbox != null) {
                    // locked -> reload to make sure nobody create it
                    DBCheck reloaedCheck = loadCheck(checkbox, currentIdentity);
                    if (reloaedCheck == null) {
                        createCheck(lockedCheckbox, currentIdentity, row.getScore(), new Boolean(check));
                    } else {
                        currentCheck = reloaedCheck;
                    }
                }
                dbInstance.commit();
            }
            if (currentCheck != null) {
                currentCheck.setScore(row.getScore());
                currentCheck.setChecked(new Boolean(check));
                em.merge(currentCheck);
            }
        // save check
        } else if (currentCheck != null) {
            currentCheck.setChecked(Boolean.FALSE);
            currentCheck.setScore(new Float(0f));
            em.merge(currentCheck);
        }
    }
}
Also used : DBCheck(org.olat.course.nodes.cl.model.DBCheck) HashMap(java.util.HashMap) IdentityImpl(org.olat.basesecurity.IdentityImpl) EntityManager(javax.persistence.EntityManager) AssessmentBatch(org.olat.course.nodes.cl.model.AssessmentBatch) Identity(org.olat.core.id.Identity) DBCheckbox(org.olat.course.nodes.cl.model.DBCheckbox) HashSet(java.util.HashSet)

Example 7 with DBCheckbox

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

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 8 with DBCheckbox

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

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 9 with DBCheckbox

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

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 10 with DBCheckbox

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

the class CheckboxManagerImpl method check.

@Override
public void check(OLATResourceable ores, String resSubPath, List<AssessmentBatch> batch) {
    Collections.sort(batch, new BatchComparator());
    EntityManager em = dbInstance.getCurrentEntityManager();
    Set<String> dbBoxUuids = new HashSet<>();
    for (AssessmentBatch row : batch) {
        dbBoxUuids.add(row.getCheckboxId());
    }
    List<DBCheckbox> boxes = loadCheckbox(ores, resSubPath, dbBoxUuids);
    Map<String, DBCheckbox> uuidToBox = new HashMap<>();
    for (DBCheckbox box : boxes) {
        uuidToBox.put(box.getCheckboxId(), box);
    }
    Identity currentIdentity = null;
    for (AssessmentBatch row : batch) {
        Long identityKey = row.getIdentityKey();
        if (currentIdentity == null || !identityKey.equals(currentIdentity.getKey())) {
            currentIdentity = em.getReference(IdentityImpl.class, identityKey);
        }
        boolean check = row.getCheck();
        DBCheckbox checkbox = uuidToBox.get(row.getCheckboxId());
        DBCheck currentCheck = loadCheck(checkbox, currentIdentity);
        if (check) {
            if (currentCheck == null) {
                DBCheckbox lockedCheckbox = loadForUpdate(checkbox);
                if (lockedCheckbox != null) {
                    // locked -> reload to make sure nobody create it
                    DBCheck reloaedCheck = loadCheck(checkbox, currentIdentity);
                    if (reloaedCheck == null) {
                        createCheck(lockedCheckbox, currentIdentity, row.getScore(), new Boolean(check));
                    } else {
                        currentCheck = reloaedCheck;
                    }
                }
                dbInstance.commit();
            }
            if (currentCheck != null) {
                currentCheck.setScore(row.getScore());
                currentCheck.setChecked(new Boolean(check));
                em.merge(currentCheck);
            }
        // save check
        } else if (currentCheck != null) {
            currentCheck.setChecked(Boolean.FALSE);
            currentCheck.setScore(new Float(0f));
            em.merge(currentCheck);
        }
    }
}
Also used : DBCheck(org.olat.course.nodes.cl.model.DBCheck) HashMap(java.util.HashMap) IdentityImpl(org.olat.basesecurity.IdentityImpl) EntityManager(javax.persistence.EntityManager) AssessmentBatch(org.olat.course.nodes.cl.model.AssessmentBatch) Identity(org.olat.core.id.Identity) DBCheckbox(org.olat.course.nodes.cl.model.DBCheckbox) HashSet(java.util.HashSet)

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