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);
}
}
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);
}
}
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();
}
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;
}
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;
}
Aggregations