Class JcrQueryDao
- java.lang.Object
-
- org.apache.avalon.framework.logger.AbstractLogEnabled
-
- org.ametys.plugins.externaldata.data.jcr.JcrQueryDao
-
- All Implemented Interfaces:
QueryDao,Component,LogEnabled,Serviceable
public class JcrQueryDao extends AbstractLogEnabled implements QueryDao, Serviceable, Component
JCR implementation of the Query DAO. This class manages DataSource and Query objects, storing them in the JCR repository.
-
-
Field Summary
Fields Modifier and Type Field Description protected CurrentUserProvider_currentUserProviderThe current user providerprotected DataSourceFactoryExtensionPoint_dataSourceFactoryEPThe Data Source factory extension point.protected ObservationManager_observationManagerThe observation managerprotected Repository_repositoryThe JCR repository.protected SiteManager_siteManagerThe Site manager.static StringDATASOURCES_NODEData sources node name.static StringPLUGIN_NODEPlugin root node name.static StringPLUGINS_NODEPlugins root node name.static StringPROPERTY_CONF_PREFIXConfiguration properties prefix.static StringPROPERTY_DATASOURCE"Type" property name.static StringPROPERTY_DESCRIPTION"Description" property name.static StringPROPERTY_NAME"Name" property name.static StringPROPERTY_TYPE"Type" property name.static StringQUERIES_NODEQueries node name.static StringQUERY_PROPERTY_PARAMETERSQuery "parameters" property name.static StringQUERY_PROPERTY_QUERYSTRINGQuery "query string" property name.static StringQUERY_PROPERTY_RESULTTYPEQuery "resultType" property name.static StringROOT_REPOJCR relative path to root node.
-
Constructor Summary
Constructors Constructor Description JcrQueryDao()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Query_extractQuery(Node node)Create a data source from a node.protected void_fillQueryNode(Query query, Node node)Store the query properties into the JCR node.protected Map<String,String>_getAdditionalConf(Node node)Get additional configuration from properties.protected Collection<String>_getMultipleProperty(Node node, String propertyName)Get the values of a string array property.protected String_getNotExistingNodeName(Node container, String baseName)Get a name for a node which doesn't already exist in this node.protected Node_getPluginNode(String siteName)Get the plugin root node in a site storage space.protected Node_getQueriesNode(String siteName)Get the queries root node.protected Query.ResultType_getResultType(String value, Query.ResultType defaultValue)Get a a result typeprotected Query.ResultType_getResultType(Node node, Query.ResultType defaultValue)Get a single property value.protected String_getSingleProperty(Node node, String propertyName, String defaultValue)Get a single property value.private boolean_matchQuery(Query query, String dataSourceId, DataSourceClientInteraction.DataSourceType dsType, Query.ResultType resultType)Map<String,String>addQuery(String siteName, Map<String,Object> parameters)Adds a query.StringaddQuery(String siteName, Query query)Add a query and set its id.Map<String,String>deleteQuery(String siteName, String id)Deletes a query.Map<String,Query>getDataSourceQueries(String siteName, String dataSourceId)Get all the queries of a site.Map<String,Query>getDataSourceQueries(String siteName, String dataSourceId, DataSourceClientInteraction.DataSourceType dataSourceType, Query.ResultType resultType)Get all the queries of a site of a specific result typeMap<String,Query>getDataSourceQueries(String siteName, String dataSourceId, Query.ResultType resultType)Get all the queries of a site of a specific result typeMap<String,Query>getQueries(String siteName)Get all the queries of a site.Map<String,Query>getQueries(String siteName, DataSourceClientInteraction.DataSourceType type)Get all the queries of a site.QuerygetQuery(String siteName, String id)Get a query from its id.Map<String,Object>getQueryProperties(String id, String siteName)Get the query properties.voidremoveQuery(String siteName, String id)Remove a query.voidservice(ServiceManager serviceManager)Map<String,String>updateQuery(String siteName, Map<String,Object> parameters)Updates a query.voidupdateQuery(String siteName, Query query)Update a query.-
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
-
-
-
-
Field Detail
-
ROOT_REPO
public static final String ROOT_REPO
JCR relative path to root node.- See Also:
- Constant Field Values
-
PLUGINS_NODE
public static final String PLUGINS_NODE
Plugins root node name.- See Also:
- Constant Field Values
-
PLUGIN_NODE
public static final String PLUGIN_NODE
Plugin root node name.- See Also:
- Constant Field Values
-
DATASOURCES_NODE
public static final String DATASOURCES_NODE
Data sources node name.- See Also:
- Constant Field Values
-
QUERIES_NODE
public static final String QUERIES_NODE
Queries node name.- See Also:
- Constant Field Values
-
PROPERTY_NAME
public static final String PROPERTY_NAME
"Name" property name.- See Also:
- Constant Field Values
-
PROPERTY_DESCRIPTION
public static final String PROPERTY_DESCRIPTION
"Description" property name.- See Also:
- Constant Field Values
-
PROPERTY_TYPE
public static final String PROPERTY_TYPE
"Type" property name.- See Also:
- Constant Field Values
-
PROPERTY_DATASOURCE
public static final String PROPERTY_DATASOURCE
"Type" property name.- See Also:
- Constant Field Values
-
PROPERTY_CONF_PREFIX
public static final String PROPERTY_CONF_PREFIX
Configuration properties prefix.- See Also:
- Constant Field Values
-
QUERY_PROPERTY_QUERYSTRING
public static final String QUERY_PROPERTY_QUERYSTRING
Query "query string" property name.- See Also:
- Constant Field Values
-
QUERY_PROPERTY_PARAMETERS
public static final String QUERY_PROPERTY_PARAMETERS
Query "parameters" property name.- See Also:
- Constant Field Values
-
QUERY_PROPERTY_RESULTTYPE
public static final String QUERY_PROPERTY_RESULTTYPE
Query "resultType" property name.- See Also:
- Constant Field Values
-
_dataSourceFactoryEP
protected DataSourceFactoryExtensionPoint _dataSourceFactoryEP
The Data Source factory extension point.
-
_repository
protected Repository _repository
The JCR repository.
-
_siteManager
protected SiteManager _siteManager
The Site manager.
-
_currentUserProvider
protected CurrentUserProvider _currentUserProvider
The current user provider
-
_observationManager
protected ObservationManager _observationManager
The observation manager
-
-
Constructor Detail
-
JcrQueryDao
public JcrQueryDao()
-
-
Method Detail
-
service
public void service(ServiceManager serviceManager) throws ServiceException
- Specified by:
servicein interfaceServiceable- Throws:
ServiceException
-
getQueries
public Map<String,Query> getQueries(String siteName) throws DataInclusionException
Description copied from interface:QueryDaoGet all the queries of a site.- Specified by:
getQueriesin interfaceQueryDao- Parameters:
siteName- the site name.- Returns:
- the queries as a Map.
- Throws:
DataInclusionException- if an error occurs while manipulating the data sources
-
getQueries
public Map<String,Query> getQueries(String siteName, DataSourceClientInteraction.DataSourceType type) throws DataInclusionException
Description copied from interface:QueryDaoGet all the queries of a site.- Specified by:
getQueriesin interfaceQueryDao- Parameters:
siteName- the site name.type- the query type- Returns:
- the queries as a Map.
- Throws:
DataInclusionException- if an error occurs while manipulating the data sources
-
getDataSourceQueries
public Map<String,Query> getDataSourceQueries(String siteName, String dataSourceId) throws DataInclusionException
Description copied from interface:QueryDaoGet all the queries of a site.- Specified by:
getDataSourceQueriesin interfaceQueryDao- Parameters:
siteName- the site name.dataSourceId- the id of the data source- Returns:
- the queries as a Map.
- Throws:
DataInclusionException- if an error occurs while manipulating the data sources
-
getDataSourceQueries
public Map<String,Query> getDataSourceQueries(String siteName, String dataSourceId, Query.ResultType resultType) throws DataInclusionException
Description copied from interface:QueryDaoGet all the queries of a site of a specific result type- Specified by:
getDataSourceQueriesin interfaceQueryDao- Parameters:
siteName- the site name.dataSourceId- the id of the data sourceresultType- Filter on result type- Returns:
- the queries as a Map.
- Throws:
DataInclusionException- if an error occurs while manipulating the data sources
-
getDataSourceQueries
public Map<String,Query> getDataSourceQueries(String siteName, String dataSourceId, DataSourceClientInteraction.DataSourceType dataSourceType, Query.ResultType resultType) throws DataInclusionException
Description copied from interface:QueryDaoGet all the queries of a site of a specific result type- Specified by:
getDataSourceQueriesin interfaceQueryDao- Parameters:
siteName- the site name.dataSourceId- the id of the data sourcedataSourceType- the query typeresultType- Filter on result type- Returns:
- the queries as a Map.
- Throws:
DataInclusionException- if an error occurs while manipulating the data sources
-
_matchQuery
private boolean _matchQuery(Query query, String dataSourceId, DataSourceClientInteraction.DataSourceType dsType, Query.ResultType resultType)
-
getQuery
public Query getQuery(String siteName, String id) throws DataInclusionException
Description copied from interface:QueryDaoGet a query from its id.- Specified by:
getQueryin interfaceQueryDao- Parameters:
siteName- the site name.id- the query id.- Returns:
- the Query.
- Throws:
DataInclusionException- if an error occurs while manipulating the data sources
-
getQueryProperties
public Map<String,Object> getQueryProperties(String id, String siteName) throws DataInclusionException
Description copied from interface:QueryDaoGet the query properties.- Specified by:
getQueryPropertiesin interfaceQueryDao- Parameters:
id- The query idsiteName- The site name- Returns:
- The properties of the query in a result map.
- Throws:
DataInclusionException- if an error occurs while manipulating the data sources
-
addQuery
public Map<String,String> addQuery(String siteName, Map<String,Object> parameters) throws Exception
Description copied from interface:QueryDaoAdds a query.
-
addQuery
public String addQuery(String siteName, Query query) throws DataInclusionException
Description copied from interface:QueryDaoAdd a query and set its id.- Specified by:
addQueryin interfaceQueryDao- Parameters:
siteName- the site namequery- the query to add. The id member doesn't need to be specified.- Returns:
- id of the newly created data source.
- Throws:
DataInclusionException- if an error occurs while manipulating the data sources
-
updateQuery
public Map<String,String> updateQuery(String siteName, Map<String,Object> parameters) throws Exception
Description copied from interface:QueryDaoUpdates a query.- Specified by:
updateQueryin interfaceQueryDao- Parameters:
siteName- The site nameparameters- The params needed to update the query- Returns:
- The id of the updated query and its type, or an error
- Throws:
Exception- if an error occurs when updating the query
-
updateQuery
public void updateQuery(String siteName, Query query) throws DataInclusionException
Description copied from interface:QueryDaoUpdate a query. Update the query specified by its id member with all the data.- Specified by:
updateQueryin interfaceQueryDao- Parameters:
siteName- the site namequery- the query to update.- Throws:
DataInclusionException- if an error occurs while manipulating the data sources
-
deleteQuery
public Map<String,String> deleteQuery(String siteName, String id) throws Exception
Description copied from interface:QueryDaoDeletes a query.- Specified by:
deleteQueryin interfaceQueryDao- Parameters:
siteName- the site nameid- The id of the query to delete- Returns:
- The id of the deleted query, or an error
- Throws:
Exception- if an error occurs when deleting the query
-
removeQuery
public void removeQuery(String siteName, String id) throws DataInclusionException
Description copied from interface:QueryDaoRemove a query.- Specified by:
removeQueryin interfaceQueryDao- Parameters:
siteName- the site nameid- the query id.- Throws:
DataInclusionException- if an error occurs while manipulating the data sources
-
_extractQuery
protected Query _extractQuery(Node node) throws RepositoryException, DataInclusionException
Create a data source from a node.- Parameters:
node- the data source node.- Returns:
- the data source.
- Throws:
RepositoryException- if an error occurs when exploring the repositoryDataInclusionException- if an error occurs while manipulating the data sources
-
_getSingleProperty
protected String _getSingleProperty(Node node, String propertyName, String defaultValue) throws RepositoryException
Get a single property value.- Parameters:
node- the JCR node.propertyName- the name of the property to get.defaultValue- the default value if the property does not exist.- Returns:
- the single property value.
- Throws:
RepositoryException- if a repository error occurs.
-
_getResultType
protected Query.ResultType _getResultType(String value, Query.ResultType defaultValue) throws RepositoryException
Get a a result type- Parameters:
value- the valuedefaultValue- the default result type- Returns:
- the result type for the value
- Throws:
RepositoryException- if an error occurs when exploring the repository
-
_getResultType
protected Query.ResultType _getResultType(Node node, Query.ResultType defaultValue) throws RepositoryException
Get a single property value.- Parameters:
node- the nodedefaultValue- the default result type- Returns:
- the result type for the value
- Throws:
RepositoryException- if an error occurs when exploring the repository
-
_getMultipleProperty
protected Collection<String> _getMultipleProperty(Node node, String propertyName) throws RepositoryException
Get the values of a string array property.- Parameters:
node- the node.propertyName- the name of the property to get.- Returns:
- the values.
- Throws:
RepositoryException- if a repository error occurs.
-
_getAdditionalConf
protected Map<String,String> _getAdditionalConf(Node node) throws RepositoryException
Get additional configuration from properties.- Parameters:
node- the node- Returns:
- the additional configuration as a Map.
- Throws:
RepositoryException- if a repository error occurs.
-
_fillQueryNode
protected void _fillQueryNode(Query query, Node node) throws RepositoryException
Store the query properties into the JCR node.- Parameters:
query- the querysnode- the query node- Throws:
RepositoryException- if a repository error occurs.
-
_getNotExistingNodeName
protected String _getNotExistingNodeName(Node container, String baseName) throws RepositoryException
Get a name for a node which doesn't already exist in this node.- Parameters:
container- the container node.baseName- the base wanted node name.- Returns:
- the name, free to be taken.
- Throws:
RepositoryException- if a repository error occurs.
-
_getPluginNode
protected Node _getPluginNode(String siteName) throws RepositoryException
Get the plugin root node in a site storage space.- Parameters:
siteName- the site name.- Returns:
- the plugin root node.
- Throws:
RepositoryException- if a repository error occurs.
-
_getQueriesNode
protected Node _getQueriesNode(String siteName) throws RepositoryException
Get the queries root node.- Parameters:
siteName- the name of the site- Returns:
- the queries root node.
- Throws:
RepositoryException- if a repository error occurs.
-
-