Search in sources :

Example 1 with AssessmentBatch

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

the class CheckboxAssessmentController method formOK.

@Override
protected void formOK(UserRequest ureq) {
    saveCurrentSelectCheckbox();
    int numOfCheckbox = checkboxList.getNumOfCheckbox();
    Map<Long, CheckListAssessmentRow> identityToInitialRow = new HashMap<>();
    for (CheckListAssessmentRow initialRow : initialRows) {
        identityToInitialRow.put(initialRow.getIdentityKey(), initialRow);
    }
    Set<Long> assessedIdentityToUpdate = new HashSet<>();
    List<CheckboxAssessmentRow> rows = model.getObjects();
    List<AssessmentBatch> batchElements = new ArrayList<>();
    for (CheckboxAssessmentRow row : rows) {
        CheckListAssessmentRow initialRow = identityToInitialRow.get(row.getIdentityKey());
        Boolean[] checked = initialRow.getChecked();
        Boolean[] editedChecked = row.getChecked();
        Float[] scores = initialRow.getScores();
        Float[] editedScores = row.getScores();
        for (int i = 0; i < numOfCheckbox; i++) {
            Checkbox box = checkboxList.getList().get(i);
            boolean currentValue = getSecureValue(checked, i);
            boolean editedValue = getSecureValue(editedChecked, i);
            Float currentPoint = getSecureValue(scores, i);
            ;
            Float editedPoint;
            if (box.getPoints() != null && box.getPoints().floatValue() > 0f) {
                editedPoint = getSecureValue(editedScores, i);
            } else {
                editedPoint = null;
            }
            if ((editedValue != currentValue) || ((currentPoint == null && editedPoint != null) || (currentPoint != null && editedPoint == null) || (currentPoint != null && !currentPoint.equals(editedPoint)))) {
                Checkbox checkbox = checkboxList.getList().get(i);
                String checkboxId = checkbox.getCheckboxId();
                batchElements.add(new AssessmentBatch(row.getIdentityKey(), checkboxId, editedPoint, editedValue));
                assessedIdentityToUpdate.add(row.getIdentityKey());
            }
        }
    }
    checkboxManager.check(courseOres, courseNode.getIdent(), batchElements);
    if (assessedIdentityToUpdate.size() > 0) {
        DBFactory.getInstance().commit();
        ICourse course = CourseFactory.loadCourse(courseOres);
        List<Identity> assessedIdentities = securityManager.loadIdentityByKeys(assessedIdentityToUpdate);
        for (Identity assessedIdentity : assessedIdentities) {
            UserCourseEnvironment assessedUserCourseEnv = AssessmentHelper.createAndInitUserCourseEnvironment(assessedIdentity, course);
            courseNode.updateScoreEvaluation(getIdentity(), assessedUserCourseEnv, assessedIdentity, Role.coach);
        }
    }
    fireEvent(ureq, Event.DONE_EVENT);
}
Also used : HashMap(java.util.HashMap) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) ArrayList(java.util.ArrayList) ICourse(org.olat.course.ICourse) AssessmentBatch(org.olat.course.nodes.cl.model.AssessmentBatch) Checkbox(org.olat.course.nodes.cl.model.Checkbox) Identity(org.olat.core.id.Identity) HashSet(java.util.HashSet)

Example 2 with AssessmentBatch

use of org.olat.course.nodes.cl.model.AssessmentBatch 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 3 with AssessmentBatch

use of org.olat.course.nodes.cl.model.AssessmentBatch 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)

Example 4 with AssessmentBatch

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

the class CheckListAssessmentController method doSave.

