Skip to content

Commit

Permalink
Add endpoint to get latest pid of ocrd-identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
joschrew committed Apr 23, 2024
1 parent 6a5497a commit 4aa74c0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
import ola.hd.longtermstorage.repository.mongo.ArchiveRepository;
import ola.hd.longtermstorage.service.ArchiveManagerService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.StringArrayPropertyEditor;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
Expand All @@ -40,9 +37,6 @@ public class SearchController {
private final ArchiveRepository archiveRepository;
private final ElasticsearchService elasticsearchService;

private static final Logger logger = LoggerFactory.getLogger(SearchController.class);

@Autowired
public SearchController(
ArchiveManagerService archiveManagerService, ArchiveRepository archiveRepository,
ElasticsearchService elasticsearchService
Expand Down Expand Up @@ -250,5 +244,22 @@ public ResponseEntity<?> search(
return ResponseEntity.ok(resultSet);
}
}

}
@ApiOperation(value = "Returns the latest PID for an Ocrd-Identifier")
@ApiResponses({ @ApiResponse(code = 200, message = "PID for Ocrd-Identifier found", response = String.class),
@ApiResponse(code = 404, message = "Ocrd-Identifier not found", response = String.class)
})
@GetMapping(value = "/search-ocrdid", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<String> searchNewestOcrdIdentifier(
@RequestParam @ApiParam(value = "Ocrd-Identifier", required = true)
String id
) throws IOException {
Archive archive = archiveRepository.findTopByOcrdIdentifierOrderByCreatedAtDesc(id);
if (archive != null && archive.getPid() != null) {
return ResponseEntity.ok(archive.getPid());
} else {
throw new HttpClientErrorException(
HttpStatus.NOT_FOUND, ErrMsg.OCRD_IDENTIFIER_NOT_FOUND
);
}
}
}
1 change: 1 addition & 0 deletions src/main/java/ola/hd/longtermstorage/msg/ErrMsg.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ private ErrMsg() {
public static final String FULL_OR_METASEARCH = "Either 'metadatasearch' or 'fulltextsearch' must be true";
public static final String FIELD_NOT_EQUALS_VALUE = "'field' and 'value' must be given the same number of times";
public static final String UNKNOWN_FILTER = "'field' contains unknown filter. Valid are: " + String.join(", ", ElasticQueryHelper.FILTER_MAP.keySet());
public static final String OCRD_IDENTIFIER_NOT_FOUND = "Ocrd-Identifier not found";

}

0 comments on commit 4aa74c0

Please sign in to comment.