Search in sources :

Example 21 with OpenXMLWorksheet

use of org.olat.core.util.openxml.OpenXMLWorksheet 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++;
                }
            }
        }
    }
}
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 22 with OpenXMLWorksheet

use of org.olat.core.util.openxml.OpenXMLWorksheet in project OpenOLAT by OpenOLAT.

the class AbstractLectureBlockAuditLogExport method generate.

@Override
protected void generate(OutputStream out) {
    Collections.sort(auditLog, new LectureBlockAuditLogComparator());
    try (OpenXMLWorkbook workbook = new OpenXMLWorkbook(out, 1)) {
        OpenXMLWorksheet exportSheet = workbook.nextWorksheet();
        addSheetSettings(exportSheet);
        addHeaders(exportSheet);
        addHeader(exportSheet);
        addContent(exportSheet, workbook);
    } catch (IOException e) {
        log.error("", e);
    } catch (Exception e) {
        log.error("", e);
    }
}
Also used : OpenXMLWorkbook(org.olat.core.util.openxml.OpenXMLWorkbook) IOException(java.io.IOException) OpenXMLWorksheet(org.olat.core.util.openxml.OpenXMLWorksheet) IOException(java.io.IOException)

Example 23 with OpenXMLWorksheet

use of org.olat.core.util.openxml.OpenXMLWorksheet in project OpenOLAT by OpenOLAT.

the class LectureBlockExport method addContent.

private void addContent(OpenXMLWorksheet exportSheet) {
    List<Identity> participants = lectureService.getParticipants(lectureBlock);
    List<LectureBlockRollCall> rollCalls = lectureService.getRollCalls(lectureBlock);
    Map<Identity, LectureBlockRollCall> participantToRollCallMap = rollCalls.stream().collect(Collectors.toMap(r -> r.getIdentity(), r -> r));
    for (Identity participant : participants) {
        Row row = exportSheet.newRow();
        int pos = 0;
        if (isAdministrativeUser) {
            row.addCell(pos++, participant.getName());
        }
        for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
            if (userPropertyHandler == null)
                continue;
            String val = userPropertyHandler.getUserProperty(participant.getUser(), translator.getLocale());
            row.addCell(pos++, val);
        }
        LectureBlockRollCall rollCall = participantToRollCallMap.get(participant);
        if (rollCall != null) {
            List<Integer> absentList = rollCall.getLecturesAbsentList();
            for (int i = 0; i < lectureBlock.getPlannedLecturesNumber(); i++) {
                String val = absentList.contains(i) ? "x" : null;
                row.addCell(pos++, val);
            }
            if (authorizedAbsenceEnabled && rollCall.getAbsenceAuthorized() != null && rollCall.getAbsenceAuthorized().booleanValue()) {
                row.addCell(pos++, "x");
                row.addCell(pos++, rollCall.getAbsenceReason());
            }
        }
    }
}
Also used : OutputStream(java.io.OutputStream) Formatter(org.olat.core.util.Formatter) Translator(org.olat.core.gui.translator.Translator) OpenXMLWorkbookResource(org.olat.core.util.openxml.OpenXMLWorkbookResource) LectureBlock(org.olat.modules.lecture.LectureBlock) OpenXMLWorksheet(org.olat.core.util.openxml.OpenXMLWorksheet) Date(java.util.Date) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler) CoreSpringFactory(org.olat.core.CoreSpringFactory) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) OpenXMLWorkbook(org.olat.core.util.openxml.OpenXMLWorkbook) UserManager(org.olat.user.UserManager) LectureService(org.olat.modules.lecture.LectureService) List(java.util.List) ParticipantListRepositoryController(org.olat.modules.lecture.ui.ParticipantListRepositoryController) Identity(org.olat.core.id.Identity) Row(org.olat.core.util.openxml.OpenXMLWorksheet.Row) Map(java.util.Map) StringHelper(org.olat.core.util.StringHelper) LectureBlockRollCall(org.olat.modules.lecture.LectureBlockRollCall) OLog(org.olat.core.logging.OLog) Tracing(org.olat.core.logging.Tracing) LectureBlockRollCall(org.olat.modules.lecture.LectureBlockRollCall) Row(org.olat.core.util.openxml.OpenXMLWorksheet.Row) Identity(org.olat.core.id.Identity) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Example 24 with OpenXMLWorksheet

use of org.olat.core.util.openxml.OpenXMLWorksheet in project OpenOLAT by OpenOLAT.

the class LecturesStatisticsExport method generate.

