Search in sources :

Example 16 with AssessmentData

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

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 17 with AssessmentData

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

the class CheckboxManagerTest method loadAssessmentDatas_inCourse.

@Test
public void loadAssessmentDatas_inCourse() {
    RepositoryEntry entry = JunitTestHelper.createAndPersistRepositoryEntry();
    Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("check-18");
    repositoryEntryRelationDao.addRole(id, entry, GroupRoles.participant.name());
    dbInstance.commitAndCloseSession();
    String checkboxId = UUID.randomUUID().toString();
    String resSubPath = UUID.randomUUID().toString();
    DBCheckbox checkbox = checkboxManager.createDBCheckbox(checkboxId, entry.getOlatResource(), resSubPath);
    DBCheck check = checkboxManager.createCheck(checkbox, id, null, Boolean.TRUE);
    dbInstance.commitAndCloseSession();
    // load and check the check
    List<AssessmentData> loadedChecks = checkboxManager.getAssessmentDatas(entry.getOlatResource(), resSubPath, entry, null);
    Assert.assertNotNull(loadedChecks);
    Assert.assertEquals(1, loadedChecks.size());
    AssessmentData data = loadedChecks.get(0);
    Assert.assertNotNull(data);
    Assert.assertNotNull(data.getChecks());
    Assert.assertEquals(1, data.getChecks().size());
    Assert.assertEquals(check, data.getChecks().get(0));
    Assert.assertEquals(id, data.getIdentity());
}
Also used : AssessmentData(org.olat.course.nodes.cl.model.AssessmentData) DBCheck(org.olat.course.nodes.cl.model.DBCheck) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) DBCheckbox(org.olat.course.nodes.cl.model.DBCheckbox) Test(org.junit.Test)

Example 18 with AssessmentData

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

the class CheckboxManagerTest method loadAssessmentDatas.

@Test
public void loadAssessmentDatas() {
    Identity id1 = JunitTestHelper.createAndPersistIdentityAsRndUser("check-4");
    Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("check-5");
    Identity id3 = JunitTestHelper.createAndPersistIdentityAsRndUser("check-6");
    OLATResourceable ores = OresHelper.createOLATResourceableInstance("checkbox-9", 2353l);
    String resSubPath = UUID.randomUUID().toString();
    String checkboxId1 = UUID.randomUUID().toString();
    DBCheckbox checkbox1 = checkboxManager.createDBCheckbox(checkboxId1, ores, resSubPath);
    String checkboxId2 = UUID.randomUUID().toString();
    DBCheckbox checkbox2 = checkboxManager.createDBCheckbox(checkboxId2, ores, resSubPath);
    // create a check
    DBCheck check1_1 = checkboxManager.createCheck(checkbox1, id1, null, Boolean.TRUE);
    DBCheck check1_2 = checkboxManager.createCheck(checkbox2, id1, null, Boolean.TRUE);
    DBCheck check2_1 = checkboxManager.createCheck(checkbox1, id2, null, Boolean.TRUE);
    DBCheck check3_1 = checkboxManager.createCheck(checkbox1, id3, null, Boolean.TRUE);
    DBCheck check3_2 = checkboxManager.createCheck(checkbox2, id3, null, Boolean.FALSE);
    dbInstance.commitAndCloseSession();
    // load the check
    List<AssessmentData> loadedChecks = checkboxManager.getAssessmentDatas(ores, resSubPath, null, null);
    Assert.assertNotNull(loadedChecks);
    Assert.assertEquals(3, loadedChecks.size());
    List<DBCheck> collectedChecks = new ArrayList<>();
    for (AssessmentData loadedCheck : loadedChecks) {
        for (DBCheck loaded : loadedCheck.getChecks()) {
            collectedChecks.add(loaded);
        }
    }
    Assert.assertEquals(5, collectedChecks.size());
    Assert.assertTrue(collectedChecks.contains(check1_1));
    Assert.assertTrue(collectedChecks.contains(check1_2));
    Assert.assertTrue(collectedChecks.contains(check2_1));
    Assert.assertTrue(collectedChecks.contains(check3_1));
    Assert.assertTrue(collectedChecks.contains(check3_2));
}
Also used : AssessmentData(org.olat.course.nodes.cl.model.AssessmentData) DBCheck(org.olat.course.nodes.cl.model.DBCheck) OLATResourceable(org.olat.core.id.OLATResourceable) ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity) DBCheckbox(org.olat.course.nodes.cl.model.DBCheckbox) Test(org.junit.Test)

Example 19 with AssessmentData

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

the class CheckListExcelExport method writeDataRow.

