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

Fixes #347 - changed order of delete dataset operations #348

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
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
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,9 +483,9 @@ public Dataset deleteDataset(@Parameter(name = "Dataset Id from data service", r
}
}
// remove dataset
dataset = repository.deleteDataset(datasetId);
if (dataset != null) {
// remove files
logger.debug("Removing files from dataset " + datasetId);
// First - remove the files from the dataset
List<FileDescriptor> fds = dataset.getFileDescriptors();
if (fds.size() > 0) {
for (FileDescriptor fd : fds) {
Expand All @@ -497,6 +497,36 @@ public Dataset deleteDataset(@Parameter(name = "Dataset Id from data service", r
}
}
}

// Files removed - delete the dataset entry
logger.debug("Deleting dataset " + datasetId);
dataset = repository.deleteDataset(datasetId);

// 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 +537,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
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,15 @@ public static void deleteFiles(File delFile) {
*/
public static void deleteFiles(File delFile, String delFileName) {
try {
if (delFile.delete()) {
logger.debug("file or directory deleted: " + delFileName);
} else {
logger.error("file or directory did not deleted: " + delFileName);
if (delFile.exists()) {
if (delFile.delete()) {
logger.debug("file or directory deleted: " + delFileName);
} else {
logger.error("file or directory did not deleted: " + delFileName);
}
}
} catch (Exception e) {
e.printStackTrace();
logger.error("Error deleting files.", e);
}
}

Expand Down
Loading