Search in sources :

Example 11 with OdfTable

use of org.odftoolkit.odfdom.doc.table.OdfTable in project trainning by fernandotomasio.

the class PLN005ODF method createAnexo2.

private void createAnexo2(List<TurmaPlanejadaDTO> turmasPlanejadas, Map<Long, CursoDTO> cursosMap) {
    Map<Long, List<TurmaDTO>> turmasMap = reportUtil.buildTurmasMapByCurso(turmasPlanejadas);
    Map<Long, AnotacaoDTO[]> anotacoesMap = new HashMap<Long, AnotacaoDTO[]>();
    reportUtil.arrangeAnotacoesMapByTurmas(turmasPlanejadas, anotacoesMap);
    List<CursoDTO> cursos = reportUtil.getCursos(cursosMap);
    try {
        for (CursoDTO curso : cursos) {
            if (curso == null) {
                continue;
            }
            odt.newParagraph(curso.getCodigo() + " - " + curso.getDescricao());
            odt.newParagraph();
            List<TurmaDTO> turmas = turmasMap.get(curso.getId());
            FolhaRostoDTO folha = planningService.findFolhaRosto(curso.getCodigo());
            if (folha == null) {
                System.out.println("folha nula" + curso.getCodigo());
            } else {
                odt.newParagraph("FOLHA DE ROSTO:");
                OdfTable folhaDeRostoTable = OdfTable.newTable(odt, 5, 1);
                OdfTableCell objetivoCell = folhaDeRostoTable.getCellByPosition(0, 0);
                objetivoCell.setStringValue("OBJETIVO: \n" + folha.getObjetivo());
                OdfTableCell nivelCell = folhaDeRostoTable.getCellByPosition(0, 1);
                nivelCell.setStringValue(folha.getNivel());
                String numero = "";
                if (curso.getDuracao() == 1) {
                    numero = "dia útil";
                } else {
                    numero = "dias úteis";
                }
                OdfTableCell duracaoCell = folhaDeRostoTable.getCellByPosition(0, 2);
                duracaoCell.setStringValue("DURAÇÃO: " + NumberConverterHelper.convert(curso.getDuracao()) + " " + numero);
                OdfTableCell requisitosCell = folhaDeRostoTable.getCellByPosition(0, 3);
                requisitosCell.setStringValue("PRÉ-REQUISITOS: \n" + folha.getPreRequisitos());
                OdfTableCell disciplinasCell = folhaDeRostoTable.getCellByPosition(0, 4);
                disciplinasCell.setStringValue("DISCIPLINAS: \n" + folha.getDisciplinas());
            }
            odt.newParagraph();
            odt.newParagraph("TURMAS PLANEJADAS:");
            if (turmas != null) {
                for (TurmaDTO turma : turmas) {
                    TurmaPlanejadaDTO turmaPlanejada = (TurmaPlanejadaDTO) turma;
                    String textTurma = "";
                    if (turmaPlanejada.getNumeroTurma() < 10) {
                        textTurma = " - TU 0";
                    } else {
                        textTurma = " - TU ";
                    }
                    odt.newParagraph(curso.getCodigo() + textTurma + String.valueOf(turmaPlanejada.getNumeroTurma()));
                    odt.newParagraph("Local de Realização: " + turmaPlanejada.getLocal());
                    String prazo = "";
                    if (turma.getDataInicio() != null) {
                        Calendar calendar = Calendar.getInstance();
                        calendar.setTime(turma.getDataInicio());
                        calendar.add(Calendar.DAY_OF_MONTH, -30);
                        prazo = df.format(calendar.getTime());
                    }
                    odt.newParagraph("Prazo para Indicação: " + prazo);
                    odt.newParagraph("Vagas: " + String.valueOf(turma.getQuantidadeVagas()));
                    odt.newParagraph("Período: ");
                    FaseDTO[] fases = turmaPlanejada.getFases();
                    OdfTable fasesTable = OdfTable.newTable(odt, fases.length + 1, 4);
                    OdfTableCell modadidadeHeader = fasesTable.getCellByPosition(0, 0);
                    modadidadeHeader.setStringValue("Modalidade");
                    modadidadeHeader.setHorizontalAlignment("center");
                    OdfTableCell localHeader = fasesTable.getCellByPosition(1, 0);
                    localHeader.setStringValue("Local");
                    localHeader.setHorizontalAlignment("center");
                    OdfTableCell inicioHeader = fasesTable.getCellByPosition(2, 0);
                    inicioHeader.setStringValue("Início");
                    inicioHeader.setHorizontalAlignment("center");
                    OdfTableCell terminoHeader = fasesTable.getCellByPosition(3, 0);
                    terminoHeader.setStringValue("Término");
                    terminoHeader.setHorizontalAlignment("center");
                    for (int i = 0; i < fases.length; i++) {
                        String local = "A DEFINIR";
                        if (fases[i].getLocal() != null) {
                            local = fases[i].getLocal().getSigla();
                        }
                        String dataInicio = "A DEFINIR";
                        if (fases[i].getDataInicio() != null) {
                            dataInicio = df.format(fases[i].getDataInicio());
                        }
                        String dataTermino = "A DEFINIR";
                        if (fases[i].getDataTermino() != null) {
                            dataTermino = df.format(fases[i].getDataTermino());
                        }
                        OdfTableCell modadidadeCell = fasesTable.getCellByPosition(0, i + 1);
                        modadidadeCell.setStringValue(fases[i].getDescricao());
                        OdfTableCell localCell = fasesTable.getCellByPosition(1, i + 1);
                        localCell.setStringValue(local);
                        localCell.setHorizontalAlignment("center");
                        OdfTableCell inicioCell = fasesTable.getCellByPosition(2, i + 1);
                        inicioCell.setStringValue(dataInicio);
                        inicioCell.setHorizontalAlignment("center");
                        OdfTableCell terminoCell = fasesTable.getCellByPosition(3, i + 1);
                        terminoCell.setStringValue(dataTermino);
                        terminoCell.setHorizontalAlignment("center");
                    }
                    odt.newParagraph("Distribuição de Vagas:");
                    DistribuicaoDTO[] distribuidas = planningService.findAllDistribuicoes(turma.getId());
                    // turmaPlanejada.getTreinamentosPlanejados();
                    Arrays.sort(distribuidas, new Comparator<DistribuicaoDTO>() {

                        @Override
                        public int compare(DistribuicaoDTO o1, DistribuicaoDTO o2) {
                            return o1.getOrganizacao().getSigla().compareTo(o2.getOrganizacao().getSigla());
                        }
                    });
                    OdfTable planejadosTable = OdfTable.newTable(odt, distribuidas.length + 1, 2);
                    OdfTableCell unidadeHeader = planejadosTable.getCellByPosition(0, 0);
                    unidadeHeader.setStringValue("Organização");
                    unidadeHeader.setHorizontalAlignment("center");
                    OdfTableCell vagasHeader = planejadosTable.getCellByPosition(1, 0);
                    vagasHeader.setStringValue("Vagas");
                    vagasHeader.setHorizontalAlignment("center");
                    for (int i = 0; i < distribuidas.length; i++) {
                        OdfTableCell unidadeCell = planejadosTable.getCellByPosition(0, i + 1);
                        unidadeCell.setStringValue(distribuidas[i].getOrganizacao().getSigla());
                        OdfTableCell vagasCell = planejadosTable.getCellByPosition(1, i + 1);
                        vagasCell.setStringValue(String.valueOf(distribuidas[i].getQuantidadeVagas()));
                        vagasCell.setHorizontalAlignment("center");
                    }
                    AnotacaoDTO[] listAnotacoes = anotacoesMap.get(turma.getId());
                    String anotacao = "";
                    if (anotacoesMap.get(turma.getId()) != null) {
                        for (AnotacaoDTO anotacaoDTO : listAnotacoes) {
                            if (!anotacaoDTO.isVisibleInTca()) {
                                anotacao += anotacaoDTO.getTexto() + "\n";
                            }
                        }
                    }
                    odt.newParagraph();
                    if (listAnotacoes != null && listAnotacoes.length > 0) {
                        odt.newParagraph("Observações: " + anotacao);
                    }
                    odt.newParagraph();
                }
            }
        }
    } catch (Exception ex) {
        Logger.getLogger(TCATrainningDocumentODF.class.getName()).log(Level.SEVERE, null, ex);
    }
}
Also used : HashMap(java.util.HashMap) TurmaDTO(com.tomasio.projects.trainning.dto.TurmaDTO) FaseDTO(com.tomasio.projects.trainning.dto.FaseDTO) List(java.util.List) TurmaPlanejadaDTO(com.tomasio.projects.trainning.dto.TurmaPlanejadaDTO) Calendar(java.util.Calendar) FolhaRostoDTO(com.tomasio.projects.trainning.dto.FolhaRostoDTO) OdfTableCell(org.odftoolkit.odfdom.doc.table.OdfTableCell) DistribuicaoDTO(com.tomasio.projects.trainning.dto.DistribuicaoDTO) AnotacaoDTO(com.tomasio.projects.trainning.dto.AnotacaoDTO) OdfTable(org.odftoolkit.odfdom.doc.table.OdfTable) CursoDTO(com.tomasio.projects.trainning.dto.CursoDTO)