private void doSave() {
    int numOfCheckbox = checkboxList.getNumOfCheckbox();
    // save all rows
    List<CheckListAssessmentRow> rows = model.getBackedUpRows();
    List<AssessmentBatch> batchElements = new ArrayList<>(rows.size());
    Set<Long> assessedIdentityToUpdate = new HashSet<>();
    for (CheckListAssessmentRow row : rows) {
        Boolean[] checked = row.getChecked();
        Boolean[] editedChecked = new Boolean[numOfCheckbox];
        MultipleSelectionElement[] checkedEls = row.getCheckedEl();
        if (checkedEls != null) {
            for (int i = 0; i < numOfCheckbox; i++) {
                MultipleSelectionElement checkEl = checkedEls[i];
                boolean editedValue = checkEl.isAtLeastSelected(1);
                editedChecked[i] = new Boolean(editedValue);
                boolean currentValue;
                if (checked != null && checked.length > 0 && i < checked.length && checked[i] != null) {
                    currentValue = checked[i].booleanValue();
                } else {
                    currentValue = false;
                }
                if (editedValue != currentValue) {
                    Checkbox checkbox = checkboxList.getList().get(i);
                    String checkboxId = checkbox.getCheckboxId();
                    Float score = editedValue ? checkbox.getPoints() : new Float(0f);
                    batchElements.add(new AssessmentBatch(row.getIdentityKey(), checkboxId, score, editedValue));
                    assessedIdentityToUpdate.add(row.getIdentityKey());
                }
                flc.remove(checkEl);
            }
        }
        row.setCheckedEl(null);
        row.setChecked(editedChecked);
    }
    doDisableEditingMode();
    checkboxManager.check(courseOres, courseNode.getIdent(), batchElements);
    if (assessedIdentityToUpdate.size() > 0) {
        DBFactory.getInstance().commit();
        ICourse course = CourseFactory.loadCourse(courseOres);
        List<Identity> assessedIdentities = securityManager.loadIdentityByKeys(assessedIdentityToUpdate);
        for (Identity assessedIdentity : assessedIdentities) {
            UserCourseEnvironment assessedUserCourseEnv = AssessmentHelper.createAndInitUserCourseEnvironment(assessedIdentity, course);
            courseNode.updateScoreEvaluation(getIdentity(), assessedUserCourseEnv, assessedIdentity, Role.coach);
        }
    }
    reloadTable();
}
Also used : UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) ArrayList(java.util.ArrayList) ICourse(org.olat.course.ICourse) MultipleSelectionElement(org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement) AssessmentBatch(org.olat.course.nodes.cl.model.AssessmentBatch) Checkbox(org.olat.course.nodes.cl.model.Checkbox) Identity(org.olat.core.id.Identity) HashSet(java.util.HashSet)

Example 5 with AssessmentBatch

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

the class AssessedIdentityCheckListController method doSave.

private void doSave() {
    List<AssessmentBatch> batchElements = new ArrayList<>();
    for (CheckboxWrapper wrapper : wrappers) {
        Float editedPoint = null;
        if (wrapper.getPointEl() != null) {
            String val = wrapper.getPointEl().getValue();
            if (StringHelper.containsNonWhitespace(val)) {
                try {
                    editedPoint = new Float(val);
                } catch (NumberFormatException e) {
                    editedPoint = null;
                }
            }
        }
        boolean editedValue = wrapper.getCheckboxEl().isAtLeastSelected(1);
        Float currentPoint = null;
        boolean currentValue = false;
        if (wrapper.getCheck() != null) {
            currentPoint = wrapper.getCheck().getScore();
            Boolean checkObj = wrapper.getCheck().getChecked();
            if (checkObj != null && checkObj.booleanValue()) {
                currentValue = checkObj.booleanValue();
            }
        }
        if ((editedValue != currentValue) || ((currentPoint == null && editedPoint != null) || (currentPoint != null && editedPoint == null) || (currentPoint != null && !currentPoint.equals(editedPoint)))) {
            String boxId = wrapper.getCheckbox().getCheckboxId();
            batchElements.add(new AssessmentBatch(assessedIdentity.getKey(), boxId, editedPoint, editedValue));
        }
    }
    checkboxManager.check(courseOres, courseNode.getIdent(), batchElements);
    courseNode.updateScoreEvaluation(getIdentity(), assessedUserCourseEnv, assessedIdentity, Role.coach);
}
Also used : AssessmentBatch(org.olat.course.nodes.cl.model.AssessmentBatch) ArrayList(java.util.ArrayList)

Aggregations

AssessmentBatch (org.olat.course.nodes.cl.model.AssessmentBatch)8 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)6 Identity (org.olat.core.id.Identity)6 HashMap (java.util.HashMap)4 ICourse (org.olat.course.ICourse)4 Checkbox (org.olat.course.nodes.cl.model.Checkbox)4 UserCourseEnvironment (org.olat.course.run.userview.UserCourseEnvironment)4 EntityManager (javax.persistence.EntityManager)2 IdentityImpl (org.olat.basesecurity.IdentityImpl)2 MultipleSelectionElement (org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement)2 DBCheck (org.olat.course.nodes.cl.model.DBCheck)2 DBCheckbox (org.olat.course.nodes.cl.model.DBCheckbox)2