Search in sources :

Example 16 with Row

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

the class XlsMembersExport method createHeader.

private void createHeader(List<UserPropertyHandler> userPropertyHandlers, Translator translator, OpenXMLWorksheet sheet, OpenXMLWorkbook workbook) {
    Row headerRow = sheet.newRow();
    for (int c = 0; c < userPropertyHandlers.size(); c++) {
        UserPropertyHandler handler = userPropertyHandlers.get(c);
        String header = translator.translate("form.name." + handler.getName());
        headerRow.addCell(c, header, workbook.getStyles().getHeaderStyle());
    }
    Translator roleTranslator = Util.createPackageTranslator(RulesDataModel.class, translator.getLocale());
    headerRow.addCell(userPropertyHandlers.size(), roleTranslator.translate("rules.role"));
}
Also used : Translator(org.olat.core.gui.translator.Translator) Row(org.olat.core.util.openxml.OpenXMLWorksheet.Row) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Example 17 with Row

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

the class CustomDBController method exportDb.

private void exportDb(UserRequest ureq, final String category) {
    final ICourse course = CourseFactory.loadCourse(courseKey);
    String label = ExportUtil.createFileNameWithTimeStamp("DBS_" + course.getCourseTitle(), "xls");
    MediaResource export = new OpenXMLWorkbookResource(label) {

        @Override
        protected void generate(OutputStream out) {
            try (OpenXMLWorkbook workbook = new OpenXMLWorkbook(out, 1)) {
                List<CourseDBEntry> content = courseDbManager.getValues(course, null, category, null);
                OpenXMLWorksheet exportSheet = workbook.nextWorksheet();
                // create the headers
                Row headerRow = exportSheet.newRow();
                headerRow.addCell(0, translate("customDb.category"), workbook.getStyles().getHeaderStyle());
                headerRow.addCell(1, translate("customDb.entry.identity"), workbook.getStyles().getHeaderStyle());
                headerRow.addCell(2, translate("customDb.entry.name"), workbook.getStyles().getHeaderStyle());
                headerRow.addCell(3, translate("customDb.entry.value"), workbook.getStyles().getHeaderStyle());
                for (CourseDBEntry entry : content) {
                    User user = entry.getIdentity().getUser();
                    String name = user.getProperty(UserConstants.FIRSTNAME, null) + " " + user.getProperty(UserConstants.LASTNAME, null);
                    Row dataRow = exportSheet.newRow();
                    dataRow.addCell(0, entry.getCategory(), null);
                    dataRow.addCell(1, name, null);
                    if (StringHelper.containsNonWhitespace(entry.getName())) {
                        dataRow.addCell(2, entry.getName(), null);
                    }
                    if (entry.getValue() != null) {
                        dataRow.addCell(3, entry.getValue().toString(), null);
                    }
                }
            } catch (IOException e) {
                logError("", e);
            }
        }
    };
    ureq.getDispatchResult().setResultingMediaResource(export);
}
Also used : User(org.olat.core.id.User) OpenXMLWorkbookResource(org.olat.core.util.openxml.OpenXMLWorkbookResource) OutputStream(java.io.OutputStream) OpenXMLWorkbook(org.olat.core.util.openxml.OpenXMLWorkbook) ICourse(org.olat.course.ICourse) MediaResource(org.olat.core.gui.media.MediaResource) Row(org.olat.core.util.openxml.OpenXMLWorksheet.Row) IOException(java.io.IOException) OpenXMLWorksheet(org.olat.core.util.openxml.OpenXMLWorksheet)

Example 18 with Row

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

the class QuestionItemAuditLogExport method addContent.

