Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
import java.util.*;
import java.util.stream.Collectors;
import ai.intellistream.datahub.api.controllers.errors.schema.ApiProblem;
import ai.intellistream.datahub.api.controllers.errors.schema.DuplicateProblem;
import ai.intellistream.datahub.api.controllers.errors.schema.RestoreRefusedProblem;
import ai.intellistream.datahub.api.controllers.errors.schema.ValidationProblem;

Expand Down Expand Up @@ -177,10 +178,10 @@ private boolean isFilesDisabled() {
mediaType = "application/problem+json",
schema = @Schema(implementation = ValidationProblem.class)
))
@ApiResponse(responseCode = "409", description = "Upload failed, a file already exists at that path.",
@ApiResponse(responseCode = "409", description = "Upload failed, a file already exists at that path or with that externalId.",
content = @Content(
mediaType = "application/problem+json",
schema = @Schema(implementation = ApiProblem.class)
schema = @Schema(implementation = DuplicateProblem.class)
))
@RequestMapping(value = "", method = RequestMethod.PUT,
produces = { "application/json", "application/xml" }
Expand Down Expand Up @@ -986,7 +987,7 @@ public ResponseEntity<?> restore(
@ApiResponse(responseCode = "409", description = "A file or folder already exists at the target path.",
content = @Content(
mediaType = "application/problem+json",
schema = @Schema(implementation = ApiProblem.class)
schema = @Schema(implementation = DuplicateProblem.class)
))
@RequestMapping(value = "/update", method = RequestMethod.POST,
consumes = { "application/json" },
Expand Down Expand Up @@ -1070,7 +1071,10 @@ public ResponseEntity<?> update(
}
} catch (FileAlreadyExistsException e) {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return new ResponseEntity<>(Problems.conflict(null, "A file or folder already exists at the target path."), HttpStatus.CONFLICT);
// The same answer, fields and all, as the upload that hits the path's unique index.
String taken = "A file or folder already exists at the target path.";
return new ResponseEntity<>(Problems.withFields(Problems.duplicate(taken, List.of()),
List.of(new Problems.FieldProblem("path", taken, null, null))), HttpStatus.CONFLICT);
} catch (IllegalArgumentException e) {
// A rejected name or destination path; the text quotes what was sent, so it stays in the log.
log.debug("File update rejected: {}", e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class DataIntegrityViolationExceptionHandler {
/** Constraint name to the request field it is really about. */
private static final Map<String, Map<String, String>> BY_CONSTRAINT = Map.of(
"node_external_id_hash_key", Map.of("externalId", "External id already exists."),
"inode_external_id_hash_key", Map.of("externalId", "External id already exists."),
"inodes_path_hash_active_uk", Map.of("path", "A file or folder already exists at this path."),
"label_hash_key", Map.of("name", "Label with same name already exists."),
"relationship_hash_key", Map.of("name", "Relationship type with same name already exists."),
"edge_unique_key", Map.of("relationship",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ void aMappedConstraintNamesTheFieldWithoutPretendingToKnowTheValue() {
Map.of("field", "name", "message", "Label with same name already exists.")));
}

/** A file upload that lands on a taken path or external id answers its documented 409 with the field. */
@Test
void aTakenFilePathNamesPath() {
ProblemDetail problem = handler.handle(violation("inodes_path_hash_active_uk"));

assertThat(problem.getType()).isEqualTo(Problems.DUPLICATE);
assertThat(problem.getProperties().get("fields")).isEqualTo(List.of(
Map.of("field", "path", "message", "A file or folder already exists at this path.")));
}

@Test
void anUnmappedConstraintIsStillAConflictWithNoFields() {
ProblemDetail problem = handler.handle(violation("some_new_key"));
Expand Down
Loading