Use exponential backoff when updating the password or last login time in WebDAV.
[pithos] / 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.Date;
31 import java.util.List;
32 import java.util.Set;
33
34 import javax.ejb.Local;
35
36 /**
37  * This class serves as a facade in front of the persistence library so client
38  * classes can be independent of the persistence implementation.
39  *
40  * @author past
41  */
42 @Local
43 public interface GSSDAO {
44
45         /**
46          * Creates the given object in the persistent storage.
47          *
48          * @param obj The object to be saved or updated
49          */
50         public void create(Object obj);
51
52         /**
53          * Updates by re-attaching the given object to the persistence context.
54          *
55          * @param obj The object to be updated
56          */
57         public void update(Object obj);
58
59         /**
60          * Refreshes an object by re-attaching it to the persistence context.
61          *
62          * @param obj the supplied object
63          */
64         public void refresh(Object obj);
65
66         /**
67          * Deletes the specified entity from the persistent storage.
68          *
69          * @param entity the object to be deleted
70          */
71         public void delete(Object entity);
72
73         /**
74          * Returns an Entity of the specified class with the specified id
75          *
76          * @param <T> The type of the entity
77          * @param _class the Class of the entity
78          * @param _id the id of the entity
79          * @return the Object found
80          * @throws ObjectNotFoundException if the Object was not found
81          */
82         public <T> T getEntityById(Class<T> _class, Object _id) throws ObjectNotFoundException;
83
84         /**
85          * Returns the list of Groups that belong to a particular User.
86          *
87          * @param userId the ID of the specified User
88          * @return a List of Group objects
89          * @throws ObjectNotFoundException
90          */
91         public List<Group> getGroups(Long userId) throws ObjectNotFoundException;
92
93         /**
94          * Retrieves the root folder for the specified user. The caller must ensure
95          * that the userId exists.
96          *
97          * @param userId
98          * @return Folder
99          * @throws ObjectNotFoundException if no Folder was found
100          */
101         public Folder getRootFolder(Long userId) throws gr.ebs.gss.client.exceptions.ObjectNotFoundException;
102
103         /**
104          * Retrieves the user for the requested username.
105          *
106          * @param username the username specified
107          * @return the user object
108          * @throws ObjectNotFoundException if no user was found
109          */
110         public User getUser(final String username) throws ObjectNotFoundException;
111
112         /**
113          * Returns a list of files contained in the folder specified by its id, CAUTION: it does not return files marked as deleted
114          *
115          * @param folderId
116          * @param userId
117          * @param ignoreDeleted
118          * @return List<FileHeader>
119          * @throws ObjectNotFoundException
120          */
121         @SuppressWarnings("unchecked")
122         public List<FileHeader> getFiles(Long folderId, Long userId, boolean ignoreDeleted) throws ObjectNotFoundException;
123
124         /**
125          * Returns a list of deleted files of user specified by userId
126          *
127          * @param userId
128          * @return List<FileHeader>
129          * @throws ObjectNotFoundException
130          */
131         @SuppressWarnings("unchecked")
132         public List<FileHeader> getDeletedFiles(Long userId) throws ObjectNotFoundException;
133
134         /**
135          * Returns a list of deleted root folders of user specified by userId
136          *
137          * @param userId
138          * @return List<Folder>
139          * @throws ObjectNotFoundException
140          */
141         @SuppressWarnings("unchecked")
142         public List<Folder> getDeletedRootFolders(Long userId) throws ObjectNotFoundException;
143
144         /**
145          * Returns a list of users for the specified group
146          *
147          * @param groupId
148          * @return List<User>
149          * @throws ObjectNotFoundException
150          */
151         public List<User> getUsers(Long groupId) throws ObjectNotFoundException;
152
153         /**
154          * Checks if a folder or file with the specified name exists under the
155          * specified parent.
156          *
157          * @param parentId
158          * @param name
159          * @return boolean
160          * @throws ObjectNotFoundException
161          * @throws ObjectNotFoundException
162          */
163         public boolean existsFolderOrFile(Long parentId, String name) throws ObjectNotFoundException;
164
165         /**
166          * Checks if a folder with the specified name exists for the specified user.
167          *
168          * @param userId the owner of the group
169          * @param name the name of the group
170          * @return true if a group with the same name exists
171          * @throws ObjectNotFoundException
172          */
173         public boolean existsGroup(Long userId, String name) throws ObjectNotFoundException;
174
175         /**
176          * Retrieves all tags defined by the specified user
177          *
178          * @param userId
179          * @return Set<String> A set of string tags
180          * @throws ObjectNotFoundException if the user was null
181          */
182         public Set<String> getUserTags(final Long userId) throws ObjectNotFoundException;
183
184         /**
185          * Flushes the persistence context
186          */
187         public void flush();
188
189         /**
190          * Retrieve the file with the supplied name that is contained
191          * in a folder with the specified ID.
192          *
193          * @param folderId the ID of the parent folder
194          * @param name the name of the file
195          * @return the file found
196          * @throws ObjectNotFoundException if the file or parent folder was not found,
197          *                      with the exception message mentioning the precise problem
198          */
199         public FileHeader getFile(Long folderId, String name) throws ObjectNotFoundException;
200
201         /**
202          * Retrieve the folder with the supplied name that is contained
203          * in a folder with the specified ID.
204          *
205          * @param parentId the ID of the parent folder
206          * @param name the name of the folder
207          * @return the folder found
208          * @throws ObjectNotFoundException if the folder or parent was not found,
209          *                      with the exception message mentioning the precise problem
210          */
211         public Folder getFolder(Long parentId, String name) throws ObjectNotFoundException;
212
213         /**
214          * Search the system for a user with the specified username.
215          * If no such user is found, the method returns null.
216          *
217          * @param username the username to search for
218          * @return the User object with the specified username
219          */
220         public User findUser(String username);
221
222         /**
223          * Search the system for a user with the specified email address.
224          * If no such user is found, the method returns null.
225          */
226         public User findUserByEmail(String email);
227
228         /**
229          * Returns a list of users matching specified username
230          *
231          * @param username the email of the User
232          * @return List<User>
233          */
234         public List<User> getUsersByUserNameLike(String username);
235
236         /**
237          * Returns a list of All Shared root folders of a user.
238          *
239          * @param userId the ID of the User
240          * @return the list of shared root folders
241          * @throws ObjectNotFoundException if the user cannot be found
242          */
243         public List<Folder> getSharedRootFolders(Long userId) throws ObjectNotFoundException;
244
245         /**
246          * Returns a list of all shared files of a user, not contained in a shared folder.
247          *
248          * @param userId the ID of the User
249          * @return the list of shared files
250          * @throws ObjectNotFoundException if the user cannot be found
251          */
252         public List<FileHeader> getSharedFilesNotInSharedFolders(Long userId) throws ObjectNotFoundException;
253
254         /**
255          * Returns a list of all shared files of a user.
256          *
257          * @param userId the ID of the User
258          * @return the list of shared files
259          * @throws ObjectNotFoundException if the user cannot be found
260          */
261         public List<FileHeader> getSharedFiles(Long userId) throws ObjectNotFoundException;
262
263         /**
264          * Returns a list of all shared folders of a user.
265          *
266          * @param userId the ID of the User
267          * @return the list of shared folders
268          * @throws ObjectNotFoundException if the user cannot be found
269          */
270         public List<Folder> getSharedFolders(Long userId) throws ObjectNotFoundException;
271
272         /**
273          * Returns a list of folders of user with permissions for specified group
274          *
275          * @param userId the ID of the User
276          * @return the list of shared root folders
277          * @param groupId
278          * @throws ObjectNotFoundException if the user cannot be found
279          */
280         public List<Folder> getFoldersPermittedForGroup(Long userId, Long groupId) throws ObjectNotFoundException;
281
282         /**
283          * Returns a list of users sharing files to specified user
284          *
285          * @param userId the ID of the User
286          * @return the list of users sharing files to selected user
287          * @throws ObjectNotFoundException if the user cannot be found
288          */
289         public List<User> getUsersSharingFoldersForUser(Long userId) throws ObjectNotFoundException;
290
291         /**
292          * Returns a list of users sharing files to specified user
293          *
294          * @param userId the ID of the User
295          * @return the list of users sharing files to selected user
296          * @throws ObjectNotFoundException if the user cannot be found
297          */
298         public List<User> getUsersSharingFilesForUser(Long userId) throws ObjectNotFoundException;
299
300         /**
301          * Returns a list of All Shared root folders of a user that calling user has permissions to read them at least.
302          *
303          * @param userId the ID of the User
304          * @param callingUserId
305          * @return the list of shared root folders
306          * @throws ObjectNotFoundException if the user cannot be found
307          */
308         public List<Folder> getSharedRootFolders(Long userId, Long callingUserId) throws ObjectNotFoundException;
309
310         /**
311          * Returns a list of All Shared files of a user not contained in a shared folder that calling user has permissions.
312          *
313          * @param userId the ID of the User
314          * @param callingUserId
315          * @return the list of shared files
316          * @throws ObjectNotFoundException if the user cannot be found
317          */
318         public List<FileHeader> getSharedFiles(Long userId, Long callingUserId) throws ObjectNotFoundException;
319
320         /**
321          * Search Files
322          * @param userId
323          * @param query
324          * @return list of files that match query
325          * @throws ObjectNotFoundException
326          */
327         public List<FileHeader> searchFiles(Long userId, String query) throws ObjectNotFoundException;
328
329         /**
330          * Find the nonce object for the specified encoded nonce, that should be
331          * associated with the specified user.
332          *
333          * @param nonce the issued nonce in Base64 encoding
334          * @param userId the ID of the user for whom this nonce should have been issued
335          * @return the retrieved nonce object
336          * @throws ObjectNotFoundException if the nonce or user were not found
337          */
338         public Nonce getNonce(String nonce, Long userId) throws ObjectNotFoundException;
339
340         /**
341          * Loads the file for indexing. That means the file is loaded with the lazy fields needed for inedexing, initialized.
342          * For now only the tags need to be initialized
343          *
344          * @param id
345          * @return the {@link FileHeader} with initialized tags
346          * @throws ObjectNotFoundException when a file with the specified id does not exist
347          */
348         public FileHeader getFileForIndexing(Long id) throws ObjectNotFoundException;
349
350         /**
351          * Calculates total file size of user.
352          *
353          * @param userId the ID of the user
354          * @return the aggregate size of all the user's files
355          */
356         public Long getFileSize(Long userId);
357
358         /**
359          * Calculates total file count of user.
360          *
361          * @param userId the ID of the user
362          * @return the total number of files in the user's namespace
363          */
364         public Long getFileCount(Long userId);
365
366         /**
367          * This method returns all file ids for rebuilding the search index
368          *
369          * @return a list of Long file ids
370          */
371         public List<Long> getAllFileIds();
372
373         public FileUploadStatus getFileUploadStatus(Long userId, String fileName);
374
375         /**
376          * Fetch the file body with the specified version number.
377          *
378          * @param fileId the ID of the file header
379          * @param version the version number
380          * @return the file body
381          * @throws ObjectNotFoundException if the file body was not found
382          */
383         public FileBody getFileVersion(Long fileId, int version) throws ObjectNotFoundException;
384
385         /**
386          * Update accounting info for given user.
387          * Adds bandwidth used to appropriate time period bucket.
388          * Bucket is created if needed.
389          *
390          * @param user The user to update
391          * @param date Date of transaction
392          * @param bandwidthDiff Bandwidth used; positive for addition,
393          * negative for subtraction (e.g. to rollback)
394          */
395         public void updateAccounting(User user, Date date, long bandwidthDiff);
396 }