Example 12 with OdfTable

use of org.odftoolkit.odfdom.doc.table.OdfTable in project trainning by fernandotomasio.

the class PLN005ODF method createAnexo1.

private void createAnexo1(Map<Long, CursoDTO> cursosMap) {
    List<CursoDTO> cursos = reportUtil.getCursos(cursosMap);
    try {
        OdfTable cursosTable = OdfTable.newTable(odt, cursos.size(), 2);
        for (int i = 0; i < cursos.size(); i++) {
            CursoDTO curso = cursos.get(i);
            if (curso == null) {
                continue;
            }
            OdfTableCell codigoCell = cursosTable.getCellByPosition(0, i);
            codigoCell.setStringValue(curso.getCodigo());
            OdfTableCell descricaoCell = cursosTable.getCellByPosition(1, i);
            descricaoCell.setStringValue(curso.getDescricao());
        }
        odt.newParagraph();
    } catch (Exception ex) {
        Logger.getLogger(TCATrainningDocumentODF.class.getName()).log(Level.SEVERE, null, ex);
    }
}
Also used : OdfTableCell(org.odftoolkit.odfdom.doc.table.OdfTableCell) OdfTable(org.odftoolkit.odfdom.doc.table.OdfTable) CursoDTO(com.tomasio.projects.trainning.dto.CursoDTO)