private void writeDataRow(AssessmentData data, AssessmentEntry entry, int num, OpenXMLWorksheet exportSheet) {
    int col = 0;
    Identity assessedIdentity = data.getIdentity();
    User assessedUser = assessedIdentity.getUser();
    Row dataRow = exportSheet.newRow();
    // sequence number
    dataRow.addCell(col++, num, null);
    for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
        if (userPropertyHandler != null) {
            String property = userPropertyHandler.getUserProperty(assessedUser, translator.getLocale());
            dataRow.addCell(col++, property, null);
        }
    }
    // homepage
    ContextEntry ce = BusinessControlFactory.getInstance().createContextEntry(assessedIdentity);
    String homepage = BusinessControlFactory.getInstance().getAsURIString(Collections.singletonList(ce), false);
    dataRow.addCell(col++, homepage, null);
    // course node points and passed
    if (courseNode.hasScoreConfigured()) {
        if (entry != null && entry.getScore() != null) {
            dataRow.addCell(col++, entry.getScore(), null);
        } else {
            col++;
        }
    }
    if (courseNode.hasPassedConfigured()) {
        if (entry != null && entry.getPassed() != null) {
            dataRow.addCell(col++, entry.getPassed().toString(), null);
        } else {
            col++;
        }
    }
    ModuleConfiguration config = courseNode.getModuleConfiguration();
    CheckboxList list = (CheckboxList) config.get(CheckListCourseNode.CONFIG_KEY_CHECKBOX);
    if (list != null && list.getList() != null && data.getChecks() != null) {
        Map<String, DBCheck> checkMap = data.getChecks().stream().collect(Collectors.toMap(c -> c.getCheckbox().getCheckboxId(), c -> c));
        List<Checkbox> checkboxList = list.getList();
        for (Checkbox checkbox : checkboxList) {
            String boxId = checkbox.getCheckboxId();
            DBCheck check = checkMap.get(boxId);
            if (check != null && check.getChecked() != null && check.getChecked().booleanValue()) {
                dataRow.addCell(col++, "x", null);
            } else {
                col++;
            }
            if (courseNode.hasScoreConfigured() && checkbox.getPoints() != null) {
                if (check != null && check.getScore() != null) {
                    dataRow.addCell(col++, check.getScore(), null);
                } else {
                    col++;
                }
            }
        }
    }
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) Util(org.olat.core.util.Util) OpenXMLWorksheet(org.olat.core.util.openxml.OpenXMLWorksheet) CoreSpringFactory(org.olat.core.CoreSpringFactory) HashMap(java.util.HashMap) DBCheck(org.olat.course.nodes.cl.model.DBCheck) OpenXMLWorkbook(org.olat.core.util.openxml.OpenXMLWorkbook) ModuleConfiguration(org.olat.modules.ModuleConfiguration) AssessmentEntry(org.olat.modules.assessment.AssessmentEntry) ContextEntry(org.olat.core.id.context.ContextEntry) CheckboxList(org.olat.course.nodes.cl.model.CheckboxList) Locale(java.util.Locale) Map(java.util.Map) AssessmentData(org.olat.course.nodes.cl.model.AssessmentData) ZipEntry(java.util.zip.ZipEntry) OLog(org.olat.core.logging.OLog) ICourse(org.olat.course.ICourse) OutputStream(java.io.OutputStream) Translator(org.olat.core.gui.translator.Translator) CellStyle(org.olat.core.util.openxml.workbookstyle.CellStyle) CheckListCourseNode(org.olat.course.nodes.CheckListCourseNode) Checkbox(org.olat.course.nodes.cl.model.Checkbox) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler) CheckboxManager(org.olat.course.nodes.cl.CheckboxManager) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) ShieldOutputStream(org.olat.core.util.io.ShieldOutputStream) BusinessControlFactory(org.olat.core.id.context.BusinessControlFactory) UserManager(org.olat.user.UserManager) List(java.util.List) User(org.olat.core.id.User) Identity(org.olat.core.id.Identity) Row(org.olat.core.util.openxml.OpenXMLWorksheet.Row) Collections(java.util.Collections) Tracing(org.olat.core.logging.Tracing) CheckboxList(org.olat.course.nodes.cl.model.CheckboxList) DBCheck(org.olat.course.nodes.cl.model.DBCheck) User(org.olat.core.id.User) ModuleConfiguration(org.olat.modules.ModuleConfiguration) ContextEntry(org.olat.core.id.context.ContextEntry) Checkbox(org.olat.course.nodes.cl.model.Checkbox) Row(org.olat.core.util.openxml.OpenXMLWorksheet.Row) Identity(org.olat.core.id.Identity) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Example 20 with AssessmentData

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

the class CheckListExcelExport method writeData.

private void writeData(List<AssessmentData> dataList, OpenXMLWorksheet exportSheet) {
    List<AssessmentEntry> entries = course.getCourseEnvironment().getAssessmentManager().getAssessmentEntries(courseNode);
    Map<Identity, AssessmentEntry> entryMap = new HashMap<>();
    for (AssessmentEntry entry : entries) {
        entryMap.put(entry.getIdentity(), entry);
    }
    int num = 1;
    for (AssessmentData data : dataList) {
        AssessmentEntry entry = entryMap.get(data.getIdentity());
        writeDataRow(data, entry, num++, exportSheet);
    }
}
Also used : AssessmentData(org.olat.course.nodes.cl.model.AssessmentData) HashMap(java.util.HashMap) Identity(org.olat.core.id.Identity) AssessmentEntry(org.olat.modules.assessment.AssessmentEntry)

Aggregations

AssessmentData (org.olat.course.nodes.cl.model.AssessmentData)20 Identity (org.olat.core.id.Identity)14 DBCheck (org.olat.course.nodes.cl.model.DBCheck)14 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)10 Test (org.junit.Test)8 DBCheckbox (org.olat.course.nodes.cl.model.DBCheckbox)8 BusinessGroup (org.olat.group.BusinessGroup)8 RepositoryEntry (org.olat.repository.RepositoryEntry)8 IOException (java.io.IOException)4 OutputStream (java.io.OutputStream)4 ZipEntry (java.util.zip.ZipEntry)4 ZipOutputStream (java.util.zip.ZipOutputStream)4 ShieldOutputStream (org.olat.core.util.io.ShieldOutputStream)4 Checkbox (org.olat.course.nodes.cl.model.Checkbox)4 AssessmentEntry (org.olat.modules.assessment.AssessmentEntry)4 Collections (java.util.Collections)2 List (java.util.List)2 Locale (java.util.Locale)2 Map (java.util.Map)2