Skip to content

Commit

Permalink
api: Include reason not deliverable in tep 404 error
Browse files Browse the repository at this point in the history
  • Loading branch information
ato committed Sep 6, 2023
1 parent 2712d40 commit 22ce280
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
15 changes: 10 additions & 5 deletions common/src/pandas/collection/Title.java
Original file line number Diff line number Diff line change
Expand Up @@ -839,17 +839,22 @@ public void setLegacyTepRelation(Tep legacyTepRelation) {
@ObjectPath({@PropertyValue(propertyName = "permission"), @PropertyValue(propertyName = "state")}),
@ObjectPath(@PropertyValue(propertyName = "legalDeposit"))})
public boolean isDeliverable() {
return getReasonNotDeliverable() == null;
}

public String getReasonNotDeliverable() {
if (getAgency() != null && getAgency().getId().equals(Agency.PADI_ID))
return false;
return "Title belongs to PADI agency";
if (getStatus().getId().equals(Status.NOMINATED_ID) ||
getStatus().getId().equals(Status.REJECTED_ID) ||
getStatus().getId().equals(Status.MONITORED_ID))
return false;
return "Title status is " + getStatus().getName();
if (getLegalDeposit())
return true;
return null;
if (getPermission() == null || getPermission().isDenied() || getPermission().isUnknown())
return false;
return true;
return "Title permission state is " +
(getPermission() == null ? "null" : getPermission().getState().getName());
return null;
}

@GenericField
Expand Down
3 changes: 2 additions & 1 deletion delivery/src/pandas/api/ApiController.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ public String help() {
@ResponseBody
public TitleDetailsJson tep(@PathVariable("pi") long pi) {
Title title = titleRepository.findByPi(pi).orElseThrow(() -> new ResponseStatusException(NOT_FOUND, "No such title"));
if (!title.isDeliverable()) throw new ResponseStatusException(NOT_FOUND, "Title not deliverable");
if (!title.isDeliverable()) throw new ResponseStatusException(NOT_FOUND, "Title not deliverable: " +
title.getReasonNotDeliverable());

TitleDetailsJson titleDetailsJson = new TitleDetailsJson(title);

Expand Down

0 comments on commit 22ce280

Please sign in to comment.