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.taxonomy;
18
19 import java.util.List;
20 import java.util.Map;
21
22 import javax.jcr.Node;
23 import javax.jcr.RepositoryException;
24
25 import org.exoplatform.container.component.ComponentPlugin;
26 import org.exoplatform.services.cms.taxonomy.impl.TaxonomyAlreadyExistsException;
27 import org.exoplatform.services.cms.taxonomy.impl.TaxonomyNodeAlreadyExistsException;
28 import org.exoplatform.services.cms.taxonomy.impl.TaxonomyPlugin;
29
30 /**
31 * Is used to work with taxonomies. In this service,
32 * there are many functions that enable you to add, find, or delete taxonomies from a node.
33 *
34 * @LevelAPI Experimental
35 */
36 public interface TaxonomyService {
37
38 /**
39 * Gets a taxonomy tree.
40 *
41 * @param taxonomyName Name of the taxonomy tree.
42 * @param system If "true", the system session is used.
43 * If "false", the user session is used.
44 * @return The taxonomy tree node.
45 * @throws RepositoryException if the taxonomy tree could not be found.
46 */
47 public Node getTaxonomyTree(String taxonomyName, boolean system)
48 throws RepositoryException;
49
50 /**
51 * Gets a taxonomy tree using the user session.
52 *
53 * @param taxonomyName Name of the taxonomy tree.
54 * @return The taxonomy tree node.
55 * @throws RepositoryException if the taxonomy tree could not be found.
56 */
57 public Node getTaxonomyTree(String taxonomyName) throws RepositoryException;
58
59 /**
60 * Gets all taxonomy trees.
61 *
62 * @param system If "true", the system session is used.
63 * If "false", the user session is used.
64 * @return The taxonomy tree nodes.
65 * @throws RepositoryException if the taxonomy trees could not be found.
66 */
67 public List<Node> getAllTaxonomyTrees(boolean system)
68 throws RepositoryException;
69
70 /**
71 * Gets all taxonomy trees using the user session.
72 *
73 * @return The taxonomy tree nodes.
74 * @throws RepositoryException if the taxonomies could not be found.
75 */
76 public List<Node> getAllTaxonomyTrees() throws RepositoryException;
77
78 /**
79 * Checks if a taxonomy tree with the given name has already been defined.
80 *
81 * @param taxonomyName Name of the taxonomy tree to be checked.
82 * @return "True" if the taxonomy tree exists. Otherwise, it returns "false".
83 * @throws RepositoryException if the taxonomy name could not be checked.
84 */
85 public boolean hasTaxonomyTree(String taxonomyName) throws RepositoryException;
86
87 /**
88 * Creates a new taxonomy tree.
89 *
90 * @param taxonomyTree The taxonomy tree to be created.
91 * @throws TaxonomyAlreadyExistsException if a taxonomy with the same name has
92 * already been defined.
93 * @throws RepositoryException if the taxonomy tree could not be defined.
94 */
95 public void addTaxonomyTree(Node taxonomyTree) throws RepositoryException,
96 TaxonomyAlreadyExistsException;
97
98 /**
99 * Updates a taxonomy tree.
100 *
101 * @param taxonomyName Name of the taxonomy.
102 * @param taxonomyTree The taxonomy tree to be updated.
103 * @throws RepositoryException if the taxonomy tree could not be updated.
104 */
105 public void updateTaxonomyTree(String taxonomyName, Node taxonomyTree) throws RepositoryException;
106
107 /**
108 * Removes a taxonomy tree.
109 *
110 * @param taxonomyName Name of the taxonomy to be removed.
111 * @throws RepositoryException if the taxonomy tree could not be removed.
112 */
113 public void removeTaxonomyTree(String taxonomyName) throws RepositoryException;
114
115 /**
116 * Adds a new taxonomy node at the given location.
117 *
118 * @param workspace Name of the workspace to which the taxonomy node is added.
119 * @param parentPath The place where the taxonomy node will be added.
120 * @param taxoNodeName Name of the taxonomy node.
121 * @param creator The user who created the taxonomy node.
122 * @throws TaxonomyNodeAlreadyExistsException if a taxonomy node with the same
123 * name has already been added.
124 * @throws RepositoryException if the taxonomy node could not be added.
125 */
126 public void addTaxonomyNode(String workspace,
127 String parentPath,
128 String taxoNodeName,
129 String creator) throws RepositoryException,
130 TaxonomyNodeAlreadyExistsException;
131
132 /**
133 * Removes a taxonomy node located at the given absolute path.
134 *
135 * @param workspace Name of the workspace from which the taxonomy node is removed.
136 * @param absPath The given absolute path.
137 * @throws RepositoryException if the taxonomy node could not be removed.
138 */
139 public void removeTaxonomyNode(String workspace, String absPath)
140 throws RepositoryException;
141
142 /**
143 * Copies or cuts the taxonomy node from source path to destination path.
144 * The parameter type indicates if the node is cut or copied.
145 *
146 * @param workspace Name of the workspace which contains the taxonomy node.
147 * @param srcPath Source path of the taxonomy node.
148 * @param destPath Destination path of the taxonomy node.
149 * @param type Type of moving: copy or cut.
150 * @throws RepositoryException if the taxonomy node could not be moved.
151 */
152 public void moveTaxonomyNode(String workspace, String srcPath, String destPath, String type) throws RepositoryException;
153
154 /**
155 * Checks if a category node exists in a given taxonomy by using the user session.
156 *
157 * @param node The category node to be checked.
158 * @param taxonomyName Name of the given taxonomy.
159 * @throws RepositoryException if the category cannot be checked.
160 */
161 public boolean hasCategories(Node node, String taxonomyName) throws RepositoryException;
162
163 /**
164 * Checks if a category node exists in a given taxonomy.
165 *
166 * @param node The category node to be checked.
167 * @param taxonomyName Name of the given taxonomy.
168 * @param system If "true", the system session is used. If "false", the user session is used.
169 * @return "True" if the category exists. Otherwise, it returns "false".
170 * @throws RepositoryException if the category cannot be checked.
171 */
172 public boolean hasCategories(Node node, String taxonomyName, boolean system) throws RepositoryException;
173
174 /**
175 * Gets all categories that contain a given node under a taxonomy tree.
176 *
177 * @param node The given node.
178 * @param taxonomyName The taxonomy tree where categories are got.
179 * @return The list of category nodes.
180 * @throws RepositoryException if the categories cannot be retrieved.
181 */
182 public List<Node> getCategories(Node node, String taxonomyName) throws RepositoryException;
183
184 /**
185 * Gets all categories that contain a given node under a taxonomy tree.
186 *
187 * @param node The given node.
188 * @param taxonomyName The taxonomy tree where categories are got.
189 * @param system If "true", the system session is used. If "false", the user session is used.
190 * @return The list of category nodes.
191 * @throws RepositoryException if the categories cannot be retrieved.
192 */
193 public List<Node> getCategories(Node node, String taxonomyName, boolean system) throws RepositoryException;
194
195 /**
196 * Gets all categories that contain a given node under all taxonomy trees.
197 *
198 * @param node The given node.
199 * @return The list of category nodes.
200 * @throws RepositoryException
201 */
202 public List<Node> getAllCategories(Node node) throws RepositoryException;
203
204 /**
205 * Gets all categories that contain a given node under all taxonomy trees.
206 *
207 * @param node The given node.
208 * @param system If "true", the system session is used. If "false", the user session is used.
209 * @return The list of category nodes.
210 * @throws RepositoryException
211 */
212 public List<Node> getAllCategories(Node node, boolean system) throws RepositoryException;
213
214 /**
215 * Removes a category from a given node.
216 *
217 * @param node The given node.
218 * @param taxonomyName The taxonomy tree that contains the removed category.
219 * @param categoryPath Path of the removed category.
220 * @throws RepositoryException if the category cannot be removed.
221 */
222 public void removeCategory(Node node, String taxonomyName, String categoryPath)
223 throws RepositoryException;
224
225 /**
226 * Removes a category from a given node.
227 *
228 * @param node The given node.
229 * @param taxonomyName The taxonomy tree that contains the removed category.
230 * @param categoryPath Path of the removed category.
231 * @param system If "true", the system session is used. If "false", the user session is used.
232 * @throws RepositoryException if the category cannot be removed.
233 */
234 public void removeCategory(Node node, String taxonomyName, String categoryPath, boolean system)
235 throws RepositoryException;
236
237 /**
238 * Adds categories to a given node.
239 *
240 * @param node The given node.
241 * @param taxonomyName The taxonomy tree that contains the added category.
242 * @param categoryPaths Paths of the added categories.
243 * @throws RepositoryException if the categories cannot be added.
244 */
245 public void addCategories(Node node, String taxonomyName, String[] categoryPaths)
246 throws RepositoryException;
247
248 /**
249 * Adds categories to a given node.
250 *
251 * @param node The given node.
252 * @param taxonomyName The taxonomy tree that contains the added category.
253 * @param categoryPaths Paths of the added categories.
254 * @param system If "true", the system session is used. If "false", the user session is used.
255 * @throws RepositoryException if the categories cannot be added.
256 */
257 public void addCategories(Node node, String taxonomyName, String[] categoryPaths, boolean system)
258 throws RepositoryException;
259
260 /**
261 * Adds a new category to a given node.
262 *
263 * @param node The given node.
264 * @param taxonomyName The taxonomy tree that contains the added category.
265 * @param categoryPath Path of the added category.
266 * @throws RepositoryException if the category cannot be added.
267 */
268 public void addCategory(Node node, String taxonomyName, String categoryPath)
269 throws RepositoryException;
270
271 /**
272 * Adds a new category to a given node.
273 *
274 * @param node The given node.
275 * @param taxonomyName The taxonomy tree that contains the added category.
276 * @param categoryPath Path of the added category.
277 * @param system If "true", the system session is used. If "false", the user session is used.
278 * @throws RepositoryException if the category cannot be added.
279 */
280 public void addCategory(Node node, String taxonomyName, String categoryPath, boolean system)
281 throws RepositoryException;
282
283 /**
284 * Gets default permissions of a taxonomy tree.
285 *
286 * @return Map that shows permissions of the taxonomy tree.
287 */
288 public Map<String, String[]> getTaxonomyTreeDefaultUserPermission();
289
290 /**
291 * Gets the limited length of a category name.
292 */
293 public String getCategoryNameLength();
294
295 /**
296 * Adds a new taxonomy plugin to the Taxonomy Service.
297 *
298 * @param plugin The plugin to be added.
299 */
300 public void addTaxonomyPlugin(ComponentPlugin plugin);
301
302 /**
303 * Initializes all taxonomy plugins that have been set in the configuration files.
304 *
305 * @see TaxonomyPlugin
306 * @throws Exception
307 */
308 public void init() throws Exception;
309 }