View Javadoc
1   /*
2    * Copyright (C) 2003-2007 eXo Platform SAS.
3    *
4    * This program is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU Affero General Public License
6    * as published by the Free Software Foundation; either version 3
7    * of the License, or (at your option) any later version.
8    *
9    * This program is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU General Public License for more details.
13   *
14   * You should have received a copy of the GNU General Public License
15   * along with this program; if not, see<http://www.gnu.org/licenses/>.
16   */
17  package org.exoplatform.services.cms.queries;
18  
19  import java.util.List;
20  import java.util.Set;
21  
22  import javax.jcr.Node;
23  import javax.jcr.query.Query;
24  import javax.jcr.query.QueryResult;
25  
26  import org.exoplatform.services.jcr.ext.common.SessionProvider;
27  
28  public interface QueryService {
29  
30    public static final String CACHE_NAME = "ecms.query";
31    
32    /**
33     * Get the relative path
34     *
35     * @return
36     */
37    public String getRelativePath();
38    
39    /**
40     * Get queries by giving the following params : userName, repository, provider
41     *
42     * @param userName String Can be <code>null</code>
43     * @param provider SessionProvider
44     * @return queries
45     * @see Query
46     * @see SessionProvider
47     * @throws Exception
48     */
49    public List<Query> getQueries(String userName, SessionProvider provider) throws Exception;
50    
51    /**
52     * Execute query by giving the following params : queryPath, workspace,
53     * provider, userId
54     *
55     * @param queryPath String The path of query
56     * @param workspace String The name of workspace
57     * @param provider SessionProvider
58     * @param userId String The id of current user
59     * @return queries QueryResult
60     * @see QueryResult
61     * @see SessionProvider
62     * @throws Exception
63     */
64    public QueryResult execute(String queryPath,
65                               String workspace,
66                               SessionProvider provider,
67                               String userId) throws Exception;
68    
69    
70    /**
71     * Add new query by giving the following params : queryName, statement,
72     * language, userName
73     *
74     * @param queryName String The name of query
75     * @param statement String The statement query
76     * @param language String The language is requested
77     * @param userName String Can be <code>null</code>
78     * @throws Exception
79     */
80    public void addQuery(String queryName, String statement, String language, String userName) throws Exception;
81    
82    /**
83     * Remove query by giving the following params : queryPath, userName
84     *
85     * @param queryPath String The path of query
86     * @param userName String Can be <code>null</code>
87     * @throws Exception
88     */
89    public void removeQuery(String queryPath, String userName) throws Exception;  
90    
91    /**
92     * Add new shared query by giving the following params: queryName, statement,
93     * language, permissions, cachedResult
94     * 
95     * @param queryName String The name of query
96     * @param statement String The statement query
97     * @param language String The language is requested
98     * @param permissions String[]
99     * @param cachedResult boolean Choosen for caching results
100    * @throws Exception
101    */
102   public void addSharedQuery(String queryName,
103                              String statement,
104                              String language,
105                              String[] permissions,
106                              boolean cachedResult) throws Exception;
107   
108   /**
109    * Add new shared query by giving the following params: queryName, statement,
110    * language, permissions, cachedResult, provider
111    * 
112    * @param queryName String The name of query
113    * @param statement String The statement query
114    * @param language String The language is requested
115    * @param permissions String[]
116    * @param cachedResult boolean Choosen for caching results
117    * @param provider Session provider
118    * @throws Exception
119    */
120   public void addSharedQuery(String queryName,
121                              String statement,
122                              String language,
123                              String[] permissions,
124                              boolean cachedResult,
125                              SessionProvider provider) throws Exception;
126 
127   
128   /**
129    * Get shared queries by giving the following params : queryName, provider
130    *
131    * @param queryName the name of query 
132    * @param provider SessionProvider
133    * @return sharedQueries
134    * @see Node
135    * @see SessionProvider
136    * @throws Exception
137    */
138   public Node getSharedQuery(String queryName, SessionProvider provider) throws Exception;
139   
140   /**
141    * Remove share query by giving the following params : queryName
142    *
143    * @param queryName String The name of query  
144    * @param provider SessionProvider
145    * @throws Exception
146    */
147   public void removeSharedQuery(String queryName, SessionProvider provider) throws Exception;  
148 
149   /**
150    * Get shared queries by giving the following params : provider
151    *
152    * @param provider SessionProvider
153    * @return sharedQueries
154    * @see Node
155    * @see SessionProvider
156    * @throws Exception
157    */
158   public List<Node> getSharedQueries(SessionProvider provider) throws Exception;
159   
160   /**
161    * Get query with path by giving the following params : queryPath, userName,
162    * provider
163    * 
164    * @param queryPath String The path of query
165    * @param userName String The name of current user
166    * @param provider SessionProvider
167    * @return query Query
168    * @see Node
169    * @see Query
170    * @see SessionProvider
171    * @throws Exception
172    */
173   public Query getQueryByPath(String queryPath, String userName, SessionProvider provider) throws Exception;
174 
175   
176   /**
177    * Get shared queries by giving the following params : userId, provider
178    *
179    * @param userId String The id of current user
180    * @param provider SessionProvider
181    * @return sharedQueries
182    * @see Node
183    * @see SessionProvider
184    * @throws Exception
185    */
186   public List<Node> getSharedQueries(String userId, SessionProvider provider) throws Exception;  
187   
188   /**
189    * Get shared queries by giving the following params : queryType, userId,
190    * provider
191    *
192    * @param queryType String The type of query
193    * @param userId String The id of current user
194    * @param provider SessionProvider
195    * @return sharedQueries
196    * @see Node
197    * @see SessionProvider
198    * @throws Exception
199    */
200   public List<Node> getSharedQueries(String queryType,
201                                      String userId,
202                                      SessionProvider provider) throws Exception;
203 
204   /**
205    * Init all query plugin in the current repository
206    * @see org.exoplatform.services.cms.queries.impl.QueryPlugin
207    * @throws Exception
208    */
209   public void init() throws Exception;
210 
211   /**
212    * Returns Query object by giving the following params : queryPath, workspace,
213    * provider, userId
214    *
215    * @param queryPath String The path of query
216    * @param workspace String The name of workspace
217    * @param provider SessionProvider
218    * @param userId String The id of current user
219    * @return queries QueryResult
220    * @see QueryResult
221    * @see SessionProvider
222    * @throws Exception
223    */  
224   public Query getQuery(String queryPath,
225                          String workspace,
226                          SessionProvider provider,
227                          String userId) throws Exception;
228   
229   /**
230    * gets all configured queries
231    * @return
232    */
233   public Set<String> getAllConfiguredQueries();
234 
235 }