fff035a5874c2c3e2b6e46bf137112750937056f
[pithos] / gss / src / gr / ebs / gss / server / ejb / GSSDAO.java
1 /*
2  * Copyright 2007, 2008, 2009 Electronic Business Systems Ltd.
3  *
4  * This file is part of GSS.
5  *
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.
10  *
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.
15  *
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/>.
18  */
19 package gr.ebs.gss.server.ejb;
20
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;
29
30 import java.util.List;
31 import java.util.Set;
32
33 import javax.ejb.Local;
34
35 /**
36  * This class serves as a facade in front of the persistence library so client
37  * classes can be independent of the persistence implementation.
38  *
39  * @author past
40  */
41 @Local
42 public interface GSSDAO {
43
44         /**
45          * Creates the given object in the persistent storage.
46          *
47          * @param obj The object to be saved or updated
48          */
49         public void create(Object obj);
50
51         /**
52          * Updates by re-attaching the given object to the persistence context.
53          *
54          * @param obj The object to be updated
55          */
56         public void update(Object obj);
57
58         /**
59          * Refreshes an object by re-attaching it to the persistence context.
60          *
61          * @param obj the supplied object
62          */
63         public void refresh(Object obj);
64
65         /**
66          * Deletes the specified entity from the persistent storage.
67          *
68          * @param entity the object to be deleted
69          */
70         public void delete(Object entity);
71
72         /**
73          * Returns an Entity of the specified class with the specified id
74          *
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
80          */
81         public <T> T getEntityById(Class<T> _class, Object _id) throws ObjectNotFoundException;
82
83         /**
84          * Returns the list of Groups that belong to a particular User.
85          *
86          * @param userId the ID of the specified User
87          * @return a List of Group objects
88          * @throws ObjectNotFoundException
89          */
90         public List<Group> getGroups(Long userId) throws ObjectNotFoundException;
91
92         /**
93          * Retrieves the root folder for the specified user. The caller must ensure
94          * that the userId exists.
95          *
96          * @param userId
97          * @return Folder
98          * @throws ObjectNotFoundException if no Folder was found
99          */
100         public Folder getRootFolder(Long userId) throws gr.ebs.gss.client.exceptions.ObjectNotFoundException;
101
102         /**
103          * Retrieves the user for the requested username.
104          *
105          * @param username the username specified
106          * @return the user object
107          * @throws ObjectNotFoundException if no user was found
108          */
109         public User getUser(final String username) throws ObjectNotFoundException;
110
111         /**
112          * Returns a list of files contained in the folder specified by its id, CAUTION: it does not return files marked as deleted
113          *
114          * @param folderId
115          * @param ignoreDeleted
116          * @return List<FileHeader>
117          * @throws ObjectNotFoundException
118          */
119         @SuppressWarnings("unchecked")
120         public List<FileHeader> getFiles(Long folderId, boolean ignoreDeleted) throws ObjectNotFoundException;
121
122         /**
123          * Returns a list of deleted files of user specified by userId
124          *
125          * @param userId
126          * @return List<FileHeader>
127          * @throws ObjectNotFoundException
128          */
129         @SuppressWarnings("unchecked")
130         public List<FileHeader> getDeletedFiles(Long userId) throws ObjectNotFoundException;
131
132         /**
133          * Returns a list of deleted root folders of user specified by userId
134          *
135          * @param userId
136          * @return List<Folder>
137          * @throws ObjectNotFoundException
138          */
139         @SuppressWarnings("unchecked")
140         public List<Folder> getDeletedRootFolders(Long userId) throws ObjectNotFoundException;
141
142         /**
143          * Returns a list of users for the specified group
144          *
145          * @param groupId
146          * @return List<User>
147          * @throws ObjectNotFoundException
148          */
149         public List<User> getUsers(Long groupId) throws ObjectNotFoundException;
150
151         /**
152          * Checks if a folder or file with the specified name exists under the
153          * specified parent.
154          *
155          * @param parentId
156          * @param name
157          * @return boolean
158          * @throws ObjectNotFoundException
159          * @throws ObjectNotFoundException
160          */
161         public boolean existsFolderOrFile(Long parentId, String name) throws ObjectNotFoundException;
162
163         /**
164          * Checks if a folder with the specified name exists for the specified user.
165          *
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
170          */
171         public boolean existsGroup(Long userId, String name) throws ObjectNotFoundException;
172
173         /**
174          * Retrieves all tags defined by the specified user
175          *
176          * @param userId
177          * @return Set<String> A set of string tags
178          * @throws ObjectNotFoundException if the user was null
179          */
180         public Set<String> getUserTags(final Long userId) throws ObjectNotFoundException;
181
182         /**
183          * Flushes the persistence context
184          */
185         public void flush();
186
187         /**
188          * Retrieve the file with the supplied name that is contained
189          * in a folder with the specified ID.
190          *
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
196          */
197         public FileHeader getFile(Long folderId, String name) throws ObjectNotFoundException;
198
199         /**
200          * Retrieve the folder with the supplied name that is contained
201          * in a folder with the specified ID.
202          *
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
208          */
209         public Folder getFolder(Long parentId, String name) throws ObjectNotFoundException;
210
211         /**
212          * Search the system for a user with the specified username.
213          * If no such user is found, the method returns null.
214          *
215          * @param username the username to search for
216          * @return the User object with the specified username
217          */
218         public User findUser(String username);
219
220         /**
221          * Search the system for a user with the specified email address.
222          * If no such user is found, the method returns null.
223          */
224         public User findUserByEmail(String email);
225
226         /**
227          * Returns a list of users matching specified username
228          *
229          * @param username the email of the User
230          * @return List<User>
231          */
232         public List<User> getUsersByUserNameLike(String username);
233
234         /**
235          * Returns a list of All Shared root folders of a user.
236          *
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
240          */
241         public List<Folder> getSharedRootFolders(Long userId) throws ObjectNotFoundException;
242
243         /**
244          * Returns a list of all shared files of a user, not contained in a shared folder.
245          *
246          * @param userId the ID of the User
247          * @return the list of shared files
248          * @throws ObjectNotFoundException if the user cannot be found
249          */
250         public List<FileHeader> getSharedFilesNotInSharedFolders(Long userId) throws ObjectNotFoundException;
251
252         /**
253          * Returns a list of all shared files of a user.
254          *
255          * @param userId the ID of the User
256          * @return the list of shared files
257          * @throws ObjectNotFoundException if the user cannot be found
258          */
259         public List<FileHeader> getSharedFiles(Long userId) throws ObjectNotFoundException;
260
261         /**
262          * Returns a list of all shared folders of a user.
263          *
264          * @param userId the ID of the User
265          * @return the list of shared folders
266          * @throws ObjectNotFoundException if the user cannot be found
267          */
268         public List<Folder> getSharedFolders(Long userId) throws ObjectNotFoundException;
269
270         /**
271          * Returns a list of folders of user with permissions for specified group
272          *
273          * @param userId the ID of the User
274          * @return the list of shared root folders
275          * @param groupId
276          * @throws ObjectNotFoundException if the user cannot be found
277          */
278         public List<Folder> getFoldersPermittedForGroup(Long userId, Long groupId) throws ObjectNotFoundException;
279
280         /**
281          * Returns a list of users sharing files to specified user
282          *
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
286          */
287         public List<User> getUsersSharingFoldersForUser(Long userId) throws ObjectNotFoundException;
288
289         /**
290          * Returns a list of users sharing files to specified user
291          *
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
295          */
296         public List<User> getUsersSharingFilesForUser(Long userId) throws ObjectNotFoundException;
297
298         /**
299          * Returns a list of All Shared root folders of a user that calling user has permissions to read them at least.
300          *
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
305          */
306         public List<Folder> getSharedRootFolders(Long userId, Long callingUserId) throws ObjectNotFoundException;
307
308         /**
309          * Returns a list of All Shared files of a user not contained in a shared folder that calling user has permissions.
310          *
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
315          */
316         public List<FileHeader> getSharedFiles(Long userId, Long callingUserId) throws ObjectNotFoundException;
317
318         /**
319          * Search Files
320          * @param userId
321          * @param query
322          * @return list of files that match query
323          * @throws ObjectNotFoundException
324          */
325         public List<FileHeader> searchFiles(Long userId, String query) throws ObjectNotFoundException;
326
327         /**
328          * Find the nonce object for the specified encoded nonce, that should be
329          * associated with the specified user.
330          *
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
335          */
336         public Nonce getNonce(String nonce, Long userId) throws ObjectNotFoundException;
337
338         /**
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
341          *
342          * @param id
343          * @return the {@link FileHeader} with initialized tags
344          * @throws ObjectNotFoundException when a file with the specified id does not exist
345          */
346         public FileHeader getFileForIndexing(Long id) throws ObjectNotFoundException;
347
348         /**
349          * Calculates total file size of user.
350          *
351          * @param userId the ID of the user
352          * @return the aggregate size of all the user's files
353          */
354         public Long getFileSize(Long userId);
355
356         /**
357          * Calculates total file count of user.
358          *
359          * @param userId the ID of the user
360          * @return the total number of files in the user's namespace
361          */
362         public Long getFileCount(Long userId);
363
364         /**
365          * This method returns all file ids for rebuilding the search index
366          *
367          * @return a list of Long file ids
368          */
369         public List<Long> getAllFileIds();
370
371         public FileUploadStatus getFileUploadStatus(Long userId, String fileName);
372
373         /**
374          * Fetch the file body with the specified version number.
375          *
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
380          */
381         public FileBody getFileVersion(Long fileId, int version) throws ObjectNotFoundException;
382 }