001/*
002 *  Copyright 2010 Anyware Services
003 *
004 *  Licensed under the Apache License, Version 2.0 (the "License");
005 *  you may not use this file except in compliance with the License.
006 *  You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 *  Unless required by applicable law or agreed to in writing, software
011 *  distributed under the License is distributed on an "AS IS" BASIS,
012 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *  See the License for the specific language governing permissions and
014 *  limitations under the License.
015 */
016package org.ametys.plugins.externaldata.data;
017
018import java.util.Map;
019
020import org.ametys.core.datasource.DataSourceClientInteraction.DataSourceType;
021import org.ametys.core.ui.Callable;
022import org.ametys.plugins.externaldata.data.Query.ResultType;
023
024/**
025 * Provider for connections and queries.
026 */
027public interface QueryDao
028{
029    
030    /** The avalon role name. */
031    public static final String ROLE = QueryDao.class.getName();
032    
033    /**
034     * Get all the queries of a site.
035     * @param siteName the site name.
036     * @return the queries as a Map.
037     * @throws DataInclusionException if an error occurs while manipulating the data sources
038     */
039    Map<String, Query> getQueries(String siteName) throws DataInclusionException;
040    
041    /**
042     * Get all the queries of a site.
043     * @param siteName the site name.
044     * @param type the query type
045     * @return the queries as a Map.
046     * @throws DataInclusionException if an error occurs while manipulating the data sources
047     */
048    Map<String, Query> getQueries(String siteName, DataSourceType type) throws DataInclusionException;
049    
050    /**
051     * Get all the queries of a site.
052     * @param siteName the site name.
053     * @param dataSourceId the id of the data source
054     * @return the queries as a Map.
055     * @throws DataInclusionException if an error occurs while manipulating the data sources
056     */
057    Map<String, Query> getDataSourceQueries(String siteName, String dataSourceId) throws DataInclusionException;
058    
059    /**
060     * Get all the queries of a site of a specific result type
061     * @param siteName the site name.
062     * @param dataSourceId the id of the data source
063     * @param resultType Filter on result type
064     * @return the queries as a Map.
065     * @throws DataInclusionException if an error occurs while manipulating the data sources
066     */
067    Map<String, Query> getDataSourceQueries(String siteName, String dataSourceId, ResultType resultType) throws DataInclusionException;
068    
069    /**
070     * Get all the queries of a site of a specific result type
071     * @param siteName the site name.
072     * @param dataSourceId the id of the data source
073     * @param dataSourceType the query type
074     * @param resultType Filter on result type
075     * @return the queries as a Map.
076     * @throws DataInclusionException if an error occurs while manipulating the data sources
077     */
078    Map<String, Query> getDataSourceQueries(String siteName, String dataSourceId, DataSourceType dataSourceType, ResultType resultType) throws DataInclusionException;
079    
080    /**
081     * Get a query from its id.
082     * @param siteName the site name.
083     * @param id the query id.
084     * @return the Query.
085     * @throws DataInclusionException if an error occurs while manipulating the data sources
086     */
087    Query getQuery(String siteName, String id) throws DataInclusionException;
088    
089    /**
090     * Get the query properties.
091     * @param id The query id
092     * @param siteName The site name
093     * @return The properties of the query in a result map.
094     * @throws DataInclusionException if an error occurs while manipulating the data sources 
095     */
096    @Callable
097    Map<String, Object> getQueryProperties(String id, String siteName) throws DataInclusionException;
098    
099    /**
100     * Adds a query.
101     * @param siteName The site name
102     * @param parameters The params needed to create the query
103     * @return The id of the created query,its parent id and its type, or an error
104     * @throws Exception if an error occurs when adding the query
105     */
106    @Callable
107    Map<String, String> addQuery(String siteName, Map<String, Object> parameters) throws Exception;
108    
109    /**
110     * Updates a query.
111     * @param siteName The site name
112     * @param parameters The params needed to update the query
113     * @return The id of the updated query and its type, or an error
114     * @throws Exception if an error occurs when updating the query
115     */
116    @Callable
117    Map<String, String> updateQuery(String siteName, Map<String, Object> parameters) throws Exception;
118    
119    /**
120     * Deletes a query.
121     * @param siteName the site name
122     * @param id The id of the query to delete
123     * @return The id of the deleted query, or an error
124     * @throws Exception if an error occurs when deleting the query
125     */
126    @Callable
127    Map<String, String> deleteQuery(String siteName, String id) throws Exception;
128    
129    /**
130     * Add a query and set its id.
131     * @param siteName the site name
132     * @param query the query to add. The id member doesn't need to be specified. 
133     * @return id of the newly created data source. 
134     * @throws DataInclusionException if an error occurs while manipulating the data sources
135     */
136    String addQuery(String siteName, Query query) throws DataInclusionException;
137    
138    /**
139     * Update a query. Update the query specified by its id member with all the data.
140     * @param siteName the site name
141     * @param query the query to update. 
142     * @throws DataInclusionException if an error occurs while manipulating the data sources
143     */
144    void updateQuery(String siteName, Query query) throws DataInclusionException;
145    
146    /**
147     * Remove a query.
148     * @param siteName the site name
149     * @param id the query id.
150     * @throws DataInclusionException if an error occurs while manipulating the data sources 
151     */
152    void removeQuery(String siteName, String id) throws DataInclusionException;
153    
154}