Esri Geoportal Server
1.0

com.esri.gpt.catalog.discovery.rest
Class RestQueryParser

java.lang.Object
  extended by com.esri.gpt.catalog.discovery.rest.RestQueryParser

public class RestQueryParser
extends Object

Provides functionality to parse a rest query URL.

The primary goal is to build filter and response components associated with the query.


Constructor Summary
RestQueryParser(HttpServletRequest request, RequestContext context, RestQuery query)
          Constructs the parser.
 
Method Summary
 void appendClause(LogicalClause parent, DiscoveryClause clause)
          Appends a clause to the query filter.
 PropertyClause extractProperty(PropertyClause clause, String restKey, String discoverableKey)
          Extracts a property clause from the HTTP request.
 DiscoveryClause extractPropertyList(String restKey, String discoverableKey, String delimiter, boolean orBased)
          Extracts a grouping of property clauses (delimited list) from the HTTP request.
 DiscoveryClause extractPropertyRange(String restLowerKey, String restUpperKey, String discoverableKey)
          Extracts a range based discovery clause from the HTTP request.
 Sortables extractSortables(String restKey)
          Extracts sort option parameters from the HTTP request.
 SpatialClause extractSpatialClause(String restBBoxKey, String restOperatorKey, String discoverableKey)
          Extracts the spatial clause from the HTTP request.
 Discoverable findDiscoverable(String discoverableKey)
          Finds the discoverable property associated with a discoverable key.
 AliasedDiscoverables getDiscoverables()
          Gets the aliased map of configured discoverable properties.
 DiscoveryFilter getFilter()
          Convenience method to return the filter associated with the query being populated.
 RestQuery getQuery()
          Gets the query being populated.
 String getRequestParameter(String parameterKey)
          Gets the HTTP request parameter value associated with a key.
 void parseMaxRecords(String restKey, int defaultValue)
          Parses and sets the maximum number of return records for the query filter.
 void parsePropertyIsEqualTo(String restKey, String discoverableKey)
          Parses and appends a PropertyIsEqualTo clause to the query filter if located.
 void parsePropertyIsLike(String restKey, String discoverableKey)
          Parses and appends a PropertyIsLike clause to the query filter if located.
 void parsePropertyList(String restKey, String discoverableKey, String delimiter, boolean orBased)
          Parses and appends a grouping of property clauses (delimited list) to the query filter if located.
 void parsePropertyRange(String restLowerKey, String restUpperKey, String discoverableKey)
          Parses and appends a range based discovery clause to the query filter if located.
 void parseRepositoryId(String restKey)
          Parses and sets the repository ID.
 void parseResponseFormat(String restKey)
          Parses and sets the response format for the query.
 void parseResponseGeometry(String restKey)
          Parses and sets the response geometry for the query.
 void parseResponseStyle(String restKey)
          Parses and sets the response style for the query.
 void parseResponseTarget(String restKey)
          Parses and sets the response target for the query.
 void parseSortables(String restKey)
          Parses sort option parameters and sets the query sortables if found.
 void parseSpatialClause(String restBBoxKey, String restOperatorKey, String discoverableKey)
          Parses and appends a spatial clause to the query filter if located.
 void parseStartRecord(String restKey, int defaultValue)
          Parses and sets the start record for the query filter.
 void setDiscoverables(AliasedDiscoverables discoverables)
          Sets the aliased map of configured discoverable properties.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RestQueryParser

public RestQueryParser(HttpServletRequest request,
                       RequestContext context,
                       RestQuery query)
Constructs the parser.

Parameters:
request - the active HTTP request
context - the request context
query - the query to populate
Method Detail

getDiscoverables

public AliasedDiscoverables getDiscoverables()
Gets the aliased map of configured discoverable properties.

Returns:
the discoverables

setDiscoverables

public void setDiscoverables(AliasedDiscoverables discoverables)
Sets the aliased map of configured discoverable properties.

Parameters:
discoverables - the discoverables

getFilter

public DiscoveryFilter getFilter()
Convenience method to return the filter associated with the query being populated.

