Skip to content

Commit

Permalink
Fixes #347 - changed order of delete dataset operations
Browse files Browse the repository at this point in the history
  • Loading branch information
navarroc committed Jan 17, 2025
1 parent 611a524 commit c81f5e8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Bug when posting additional fields which need to be ignored [#338](https://github.com/IN-CORE/incore-services/issues/338)

### Changed
- Order of delete dataset operations [#347](https://github.com/IN-CORE/incore-services/issues/347)
- GeoTools to version 32.1 [#341](https://github.com/IN-CORE/incore-services/issues/341)

## [1.27.1] - 2024-11-01
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -483,8 +483,10 @@ public Dataset deleteDataset(@Parameter(name = "Dataset Id from data service", r
}
}
// remove dataset
logger.debug("Deleting dataset " + datasetId);
dataset = repository.deleteDataset(datasetId);
if (dataset != null) {
logger.debug("Removing files from dataset " + datasetId);
// remove files
List<FileDescriptor> fds = dataset.getFileDescriptors();
if (fds.size() > 0) {
Expand All @@ -497,6 +499,32 @@ public Dataset deleteDataset(@Parameter(name = "Dataset Id from data service", r
}
}
}

// Adjust user quota after removing the dataset and files
// check if the dataset is hazard dataset
String dataType = dataset.getDataType();
String subDataType;
if (dataType.contains(":")) {
// Compare what comes after the name space (e.g. probabilisticEarthquakeRaster from ergo:probabilisticEarthquakeRaster)
subDataType = dataType.split(":")[1];
} else {
subDataType = dataType;
}
boolean isHazardDataset = HazardConstants.DATA_TYPE_HAZARD.stream().anyMatch(s1 -> s1.contains(subDataType));

// reduce the number of hazard from the space
if (isHazardDataset) {
logger.debug("Decreasing hazard dataset quota");
AllocationUtils.decreaseUsage(allocationsRepository, this.username, "hazardDatasets");
} else {
logger.debug("Decreasing dataset quota");
AllocationUtils.decreaseUsage(allocationsRepository, this.username, "datasets");
}

// decrease file size to usage
UserAllocations allocation = allocationsRepository.getAllocationByUsername(username);
AllocationUtils.decreaseDatasetFileSize(allocation, allocationsRepository, fileSize, isHazardDataset);

// remove geoserver layer
if (geoserverUsed) {
boolean isRemoved = GeoserverUtils.removeStoreFromGeoserver(datasetId);
Expand All @@ -507,27 +535,6 @@ public Dataset deleteDataset(@Parameter(name = "Dataset Id from data service", r
this.username + " is not authorized to delete the dataset " + datasetId);
}

// check if the dataset is hazard dataset
String dataType = dataset.getDataType();
String subDataType;
if (dataType.contains(":")) {
// Compare what comes after the name space (e.g. probabilisticEarthquakeRaster from ergo:probabilisticEarthquakeRaster)
subDataType = dataType.split(":")[1];
} else {
subDataType = dataType;
}
boolean isHazardDataset = HazardConstants.DATA_TYPE_HAZARD.stream().anyMatch(s1 -> s1.contains(subDataType));

// reduce the number of hazard from the space
if (isHazardDataset) {
AllocationUtils.decreaseUsage(allocationsRepository, this.username, "hazardDatasets");
} else {
AllocationUtils.decreaseUsage(allocationsRepository, this.username, "datasets");
}

// decrease file size to usage
UserAllocations allocation = allocationsRepository.getAllocationByUsername(username);
AllocationUtils.decreaseDatasetFileSize(allocation, allocationsRepository, fileSize, isHazardDataset);

return dataset;

Expand Down

0 comments on commit c81f5e8

Please sign in to comment.