Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement /product-properties endpoint #322

Merged
merged 2 commits into from
May 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
26 changes: 23 additions & 3 deletions model/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ info:
license:
name: Apache 2.0
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'

tags:
- name: 1. all products
description: search any classe of product and resolve product's identifiers
- name: 2. product references
description: explore the product hierarchy
- name: 3. by product classes
- name: 3. by product classes
description: search by class of product, bundles, collections, ...
- name: 4. deprecated
description: end-points which should not be used anymore

externalDocs:
description: User's Guide
url: https://nasa-pds.github.io/pds-api/guides/search.html

servers:
- url: https://pds.nasa.gov/api/registry/1
description: production server
Expand Down Expand Up @@ -311,6 +311,26 @@ paths:
- $ref: "#/components/parameters/Sort"
- $ref: "#/components/parameters/Start"

/product-properties:
alexdunnjpl marked this conversation as resolved.
Show resolved Hide resolved
get:
tags:
- 1. all products
summary: |
return a list of all possible searchable metadata fields for products published in the registry
operationId: product-properties-list
responses:
'200':
$ref: "#/components/responses/Plural"
alexdunnjpl marked this conversation as resolved.
Show resolved Hide resolved
'400':
$ref: "#/components/responses/Error"
'404':
$ref: "#/components/responses/Error"
'500':
$ref: "#/components/responses/Error"
'501':
$ref: "#/components/responses/Error"
parameters: []

/products/{identifier}:
get:
tags:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package gov.nasa.pds.api.registry.controller;

import java.io.IOException;
import java.util.Arrays;import java.util.HashMap;import java.util.List;import java.util.Map;import java.util.Set;

import com.fasterxml.jackson.databind.JsonNode;import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;import org.opensearch.client.RequestOptions;import org.opensearch.client.RestHighLevelClient;import org.opensearch.client.indices.GetIndexRequest;
import org.opensearch.client.indices.GetIndexResponse;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

import gov.nasa.pds.api.registry.ControlContext;
import gov.nasa.pds.api.registry.UserContext;

class GetIndexHandler implements EndpointHandler {
private String indexName;

public GetIndexHandler(String indexName) {
if (indexName == null || indexName.strip().equals("")) {
throw new IllegalArgumentException("Cannot initialize GetIndexHandler with null/empty index name");
}
this.indexName = indexName;
}

@Override
public ResponseEntity<Object> transmute(ControlContext control, UserContext _ignored)
throws IOException {

ObjectMapper mapper = new ObjectMapper();
mapper.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true);

GetIndexRequest req = new GetIndexRequest(indexName);
RestHighLevelClient client = control.getConnection().getRestHighLevelClient();;
GetIndexResponse response = client.indices().get(req, RequestOptions.DEFAULT);
JsonNode content = mapper.valueToTree(response.getMappings().get(indexName).getSourceAsMap()).get("properties");

String propertiesAsString = mapper.writeValueAsString(content);

return new ResponseEntity<>(propertiesAsString, HttpStatus.OK);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.List;
import java.util.Optional;
import gov.nasa.pds.api.base.ProductPropertiesApi;
import jakarta.validation.Valid;
import jakarta.validation.constraints.Min;
import org.springframework.http.ResponseEntity;
Expand All @@ -12,7 +13,7 @@
import gov.nasa.pds.api.registry.model.ProductVersionSelector;

abstract class SwaggerJavaProductsTransmuter extends SwaggerJavaClassesTransmuter
implements ControlContext, ProductsApi, ClassesApi {
implements ControlContext, ProductsApi, ClassesApi, ProductPropertiesApi {

public Optional<NativeWebRequest> getRequest() {
return Optional.empty();
Expand Down Expand Up @@ -112,4 +113,13 @@ public ResponseEntity<Object> selectByLidvidLatest(String identifier,
return this.processs(new Standard(), this.uriParametersBuilder.setIdentifier(identifier)
.setFields(fields).setVersion(ProductVersionSelector.LATEST).build());
}

@Override
public ResponseEntity<Object> productPropertiesList() {

String registryIndexName = this.getConnection().getRegistryIndex();
alexdunnjpl marked this conversation as resolved.
Show resolved Hide resolved
EndpointHandler handler = new GetIndexHandler(registryIndexName);
URIParameters uriParameters = this.uriParametersBuilder.build();
return this.processs(handler, uriParameters);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.IOException;
import java.util.List;
import gov.nasa.pds.api.base.ProductPropertiesApi;
import jakarta.validation.Valid;
import jakarta.validation.constraints.Min;
import org.antlr.v4.runtime.NoViableAltException;
Expand Down Expand Up @@ -31,7 +32,7 @@

@Controller
public class SwaggerJavaTransmuter extends SwaggerJavaDeprecatedTransmuter
implements ControlContext, BundlesApi, CollectionsApi, ClassesApi, ProductsApi {
implements ControlContext, BundlesApi, CollectionsApi, ClassesApi, ProductsApi, ProductPropertiesApi {


private static final Logger log = LoggerFactory.getLogger(SwaggerJavaTransmuter.class);
Expand Down Expand Up @@ -430,9 +431,16 @@ public ResponseEntity<Object> classMembersMembersVers(String propertyClass, Stri

@Override
public ResponseEntity<Object> classMembersVers(String propertyClass, String identifier,
String versions, @Valid List<String> fields, @Min(0) @Valid Integer limit,
@Valid List<String> sort, @Min(0) @Valid Integer start) {
String versions, @Valid List<String> fields, @Min(0) @Valid Integer limit,
@Valid List<String> sort, @Min(0) @Valid Integer start) {
// TODO Auto-generated method stub
return super.classMembersVers(propertyClass, identifier, versions, fields, limit, sort, start);
}

@Override
public ResponseEntity<Object> productPropertiesList() {
// TODO Auto-generated method stub
return super.productPropertiesList();
}

}