org.gcube.opensearch.opensearchlibrary.query
Class BasicQueryBuilder

java.lang.Object
  extended by org.gcube.opensearch.opensearchlibrary.query.BasicQueryBuilder
All Implemented Interfaces:
QueryBuilder

public class BasicQueryBuilder
extends java.lang.Object
implements QueryBuilder

Query builder class that implements the QueryBuilder interface, providing standard OpenSearch parameter functionality.

Author:
gerasimos.farantatos

Constructor Summary
BasicQueryBuilder(URLTemplate template, java.lang.String startIndexDef, java.lang.String startPageDef)
          Creates a new BasicQueryBuilder operating on a URL template, with default values for startIndex and startPage OpenSearch parameters (typically provided from the URL element which encloses the URL template)
BasicQueryBuilder(URLTemplate template, java.lang.String countDef, java.lang.String startIndexDef, java.lang.String startPageDef)
          Creates a new BasicQueryBuilder.
 
Method Summary
 QueryBuilder clone()
          Returns a copy of this query builder
 java.util.List<java.lang.String> getOptionalParameters()
          Returns a list containing all optional parameters of the query builder
 java.lang.String getParameterValue(java.lang.String name)
          Retrieves the value assigned to a parameter of the query builder
 java.lang.String getQuery()
          Retrieves the search query corresponding to the current state of the query builder
 java.lang.String getRawTemplate()
          Returns the query template associated with this query builder
 java.util.List<java.lang.String> getRequiredParameters()
          Returns a list containing all required parameters of the query builder
 java.lang.Integer getStartIndexDef()
          Returns the default value of the StartIndex OpenSearch parameter associated with this query builder
 java.lang.Integer getStartPageDef()
          Returns the default value of the StartPage OpenSearch parameter associated with this query builder
 java.util.List<java.lang.String> getUnsetParameters()
          Returns a list containing all parameters to which no value has been assigned
 boolean hasParameter(java.lang.String name)
          Determines if a parameter is contained in the parameter set of the query builder
 boolean isParameterSet(java.lang.String name)
          Determines if a parameter has an assigned value.
 boolean isQueryComplete()
          Determines whether the query is complete and therefore ready to be issued, i.e.
static void main(java.lang.String[] args)
           
 BasicQueryBuilder setParameter(java.lang.String name, java.lang.Integer value)
          Assigns an integral value to a parameter of the query builder
 BasicQueryBuilder setParameter(java.lang.String name, java.lang.String value)
          Assigns a string value to a parameter of the query builder
 BasicQueryBuilder setParameters(java.util.List<java.lang.String> names, java.util.List<java.lang.Object> values)
          Assigns to each parameter contained in the list of the first argument the respective value contained in the list of the secord argument
 QueryBuilder setParameters(QueryElement queryEl)
          Sets all parameters of the query builder that are also contained in the QueryElement provided with the values contained in the QueryElement
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BasicQueryBuilder

public BasicQueryBuilder(URLTemplate template,
                         java.lang.String startIndexDef,
                         java.lang.String startPageDef)
                  throws java.lang.Exception
Creates a new BasicQueryBuilder operating on a URL template, with default values for startIndex and startPage OpenSearch parameters (typically provided from the URL element which encloses the URL template)

Parameters:
template - The query template that will be used to construct queries
startIndexDef - The default value for the startIndex standard OpenSearch parameter
startPageDef - The default value for the startPage standard OpenSearch parameter
Throws:
java.lang.Exception - In case of error

BasicQueryBuilder

public BasicQueryBuilder(URLTemplate template,
                         java.lang.String countDef,
                         java.lang.String startIndexDef,
                         java.lang.String startPageDef)
                  throws java.lang.Exception
Creates a new BasicQueryBuilder. Similar to BasicQueryBuilder(URLTemplate, String, String) except that it takes an additional default value for the count standard OpenSearch parameter

Parameters:
template - The query template that will be used to construct queries
countDef - The default value for the count standard OpenSearch parameter
startIndexDef - The default value for the startIndex standard OpenSearch parameter
startPageDef - The default value for the startPage standard OpenSearch parameter
Throws:
java.lang.Exception - In case of error
Method Detail

clone

public QueryBuilder clone()
Description copied from interface: QueryBuilder
Returns a copy of this query builder

Specified by:
clone in interface QueryBuilder
Overrides:
clone in class java.lang.Object
Returns:
A new query builder whose state is the same as this instance

getRequiredParameters

public java.util.List<java.lang.String> getRequiredParameters()
Returns a list containing all required parameters of the query builder

Specified by:
getRequiredParameters in interface QueryBuilder
Returns:
A list of all required parameters
See Also:
QueryBuilder.getRequiredParameters()

getOptionalParameters

public java.util.List<java.lang.String> getOptionalParameters()
Returns a list containing all optional parameters of the query builder

Specified by:
getOptionalParameters in interface QueryBuilder
Returns:
A list of all optional parameters
See Also:
QueryBuilder.getOptionalParameters()

getParameterValue

public java.lang.String getParameterValue(java.lang.String name)
                                   throws NonExistentParameterException
Retrieves the value assigned to a parameter of the query builder

Specified by:
getParameterValue in interface QueryBuilder
Parameters:
name - The qualified name of the parameter
Returns:
The value of the parameter. or null if the parameter has no assigned value
Throws:
NonExistentParameterException - If the parameter is not contained in the parameter set of the query builder
See Also:
QueryBuilder.getParameterValue(String)

