All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.datakurator.postprocess.DataTable Maven / Gradle / Ivy

Go to download

Data quality assertion framework. Provides utilities for capturing provenance data and generation of data quality reports using FFDQ.

There is a newer version: 2.0.2
Show newest version
package org.datakurator.postprocess;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.datakurator.data.ffdq.DataResource;
import org.datakurator.data.ffdq.assertions.Result;

import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * Created by lowery on 11/21/16.
 */
public class DataTable {
    private List data;

    public DataTable(List data) {
        this.data = data;
    }

    public void drawXls(OutputStream out) throws IOException {
        Workbook workbook = new HSSFWorkbook();
        Sheet sheet = workbook.createSheet("Curated Values");

        List fieldNames = new ArrayList<>(data.get(0).getFields());

        // create header
        Row header = sheet.createRow(0);

        for (int i = 0; i < fieldNames.size(); i++) {
            String fieldName = fieldNames.get(i);
            Cell cell = header.createCell(i);

            cell.setCellValue(fieldName);
        }

        int rowNum = 1;

        // create rows
        for (DataResource record : data) {
            Row row = sheet.createRow(rowNum++);

            for (int i = 0; i < fieldNames.size(); i++) {
                String fieldName = fieldNames.get(i);

                Cell cell = row.createCell(i);
                cell.setCellValue(record.getCuratedValues().get(fieldName));
            }
        }

        workbook.write(out);
        out.close();
        workbook.close();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy