ee7edbb3c10b6279394a48b74e54febe5f2989df
[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          * Returns a list of users matching specified username
222          *
223          * @param username the email of the User
224          * @return List<User>
225          */
226         public List<User> getUsersByUserNameLike(String username);
227
228         /**
229          * Returns a list of All Shared root folders of a user.
230          *
231          * @param userId the ID of the User
232          * @return the list of shared root folders
233          * @throws ObjectNotFoundException if the user cannot be found
234          */
235         public List<Folder> getSharedRootFolders(Long userId) throws ObjectNotFoundException;
236
237         /**
238          * Returns a list of all shared files of a user, not contained in a shared folder.
239          *
240          * @param userId the ID of the User
241          * @return the list of shared files
242          * @throws ObjectNotFoundException if the user cannot be found
243          */
244         public List<FileHeader> getSharedFilesNotInSharedFolders(Long userId) throws ObjectNotFoundException;
245
246         /**
247          * Returns a list of all shared files of a user.
248          *
249          * @param userId the ID of the User
250          * @return the list of shared files
251          * @throws ObjectNotFoundException if the user cannot be found
252          */
253         public List<FileHeader> getSharedFiles(Long userId) throws ObjectNotFoundException;
254
255         /**
256          * Returns a list of all shared folders of a user.
257          *
258          * @param userId the ID of the User
259          * @return the list of shared folders
260          * @throws ObjectNotFoundException if the user cannot be found
261          */
262         public List<Folder> getSharedFolders(Long userId) throws ObjectNotFoundException;
263
264         /**
265          * Returns a list of folders of user with permissions for specified group
266          *
267          * @param userId the ID of the User
268          * @return the list of shared root folders
269          * @param groupId
270          * @throws ObjectNotFoundException if the user cannot be found
271          */
272         public List<Folder> getFoldersPermittedForGroup(Long userId, Long groupId) throws ObjectNotFoundException;
273
274         /**
275          * Returns a list of users sharing files to specified user
276          *
277          * @param userId the ID of the User
278          * @return the list of users sharing files to selected user
279          * @throws ObjectNotFoundException if the user cannot be found
280          */
281         public List<User> getUsersSharingFoldersForUser(Long userId) throws ObjectNotFoundException;
282
283         /**
284          * Returns a list of users sharing files to specified user
285          *
286          * @param userId the ID of the User
287          * @return the list of users sharing files to selected user
288          * @throws ObjectNotFoundException if the user cannot be found
289          */
290         public List<User> getUsersSharingFilesForUser(Long userId) throws ObjectNotFoundException;
291
292         /**
293          * Returns a list of All Shared root folders of a user that calling user has permissions to read them at least.
294          *
295          * @param userId the ID of the User
296          * @param callingUserId
297          * @return the list of shared root folders
298          * @throws ObjectNotFoundException if the user cannot be found
299          */
300         public List<Folder> getSharedRootFolders(Long userId, Long callingUserId) throws ObjectNotFoundException;
301
302         /**
303          * Returns a list of All Shared files of a user not contained in a shared folder that calling user has permissions.
304          *
305          * @param userId the ID of the User
306          * @param callingUserId
307          * @return the list of shared files
308          * @throws ObjectNotFoundException if the user cannot be found
309          */
310         public List<FileHeader> getSharedFiles(Long userId, Long callingUserId) throws ObjectNotFoundException;
311
312         /**
313          * Search Files
314          * @param userId
315          * @param query
316          * @return list of files that match query
317          * @throws ObjectNotFoundException
318          */
319         public List<FileHeader> searchFiles(Long userId, String query) throws ObjectNotFoundException;
320
321         /**
322          * Find the nonce object for the specified encoded nonce, that should be
323          * associated with the specified user.
324          *
325          * @param nonce the issued nonce in Base64 encoding
326          * @param userId the ID of the user for whom this nonce should have been issued
327          * @return the retrieved nonce object
328          * @throws ObjectNotFoundException if the nonce or user were not found
329          */
330         public Nonce getNonce(String nonce, Long userId) throws ObjectNotFoundException;
331
332         /**
333          * Loads the file for indexing. That means the file is loaded with the lazy fields needed for inedexing, initialized.
334          * For now only the tags need to be initialized
335          *
336          * @param id
337          * @return the {@link FileHeader} with initialized tags
338          * @throws ObjectNotFoundException when a file with the specified id does not exist
339          */
340         public FileHeader getFileForIndexing(Long id) throws ObjectNotFoundException;
341
342         /**
343          * Calculates total file size of user.
344          *
345          * @param userId the ID of the user
346          * @return the aggregate size of all the user's files
347          */
348         public Long getFileSize(Long userId);
349
350         /**
351          * Calculates total file count of user.
352          *
353          * @param userId the ID of the user
354          * @return the total number of files in the user's namespace
355          */
356         public Long getFileCount(Long userId);
357
358         /**
359          * This method returns all file ids for rebuilding the search index
360          *
361          * @return a list of Long file ids
362          */
363         public List<Long> getAllFileIds();
364
365         public FileUploadStatus getFileUploadStatus(Long userId, String fileName);
366
367         /**
368          * Fetch the file body with the specified version number.
369          *
370          * @param fileId the ID of the file header
371          * @param version the version number
372          * @return the file body
373          * @throws ObjectNotFoundException if the file body was not found
374          */
375         public FileBody getFileVersion(Long fileId, int version) throws ObjectNotFoundException;
376 }