Search in sources :

Example 1 with DBCheck

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

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

the class CheckListAssessmentController method getAssessmentDataViews.

private List<CheckListAssessmentRow> getAssessmentDataViews(List<AssessmentData> datas, List<Checkbox> checkbox) {
    List<CheckListAssessmentRow> dataViews = new ArrayList<>();
    int numOfcheckbox = checkbox.size();
    Map<String, Integer> indexed = new HashMap<>();
    for (int i = numOfcheckbox; i-- > 0; ) {
        indexed.put(checkbox.get(i).getCheckboxId(), new Integer(i));
    }
    for (AssessmentData data : datas) {
        Float[] scores = new Float[numOfcheckbox];
        Boolean[] checkBool = new Boolean[numOfcheckbox];
        float totalPoints = 0.0f;
        for (DBCheck check : data.getChecks()) {
            Float score = check.getScore();
            if (score != null) {
                totalPoints += score.floatValue();
            }
            if (check.getChecked() == null)
                continue;
            check.getCheckbox();
            Integer index = indexed.get(check.getCheckbox().getCheckboxId());
            if (index != null) {
                int i = index.intValue();
                if (i >= 0 && i < numOfcheckbox) {
                    scores[i] = score;
                    checkBool[i] = check.getChecked();
                }
            }
        }
        if (maxScore != null && maxScore.floatValue() > 0f && totalPoints > maxScore.floatValue()) {
            totalPoints = maxScore.floatValue();
        }
        CheckListAssessmentRow row = new CheckListAssessmentRow(data.getIdentity(), checkBool, scores, totalPoints, userPropertyHandlers, getLocale());
        dataViews.add(row);
    }
    return dataViews;
}
Also used : DBCheck(org.olat.course.nodes.cl.model.DBCheck) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AssessmentData(org.olat.course.nodes.cl.model.AssessmentData)

Example 3 with DBCheck

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

the class CheckListRunController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    boolean readOnly = isReadOnly();
    if (formLayout instanceof FormLayoutContainer) {
        FormLayoutContainer layoutCont = (FormLayoutContainer) formLayout;
        layoutCont.contextPut("readOnly", Boolean.valueOf(readOnly));
        if (dueDate != null) {
            layoutCont.contextPut("dueDate", dueDate);
            layoutCont.contextPut("in-due-date", isPanelOpen(ureq, "due-date", true));
            if (dueDate.compareTo(new Date()) < 0) {
                layoutCont.contextPut("afterDueDate", Boolean.TRUE);
            }
        }
        layoutCont.contextPut("withScore", new Boolean(withScore));
        if (courseNode.getModuleConfiguration().getBooleanSafe(MSCourseNode.CONFIG_KEY_HAS_SCORE_FIELD, false)) {
            HighScoreRunController highScoreCtr = new HighScoreRunController(ureq, getWindowControl(), userCourseEnv, courseNode, this.mainForm);
            if (highScoreCtr.isViewHighscore()) {
                Component highScoreComponent = highScoreCtr.getInitialComponent();
                layoutCont.put("highScore", highScoreComponent);
            }
        }
        List<DBCheck> checks = checkboxManager.loadCheck(getIdentity(), courseOres, courseNode.getIdent());
        Map<String, DBCheck> uuidToCheckMap = new HashMap<>();
        for (DBCheck check : checks) {
            uuidToCheckMap.put(check.getCheckbox().getCheckboxId(), check);
        }
        List<Checkbox> list = checkboxList.getList();
        List<CheckboxWrapper> wrappers = new ArrayList<>(list.size());
        for (Checkbox checkbox : list) {
            DBCheck check = uuidToCheckMap.get(checkbox.getCheckboxId());
            CheckboxWrapper wrapper = forgeCheckboxWrapper(checkbox, check, readOnly, formLayout);
            layoutCont.add(wrapper.getCheckboxEl());
            wrappers.add(wrapper);
        }
        layoutCont.contextPut("checkboxList", wrappers);
        if (withScore || withPassed) {
            layoutCont.contextPut("enableScoreInfo", Boolean.TRUE);
            exposeConfigToVC(ureq, layoutCont);
            exposeUserDataToVC(ureq, layoutCont);
        } else {
            layoutCont.contextPut("enableScoreInfo", Boolean.FALSE);
        }
    }
}
Also used : DBCheck(org.olat.course.nodes.cl.model.DBCheck) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) HighScoreRunController(org.olat.course.highscore.ui.HighScoreRunController) Date(java.util.Date) Checkbox(org.olat.course.nodes.cl.model.Checkbox) DBCheckbox(org.olat.course.nodes.cl.model.DBCheckbox) Component(org.olat.core.gui.components.Component)

Example 4 with DBCheck

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

the class AssessedIdentityCheckListController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    if (formLayout instanceof FormLayoutContainer) {
        FormLayoutContainer layoutCont = (FormLayoutContainer) formLayout;
        List<DBCheck> checks = checkboxManager.loadCheck(assessedIdentity, courseOres, courseNode.getIdent());
        Map<String, DBCheck> uuidToCheckMap = new HashMap<>();
        for (DBCheck check : checks) {
            uuidToCheckMap.put(check.getCheckbox().getCheckboxId(), check);
        }
        List<Checkbox> list = checkboxList.getList();
        wrappers = new ArrayList<>(list.size());
        for (Checkbox checkbox : list) {
            DBCheck check = uuidToCheckMap.get(checkbox.getCheckboxId());
            boolean readOnly = false;
            CheckboxWrapper wrapper = forgeCheckboxWrapper(checkbox, check, readOnly, formLayout);
            wrappers.add(wrapper);
        }
        layoutCont.contextPut("checkboxList", wrappers);
    }
    FormLayoutContainer buttonCont = FormLayoutContainer.createButtonLayout("buttons", getTranslator());
    formLayout.add(buttonCont);
    FormSubmit saveButton = uifactory.addFormSubmitButton("save", "save", buttonCont);
    saveButton.setEnabled(checkboxList.getNumOfCheckbox() > 0);
    saveButton.setVisible(!coachCourseEnv.isCourseReadOnly());
    saveAndCloseLink = uifactory.addFormLink("save.close", buttonCont, Link.BUTTON);
    saveAndCloseLink.setEnabled(checkboxList.getNumOfCheckbox() > 0);
    saveAndCloseLink.setVisible(saveAndClose && !coachCourseEnv.isCourseReadOnly());
    if (cancel) {
        uifactory.addFormCancelButton("cancel", buttonCont, ureq, getWindowControl());
    }
}
Also used : DBCheck(org.olat.course.nodes.cl.model.DBCheck) FormSubmit(org.olat.core.gui.components.form.flexible.impl.elements.FormSubmit) HashMap(java.util.HashMap) Checkbox(org.olat.course.nodes.cl.model.Checkbox) DBCheckbox(org.olat.course.nodes.cl.model.DBCheckbox) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)

Example 5 with DBCheck

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

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