Example 13 with OdfTable

use of org.odftoolkit.odfdom.doc.table.OdfTable in project OpenRefine by OpenRefine.

the class OdsExporter method export.

@Override
public void export(final Project project, Properties params, Engine engine, OutputStream outputStream) throws IOException {
    final OdfSpreadsheetDocument odfDoc;
    try {
        odfDoc = OdfSpreadsheetDocument.newSpreadsheetDocument();
    } catch (Exception e) {
        throw new IOException("Failed to create spreadsheet", e);
    }
    TabularSerializer serializer = new TabularSerializer() {

        OdfTable table;

        // int rowCount = 0;
        @Override
        public void startFile(JsonNode options) {
            table = OdfTable.newTable(odfDoc);
            table.setTableName(ProjectManager.singleton.getProjectMetadata(project.id).getName());
        }

        @Override
        public void endFile() {
        }

        @Override
        public void addRow(List<CellData> cells, boolean isHeader) {
            OdfTableRow r = table.appendRow();
            for (int i = 0; i < cells.size(); i++) {
                // implicitly creates cell
                OdfTableCell c = r.getCellByIndex(i);
                CellData cellData = cells.get(i);
                if (cellData != null && cellData.text != null && cellData.value != null) {
                    Object v = cellData.value;
                    if (v instanceof Number) {
                        c.setDoubleValue(((Number) v).doubleValue());
                    } else if (v instanceof Boolean) {
                        c.setBooleanValue(((Boolean) v).booleanValue());
                    } else if (v instanceof OffsetDateTime) {
                        OffsetDateTime odt = (OffsetDateTime) v;
                        c.setDateValue(ParsingUtilities.offsetDateTimeToCalendar(odt));
                    } else {
                        c.setStringValue(cellData.text);
                    }
                    if (cellData.link != null) {
                    // TODO: How do we do output hyperlinks?
                    }
                }
            }
        }
    };
    CustomizableTabularExporterUtilities.exportRows(project, engine, params, serializer);
    try {
        odfDoc.save(outputStream);
    } catch (Exception e) {
        throw new IOException("Error saving spreadsheet", e);
    }
    outputStream.flush();
}
Also used : OdfSpreadsheetDocument(org.odftoolkit.odfdom.doc.OdfSpreadsheetDocument) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) IOException(java.io.IOException) OdfTableCell(org.odftoolkit.odfdom.doc.table.OdfTableCell) OffsetDateTime(java.time.OffsetDateTime) OdfTable(org.odftoolkit.odfdom.doc.table.OdfTable) List(java.util.List) OdfTableRow(org.odftoolkit.odfdom.doc.table.OdfTableRow)

