Skip to content

Commit

Permalink
More work on search response encoding, now with basic metadata and pa…
Browse files Browse the repository at this point in the history
…gination links
  • Loading branch information
aaime committed Mar 7, 2017
1 parent f28e846 commit 53fdee2
Show file tree
Hide file tree
Showing 18 changed files with 332 additions and 56 deletions.
Expand Up @@ -84,11 +84,14 @@
<!-- kvp request readers --> <!-- kvp request readers -->
<bean id="oseoDescriptionRequestKvpParser" class="org.geoserver.opensearch.eo.kvp.DescriptionRequestKvpReader"/> <bean id="oseoDescriptionRequestKvpParser" class="org.geoserver.opensearch.eo.kvp.DescriptionRequestKvpReader"/>
<bean id="oseoSearchRequestKvpParser" class="org.geoserver.opensearch.eo.kvp.SearchRequestKvpReader"> <bean id="oseoSearchRequestKvpParser" class="org.geoserver.opensearch.eo.kvp.SearchRequestKvpReader">
<constructor-arg ref="geoServer"/>
<constructor-arg ref="openSearchEoService"/> <constructor-arg ref="openSearchEoService"/>
</bean> </bean>


<!-- responses --> <!-- responses -->
<bean id="oseoDescriptionResponse" class="org.geoserver.opensearch.eo.response.DescriptionResponse"/> <bean id="oseoDescriptionResponse" class="org.geoserver.opensearch.eo.response.DescriptionResponse"/>
<bean id="oseoAtomSearchResponse" class="org.geoserver.opensearch.eo.response.AtomSearchResponse"/> <bean id="oseoAtomSearchResponse" class="org.geoserver.opensearch.eo.response.AtomSearchResponse">
<constructor-arg ref="geoServer"/>
</bean>


</beans> </beans>
Expand Up @@ -9,7 +9,8 @@