getUnsetParameters

public java.util.List<java.lang.String> getUnsetParameters()
Returns a list containing all parameters to which no value has been assigned

Specified by:
getUnsetParameters in interface QueryBuilder
Returns:
A list of all unset parameters
See Also:
QueryBuilder.getUnsetParameters()

getRawTemplate

public java.lang.String getRawTemplate()
Returns the query template associated with this query builder

Specified by:
getRawTemplate in interface QueryBuilder
Returns:
The query template
See Also:
QueryBuilder.getRawTemplate()

hasParameter

public boolean hasParameter(java.lang.String name)
Determines if a parameter is contained in the parameter set of the query builder

Specified by:
hasParameter in interface QueryBuilder
Parameters:
name - The qualified name of the parameter to be checked
Returns:
true if the parameter is present in the parameter set, false otherwise
See Also:
QueryBuilder.hasParameter(String)

setParameter

public BasicQueryBuilder setParameter(java.lang.String name,
                                      java.lang.String value)
                               throws NonExistentParameterException,
                                      java.lang.Exception
Assigns a string value to a parameter of the query builder

Specified by:
setParameter in interface QueryBuilder
Parameters:
name - The qualified name of the parameter
value - The value to be assigned to the parameter
Returns:
The query builder with the parameter value assigned to the parameter
Throws:
NonExistentParameterException - If the parameter is not contained in the parameter set of the query builder
java.lang.Exception - In case of other error
See Also:
QueryBuilder.setParameter(String, String)

setParameter

public BasicQueryBuilder setParameter(java.lang.String name,
                                      java.lang.Integer value)
                               throws NonExistentParameterException
Assigns an integral value to a parameter of the query builder

Specified by:
setParameter in interface QueryBuilder
Parameters:
name - The qualified name of the parameter
value - The value to be assigned to the parameter
Returns:
The query builder with the parameter value assigned to the parameter
Throws:
NonExistentParameterException - If the parameter is not contained in the parameter set of the query builder
See Also:
QueryBuilder.setParameter(String, Integer)

setParameters

public BasicQueryBuilder setParameters(java.util.List<java.lang.String> names,
                                       java.util.List<java.lang.Object> values)
                                throws NonExistentParameterException,
                                       java.lang.Exception
Assigns to each parameter contained in the list of the first argument the respective value contained in the list of the secord argument

Specified by:
setParameters in interface QueryBuilder
Parameters:
names - A list of parameter qualified names
values - A list of parameter values to be assigned to the respective parameter
Returns:
The query builder with the values assigned to the parameters
Throws:
NonExistentParameterException - If a parameter of the list is not contained in the parameter of the query builder
java.lang.Exception - In case of other error
See Also:
QueryBuilder.setParameters(List, List)

isParameterSet

public boolean isParameterSet(java.lang.String name)
Determines if a parameter has an assigned value. More specifically, true is returned if and only if the parameter is present and its value is not equal to null and not equal to the empty string.

Specified by:
isParameterSet in interface QueryBuilder
Parameters:
name - The qualified name of the parameter
Returns:
true if the value of the parameter is set, false otherwise
See Also:
QueryBuilder.isParameterSet(String)

isQueryComplete

public boolean isQueryComplete()
Determines whether the query is complete and therefore ready to be issued, i.e. there are no unset required parameters

Specified by:
isQueryComplete in interface QueryBuilder
Returns:
true if the query is complete, false otherwise
See Also:
QueryBuilder.isQueryComplete()

getQuery

public java.lang.String getQuery()
                          throws IncompleteQueryException,
                                 MalformedQueryException,
                                 java.lang.Exception
Retrieves the search query corresponding to the current state of the query builder

Specified by:
getQuery in interface QueryBuilder
Returns:
The search query
Throws:
IncompleteQueryException - If the query is not complete, i.e. there still exist unset required parameters
MalformedQueryException - If the query is malformed, e.g. if a parameter value is not of the correct form
java.lang.Exception - In case of other error
See Also:
QueryBuilder.getQuery()

setParameters

public QueryBuilder setParameters(QueryElement queryEl)
                           throws NonExistentParameterException,
                                  java.lang.Exception
Sets all parameters of the query builder that are also contained in the QueryElement provided with the values contained in the QueryElement

Specified by:
setParameters in interface QueryBuilder
Parameters:
queryEl - The query element which will be used to assign values to the parameters of the query builder
Returns:
The query builder with the QueryElement's values assigned
Throws:
java.lang.Exception - In case of error
NonExistentParameterException
See Also:
QueryBuilder.setParameters(QueryElement)

getStartIndexDef

public java.lang.Integer getStartIndexDef()
Returns the default value of the StartIndex OpenSearch parameter associated with this query builder

Specified by:
getStartIndexDef in interface QueryBuilder
Returns:
The default value of the StartIndex parameter
See Also:
QueryBuilder.getStartIndexDef()

getStartPageDef

public java.lang.Integer getStartPageDef()
Returns the default value of the StartPage OpenSearch parameter associated with this query builder

Specified by:
getStartPageDef in interface QueryBuilder
Returns:
The default value of the StartPage parameter
See Also:
QueryBuilder.getStartPageDef()

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Throws:
java.lang.Exception