Returns:
the filter

getQuery

public RestQuery getQuery()
Gets the query being populated.

Returns:
the query

appendClause

public void appendClause(LogicalClause parent,
                         DiscoveryClause clause)
Appends a clause to the query filter.
The clause will not be appended if it or it's parent is null.

Parameters:
parent - the parent to which the supplied discovery clause will be appended
clause - the clause to append

extractProperty

public PropertyClause extractProperty(PropertyClause clause,
                                      String restKey,
                                      String discoverableKey)
Extracts a property clause from the HTTP request.
This method checks the HTTP request parameter map for the value associated with a supplied key. If found, the supplied PropertyClause is populated with an appropriate literal and target, then returned.

Parameters:
clause - the property clause to populate and return
restKey - the URL key for the parameter
discoverableKey - the key associated with the target discoverable
Returns:
the property clause (null if not validly located within the request)

extractPropertyList

public DiscoveryClause extractPropertyList(String restKey,
                                           String discoverableKey,
                                           String delimiter,
                                           boolean orBased)
Extracts a grouping of property clauses (delimited list) from the HTTP request.
This method checks the HTTP request parameter map for the delimited value associated with a supplied key.
If found, the delimited value is tokenized into a collection of "equal to" property clauses (PropertyClause.PropertyIsEqualTo).
If multiple values are found, they will be logically grouped based upon the supplied "orBased" parameter (LogicalClause).

Parameters:
restKey - the URL key for the parameter
discoverableKey - the key associated with the target discoverable
delimiter - the value delimiter
orBased - if true, group within a logical or, otherwise group within a logical and
Returns:
an appropriate discovery clause (null if not validly located within the request)

extractPropertyRange

public DiscoveryClause extractPropertyRange(String restLowerKey,
                                            String restUpperKey,
                                            String discoverableKey)
Extracts a range based discovery clause from the HTTP request.
This method checks the HTTP request parameter map for the lower and/or upper boundaries of a range based query.
If found, the lower boundary will be associated with a PropertyClause.PropertyIsGreaterThanOrEqualTo clause, the upper boundary with a PropertyClause.PropertyIsLessThanOrEqualTo clause.
If both are found, a LogicalClause.LogicalAnd clause is returned.

Parameters:
restLowerKey - the URL key for the lower value parameter of the range
restUpperKey - the URL key for the upper value parameter of the range
discoverableKey - the key associated with the target discoverable
Returns:
an appropriate discovery clause (null if not validly located within the request)

extractSortables

public Sortables extractSortables(String restKey)
Extracts sort option parameters from the HTTP request.
This method checks the HTTP request parameter map for an order by parameter and constructs an appropriate Sortables component if located.

Parameters:
restKey - the URL key for the sort option parameter
Returns:
the sortables (null if not validly located within the request)

extractSpatialClause

public SpatialClause extractSpatialClause(String restBBoxKey,
                                          String restOperatorKey,
                                          String discoverableKey)
Extracts the spatial clause from the HTTP request.
This method checks the HTTP request parameter map for spatial related parameters and constructs a SpatialClause if located (filter related).

Parameters:
restBBoxKey - the URL key for the BBOX parameter
restOperatorKey - the URL key for the spatial operator parameter
discoverableKey - the key associated with the target discoverable
Returns:
the spatial clause (null if not validly located within the request)

findDiscoverable

public Discoverable findDiscoverable(String discoverableKey)
Finds the discoverable property associated with a discoverable key.

Parameters:
discoverableKey - the discoverable key (or alias)
Returns:
the discoverable property (null if none was found);

getRequestParameter

public String getRequestParameter(String parameterKey)
Gets the HTTP request parameter value associated with a key.

Parameters:
parameterKey - the parameter key
Returns:
the parameter value (empty string if not found)

parseMaxRecords

public void parseMaxRecords(String restKey,
                            int defaultValue)
Parses and sets the maximum number of return records for the query filter.
See: DiscoveryFilter.setMaxRecords(int)

