Skip to content
Snippets Groups Projects
Commit 9912b0a9 authored by I. Nüske's avatar I. Nüske
Browse files

ENH: Add delete method and rename base deletion

parent 427748b4
No related branches found
No related tags found
1 merge request!7Draft: Add tombstone delete
......@@ -248,7 +248,7 @@ paths:
tags:
- FDOs
description: "Delete an FDO."
operationId: baseDelete
operationId: delete
parameters:
- $ref: '#/components/parameters/Prefix'
- $ref: '#/components/parameters/Suffix'
......
......@@ -108,12 +108,39 @@ public class FDOApiImpl extends BaseController implements FdoApi {
}
@Override
public ResponseEntity<Void> baseDelete(
public ResponseEntity<Void> delete(
String prefix, String suffix, Boolean purge, Boolean deleteMD) {
if (purge) {
return purgeFDO(prefix, suffix);
}
throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED);
return deleteFDO(prefix, suffix, deleteMD);
}
public ResponseEntity<Void> deleteFDO(String prefix, String suffix, boolean deleteMD) {
try (Manager manager = getManager()) {
String pid = prefix + "/" + suffix;
DigitalObject fdo = manager.resolvePID(pid);
String repoId = manager.deleteFDO(pid, deleteMD);
if (repoId != null && !repoId.isEmpty()) {
RepositoryConnection repository =
manager.getRepositoryRegistry().createRepositoryConnection(repoId);
getLogger().deleteFDO(fdo, repository);
return ResponseEntity.noContent().build();
} else {
throw new ResponseStatusException(
HttpStatus.INTERNAL_SERVER_ERROR, "Could not delete PID " + pid + " due to inability to connect to repository.");
}
} catch (PidUnresolvableException e) {
throw new ResponseStatusException(
HttpStatus.NOT_FOUND, "Not found. Could not resolve PID " + e.getPid());
} catch (UnknownRepositoryException e) {
e.printStackTrace();
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Not found. Repository unknown.");
} catch (UnsuccessfulOperationException e) {
e.printStackTrace();
throw new ResponseStatusException(
HttpStatus.INTERNAL_SERVER_ERROR, "Deletion unsuccessful: " + e.getMessage());
}
}
public ResponseEntity<Void> purgeFDO(String prefix, String suffix) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment