use of net.geoprism.data.etl.excel.ExcelSheetReader in project geoprism-registry by terraframe.
the class ExcelImporter method getWorkTotal.
private Long getWorkTotal(File file) throws Exception {
try (FileInputStream istream = new FileInputStream(file)) {
CountSheetHandler handler = new CountSheetHandler();
ExcelDataFormatter formatter = new ExcelDataFormatter();
ExcelSheetReader reader = new ExcelSheetReader(handler, formatter);
reader.process(istream);
// Header row doesn't count as
return (long) (handler.getRowNum() - 1);
// work
}
}
use of net.geoprism.data.etl.excel.ExcelSheetReader in project geoprism-registry by terraframe.
the class ExcelService method getExcelConfiguration.
public JSONObject getExcelConfiguration(String type, Date startDate, Date endDate, String fileName, InputStream fileStream, ImportStrategy strategy, Boolean copyBlank) {
// Save the file to the file system
try {
ServerGeoObjectType geoObjectType = ServerGeoObjectType.get(type);
VaultFile vf = VaultFile.createAndApply(fileName, fileStream);
try (InputStream is = vf.openNewStream()) {
SimpleDateFormat format = new SimpleDateFormat(GeoObjectImportConfiguration.DATE_FORMAT);
format.setTimeZone(GeoRegistryUtil.SYSTEM_TIMEZONE);
ExcelFieldContentsHandler handler = new ExcelFieldContentsHandler();
ExcelDataFormatter formatter = new ExcelDataFormatter();
ExcelSheetReader reader = new ExcelSheetReader(handler, formatter);
reader.process(is);
JSONObject object = new JSONObject();
object.put(GeoObjectImportConfiguration.TYPE, this.getType(geoObjectType));
object.put(GeoObjectImportConfiguration.SHEET, handler.getSheets().getJSONObject(0));
object.put(ImportConfiguration.VAULT_FILE_ID, vf.getOid());
object.put(ImportConfiguration.FILE_NAME, fileName);
object.put(GeoObjectImportConfiguration.HAS_POSTAL_CODE, PostalCodeFactory.isAvailable(geoObjectType));
object.put(ImportConfiguration.IMPORT_STRATEGY, strategy.name());
object.put(ImportConfiguration.FORMAT_TYPE, FormatImporterType.EXCEL.name());
object.put(ImportConfiguration.OBJECT_TYPE, ObjectImporterFactory.ObjectImportType.GEO_OBJECT.name());
object.put(ImportConfiguration.COPY_BLANK, copyBlank);
if (startDate != null) {
object.put(GeoObjectImportConfiguration.START_DATE, format.format(startDate));
}
if (endDate != null) {
object.put(GeoObjectImportConfiguration.END_DATE, format.format(endDate));
}
return object;
}
} catch (InvalidFormatException e) {
InvalidExcelFileException ex = new InvalidExcelFileException(e);
ex.setFileName(fileName);
throw ex;
} catch (RunwayException | SmartException e) {
throw e;
} catch (Exception e) {
throw new ProgrammingErrorException(e);
}
}
use of net.geoprism.data.etl.excel.ExcelSheetReader in project geoprism-registry by terraframe.
the class ExcelImporter method process.
@Request
private void process(ImportStage stage, File file) throws InvocationTargetException, IOException {
try {
/*
* Check permissions
*/
ImportConfiguration config = this.getObjectImporter().getConfiguration();
config.enforceCreatePermissions();
// TODO Determine permissions for
this.progressListener.setWorkTotal(this.getWorkTotal(file));
if (this.config.isExternalImport() && this.config.getExternalSystem() instanceof RevealExternalSystem && this.config instanceof GeoObjectImportConfiguration) {
this.excelHandler = new RevealExcelContentHandler(this.objectImporter, stage, this.getStartIndex(), ((GeoObjectImportConfiguration) this.config).getRevealGeometryColumn());
} else {
this.excelHandler = new ExcelContentHandler(this.objectImporter, stage, this.getStartIndex());
}
ExcelDataFormatter formatter = new ExcelDataFormatter();
ExcelSheetReader reader = new ExcelSheetReader(excelHandler, formatter);
reader.process(new FileInputStream(file));
} catch (Exception e) {
throw new ProgrammingErrorException(e);
}
}
use of net.geoprism.data.etl.excel.ExcelSheetReader in project geoprism-registry by terraframe.
the class ExcelService method getBusinessTypeConfiguration.
public JSONObject getBusinessTypeConfiguration(String type, Date date, String fileName, InputStream fileStream, ImportStrategy strategy, Boolean copyBlank) {
// Save the file to the file system
try {
BusinessType businessType = BusinessType.getByCode(type);
VaultFile vf = VaultFile.createAndApply(fileName, fileStream);
try (InputStream is = vf.openNewStream()) {
SimpleDateFormat format = new SimpleDateFormat(GeoObjectImportConfiguration.DATE_FORMAT);
format.setTimeZone(GeoRegistryUtil.SYSTEM_TIMEZONE);
ExcelFieldContentsHandler handler = new ExcelFieldContentsHandler();
ExcelDataFormatter formatter = new ExcelDataFormatter();
ExcelSheetReader reader = new ExcelSheetReader(handler, formatter);
reader.process(is);
JSONObject object = new JSONObject();
object.put(BusinessObjectImportConfiguration.TYPE, this.getType(businessType));
object.put(BusinessObjectImportConfiguration.SHEET, handler.getSheets().getJSONObject(0));
object.put(BusinessObjectImportConfiguration.VAULT_FILE_ID, vf.getOid());
object.put(BusinessObjectImportConfiguration.FILE_NAME, fileName);
object.put(BusinessObjectImportConfiguration.IMPORT_STRATEGY, strategy.name());
object.put(BusinessObjectImportConfiguration.FORMAT_TYPE, FormatImporterType.EXCEL.name());
object.put(BusinessObjectImportConfiguration.OBJECT_TYPE, ObjectImporterFactory.ObjectImportType.BUSINESS_OBJECT.name());
object.put(BusinessObjectImportConfiguration.COPY_BLANK, copyBlank);
if (date != null) {
object.put(BusinessObjectImportConfiguration.DATE, format.format(date));
}
return object;
}
} catch (InvalidFormatException e) {
InvalidExcelFileException ex = new InvalidExcelFileException(e);
ex.setFileName(fileName);
throw ex;
} catch (RunwayException | SmartException e) {
throw e;
} catch (Exception e) {
throw new ProgrammingErrorException(e);
}
}
Aggregations