@Override
protected void generate(OutputStream out) {
    try (OpenXMLWorkbook workbook = new OpenXMLWorkbook(out, 2)) {
        OpenXMLWorksheet exportSheet = workbook.nextWorksheet();
        exportSheet.setHeaderRows(1);
        addHeadersAggregated(exportSheet);
        addContentAggregated(exportSheet, workbook);
        exportSheet = workbook.nextWorksheet();
        exportSheet.setHeaderRows(1);
        addHeadersDetailled(exportSheet);
        addContentDetailled(exportSheet, workbook);
    } catch (IOException e) {
        log.error("", e);
    }
}
Also used : OpenXMLWorkbook(org.olat.core.util.openxml.OpenXMLWorkbook) IOException(java.io.IOException) OpenXMLWorksheet(org.olat.core.util.openxml.OpenXMLWorksheet)

Example 25 with OpenXMLWorksheet

use of org.olat.core.util.openxml.OpenXMLWorksheet in project openolat by klemens.

the class LectureBlockExport method addContent.

private void addContent(OpenXMLWorksheet exportSheet) {
    List<Identity> participants = lectureService.getParticipants(lectureBlock);
    List<LectureBlockRollCall> rollCalls = lectureService.getRollCalls(lectureBlock);
    Map<Identity, LectureBlockRollCall> participantToRollCallMap = rollCalls.stream().collect(Collectors.toMap(r -> r.getIdentity(), r -> r));
    for (Identity participant : participants) {
        Row row = exportSheet.newRow();
        int pos = 0;
        if (isAdministrativeUser) {
            row.addCell(pos++, participant.getName());
        }
        for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
            if (userPropertyHandler == null)
                continue;
            String val = userPropertyHandler.getUserProperty(participant.getUser(), translator.getLocale());
            row.addCell(pos++, val);
        }
        LectureBlockRollCall rollCall = participantToRollCallMap.get(participant);
        if (rollCall != null) {
            List<Integer> absentList = rollCall.getLecturesAbsentList();
            for (int i = 0; i < lectureBlock.getPlannedLecturesNumber(); i++) {
                String val = absentList.contains(i) ? "x" : null;
                row.addCell(pos++, val);
            }
            if (authorizedAbsenceEnabled && rollCall.getAbsenceAuthorized() != null && rollCall.getAbsenceAuthorized().booleanValue()) {
                row.addCell(pos++, "x");
                row.addCell(pos++, rollCall.getAbsenceReason());
            }
        }
    }
}
Also used : OutputStream(java.io.OutputStream) Formatter(org.olat.core.util.Formatter) Translator(org.olat.core.gui.translator.Translator) OpenXMLWorkbookResource(org.olat.core.util.openxml.OpenXMLWorkbookResource) LectureBlock(org.olat.modules.lecture.LectureBlock) OpenXMLWorksheet(org.olat.core.util.openxml.OpenXMLWorksheet) Date(java.util.Date) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler) CoreSpringFactory(org.olat.core.CoreSpringFactory) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) OpenXMLWorkbook(org.olat.core.util.openxml.OpenXMLWorkbook) UserManager(org.olat.user.UserManager) LectureService(org.olat.modules.lecture.LectureService) List(java.util.List) ParticipantListRepositoryController(org.olat.modules.lecture.ui.ParticipantListRepositoryController) Identity(org.olat.core.id.Identity) Row(org.olat.core.util.openxml.OpenXMLWorksheet.Row) Map(java.util.Map) StringHelper(org.olat.core.util.StringHelper) LectureBlockRollCall(org.olat.modules.lecture.LectureBlockRollCall) OLog(org.olat.core.logging.OLog) Tracing(org.olat.core.logging.Tracing) LectureBlockRollCall(org.olat.modules.lecture.LectureBlockRollCall) Row(org.olat.core.util.openxml.OpenXMLWorksheet.Row) Identity(org.olat.core.id.Identity) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Aggregations

IOException (java.io.IOException)32 OpenXMLWorkbook (org.olat.core.util.openxml.OpenXMLWorkbook)32 OpenXMLWorksheet (org.olat.core.util.openxml.OpenXMLWorksheet)32 OutputStream (java.io.OutputStream)16 Date (java.util.Date)14 OpenXMLWorkbookResource (org.olat.core.util.openxml.OpenXMLWorkbookResource)14 Translator (org.olat.core.gui.translator.Translator)10 Row (org.olat.core.util.openxml.OpenXMLWorksheet.Row)10 Identity (org.olat.core.id.Identity)6 ICourse (org.olat.course.ICourse)6 UserPropertyHandler (org.olat.user.propertyhandlers.UserPropertyHandler)6 File (java.io.File)4 List (java.util.List)4 Map (java.util.Map)4 Collectors (java.util.stream.Collectors)4 ZipOutputStream (java.util.zip.ZipOutputStream)4 CoreSpringFactory (org.olat.core.CoreSpringFactory)4 User (org.olat.core.id.User)4 ContextEntry (org.olat.core.id.context.ContextEntry)4 OLog (org.olat.core.logging.OLog)4