Example 14 with OdfTable

use of org.odftoolkit.odfdom.doc.table.OdfTable in project OpenRefine by OpenRefine.

the class OdsImporter method createParserUIInitializationData.

@Override
public ObjectNode createParserUIInitializationData(ImportingJob job, List<ObjectNode> fileRecords, String format) {
    ObjectNode options = super.createParserUIInitializationData(job, fileRecords, format);
    ArrayNode sheetRecords = ParsingUtilities.mapper.createArrayNode();
    JSONUtilities.safePut(options, "sheetRecords", sheetRecords);
    OdfDocument odfDoc = null;
    try {
        for (int index = 0; index < fileRecords.size(); index++) {
            ObjectNode fileRecord = fileRecords.get(index);
            File file = ImportingUtilities.getFile(job, fileRecord);
            InputStream is = new FileInputStream(file);
            odfDoc = OdfDocument.loadDocument(is);
            List<OdfTable> tables = odfDoc.getTableList();
            int sheetCount = tables.size();
            for (int i = 0; i < sheetCount; i++) {
                OdfTable sheet = tables.get(i);
                int rows = sheet.getRowCount();
                ObjectNode sheetRecord = ParsingUtilities.mapper.createObjectNode();
                JSONUtilities.safePut(sheetRecord, "name", file.getName() + "#" + sheet.getTableName());
                JSONUtilities.safePut(sheetRecord, "fileNameAndSheetIndex", file.getName() + "#" + i);
                JSONUtilities.safePut(sheetRecord, "rows", rows);
                if (rows > 0) {
                    JSONUtilities.safePut(sheetRecord, "selected", true);
                } else {
                    JSONUtilities.safePut(sheetRecord, "selected", false);
                }
                JSONUtilities.append(sheetRecords, sheetRecord);
            }
        }
    } catch (FileNotFoundException e) {
        logger.info("File not found", e);
    } catch (Exception e) {
        // ODF throws *VERY* wide exceptions
        logger.info("Error reading ODF spreadsheet", e);
    } finally {
        if (odfDoc != null) {
            odfDoc.close();
        }
    }
    return options;
}
Also used : OdfDocument(org.odftoolkit.odfdom.doc.OdfDocument) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) OdfTable(org.odftoolkit.odfdom.doc.table.OdfTable) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) File(java.io.File) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 15 with OdfTable

use of org.odftoolkit.odfdom.doc.table.OdfTable in project pentaho-kettle by pentaho.

the class OdfWorkbook method getSheet.

@Override
public KSheet getSheet(String sheetName) {
    OdfSheet sheet = openSheetsMap.get(sheetName);
    if (sheet == null) {
        OdfTable table = document.getTableByName(sheetName);
        if (table == null) {
            return null;
        } else {
            sheet = new OdfSheet(table);
            openSheetsMap.put(sheetName, sheet);
        }
    }
    return sheet;
}
Also used : OdfTable(org.odftoolkit.odfdom.doc.table.OdfTable)

Aggregations

OdfTable (org.odftoolkit.odfdom.doc.table.OdfTable)18 OdfTableCell (org.odftoolkit.odfdom.doc.table.OdfTableCell)14 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 AtividadesEnsinoService (com.tomasio.projects.trainning.interfaces.AtividadesEnsinoService)5 List (java.util.List)5 CursoDTO (com.tomasio.projects.trainning.dto.CursoDTO)4 OrganizationalService (com.tomasio.projects.trainning.interfaces.OrganizationalService)4 FileNotFoundException (java.io.FileNotFoundException)4 OdfDocument (org.odftoolkit.odfdom.doc.OdfDocument)4 TurmaDTO (com.tomasio.projects.trainning.dto.TurmaDTO)3 File (java.io.File)3 Map (java.util.Map)3 OdfSpreadsheetDocument (org.odftoolkit.odfdom.doc.OdfSpreadsheetDocument)3 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 Cell (com.google.refine.model.Cell)2 Recon (com.google.refine.model.Recon)2 AnotacaoDTO (com.tomasio.projects.trainning.dto.AnotacaoDTO)2