public interface OSEOInfo extends ServiceInfo { public interface OSEOInfo extends ServiceInfo {


public static int DEFAULT_MAXIMUM_RECORDS = 50; public static int DEFAULT_MAXIMUM_RECORDS = 100;
public static int DEFAULT_RECORDS_PER_PAGE = 10;


/** /**
* Version 1.0.0 * Version 1.0.0
Expand Down Expand Up @@ -38,5 +39,18 @@ public interface OSEOInfo extends ServiceInfo {
* @param maximumRecords * @param maximumRecords
*/ */
void setMaximumRecords(int maximumRecords); void setMaximumRecords(int maximumRecords);

/**
* Returns the default records per page when no "count" parameter is provided
* @return
*/
public int getRecordsPerPage();

/**
* Sets the records per page, when no record is provided
* @param recordsPerPage
*/
public void setRecordsPerPage(int recordsPerPage);



} }
Expand Up @@ -13,6 +13,16 @@ public class OSEOInfoImpl extends ServiceInfoImpl implements OSEOInfo {
String openSearchAccessStoreId; String openSearchAccessStoreId;


int maximumRecords = OSEOInfo.DEFAULT_MAXIMUM_RECORDS; int maximumRecords = OSEOInfo.DEFAULT_MAXIMUM_RECORDS;

int recordsPerPage = OSEOInfo.DEFAULT_RECORDS_PER_PAGE;

public int getRecordsPerPage() {
return recordsPerPage;
}

public void setRecordsPerPage(int defaultRecords) {
this.recordsPerPage = defaultRecords;
}


public int getMaximumRecords() { public int getMaximumRecords() {
return maximumRecords; return maximumRecords;
Expand Down
Expand Up @@ -36,6 +36,8 @@ protected OSEOInfo createServiceFromScratch(GeoServer gs) {
oseo.setName("OSEO"); oseo.setName("OSEO");
oseo.setAbstract("Provides interoperable access, following ISO/OGC interface guidelines, to Earth Observation metadata."); oseo.setAbstract("Provides interoperable access, following ISO/OGC interface guidelines, to Earth Observation metadata.");
oseo.setTitle("OpenSearch for Earth Observation"); oseo.setTitle("OpenSearch for Earth Observation");
oseo.setMaximumRecords(OSEOInfo.DEFAULT_MAXIMUM_RECORDS);
oseo.setRecordsPerPage(OSEOInfo.DEFAULT_RECORDS_PER_PAGE);
final List<KeywordInfo> keywords = oseo.getKeywords(); final List<KeywordInfo> keywords = oseo.getKeywords();
keywords.add(new Keyword("EarthObservation")); keywords.add(new Keyword("EarthObservation"));
keywords.add(new Keyword("OGC")); keywords.add(new Keyword("OGC"));
Expand Down
Expand Up @@ -20,11 +20,15 @@
*/ */
public class OpenSearchParameters { public class OpenSearchParameters {


public static String PARAM_PREFIX = "parameterPrefix"; public static final Parameter<?> SEARCH_TERMS = new ParameterBuilder("searchTerms", String.class).prefix("os").build();


public static String MIN_INCLUSIVE = "minInclusive"; public static final Parameter<?> START_INDEX = new ParameterBuilder("startIndex", Integer.class).prefix("os").build();


public static String MAX_INCLUSIVE = "maxInclusive"; public static final String PARAM_PREFIX = "parameterPrefix";

public static final String MIN_INCLUSIVE = "minInclusive";

public static final String MAX_INCLUSIVE = "maxInclusive";


private static final List<Parameter<?>> BASIC_OPENSEARCH; private static final List<Parameter<?>> BASIC_OPENSEARCH;


Expand All @@ -37,8 +41,8 @@ public class OpenSearchParameters {


private static List<Parameter<?>> basicOpenSearchParameters() { private static List<Parameter<?>> basicOpenSearchParameters() {
return Arrays.asList( // return Arrays.asList( //
new ParameterBuilder("searchTerms", String.class).prefix("os").build(), SEARCH_TERMS,
new ParameterBuilder("startIndex", Integer.class).prefix("os").build()); START_INDEX);
} }


private static List<Parameter<?>> geoTimeOpenSearchParameters() { private static List<Parameter<?>> geoTimeOpenSearchParameters() {
Expand Down Expand Up @@ -90,8 +94,18 @@ public static List<Parameter<?>> getGeoTimeOpensearch() {
* @return * @return
*/ */
public static String getQualifiedParamName(Parameter p) { public static String getQualifiedParamName(Parameter p) {
return getQualifiedParamName(p, true);
}

/**
* Returns the qualified name of a parameter, in case the parameter has a PARAM_PREFIX among its metadata, or the simple parameter key other
*
* @param p
* @return
*/
public static String getQualifiedParamName(Parameter p, boolean qualifyOpenSearchNative) {
String prefix = p.metadata == null ? null : (String) p.metadata.get(PARAM_PREFIX); String prefix = p.metadata == null ? null : (String) p.metadata.get(PARAM_PREFIX);
if (prefix != null) { if (prefix != null && (!"os".equals(prefix) || qualifyOpenSearchNative)) {
return prefix + ":" + p.key; return prefix + ":" + p.key;
} else { } else {
return p.key; return p.key;
Expand Down
Expand Up @@ -4,6 +4,7 @@
*/ */
package org.geoserver.opensearch.eo; package org.geoserver.opensearch.eo;


import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;


Expand Down Expand Up @@ -55,7 +56,7 @@ public Parameter build() {
metadata.put(OpenSearchParameters.MAX_INCLUSIVE, max); metadata.put(OpenSearchParameters.MAX_INCLUSIVE, max);
} }
return new Parameter<>(key, type, null, null, required, required ? 1 : 0, 1, null, return new Parameter<>(key, type, null, null, required, required ? 1 : 0, 1, null,
metadata); Collections.unmodifiableMap(metadata));
} }


public ParameterBuilder minimumInclusive(int min) { public ParameterBuilder minimumInclusive(int min) {
Expand Down
Expand Up @@ -24,7 +24,17 @@ public class SearchRequest {


String httpAccept; String httpAccept;


private Map<String, String> searchParameters; private Map<Parameter, String> searchParameters;

transient String baseUrl;

public String getBaseUrl() {
return baseUrl;
}

public void setBaseUrl(String baseUrl) {
this.baseUrl = baseUrl;
}


public String getParentId() { public String getParentId() {
return parentId; return parentId;
Expand All @@ -50,11 +60,11 @@ public void setHttpAccept(String httpAccept) {
this.httpAccept = httpAccept; this.httpAccept = httpAccept;
} }


public void setSearchParameters(Map<String, String> searchParameters) { public void setSearchParameters(Map<Parameter, String> searchParameters) {
this.searchParameters = searchParameters; this.searchParameters = searchParameters;
} }

public Map<String, String> getSearchParameters() { public Map<Parameter, String> getSearchParameters() {
return searchParameters; return searchParameters;
} }


Expand Down
Expand Up @@ -18,6 +18,8 @@
import java.util.stream.Collectors; import java.util.stream.Collectors;


import org.geoserver.catalog.Predicates; import org.geoserver.catalog.Predicates;
import org.geoserver.config.GeoServer;
import org.geoserver.opensearch.eo.OSEOInfo;
import org.geoserver.opensearch.eo.OpenSearchEoService; import org.geoserver.opensearch.eo.OpenSearchEoService;
import org.geoserver.opensearch.eo.OpenSearchParameters; import org.geoserver.opensearch.eo.OpenSearchParameters;
import org.geoserver.opensearch.eo.SearchRequest; import org.geoserver.opensearch.eo.SearchRequest;
Expand Down Expand Up @@ -50,9 +52,12 @@ public class SearchRequestKvpReader extends KvpRequestReader {


private OpenSearchEoService oseo; private OpenSearchEoService oseo;


public SearchRequestKvpReader(OpenSearchEoService service) { private GeoServer gs;

public SearchRequestKvpReader(GeoServer gs, OpenSearchEoService service) {
super(SearchRequest.class); super(SearchRequest.class);
this.oseo = service; this.oseo = service;
this.gs = gs;
} }


@Override @Override
Expand All @@ -61,7 +66,7 @@ public Object read(Object requestObject, Map kvp, Map rawKvp) throws Exception {


// collect the valid search parameters // collect the valid search parameters
Collection<Parameter<?>> parameters = getSearchParameters(request); Collection<Parameter<?>> parameters = getSearchParameters(request);
Map<String, String> parameterValues = getSearchParameterValues(rawKvp, parameters); Map<Parameter, String> parameterValues = getSearchParameterValues(rawKvp, parameters);
request.setSearchParameters(parameterValues); request.setSearchParameters(parameterValues);


// prepare query // prepare query
Expand All @@ -80,7 +85,14 @@ public Object read(Object requestObject, Map kvp, Map rawKvp) throws Exception {
throw new OWS20Exception("Invalid 'count' value, should be positive or zero", throw new OWS20Exception("Invalid 'count' value, should be positive or zero",
OWSExceptionCode.InvalidParameterValue); OWSExceptionCode.InvalidParameterValue);
} }
int configuredMaxFeatures = getConfiguredMaxFeatures();
if (ic > configuredMaxFeatures) {
throw new OWS20Exception("Invalid 'count' value, should not be greater than "
+ configuredMaxFeatures, OWSExceptionCode.InvalidParameterValue);
}
query.setMaxFeatures(ic); query.setMaxFeatures(ic);
} else {
query.setMaxFeatures(getDefaultRecords());
} }
Integer startIndex = getParameter(START_INDEX, rawKvp, Integer.class); Integer startIndex = getParameter(START_INDEX, rawKvp, Integer.class);
if (startIndex != null) { if (startIndex != null) {
Expand All @@ -95,15 +107,32 @@ public Object read(Object requestObject, Map kvp, Map rawKvp) throws Exception {
return request; return request;
} }


private Map<String, String> getSearchParameterValues(Map rawKvp, private int getDefaultRecords() {
OSEOInfo info = gs.getService(OSEOInfo.class);
if (info == null) {
return OSEOInfo.DEFAULT_RECORDS_PER_PAGE;
} else {
return info.getRecordsPerPage();
}
}

private int getConfiguredMaxFeatures() {
OSEOInfo info = gs.getService(OSEOInfo.class);
if (info == null) {
return OSEOInfo.DEFAULT_MAXIMUM_RECORDS;
} else {
return info.getMaximumRecords();
}
}

private Map<Parameter, String> getSearchParameterValues(Map rawKvp,
Collection<Parameter<?>> parameters) { Collection<Parameter<?>> parameters) {
Map<String, String> result = new LinkedHashMap<>(); Map<Parameter, String> result = new LinkedHashMap<>();
for (Parameter<?> parameter : parameters) { for (Parameter<?> parameter : parameters) {
Object value = rawKvp.get(parameter.key); Object value = rawKvp.get(parameter.key);
if (value != null) { if (value != null) {
final String sv = Converters.convert(value, String.class); final String sv = Converters.convert(value, String.class);
final String qn = OpenSearchParameters.getQualifiedParamName(parameter); result.put(parameter, sv);
result.put(qn, sv);
} }
} }


Expand Down

0 comments on commit 53fdee2

Please sign in to comment.