Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added raster geopackage checker #264

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]

### Added
- Add `hazardDatasets` field to TornadoDataset, TornadoModel and EarthquakeModel class [#213](https://github.com/IN-CORE/incore-services/issues/213)
- GeoPakage handling in services [#205](https://github.com/IN-CORE/incore-services/issues/205)
- Raster GeoPackage checker for not supporting it [#258](https://github.com/IN-CORE/incore-services/issues/258)
- `hazardDatasets` field to TornadoDataset, TornadoModel and EarthquakeModel class [#213](https://github.com/IN-CORE/incore-services/issues/213)

### Changed
- Use Java models to represent semantics [#239](https://github.com/IN-CORE/incore-services/issues/239)
Expand All @@ -28,7 +30,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [1.21.0] - 2023-10-11

### Added
- Geopakage handling in services [#205](https://github.com/IN-CORE/incore-services/issues/205)
- Template dataset generation (CSV and Shapefile) API to semantics-service [#214](https://github.com/IN-CORE/incore-services/issues/214)
- Owner item added to the dataset, hazard, and dfr3 object [#92](https://github.com/IN-CORE/incore-services/issues/92)
- Attenuation model Sadigh et al. 1997 [#208](https://github.com/IN-CORE/incore-services/issues/208)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import edu.illinois.ncsa.incore.common.utils.UserInfoUtils;
import edu.illinois.ncsa.incore.common.utils.AllocationUtils;
import edu.illinois.ncsa.incore.common.AllocationConstants;
import edu.illinois.ncsa.incore.common.utils.GeoUtils;
import edu.illinois.ncsa.incore.service.data.dao.IRepository;
import edu.illinois.ncsa.incore.service.data.models.Dataset;
import edu.illinois.ncsa.incore.service.data.models.FileDescriptor;
Expand Down Expand Up @@ -893,12 +894,25 @@ public Dataset uploadFiles(@Parameter(name = "Dataset Id from data service", req
}
File tmpFile = new File(FilenameUtils.concat(DATA_REPO_FOLDER, dataFDs.get(0).getDataURL()));

// check if geopackage only has a single layer and the layer name is the same as file name
if (!GeotoolsUtils.isGpkgSingleLayer(tmpFile)) {
// check if geopackage only has a single layer
// and the layer name is the same as file name
// and it is not the raster data since incore-service doesn't support it yet
GeoUtils.gpkgValidationResult isGpkgFit = GeotoolsUtils.isGpkgFitToService(tmpFile);
if (isGpkgFit != GeoUtils.gpkgValidationResult.VALID) {
FileUtils.removeFilesFromFileDescriptor(dataset.getFileDescriptors());
logger.debug("The geopackage has to have a single layer, and layer name should be the same as file name.");
throw new IncoreHTTPException(Response.Status.NOT_ACCEPTABLE,
"Geopackage is not a single layer or layer name is not the same as file name.");
if (isGpkgFit == GeoUtils.gpkgValidationResult.RASTER_OR_NO_VECTOR_LAYER) {
logger.debug("The geopackage has not vector layer or contains the raster layer that is not being supported yet.");
throw new IncoreHTTPException(Response.Status.NOT_ACCEPTABLE,
"The geopackage has no vector layer or contains the raster layer that is not being supported yet.");
} else if (isGpkgFit == GeoUtils.gpkgValidationResult.MULTIPLE_VECTOR_LAYERS) {
logger.debug("The geopackage has to have a single layer.");
throw new IncoreHTTPException(Response.Status.NOT_ACCEPTABLE,
"The geopackage has to have a single layer.");
} else if (isGpkgFit == GeoUtils.gpkgValidationResult.NAME_MISMATCH) {
logger.debug("The geopackage's'layer name should be the same as file name.");
throw new IncoreHTTPException(Response.Status.NOT_ACCEPTABLE,
"The geopackage's'layer name should be the same as file name.");
}
}

// check if geopackage has guid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import com.opencsv.CSVReader;
import edu.illinois.ncsa.incore.common.exceptions.IncoreHTTPException;
import edu.illinois.ncsa.incore.common.utils.GeoUtils;
import edu.illinois.ncsa.incore.service.data.models.Dataset;
import org.apache.commons.io.FilenameUtils;
import org.apache.log4j.Logger;
Expand Down Expand Up @@ -44,6 +45,7 @@
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
import org.opengis.feature.type.AttributeDescriptor;
import org.opengis.feature.type.Name;
import org.opengis.filter.Filter;
import org.opengis.parameter.GeneralParameterValue;
import org.opengis.parameter.ParameterValueGroup;
Expand Down Expand Up @@ -969,39 +971,49 @@ public static boolean doesGuidExist(SimpleFeatureCollection inputFeatures) {
}

/**
* check if geopackage has single layer and layer name is the same as the file name
* check if geopackage has single layer
* and layer name is the same as the file name
* and layer is not raster
* since incore-services doesn't support raster geopackage yet
*
* @param inFile
* @return
* @throws IOException
*/
public static boolean isGpkgSingleLayer(File inFile) throws IOException {
Boolean output = false;
public static GeoUtils.gpkgValidationResult isGpkgFitToService(File inFile) throws IOException {
int output = 0;
try {
HashMap<String, Object> map = new HashMap<>();
map.put(GeoPkgDataStoreFactory.DBTYPE.key, "geopkg");
map.put(GeoPkgDataStoreFactory.DATABASE.key, inFile.getAbsoluteFile());
DataStore dataStore = DataStoreFinder.getDataStore(map);

if (dataStore == null) {
throw new IOException("Unable to open geopackage file");
}

// get all layer names in input geopackage file
// if the layerNames list is more than one, it means there are multiple vector layer
// if the layerNames list empty then, there is no vector layer or it could be a raster data
String[] layerNames = dataStore.getTypeNames();

if (layerNames.length == 1) {
// check if the layername is the same as file name
String layerName = layerNames[0];
String fileName = inFile.getName().split("\\.")[0];
if (layerName.equals(fileName)) {
output = true;
if (!layerName.equals(fileName)) {
return GeoUtils.gpkgValidationResult.NAME_MISMATCH;
}
} else if (layerNames.length == 0) {
return GeoUtils.gpkgValidationResult.RASTER_OR_NO_VECTOR_LAYER;
} else if (layerNames.length > 1) {
return GeoUtils.gpkgValidationResult.MULTIPLE_VECTOR_LAYERS;
}
} catch (IOException e) {
throw new IOException("Unable to open geopackage file.");
}

return output;
return GeoUtils.gpkgValidationResult.VALID;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package edu.illinois.ncsa.incore.common.utils;

public class GeoUtils {
public static enum gpkgValidationResult {
VALID,
RASTER_OR_NO_VECTOR_LAYER,
MULTIPLE_VECTOR_LAYERS,
NAME_MISMATCH
}
}
Loading