Search in sources :

Example 6 with VaultFile

use of com.runwaysdk.system.VaultFile 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);
    }
}
Also used : SmartException(com.runwaysdk.business.SmartException) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) InputStream(java.io.InputStream) InvalidExcelFileException(net.geoprism.data.etl.excel.InvalidExcelFileException) ExcelSheetReader(net.geoprism.data.etl.excel.ExcelSheetReader) ExcelFieldContentsHandler(net.geoprism.registry.excel.ExcelFieldContentsHandler) InvalidFormatException(org.apache.poi.openxml4j.exceptions.InvalidFormatException) RunwayException(com.runwaysdk.RunwayException) SmartException(com.runwaysdk.business.SmartException) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) RunwayException(com.runwaysdk.RunwayException) InvalidFormatException(org.apache.poi.openxml4j.exceptions.InvalidFormatException) InvalidExcelFileException(net.geoprism.data.etl.excel.InvalidExcelFileException) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) ExcelDataFormatter(net.geoprism.data.etl.excel.ExcelDataFormatter) JSONObject(org.json.JSONObject) VaultFile(com.runwaysdk.system.VaultFile) SimpleDateFormat(java.text.SimpleDateFormat)

Example 7 with VaultFile

use of com.runwaysdk.system.VaultFile in project geoprism-registry by terraframe.

the class ShapefileService method getShapefileConfiguration.

@Request(RequestType.SESSION)
public JSONObject getShapefileConfiguration(String sessionId, 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 (CloseableFile dbf = ShapefileImporter.getShapefileFromResource(vf, "dbf")) {
            SimpleDateFormat format = new SimpleDateFormat(GeoObjectImportConfiguration.DATE_FORMAT);
            format.setTimeZone(GeoRegistryUtil.SYSTEM_TIMEZONE);
            JSONObject object = new JSONObject();
            object.put(GeoObjectImportConfiguration.TYPE, this.getType(geoObjectType));
            object.put(GeoObjectImportConfiguration.SHEET, this.getSheetInformation(dbf));
            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.SHAPEFILE.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 (RunwayException | SmartException e) {
        throw e;
    } catch (Exception e) {
        throw new ProgrammingErrorException(e);
    }
}
Also used : JSONObject(org.json.JSONObject) SmartException(com.runwaysdk.business.SmartException) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) VaultFile(com.runwaysdk.system.VaultFile) CloseableFile(com.runwaysdk.resource.CloseableFile) SimpleDateFormat(java.text.SimpleDateFormat) RunwayException(com.runwaysdk.RunwayException) SmartException(com.runwaysdk.business.SmartException) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) RunwayException(com.runwaysdk.RunwayException) ShapefileFormatException(net.geoprism.registry.etl.ShapefileFormatException) IOException(java.io.IOException) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) Request(com.runwaysdk.session.Request)

Example 8 with VaultFile

use of com.runwaysdk.system.VaultFile in project geoprism-registry by terraframe.

the class ETLService method resolveImportInTrans.

@Transaction
private void resolveImportInTrans(String historyId, ImportHistory hist) {
    hist.appLock();
    ImportErrorQuery ieq = new ImportErrorQuery(new QueryFactory());
    ieq.WHERE(ieq.getHistory().EQ(historyId));
    OIterator<? extends ImportError> it = ieq.getIterator();
    try {
        ImportError err = it.next();
        err.delete();
    } finally {
        it.close();
    }
    hist.clearStatus();
    hist.addStatus(AllJobStatus.SUCCESS);
    hist.clearStage();
    hist.addStage(ImportStage.COMPLETE);
    hist.apply();
    VaultFile file = hist.getImportFile();
    file.delete();
}
Also used : QueryFactory(com.runwaysdk.query.QueryFactory) VaultFile(com.runwaysdk.system.VaultFile) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 9 with VaultFile

use of com.runwaysdk.system.VaultFile in project geoprism-registry by terraframe.

the class ChangeRequestService method deleteDocumentInTransCR.

@Transaction
void deleteDocumentInTransCR(String crOid, String vfOid) {
    ChangeRequest request = ChangeRequest.get(crOid);
    if (!this.permService.getPermissions(request).contains(ChangeRequestPermissionAction.WRITE_DOCUMENTS)) {
        throw new CGRPermissionException();
    }
    VaultFile vf = VaultFile.get(vfOid);
    vf.delete();
}
Also used : CGRPermissionException(net.geoprism.registry.CGRPermissionException) VaultFile(com.runwaysdk.system.VaultFile) ChangeRequest(net.geoprism.registry.action.ChangeRequest) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 10 with VaultFile

use of com.runwaysdk.system.VaultFile 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);
    }
}
Also used : SmartException(com.runwaysdk.business.SmartException) InputStream(java.io.InputStream) InvalidExcelFileException(net.geoprism.data.etl.excel.InvalidExcelFileException) BusinessType(net.geoprism.registry.BusinessType) ExcelSheetReader(net.geoprism.data.etl.excel.ExcelSheetReader) ExcelFieldContentsHandler(net.geoprism.registry.excel.ExcelFieldContentsHandler) InvalidFormatException(org.apache.poi.openxml4j.exceptions.InvalidFormatException) RunwayException(com.runwaysdk.RunwayException) SmartException(com.runwaysdk.business.SmartException) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) RunwayException(com.runwaysdk.RunwayException) InvalidFormatException(org.apache.poi.openxml4j.exceptions.InvalidFormatException) InvalidExcelFileException(net.geoprism.data.etl.excel.InvalidExcelFileException) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) ExcelDataFormatter(net.geoprism.data.etl.excel.ExcelDataFormatter) JSONObject(org.json.JSONObject) VaultFile(com.runwaysdk.system.VaultFile) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

VaultFile (com.runwaysdk.system.VaultFile)10 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)4 CGRPermissionException (net.geoprism.registry.CGRPermissionException)4 ChangeRequest (net.geoprism.registry.action.ChangeRequest)4 RunwayException (com.runwaysdk.RunwayException)3 SmartException (com.runwaysdk.business.SmartException)3 ProgrammingErrorException (com.runwaysdk.dataaccess.ProgrammingErrorException)3 InputStream (java.io.InputStream)3 SimpleDateFormat (java.text.SimpleDateFormat)3 JSONObject (org.json.JSONObject)3 JsonObject (com.google.gson.JsonObject)2 IOException (java.io.IOException)2 ExcelDataFormatter (net.geoprism.data.etl.excel.ExcelDataFormatter)2 ExcelSheetReader (net.geoprism.data.etl.excel.ExcelSheetReader)2 InvalidExcelFileException (net.geoprism.data.etl.excel.InvalidExcelFileException)2 ExcelFieldContentsHandler (net.geoprism.registry.excel.ExcelFieldContentsHandler)2 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)2 InvalidFormatException (org.apache.poi.openxml4j.exceptions.InvalidFormatException)2 JsonArray (com.google.gson.JsonArray)1 QueryFactory (com.runwaysdk.query.QueryFactory)1