@SuppressWarnings("deprecation")
private void addContent(OpenXMLWorksheet exportSheet, OpenXMLWorkbook workbook) {
    for (QuestionItemAuditLog logEntry : auditLog) {
        int pos = 0;
        Row row = exportSheet.newRow();
        Date creationDate = logEntry.getCreationDate();
        row.addCell(pos++, creationDate, workbook.getStyles().getDateTimeStyle());
        row.addCell(pos++, logEntry.getAction());
        QuestionItem item = null;
        if (logEntry.getQuestionItemKey() != null) {
            item = qpoolService.toAuditQuestionItem(logEntry.getAfter());
        }
        if (item != null) {
            row.addCell(pos++, item.getTitle());
            row.addCell(pos++, item.getTopic());
            if (qpoolModule.isTaxonomyEnabled()) {
                row.addCell(pos++, item.getTaxonomicPath());
            }
            if (qpoolModule.isEducationalContextEnabled()) {
                row.addCell(pos++, getTranslatedContext(item.getEducationalContext()));
            }
            row.addCell(pos++, item.getKeywords());
            row.addCell(pos++, item.getAdditionalInformations());
            row.addCell(pos++, item.getCoverage());
            row.addCell(pos++, item.getLanguage());
            row.addCell(pos++, getTranslatedAssessmentType(item.getAssessmentType()));
            row.addCell(pos++, getTranslatedItemType(item.getItemType()));
            row.addCell(pos++, item.getEducationalLearningTime());
            row.addCell(pos++, format(item.getDifficulty()));
            row.addCell(pos++, format(item.getStdevDifficulty()));
            row.addCell(pos++, format(item.getDifferentiation()));
            row.addCell(pos++, String.valueOf(item.getNumOfAnswerAlternatives()));
            row.addCell(pos++, String.valueOf(item.getUsage()));
            row.addCell(pos++, item.getItemVersion());
            row.addCell(pos++, getTranslatedStatus(item.getQuestionStatus()));
        } else {
            pos += 16;
            if (qpoolModule.isTaxonomyEnabled()) {
                pos++;
            }
            if (qpoolModule.isEducationalContextEnabled()) {
                pos++;
            }
        }
        if (licenseModule.isEnabled(licenseHandler)) {
            License license = licenseService.licenseFromXml(logEntry.getLicenseAfter());
            if (license != null) {
                row.addCell(pos++, license.getLicenseType() != null ? license.getLicenseType().getName() : null);
                row.addCell(pos++, license.getLicensor());
            } else if (item != null) {
                // Backward compatibility:
                // Before the introduction of the LicenseService the license was stored in the item itself.
                row.addCell(pos++, item.getLicense() != null ? item.getLicense().getLicenseKey() : null);
                row.addCell(pos++, item.getCreator());
            } else {
                pos += 2;
            }
        }
        Long authorKey = logEntry.getAuthorKey();
        if (authorKey != null) {
            String fullname = userManager.getUserDisplayName(authorKey);
            row.addCell(pos++, fullname);
        }
    }
}
Also used : License(org.olat.core.commons.services.license.License) Row(org.olat.core.util.openxml.OpenXMLWorksheet.Row) QuestionItem(org.olat.modules.qpool.QuestionItem) QuestionItemAuditLog(org.olat.modules.qpool.QuestionItemAuditLog) Date(java.util.Date)

Example 19 with Row

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

the class OpenXmlWorkbookTest method creationOfWorkbook.

/**
 * Sadly, I can only test if our system produce a non empty file.
 * @throws IOException
 */
@Test
public void creationOfWorkbook() throws IOException {
    File file = File.createTempFile("workbook", "_min.xlsx");
    FileOutputStream fileOut = new FileOutputStream(file);
    OpenXMLWorkbook workbook = new OpenXMLWorkbook(fileOut, 1);
    OpenXMLWorksheet sheet = workbook.nextWorksheet();
    sheet.setHeaderRows(1);
    // 0 empty
    sheet.newRow();
    Row row1 = sheet.newRow();
    row1.addCell(1, "Title", null);
    row1.addCell(2, "Titre", null);
    row1.addCell(1, 1.0d, null);
    Row row2 = sheet.newRow();
    row2.addCell(2, "Hello", null);
    row2.addCell(2, "Border", workbook.getStyles().getBorderRightStyle());
    sheet.newRow();
    Row row4 = sheet.newRow();
    row4.addCell(5, new Date(), workbook.getStyles().getDateStyle());
    workbook.close();
    fileOut.flush();
    IOUtils.closeQuietly(fileOut);
    Assert.assertTrue(file.exists());
    Assert.assertTrue(file.length() > 4096);
    file.delete();
}
Also used : FileOutputStream(java.io.FileOutputStream) Row(org.olat.core.util.openxml.OpenXMLWorksheet.Row) File(java.io.File) Date(java.util.Date) Test(org.junit.Test)

Example 20 with Row

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

the class QTI21ArchiveFormat method writeHeaders_1.

