2 * Copyright 2007, 2008, 2009 Electronic Business Systems Ltd.
4 * This file is part of GSS.
6 * GSS is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * GSS is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GSS. If not, see <http://www.gnu.org/licenses/>.
19 package gr.ebs.gss.server.ejb;
21 import gr.ebs.gss.client.exceptions.ObjectNotFoundException;
22 import gr.ebs.gss.server.domain.FileBody;
23 import gr.ebs.gss.server.domain.FileHeader;
24 import gr.ebs.gss.server.domain.FileUploadStatus;
25 import gr.ebs.gss.server.domain.Folder;
26 import gr.ebs.gss.server.domain.Group;
27 import gr.ebs.gss.server.domain.Nonce;
28 import gr.ebs.gss.server.domain.User;
30 import java.util.List;
33 import javax.ejb.Local;
36 * This class serves as a facade in front of the persistence library so client
37 * classes can be independent of the persistence implementation.
42 public interface GSSDAO {
45 * Creates the given object in the persistent storage.
47 * @param obj The object to be saved or updated
49 public void create(Object obj);
52 * Updates by re-attaching the given object to the persistence context.
54 * @param obj The object to be updated
56 public void update(Object obj);
59 * Refreshes an object by re-attaching it to the persistence context.
61 * @param obj the supplied object
63 public void refresh(Object obj);
66 * Deletes the specified entity from the persistent storage.
68 * @param entity the object to be deleted
70 public void delete(Object entity);
73 * Returns an Entity of the specified class with the specified id
75 * @param <T> The type of the entity
76 * @param _class the Class of the entity
77 * @param _id the id of the entity
78 * @return the Object found
79 * @throws ObjectNotFoundException if the Object was not found
81 public <T> T getEntityById(Class<T> _class, Object _id) throws ObjectNotFoundException;
84 * Returns the list of Groups that belong to a particular User.
86 * @param userId the ID of the specified User
87 * @return a List of Group objects
88 * @throws ObjectNotFoundException
90 public List<Group> getGroups(Long userId) throws ObjectNotFoundException;
93 * Retrieves the root folder for the specified user. The caller must ensure
94 * that the userId exists.
98 * @throws ObjectNotFoundException if no Folder was found
100 public Folder getRootFolder(Long userId) throws gr.ebs.gss.client.exceptions.ObjectNotFoundException;
103 * Retrieves the user for the requested username.
105 * @param username the username specified
106 * @return the user object
107 * @throws ObjectNotFoundException if no user was found
109 public User getUser(final String username) throws ObjectNotFoundException;
112 * Returns a list of files contained in the folder specified by its id, CAUTION: it does not return files marked as deleted
115 * @param ignoreDeleted
116 * @return List<FileHeader>
117 * @throws ObjectNotFoundException
119 @SuppressWarnings("unchecked")
120 public List<FileHeader> getFiles(Long folderId, boolean ignoreDeleted) throws ObjectNotFoundException;
123 * Returns a list of deleted files of user specified by userId
126 * @return List<FileHeader>
127 * @throws ObjectNotFoundException
129 @SuppressWarnings("unchecked")
130 public List<FileHeader> getDeletedFiles(Long userId) throws ObjectNotFoundException;
133 * Returns a list of deleted root folders of user specified by userId
136 * @return List<Folder>
137 * @throws ObjectNotFoundException
139 @SuppressWarnings("unchecked")
140 public List<Folder> getDeletedRootFolders(Long userId) throws ObjectNotFoundException;
143 * Returns a list of users for the specified group
147 * @throws ObjectNotFoundException
149 public List<User> getUsers(Long groupId) throws ObjectNotFoundException;
152 * Checks if a folder or file with the specified name exists under the
158 * @throws ObjectNotFoundException
159 * @throws ObjectNotFoundException
161 public boolean existsFolderOrFile(Long parentId, String name) throws ObjectNotFoundException;
164 * Checks if a folder with the specified name exists for the specified user.
166 * @param userId the owner of the group
167 * @param name the name of the group
168 * @return true if a group with the same name exists
169 * @throws ObjectNotFoundException
171 public boolean existsGroup(Long userId, String name) throws ObjectNotFoundException;
174 * Retrieves all tags defined by the specified user
177 * @return Set<String> A set of string tags
178 * @throws ObjectNotFoundException if the user was null
180 public Set<String> getUserTags(final Long userId) throws ObjectNotFoundException;
183 * Flushes the persistence context
188 * Retrieve the file with the supplied name that is contained
189 * in a folder with the specified ID.
191 * @param folderId the ID of the parent folder
192 * @param name the name of the file
193 * @return the file found
194 * @throws ObjectNotFoundException if the file or parent folder was not found,
195 * with the exception message mentioning the precise problem
197 public FileHeader getFile(Long folderId, String name) throws ObjectNotFoundException;
200 * Retrieve the folder with the supplied name that is contained
201 * in a folder with the specified ID.
203 * @param parentId the ID of the parent folder
204 * @param name the name of the folder
205 * @return the folder found
206 * @throws ObjectNotFoundException if the folder or parent was not found,
207 * with the exception message mentioning the precise problem
209 public Folder getFolder(Long parentId, String name) throws ObjectNotFoundException;
212 * Search the system for a user with the specified username.
213 * If no such user is found, the method returns null.
215 * @param username the username to search for
216 * @return the User object with the specified username
218 public User findUser(String username);
221 * Search the system for a user with the specified email address.
222 * If no such user is found, the method returns null.
224 public User findUserByEmail(String email);
227 * Returns a list of users matching specified username
229 * @param username the email of the User
232 public List<User> getUsersByUserNameLike(String username);
235 * Returns a list of All Shared root folders of a user.
237 * @param userId the ID of the User
238 * @return the list of shared root folders
239 * @throws ObjectNotFoundException if the user cannot be found
241 public List<Folder> getSharedRootFolders(Long userId) throws ObjectNotFoundException;
244 * Returns a list of all shared files of a user, not contained in a shared folder.
246 * @param userId the ID of the User
247 * @return the list of shared files
248 * @throws ObjectNotFoundException if the user cannot be found
250 public List<FileHeader> getSharedFilesNotInSharedFolders(Long userId) throws ObjectNotFoundException;
253 * Returns a list of all shared files of a user.
255 * @param userId the ID of the User
256 * @return the list of shared files
257 * @throws ObjectNotFoundException if the user cannot be found
259 public List<FileHeader> getSharedFiles(Long userId) throws ObjectNotFoundException;
262 * Returns a list of all shared folders of a user.
264 * @param userId the ID of the User
265 * @return the list of shared folders
266 * @throws ObjectNotFoundException if the user cannot be found
268 public List<Folder> getSharedFolders(Long userId) throws ObjectNotFoundException;
271 * Returns a list of folders of user with permissions for specified group
273 * @param userId the ID of the User
274 * @return the list of shared root folders
276 * @throws ObjectNotFoundException if the user cannot be found
278 public List<Folder> getFoldersPermittedForGroup(Long userId, Long groupId) throws ObjectNotFoundException;
281 * Returns a list of users sharing files to specified user
283 * @param userId the ID of the User
284 * @return the list of users sharing files to selected user
285 * @throws ObjectNotFoundException if the user cannot be found
287 public List<User> getUsersSharingFoldersForUser(Long userId) throws ObjectNotFoundException;
290 * Returns a list of users sharing files to specified user
292 * @param userId the ID of the User
293 * @return the list of users sharing files to selected user
294 * @throws ObjectNotFoundException if the user cannot be found
296 public List<User> getUsersSharingFilesForUser(Long userId) throws ObjectNotFoundException;
299 * Returns a list of All Shared root folders of a user that calling user has permissions to read them at least.
301 * @param userId the ID of the User
302 * @param callingUserId
303 * @return the list of shared root folders
304 * @throws ObjectNotFoundException if the user cannot be found
306 public List<Folder> getSharedRootFolders(Long userId, Long callingUserId) throws ObjectNotFoundException;
309 * Returns a list of All Shared files of a user not contained in a shared folder that calling user has permissions.
311 * @param userId the ID of the User
312 * @param callingUserId
313 * @return the list of shared files
314 * @throws ObjectNotFoundException if the user cannot be found
316 public List<FileHeader> getSharedFiles(Long userId, Long callingUserId) throws ObjectNotFoundException;
322 * @return list of files that match query
323 * @throws ObjectNotFoundException
325 public List<FileHeader> searchFiles(Long userId, String query) throws ObjectNotFoundException;
328 * Find the nonce object for the specified encoded nonce, that should be
329 * associated with the specified user.
331 * @param nonce the issued nonce in Base64 encoding
332 * @param userId the ID of the user for whom this nonce should have been issued
333 * @return the retrieved nonce object
334 * @throws ObjectNotFoundException if the nonce or user were not found
336 public Nonce getNonce(String nonce, Long userId) throws ObjectNotFoundException;
339 * Loads the file for indexing. That means the file is loaded with the lazy fields needed for inedexing, initialized.
340 * For now only the tags need to be initialized
343 * @return the {@link FileHeader} with initialized tags
344 * @throws ObjectNotFoundException when a file with the specified id does not exist
346 public FileHeader getFileForIndexing(Long id) throws ObjectNotFoundException;
349 * Calculates total file size of user.
351 * @param userId the ID of the user
352 * @return the aggregate size of all the user's files
354 public Long getFileSize(Long userId);
357 * Calculates total file count of user.
359 * @param userId the ID of the user
360 * @return the total number of files in the user's namespace
362 public Long getFileCount(Long userId);
365 * This method returns all file ids for rebuilding the search index
367 * @return a list of Long file ids
369 public List<Long> getAllFileIds();
371 public FileUploadStatus getFileUploadStatus(Long userId, String fileName);
374 * Fetch the file body with the specified version number.
376 * @param fileId the ID of the file header
377 * @param version the version number
378 * @return the file body
379 * @throws ObjectNotFoundException if the file body was not found
381 public FileBody getFileVersion(Long fileId, int version) throws ObjectNotFoundException;