use of org.apache.poi.openxml4j.exceptions.InvalidFormatException in project local-data-aragopedia by aragonopendata.
the class GenerateRDF method readXlsxFile.
private void readXlsxFile(File file, ConfigBean configBean) {
log.debug("Init readXlsxFile");
InputStream inp = null;
Workbook wb = null;
try {
inp = new FileInputStream(file);
wb = WorkbookFactory.create(inp);
} catch (FileNotFoundException e) {
log.error(e.getMessage());
} catch (InvalidFormatException e) {
log.error(e.getMessage());
} catch (IOException e) {
log.error(e.getMessage());
}
Sheet sheet = wb.getSheetAt(0);
Row rowName = sheet.getRow(0);
Row rowNameNormalized = sheet.getRow(1);
Row rowNormalization = sheet.getRow(2);
Row rowDimMesure = sheet.getRow(3);
Row rowType = sheet.getRow(4);
Row rowSkosfile = sheet.getRow(5);
Row rowConstant = sheet.getRow(6);
Row rowConstantValue = sheet.getRow(7);
Row rowRelationKos = sheet.getRow(8);
Row rowKosNameNormalized = sheet.getRow(9);
Row rowKosName = sheet.getRow(10);
boolean cont = true;
int columnReaded = 0;
while (cont) {
Cell cellName = rowName.getCell(columnReaded);
Cell cellNameNormalized = rowNameNormalized.getCell(columnReaded);
Cell cellNormalization = rowNormalization.getCell(columnReaded);
Cell cellDimMesure = rowDimMesure.getCell(columnReaded);
Cell cellType = rowType.getCell(columnReaded);
Cell cellSkosfile = null;
if (rowSkosfile != null)
cellSkosfile = rowSkosfile.getCell(columnReaded);
Cell cellConstant = null;
if (rowConstant != null)
cellConstant = rowConstant.getCell(columnReaded);
Cell cellConstantValue = null;
if (rowConstantValue != null)
cellConstantValue = rowConstantValue.getCell(columnReaded);
Cell cellRelationKos = null;
if (rowRelationKos != null)
cellRelationKos = rowRelationKos.getCell(columnReaded);
Cell cellKosName = null;
if (rowKosName != null)
cellKosName = rowKosName.getCell(columnReaded);
Cell cellKosNameNormalized = null;
if (rowKosNameNormalized != null)
cellKosNameNormalized = rowKosNameNormalized.getCell(columnReaded);
DataBean dataBean = new DataBean();
if (cellName == null) {
if (rowName.getCell((columnReaded + 1)) == null)
cont = false;
else
columnReaded++;
} else {
dataBean.setName(cellName.getStringCellValue());
if (cellNameNormalized != null) {
dataBean.setNameNormalized(cellNameNormalized.getStringCellValue());
} else {
log.error("Error in config " + file.getName() + " in cell name normalized");
}
if (cellNormalization != null) {
dataBean.setNormalizacion(cellNormalization.getStringCellValue());
} else {
log.error("Error in config " + file.getName() + " in cell normalization");
}
if (cellDimMesure != null) {
dataBean.setDimensionMesure(cellDimMesure.getStringCellValue());
} else {
log.error("Error in config " + file.getName() + " in cell dim mesure");
}
dataBean.setIdConfig(configBean.getId());
String type = "";
if (cellType != null) {
type = cellType.getStringCellValue();
} else {
type = "xsd:string";
}
dataBean.setType(type);
if (cellSkosfile != null && !cellSkosfile.getStringCellValue().equals("")) {
HashMap<String, SkosBean> mapSkos = readMappingFile(cellSkosfile.getStringCellValue());
dataBean.setMapSkos(mapSkos);
configBean.getMapData().put(dataBean.getNameNormalized(), dataBean);
dataWithSkos.add(dataBean);
} else {
configBean.getMapData().put(dataBean.getNameNormalized(), dataBean);
}
if (Prop.addDataConstant && cellConstant != null && cellConstant.getStringCellValue().equals(Constants.constante)) {
if (cellConstantValue != null) {
dataBean.setConstant(cellConstantValue.getStringCellValue() + "");
configBean.getListDataConstant().add(dataBean);
}
}
if (cellRelationKos != null) {
if (Utils.v(cellRelationKos.getStringCellValue())) {
dataBean.setRelationKos(cellRelationKos.getStringCellValue());
dataWithSkosHierarchical.add(dataBean);
}
}
if (Utils.v(cellKosNameNormalized) && Utils.v(cellKosNameNormalized.getStringCellValue())) {
dataBean.setKosNameNormalized(cellKosNameNormalized.getStringCellValue());
} else {
dataBean.setKosNameNormalized(dataBean.getNameNormalized());
}
if (Utils.v(cellKosName) && Utils.v(cellKosName.getStringCellValue())) {
dataBean.setKosName(cellKosName.getStringCellValue());
} else {
dataBean.setKosName(dataBean.getName());
}
columnReaded++;
}
}
log.debug("End readXlsxFile");
}
Aggregations