Search in sources :

Example 6 with DBCheck

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

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

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

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

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

the class CheckboxManagerImpl method getAssessmentDatas.

@Override
public List<AssessmentData> getAssessmentDatas(OLATResourceable ores, String resSubPath, RepositoryEntry re, List<BusinessGroup> businessGroups) {
    StringBuilder sb = new StringBuilder();
    sb.append("select check from clcheck check").append(" inner join fetch check.checkbox box").append(" inner join fetch check.identity ident").append(" inner join fetch ident.user identUser").append(" where box.resName=:resName and box.resId=:resId");
    if (StringHelper.containsNonWhitespace(resSubPath)) {
        sb.append(" and box.resSubPath=:resSubPath");
    }
    boolean hasBusinessGroups = businessGroups != null && businessGroups.size() > 0;
    if (hasBusinessGroups) {
        sb.append(" and ");
        if (re != null) {
            sb.append(" ( ");
        }
        sb.append(" check.identity.key in ( select membership.identity.key from bgroupmember membership ").append("   where membership.group in (:baseGroups) and membership.role='").append(GroupRole.participant).append("'").append(" )");
    }
    if (re != null) {
        if (hasBusinessGroups) {
            sb.append(" or ");
        } else {
            sb.append(" and ");
        }
        sb.append(" check.identity.key in ( select membership.identity.key from repoentrytogroup as rel, bgroup as reBaseGroup, bgroupmember membership ").append("   where rel.entry.key=:repoKey and rel.group=reBaseGroup and membership.group=reBaseGroup and membership.role='").append(GroupRole.participant).append("'").append(" )");
        if (hasBusinessGroups) {
            sb.append(" ) ");
        }
    }
    TypedQuery<DBCheck> query = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), DBCheck.class).setParameter("resName", ores.getResourceableTypeName()).setParameter("resId", ores.getResourceableId());
    if (StringHelper.containsNonWhitespace(resSubPath)) {
        query.setParameter("resSubPath", resSubPath);
    }
    if (hasBusinessGroups) {
        List<Group> groups = new ArrayList<>(businessGroups.size());
        for (BusinessGroup businessGroup : businessGroups) {
            groups.add(businessGroup.getBaseGroup());
        }
        query.setParameter("baseGroups", groups);
    }
    if (re != null) {
        query.setParameter("repoKey", re.getKey());
    }
    List<DBCheck> checks = query.getResultList();
    Map<Long, AssessmentData> identToBox = new HashMap<Long, AssessmentData>();
    for (DBCheck check : checks) {
        AssessmentData data = identToBox.get(check.getIdentity().getKey());
        if (data == null) {
            data = new AssessmentData(check.getIdentity());
            identToBox.put(check.getIdentity().getKey(), data);
        }
        data.getChecks().add(check);
    }
    return new ArrayList<AssessmentData>(identToBox.values());
}
Also used : Group(org.olat.basesecurity.Group) BusinessGroup(org.olat.group.BusinessGroup) DBCheck(org.olat.course.nodes.cl.model.DBCheck) BusinessGroup(org.olat.group.BusinessGroup) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AssessmentData(org.olat.course.nodes.cl.model.AssessmentData)

Example 9 with DBCheck

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

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

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