Parameters:
restKey - the URL key for the parameter
defaultValue - the default value (if the parameter is not located on the URL)

parsePropertyIsEqualTo

public void parsePropertyIsEqualTo(String restKey,
                                   String discoverableKey)
Parses and appends a PropertyIsEqualTo clause to the query filter if located.
See: extractProperty(PropertyClause, String, String)
See: PropertyClause.PropertyIsEqualTo
See: DiscoveryQuery.getFilter()

Parameters:
restKey - the URL key for the parameter
discoverableKey - the key associated with the target discoverable

parsePropertyIsLike

public void parsePropertyIsLike(String restKey,
                                String discoverableKey)
Parses and appends a PropertyIsLike clause to the query filter if located.
See: extractProperty(PropertyClause, String, String)
See: PropertyClause.PropertyIsLike
See: DiscoveryQuery.getFilter()

Parameters:
restKey - the URL key for the parameter
discoverableKey - the key associated with the target discoverable

parsePropertyList

public void parsePropertyList(String restKey,
                              String discoverableKey,
                              String delimiter,
                              boolean orBased)
Parses and appends a grouping of property clauses (delimited list) to the query filter if located.
See: extractPropertyList(String, String, String, boolean)
See: DiscoveryQuery.getFilter()

Parameters:
restKey - the URL key for the parameter
discoverableKey - the key associated with the target discoverable
delimiter - the value delimiter
orBased - if true, group within a logical or, otherwise group within a logical and

parsePropertyRange

public void parsePropertyRange(String restLowerKey,
                               String restUpperKey,
                               String discoverableKey)
Parses and appends a range based discovery clause to the query filter if located.
See: extractPropertyRange(String, String, String)
See: DiscoveryQuery.getFilter()

Parameters:
restLowerKey - the URL key for the lower value parameter of the range
restUpperKey - the URL key for the upper value parameter of the range
discoverableKey - the key associated with the target discoverable

parseRepositoryId

public void parseRepositoryId(String restKey)
Parses and sets the repository ID.
See: RestQuery.setRepositoryId(String)

Parameters:
restKey - the URL key for the parameter

parseResponseFormat

public void parseResponseFormat(String restKey)
Parses and sets the response format for the query.
See: RestQuery.setResponseFormat(String)

Parameters:
restKey - the URL key for the parameter

parseResponseGeometry

public void parseResponseGeometry(String restKey)
Parses and sets the response geometry for the query.
See: RestQuery.setResponseGeometry(String)

Parameters:
restKey - the URL key for the parameter

parseResponseStyle

public void parseResponseStyle(String restKey)
Parses and sets the response style for the query.
See: RestQuery.setResponseStyle(String)

Parameters:
restKey - the URL key for the parameter

parseResponseTarget

public void parseResponseTarget(String restKey)
Parses and sets the response target for the query.
See: RestQuery.setResponseTarget(String)

Parameters:
restKey - the URL key for the parameter

parseSortables

public void parseSortables(String restKey)
Parses sort option parameters and sets the query sortables if found.
See: extractSortables(String)
See: DiscoveryQuery.setSortables(Sortables)

Parameters:
restKey - the URL key for the parameter

parseSpatialClause

public void parseSpatialClause(String restBBoxKey,
                               String restOperatorKey,
                               String discoverableKey)
Parses and appends a spatial clause to the query filter if located.
See: extractSpatialClause(String, String, String)
See: DiscoveryQuery.getFilter()

Parameters:
restBBoxKey - the URL key for the BBOX parameter
restOperatorKey - the URL key for the spatial operator parameter
discoverableKey - the key associated with the target discoverable

parseStartRecord

public void parseStartRecord(String restKey,
                             int defaultValue)
Parses and sets the start record for the query filter.
See: DiscoveryFilter.setStartRecord(int)

Parameters:
restKey - the URL key for the parameter
defaultValue - the default value (if the parameter is not located on the URL)

Esri Geoportal Server
1.0

Copyright 2011 Environmental Systems Research Institute. All rights reserved. Use is subject to license terms.