use of org.trellisldp.api.StorageConflictException in project trellis by trellis-ldp.
the class DBResourceService method storeResource.
private void storeResource(final Metadata metadata, final Dataset dataset, final Instant time, final OperationType opType) {
try {
jdbi.useTransaction(handle -> {
final int resourceId = updateResource(handle, metadata, dataset, time, opType == OperationType.DELETE);
updateDescription(handle, resourceId, dataset, batchSize);
updateAcl(handle, resourceId, dataset, batchSize);
updateExtra(handle, resourceId, metadata.getIdentifier(), dataset);
extensions.forEach((ext, graph) -> dataset.getGraph(graph).filter(g -> !"acl".equals(ext)).ifPresent(g -> updateExtension(handle, resourceId, ext, g)));
if (opType == OperationType.DELETE) {
// Verify that the container really is empty
final String query = "SELECT EXISTS(SELECT 1 FROM resource WHERE is_part_of = ?)";
if (Boolean.TRUE.equals(handle.select(query, metadata.getIdentifier().getIRIString()).map((rs, ctx) -> rs.getBoolean(1)).one())) {
throw new StorageConflictException("Cannot delete non-empty containers");
}
}
});
} catch (final TrellisRuntimeException ex) {
throw ex;
} catch (final Exception ex) {
throw new TrellisRuntimeException("Could not update data for " + metadata.getIdentifier(), ex);
}
}
Aggregations