Skip to content

Commit

Permalink
Minimum Viable Product working with multitenant Registry on Opensearc…
Browse files Browse the repository at this point in the history
…h Serverless (#531)

* implement RegistrySearchRequestBuilder.applyMultipleProductsDefaults()

* switch /products and membership endpoints to use applyMultipleProductsDefaults()

* rename RegistrySearchRequestBuilder.onlyLatest() to noSupersededProducts()
the semantics of the new name are clearer and cannot lead to confusion about its behaviour

* fix terraform deployment on MCP dev

* add ssm parameter to share the load balancer domain with other components

* rename noSupersededProduct -> excludeSupersededProducts

* update application.properties for latest code

* make operator, NOT, LIKE, AND, OR antlr tokens case-insensitive

* add Query parameter to membership endpoints (#526)

* Handle Accept header with multiple values (#529)

* properly manage Accept header with multiple options

* move MVC function in appropriate class, add unit tests

---------

Co-authored-by: thomas loubrieu <[email protected]>

* implement PdsProperty

* apply propertiesList response schema to '*' content-type

* implement /properties endpoint

* add warning on /docs end-point which does not work yet

---------

Co-authored-by: edunn <[email protected]>
Co-authored-by: thomas loubrieu <[email protected]>
Co-authored-by: Jordan Padams <[email protected]>
  • Loading branch information
4 people authored Sep 3, 2024
1 parent e3162f1 commit 144aa35
Show file tree
Hide file tree
Showing 11 changed files with 607 additions and 261 deletions.
49 changes: 39 additions & 10 deletions lexer/src/main/antlr4/gov/nasa/pds/api/registry/lexer/Search.g4
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,54 @@ comparison : FIELD operator ( NUMBER | STRINGVAL ) ;
likeComparison : FIELD LIKE STRINGVAL ;
operator : EQ | NE | GT | GE | LT | LE ;

NOT : 'not' ;
NOT : 'NOT' | 'not' ;

EQ : 'eq' ;
NE : 'ne' ;
GT : 'gt' ;
GE : 'ge' ;
LT : 'lt' ;
LE : 'le' ;
EQ : E Q ;
NE : N E ;
GT : G T ;
GE : G E ;
LT : L T ;
LE : L E ;

LIKE: 'like';
LIKE: L I K E;

LPAREN : '(' ;
RPAREN : ')' ;

AND : 'AND' | 'and' ;
OR : 'OR' | 'or' ;
AND : A N D ;
OR : O R ;

FIELD : [A-Za-z_] [A-Za-z0-9_.:/]* ;
STRINGVAL : '"' ~["\r\n]* '"' ;
NUMBER : ('-')? [0-9]+ ('.' [0-9]*)? ;
WS : [ \t\r\n]+ -> skip ;
// case-insensitivity fragments, per https://chromium.googlesource.com/external/github.com/antlr/antlr4/+/2191c386190a7d57d457319dd2f6aec4f0231d4c/doc/case-insensitive-lexing.md
fragment A : [aA];
fragment B : [bB];
fragment C : [cC];
fragment D : [dD];
fragment E : [eE];
fragment F : [fF];
fragment G : [gG];
fragment H : [hH];
fragment I : [iI];
fragment J : [jJ];
fragment K : [kK];
fragment L : [lL];
fragment M : [mM];
fragment N : [nN];
fragment O : [oO];
fragment P : [pP];
fragment Q : [qQ];
fragment R : [rR];
fragment S : [sS];
fragment T : [tT];
fragment U : [uU];
fragment V : [vV];
fragment W : [wW];
fragment X : [xX];
fragment Y : [yY];
fragment Z : [zZ];
12 changes: 10 additions & 2 deletions model/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ paths:
tags:
- 5. all docs
summary: |
search on all registry documents by posting an OpenSearch DSL query
WORK IN PROGRESS: search on all registry documents by posting an OpenSearch DSL query
operationId: docs
requestBody:
description: OpenSearch DSL query
Expand Down Expand Up @@ -278,6 +278,7 @@ paths:
- $ref: "#/components/parameters/Fields"
- $ref: "#/components/parameters/Identifier"
- $ref: "#/components/parameters/Limit"
- $ref: "#/components/parameters/Query"
- $ref: "#/components/parameters/Sort"
- $ref: "#/components/parameters/SearchAfter"
/products/{identifier}/members/{versions}:
Expand All @@ -302,6 +303,7 @@ paths:
- $ref: "#/components/parameters/Fields"
- $ref: "#/components/parameters/Identifier"
- $ref: "#/components/parameters/Limit"
- $ref: "#/components/parameters/Query"
- $ref: "#/components/parameters/Sort"
- $ref: "#/components/parameters/SearchAfter"
- $ref: "#/components/parameters/Versions"
Expand All @@ -327,6 +329,7 @@ paths:
- $ref: "#/components/parameters/Fields"
- $ref: "#/components/parameters/Identifier"
- $ref: "#/components/parameters/Limit"
- $ref: "#/components/parameters/Query"
- $ref: "#/components/parameters/Sort"
- $ref: "#/components/parameters/SearchAfter"
/products/{identifier}/members/members/{versions}:
Expand All @@ -351,6 +354,7 @@ paths:
- $ref: "#/components/parameters/Fields"
- $ref: "#/components/parameters/Identifier"
- $ref: "#/components/parameters/Limit"
- $ref: "#/components/parameters/Query"
- $ref: "#/components/parameters/Sort"
- $ref: "#/components/parameters/SearchAfter"
- $ref: "#/components/parameters/Versions"
Expand All @@ -376,6 +380,7 @@ paths:
- $ref: "#/components/parameters/Fields"
- $ref: "#/components/parameters/Identifier"
- $ref: "#/components/parameters/Limit"
- $ref: "#/components/parameters/Query"
- $ref: "#/components/parameters/Sort"
- $ref: "#/components/parameters/SearchAfter"
/products/{identifier}/member-of/{versions}:
Expand All @@ -400,6 +405,7 @@ paths:
- $ref: "#/components/parameters/Fields"
- $ref: "#/components/parameters/Identifier"
- $ref: "#/components/parameters/Limit"
- $ref: "#/components/parameters/Query"
- $ref: "#/components/parameters/Sort"
- $ref: "#/components/parameters/SearchAfter"
- $ref: "#/components/parameters/Versions"
Expand All @@ -425,6 +431,7 @@ paths:
- $ref: "#/components/parameters/Fields"
- $ref: "#/components/parameters/Identifier"
- $ref: "#/components/parameters/Limit"
- $ref: "#/components/parameters/Query"
- $ref: "#/components/parameters/Sort"
- $ref: "#/components/parameters/SearchAfter"
/products/{identifier}/member-of/member-of/{versions}:
Expand All @@ -449,6 +456,7 @@ paths:
- $ref: "#/components/parameters/Fields"
- $ref: "#/components/parameters/Identifier"
- $ref: "#/components/parameters/Limit"
- $ref: "#/components/parameters/Query"
- $ref: "#/components/parameters/Sort"
- $ref: "#/components/parameters/SearchAfter"
- $ref: "#/components/parameters/Versions"
Expand Down Expand Up @@ -660,7 +668,7 @@ components:
content:
"*":
schema:
type: object
$ref: '#/components/schemas/propertiesList'
"*/*":
schema:
$ref: '#/components/schemas/propertiesList'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package gov.nasa.pds.api.registry.configuration;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
Expand All @@ -15,6 +18,11 @@
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import gov.nasa.pds.api.registry.controllers.ProductsController;
import gov.nasa.pds.api.registry.model.api_responses.PdsProductBusinessObject;
import gov.nasa.pds.api.registry.model.api_responses.ProductBusinessLogic;
import gov.nasa.pds.api.registry.model.api_responses.WyriwygBusinessObject;
import gov.nasa.pds.api.registry.model.exceptions.AcceptFormatNotSupportedException;
import gov.nasa.pds.api.registry.view.CsvErrorMessageSerializer;
import gov.nasa.pds.api.registry.view.CsvPluralSerializer;
import gov.nasa.pds.api.registry.view.CsvSingularSerializer;
Expand All @@ -39,9 +47,37 @@
public class WebMVCConfig implements WebMvcConfigurer {
private static final Logger log = LoggerFactory.getLogger(WebMVCConfig.class);



@Value("${server.contextPath}")
private String contextPath;

private static Map<String, Class<? extends ProductBusinessLogic>> formatters =
new HashMap<String, Class<? extends ProductBusinessLogic>>();

static public Map<String, Class<? extends ProductBusinessLogic>> getFormatters() {
return formatters;
}

static {
// TODO move that at a better place, it is not specific to this controller
formatters.put("*", PdsProductBusinessObject.class);
formatters.put("*/*", PdsProductBusinessObject.class);
formatters.put("application/csv", WyriwygBusinessObject.class);
formatters.put("application/json", PdsProductBusinessObject.class);
formatters.put("application/kvp+json", WyriwygBusinessObject.class);
// this.formatters.put("application/vnd.nasa.pds.pds4+json", new
// Pds4ProductBusinessObject(true));
// this.formatters.put("application/vnd.nasa.pds.pds4+xml", new
// Pds4ProductBusinessObject(false));
formatters.put("application/xml", PdsProductBusinessObject.class);
formatters.put("text/csv", WyriwygBusinessObject.class);
formatters.put("text/html", PdsProductBusinessObject.class);
formatters.put("text/xml", PdsProductBusinessObject.class);
}



@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
String contextPath = this.contextPath.endsWith("/") ? this.contextPath : this.contextPath + "/";
Expand Down Expand Up @@ -120,4 +156,27 @@ public void configureMessageConverters(List<HttpMessageConverter<?>> converters)
WebMVCConfig.log.info("Number of converters available after adding locals "
+ Integer.toString(converters.size()));
}



static public Class<? extends ProductBusinessLogic> selectFormatterClass(String acceptHeaderValue)
throws AcceptFormatNotSupportedException {


// split by , and remove extra spaces
String[] acceptOrderedValues =
Arrays.stream(acceptHeaderValue.split(",")).map(String::trim).toArray(String[]::new);

for (String acceptValue : acceptOrderedValues) {
if (WebMVCConfig.formatters.containsKey(acceptValue)) {
return WebMVCConfig.formatters.get(acceptValue);
}
}

// if none of the Accept format proposed matches
throw new AcceptFormatNotSupportedException(
"None of the format(s) " + acceptHeaderValue + " is supported.");

}

}
Loading

0 comments on commit 144aa35

Please sign in to comment.