private void writeHeaders_1(OpenXMLWorksheet exportSheet, OpenXMLWorkbook workbook) {
    CellStyle headerStyle = workbook.getStyles().getHeaderStyle();
    // first header
    Row header1Row = exportSheet.newRow();
    int col = 1;
    if (anonymizerCallback != null) {
        // anonymized name -> test duration
        col += 0;
    } else {
        for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
            if (userPropertyHandler != null) {
                col++;
            }
        }
        // homepage -> test duration
        col += 1;
    }
    // course node points and passed
    if (courseNode instanceof AssessableCourseNode) {
        AssessableCourseNode assessableCourseNode = (AssessableCourseNode) courseNode;
        if (assessableCourseNode.hasScoreConfigured()) {
            header1Row.addCell(col++, translator.translate("archive.table.header.node"), headerStyle);
        }
        if (assessableCourseNode.hasPassedConfigured()) {
            if (assessableCourseNode.hasScoreConfigured()) {
                col++;
            } else {
                header1Row.addCell(col++, translator.translate("archive.table.header.node"), headerStyle);
            }
        }
    }
    // test points, passed and dates
    header1Row.addCell(col++, translator.translate("archive.table.header.test"), headerStyle);
    col += 5;
    List<AbstractInfos> infos = getItemInfos();
    for (int i = 0; i < infos.size(); i++) {
        int delta = col;
        AbstractInfos info = infos.get(i);
        if (info instanceof ItemInfos) {
            ItemInfos item = (ItemInfos) info;
            if (exportConfig.isResponseCols() || exportConfig.isPointCol() || exportConfig.isTimeCols() || exportConfig.isCommentCol()) {
                List<Interaction> interactions = item.getInteractions();
                for (int j = 0; j < interactions.size(); j++) {
                    Interaction interaction = interactions.get(j);
                    col = interactionArchiveMap.get(interaction.getQtiClassName()).writeHeader1(item.getAssessmentItem(), interaction, i, j, header1Row, col, workbook);
                }
            }
            if (!exportConfig.isResponseCols()) {
                col -= col - delta;
            }
            if (exportConfig.isPointCol()) {
                col++;
            }
            if (exportConfig.isCommentCol()) {
                col++;
            }
            if (exportConfig.isTimeCols()) {
                col += anonymizerCallback != null ? 1 : 2;
            }
        } else if (numOfSections > 1 && info instanceof SectionInfos) {
            SectionInfos section = (SectionInfos) info;
            if (!section.getItemInfos().isEmpty()) {
                String sectionTitle = translator.translate("archive.table.header.section", new String[] { section.getAssessmentSection().getTitle() });
                header1Row.addCell(col++, sectionTitle, headerStyle);
            }
        }
    }
}
Also used : AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) DrawingInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.DrawingInteraction) EndAttemptInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.EndAttemptInteraction) GraphicOrderInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.GraphicOrderInteraction) TextEntryInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.TextEntryInteraction) ExtendedTextInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.ExtendedTextInteraction) OrderInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.OrderInteraction) Interaction(uk.ac.ed.ph.jqtiplus.node.item.interaction.Interaction) HottextInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.HottextInteraction) GraphicAssociateInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.GraphicAssociateInteraction) CustomInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.CustomInteraction) InlineChoiceInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.InlineChoiceInteraction) HotspotInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.HotspotInteraction) UploadInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.UploadInteraction) AssociateInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.AssociateInteraction) ChoiceInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction) MatchInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.MatchInteraction) SelectPointInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.SelectPointInteraction) SliderInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.SliderInteraction) PositionObjectInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.PositionObjectInteraction) GraphicGapMatchInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.GraphicGapMatchInteraction) MediaInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.MediaInteraction) GapMatchInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.GapMatchInteraction) CellStyle(org.olat.core.util.openxml.workbookstyle.CellStyle) Row(org.olat.core.util.openxml.OpenXMLWorksheet.Row) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Aggregations

Row (org.olat.core.util.openxml.OpenXMLWorksheet.Row)66 UserPropertyHandler (org.olat.user.propertyhandlers.UserPropertyHandler)24 Date (java.util.Date)12 Identity (org.olat.core.id.Identity)12 IOException (java.io.IOException)10 Translator (org.olat.core.gui.translator.Translator)10 OpenXMLWorkbook (org.olat.core.util.openxml.OpenXMLWorkbook)10 OpenXMLWorksheet (org.olat.core.util.openxml.OpenXMLWorksheet)10 OutputStream (java.io.OutputStream)8 CellStyle (org.olat.core.util.openxml.workbookstyle.CellStyle)8 AssessableCourseNode (org.olat.course.nodes.AssessableCourseNode)8 User (org.olat.core.id.User)6 Formatter (org.olat.core.util.Formatter)6 OpenXMLWorkbookResource (org.olat.core.util.openxml.OpenXMLWorkbookResource)6 AssociateInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.AssociateInteraction)6 ChoiceInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction)6 CustomInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.CustomInteraction)6 DrawingInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.DrawingInteraction)6 EndAttemptInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.EndAttemptInteraction)6 ExtendedTextInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.ExtendedTextInteraction)6