use of org.olat.course.nodes.cl.model.AssessmentData in project OpenOLAT by OpenOLAT.
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));
}
use of org.olat.course.nodes.cl.model.AssessmentData in project OpenOLAT by OpenOLAT.
the class CheckListAssessmentController method loadDatas.
private List<CheckListAssessmentRow> loadDatas() {
if (!(coachCourseEnv instanceof UserCourseEnvironmentImpl)) {
return Collections.emptyList();
}
UserCourseEnvironmentImpl env = (UserCourseEnvironmentImpl) coachCourseEnv;
List<Checkbox> checkboxColl = checkboxList.getList();
int numOfCheckbox = checkboxList.getNumOfCheckbox();
boolean courseAdmin = env.isAdmin();
RepositoryEntry re = env.getCourseRepositoryEntry();
boolean courseTutor = repositoryService.hasRole(getIdentity(), re, GroupRoles.coach.name());
Set<Long> missingIdentityKeys = new HashSet<>();
if (courseTutor || courseAdmin) {
List<RepositoryEntryMembership> repoMemberships = repositoryManager.getRepositoryEntryMembership(re);
for (RepositoryEntryMembership repoMembership : repoMemberships) {
if (repoMembership.isParticipant()) {
missingIdentityKeys.add(repoMembership.getIdentityKey());
}
}
}
List<BusinessGroup> coachedGroups = courseAdmin ? coachCourseEnv.getCourseEnvironment().getCourseGroupManager().getAllBusinessGroups() : env.getCoachedGroups();
List<AssessmentData> dataList = checkboxManager.getAssessmentDatas(courseOres, courseNode.getIdent(), courseTutor || courseAdmin ? re : null, coachedGroups);
List<CheckListAssessmentRow> boxList = getAssessmentDataViews(dataList, checkboxColl);
Map<Long, CheckListAssessmentRow> identityToView = new HashMap<>();
for (CheckListAssessmentRow box : boxList) {
identityToView.put(box.getIdentityKey(), box);
missingIdentityKeys.remove(box.getIdentityKey());
}
List<BusinessGroupMembership> memberships = businessGroupService.getBusinessGroupsMembership(coachedGroups);
for (BusinessGroupMembership membership : memberships) {
if (!membership.isParticipant())
continue;
Long identityKey = membership.getIdentityKey();
if (!identityToView.containsKey(identityKey)) {
missingIdentityKeys.add(identityKey);
}
}
List<Identity> missingIdentities = securityManager.loadIdentityByKeys(missingIdentityKeys);
for (Identity missingIdentity : missingIdentities) {
Boolean[] checked = new Boolean[numOfCheckbox];
Float[] scores = new Float[numOfCheckbox];
CheckListAssessmentRow view = new CheckListAssessmentRow(missingIdentity, checked, scores, null, userPropertyHandlers, getLocale());
identityToView.put(missingIdentity.getKey(), view);
}
for (BusinessGroupMembership membership : memberships) {
if (!membership.isParticipant())
continue;
CheckListAssessmentRow view = identityToView.get(membership.getIdentityKey());
if (view != null) {
view.addGroupKey(membership.getGroupKey());
}
}
List<CheckListAssessmentRow> views = new ArrayList<>();
views.addAll(identityToView.values());
return views;
}
use of org.olat.course.nodes.cl.model.AssessmentData in project OpenOLAT by OpenOLAT.
the class CheckListExcelExport method exportAll.
public void exportAll(String filename, ZipOutputStream exportStream) {
List<AssessmentData> dataList = checkboxManager.getAssessmentDatas(course, courseNode.getIdent(), null, null);
try (OutputStream out = new ShieldOutputStream(exportStream)) {
exportStream.putNextEntry(new ZipEntry(filename + ".xlsx"));
exportWorkbook(dataList, out);
exportStream.closeEntry();
} catch (IOException e) {
log.error("", e);
}
}
use of org.olat.course.nodes.cl.model.AssessmentData in project OpenOLAT by OpenOLAT.
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++;
}
}
}
}
}
use of org.olat.course.nodes.cl.model.AssessmentData in project OpenOLAT by OpenOLAT.
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);
}
}
Aggregations