Class QueryParameters
- java.lang.Object
-
- com.sodius.oslc.server.process.query.QueryParameters
-
public class QueryParameters extends Object
OSLC query parameters parsed from an HTTP request.- Since:
- 3.6.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
QueryParameters.QueryParametersBuilder
A builder to parse OSLC query parameters.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
applySelectedProperties(HttpServletRequest request, Class<?> resourceShape)
Configures the request to support selective properties, to enable clients to retrieve only selected property values.static QueryParameters.QueryParametersBuilder
from(HttpServletRequest request, QueryParameter... scope)
Creates a builder to parse OSLC query parameters, controlled by the given scope.Optional<OrderByClause>
getOrderBy()
Returns the order by clause parsed from theoslc.orderBy
parameter, or an empty optional if absent.Optional<Integer>
getPageSize()
Returns theoslc.pageSize
parameter, or an empty optional if absent.Map<String,String>
getPrefixes()
Returns the map of prefix/namespace mappings defined in theoslc.prefix
parameter, or an empty map if absent.Optional<PropertiesClause>
getProperties()
Returns the properties clause parsed from theoslc.properties
parameter, or an empty optional if absent.Predicate<Object>
getPropertiesPredicate()
Returns a predicate to test whether a given property is part of the ones set in theoslc.properties
parameter.Optional<SearchTermsClause>
getSearchTerm()
Returns the search terms clause parsed from theoslc.searchTerms
parameter, or an empty optional if absent.Optional<SelectClause>
getSelect()
Returns the select clause parsed from theoslc.select
parameter, or an empty optional if absent.Map<String,Object>
getSelectInvertedProperties()
Returns the selected properties, as found on theoslc.select
parameter.Predicate<Object>
getSelectPredicate()
Returns a predicate to test whether a given property is part of the ones set in theoslc.select
parameter.Optional<WhereClause>
getWhere()
Returns the where clause parsed from theoslc.where
parameter, or an empty optional if absent.boolean
isPaging()
Returns theoslc.paging
parameter, orfalse
if absent
-
-
-
Method Detail
-
from
public static QueryParameters.QueryParametersBuilder from(HttpServletRequest request, QueryParameter... scope)
Creates a builder to parse OSLC query parameters, controlled by the given scope.The given array of parameters is to restrict which ones are parsed from the HTTP request. Any parameter not listed here is ignored, i.e. the parameter is not parsed from the HTTP request even if present. If the array is empty, all known parameters are parsed.
To use only selective properties for a GET end-point, you may prefer using
applySelectedProperties(HttpServletRequest, Class)
. To use only selective properties for a PUT end-point, you may prefer usingOslcProperties.of(HttpServletRequest)
.- Parameters:
request
- the HTTP requestscope
- the OSLC query parameters to parse- Returns:
- a new builder instance
- Throws:
NullPointerException
- if request is null
-
applySelectedProperties
public static void applySelectedProperties(HttpServletRequest request, Class<?> resourceShape)
Configures the request to support selective properties, to enable clients to retrieve only selected property values. This method shall be called on a GET end-point before responding with a given resource.This method parses the
oslc.select
andoslc.prefix
parameters and sets the"org.eclipse.lyo.oslc4j.selected.properties"
attribute on the request. This makes the XML and JSON serializers to respond only with properties that match the selected ones.The prefixes used in the
oslc.select
expression are resolved to namespaces using theoslc.prefix
parameter, if any, but also with ones defined on theOslcSchema
of the given resource shape and, last, with well known OSLC prefixes (RDF, OSLC Core, etc.).- Parameters:
request
- the HTTP requestresourceShape
- the type of resource responded by the GET end-point, to determine the OSLC prefixes that can be used- Throws:
NullPointerException
- if request or resourceShape is null
-
getPrefixes
public Map<String,String> getPrefixes()
Returns the map of prefix/namespace mappings defined in theoslc.prefix
parameter, or an empty map if absent.- Returns:
- an unmodifiable map of prefix/namespace mappings
-
getWhere
public Optional<WhereClause> getWhere()
Returns the where clause parsed from theoslc.where
parameter, or an empty optional if absent.The where clause can then be processed using a
QueryWhereHandler
.- Returns:
- the parsed where clause
- See Also:
QueryWhereHandler
-
getSearchTerm
public Optional<SearchTermsClause> getSearchTerm()
Returns the search terms clause parsed from theoslc.searchTerms
parameter, or an empty optional if absent.- Returns:
- the parsed search terms clause
-
getOrderBy
public Optional<OrderByClause> getOrderBy()
Returns the order by clause parsed from theoslc.orderBy
parameter, or an empty optional if absent.- Returns:
- the parsed order by clause
-
getProperties
public Optional<PropertiesClause> getProperties()
Returns the properties clause parsed from theoslc.properties
parameter, or an empty optional if absent.- Returns:
- the parsed properties clause
-
getPropertiesPredicate
public Predicate<Object> getPropertiesPredicate()
Returns a predicate to test whether a given property is part of the ones set in theoslc.properties
parameter. If the parameter is absent or is a wildcard ("*"
), the predicate returnstrue
.The property used as predicate argument can be either:
- a
URI
- the namespace and local part of a property (e.g.http://purl.org/dc/terms/title
) - a
String
- either a URI string (e.g.http://purl.org/dc/terms/title
) or prefixed name (e.g.dcterms:title
) - a
javax.xml.namespace.QName
- either a namespace and local part (e.g.http://purl.org/dc/terms/title
) or prefix and local part (e.g.dcterms:title
)
- Returns:
- a predicate to test whether a given property is accepted
- a
-
getSelect
public Optional<SelectClause> getSelect()
Returns the select clause parsed from theoslc.select
parameter, or an empty optional if absent.- Returns:
- the parsed select clause
-
getSelectInvertedProperties
public Map<String,Object> getSelectInvertedProperties()
Returns the selected properties, as found on theoslc.select
parameter. The returned map can be set either:- as
"org.eclipse.lyo.oslc4j.selected.properties"
attribute on the request (you may prefer usingapplySelectedProperties(HttpServletRequest, Class)
for this) - as
properties
argument ofResponseInfoCollection
orResponseInfoArray
- Returns:
- the selected properties found on the
oslc.select
parameter
- as
-
getSelectPredicate
public Predicate<Object> getSelectPredicate()
Returns a predicate to test whether a given property is part of the ones set in theoslc.select
parameter. If the parameter is absent or is a wildcard ("*"
), the predicate returnstrue
.The property used as predicate argument can be either:
- a
URI
- the namespace and local part of a property (e.g.http://purl.org/dc/terms/title
) - a
String
- either a URI string (e.g.http://purl.org/dc/terms/title
) or prefixed name (e.g.dcterms:title
) - a
javax.xml.namespace.QName
- either a namespace and local part (e.g.http://purl.org/dc/terms/title
) or prefix and local part (e.g.dcterms:title
)
- Returns:
- a predicate to test whether a given property is accepted
- a
-
isPaging
public boolean isPaging()
Returns theoslc.paging
parameter, orfalse
if absent- Returns:
- the
oslc.paging
parameter
-
-