Skip to content

Commit

Permalink
squash! [untested, interim] implement member-of and member-of/member-…
Browse files Browse the repository at this point in the history
…of endpoints
  • Loading branch information
alexdunnjpl committed Jul 19, 2024
1 parent b5bb420 commit 2b80b08
Showing 1 changed file with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -546,4 +546,41 @@ public ResponseEntity<Object> productMemberOf(
}
}

@Override
public ResponseEntity<Object> productMemberOfOf(
String identifier, List<String> fields, Integer limit, List<String> sort, List<String> searchAfter)
throws NotFoundException, UnhandledException, SortSearchAfterMismatchException, MiscellaneousBadRequestException,
AcceptFormatNotSupportedException{

try{
PdsProductIdentifier pdsIdentifier = PdsProductIdentifier.fromString(identifier);
PdsProductClasses productClass = resolveProductClass(pdsIdentifier);

List<PdsLidVid> parentIds;
if (productClass.isBasicProduct()) {
parentIds = resolveLidVidsFromProductField(pdsIdentifier, "ops:Provenance/ops:parent_bundle_identifier");
} else {
// TODO: replace with enumeration of acceptable values later
throw new MiscellaneousBadRequestException("productMembersOf endpoint is not valid for products with Product_Class '" +
PdsProductClasses.Product_Bundle + "' or '" + PdsProductClasses.Product_Collection + "' (got '" + productClass + "')");
}

SearchRequest searchRequest = new RegistrySearchRequestBuilder(this.connectionContext)
.matchFieldAnyOfIdentifiers("_id", parentIds)
.fieldsFromStrings(fields)
.paginate(limit, sort, searchAfter)
.build();

SearchResponse<HashMap> searchResponse =
this.openSearchClient.search(searchRequest, HashMap.class);

RawMultipleProductResponse products = new RawMultipleProductResponse(searchResponse);

return formatMultipleProducts(products, fields);

} catch (IOException | OpenSearchException e) {
throw new UnhandledException(e);
}
}

}

0 comments on commit 2b80b08

Please sign in to comment.