use celltable for search results, add (InTrash) next to path for trashed files in...
[pithos] / src / gr / ebs / gss / server / ejb / GSSDAO.java
1 /*
2  * Copyright 2007, 2008, 2009, 2010 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.AccountingInfo;
23 import gr.ebs.gss.server.domain.FileBody;
24 import gr.ebs.gss.server.domain.FileHeader;
25 import gr.ebs.gss.server.domain.FileUploadStatus;
26 import gr.ebs.gss.server.domain.Folder;
27 import gr.ebs.gss.server.domain.Group;
28 import gr.ebs.gss.server.domain.Invitation;
29 import gr.ebs.gss.server.domain.Nonce;
30 import gr.ebs.gss.server.domain.User;
31 import gr.ebs.gss.server.domain.UserClass;
32 import gr.ebs.gss.server.domain.UserLogin;
33
34 import java.util.Date;
35 import java.util.List;
36 import java.util.Set;
37
38 import javax.ejb.Local;
39
40 /**
41  * This class serves as a facade in front of the persistence library so client
42  * classes can be independent of the persistence implementation.
43  *
44  * @author past
45  */
46 @Local
47 public interface GSSDAO {
48
49         /**
50          * Creates the given object in the persistent storage.
51          *
52          * @param obj The object to be saved or updated
53          */
54         public void create(Object obj);
55
56         /**
57          * Updates by re-attaching the given object to the persistence context.
58          *
59          * @param obj The object to be updated
60          */
61         public void update(Object obj);
62
63         /**
64          * Refreshes an object by re-attaching it to the persistence context.
65          *
66          * @param obj the supplied object
67          */
68         public void refresh(Object obj);
69
70         /**
71          * Deletes the specified entity from the persistent storage.
72          *
73          * @param entity the object to be deleted
74          */
75         public void delete(Object entity);
76
77         /**
78          * Returns an Entity of the specified class with the specified id
79          *
80          * @param <T> The type of the entity
81          * @param _class the Class of the entity
82          * @param _id the id of the entity
83          * @return the Object found
84          * @throws ObjectNotFoundException if the Object was not found
85          */
86         public <T> T getEntityById(Class<T> _class, Object _id) throws ObjectNotFoundException;
87
88         /**
89          * Returns the list of Groups that belong to a particular User.
90          *
91          * @param userId the ID of the specified User
92          * @return a List of Group objects
93          * @throws ObjectNotFoundException
94          */
95         public List<Group> getGroups(Long userId) throws ObjectNotFoundException;
96
97         /**
98          * Retrieves the root folder id for the specified user. The caller must ensure
99          * that the userId exists.
100          *
101          * @param userId
102          * @return Long The id
103          * @throws ObjectNotFoundException if no Folder was found
104          */
105         public Long getRootFolderId(final Long userId) throws ObjectNotFoundException;
106         
107         /**
108          * Retrieves the root folder for the specified user. The caller must ensure
109          * that the userId exists.
110          *
111          * @param userId
112          * @return Folder
113          * @throws ObjectNotFoundException if no Folder was found
114          */
115         public Folder getRootFolder(Long userId) throws gr.ebs.gss.client.exceptions.ObjectNotFoundException;
116
117         /**
118          * Retrieves the user for the requested username.
119          *
120          * @param username the username specified
121          * @return the user object
122          * @throws ObjectNotFoundException if no user was found
123          */
124         public User getUser(final String username) throws ObjectNotFoundException;
125
126         /**
127          * Returns a list of files contained in the folder specified by its id, CAUTION: it does not return files marked as deleted
128          *
129          * @param folderId
130          * @param userId
131          * @param ignoreDeleted
132          * @return List<FileHeader>
133          * @throws ObjectNotFoundException
134          */
135         @SuppressWarnings("unchecked")
136         public List<FileHeader> getFiles(Long folderId, Long userId, boolean ignoreDeleted) throws ObjectNotFoundException;
137
138         /**
139          * Returns a list of deleted files of user specified by userId
140          *
141          * @param userId
142          * @return List<FileHeader>
143          * @throws ObjectNotFoundException
144          */
145         @SuppressWarnings("unchecked")
146         public List<FileHeader> getDeletedFiles(Long userId) throws ObjectNotFoundException;
147
148         /**
149          * Returns a list of deleted root folders of user specified by userId
150          *
151          * @param userId
152          * @return List<Folder>
153          * @throws ObjectNotFoundException
154          */
155         @SuppressWarnings("unchecked")
156         public List<Folder> getDeletedRootFolders(Long userId) throws ObjectNotFoundException;
157
158         /**
159          * Returns a list of users for the specified group
160          *
161          * @param groupId
162          * @return List<User>
163          * @throws ObjectNotFoundException
164          */
165         public List<User> getUsers(Long groupId) throws ObjectNotFoundException;
166
167         /**
168          * Checks if a folder or file with the specified name exists under the
169          * specified parent.
170          *
171          * @param parentId
172          * @param name
173          * @return boolean
174          * @throws ObjectNotFoundException
175          * @throws ObjectNotFoundException
176          */
177         public boolean existsFolderOrFile(Long parentId, String name) throws ObjectNotFoundException;
178
179         /**
180          * Checks if a folder with the specified name exists for the specified user.
181          *
182          * @param userId the owner of the group
183          * @param name the name of the group
184          * @return true if a group with the same name exists
185          * @throws ObjectNotFoundException
186          */
187         public boolean existsGroup(Long userId, String name) throws ObjectNotFoundException;
188
189         /**
190          * Retrieves all tags defined by the specified user
191          *
192          * @param userId
193          * @return Set<String> A set of string tags
194          * @throws ObjectNotFoundException if the user was null
195          */
196         public Set<String> getUserTags(final Long userId) throws ObjectNotFoundException;
197
198         /**
199          * Flushes the persistence context
200          */
201         public void flush();
202
203         /**
204          * Retrieve the file with the supplied name that is contained
205          * in a folder with the specified ID.
206          *
207          * @param folderId the ID of the parent folder
208          * @param name the name of the file
209          * @return the file found
210          * @throws ObjectNotFoundException if the file or parent folder was not found,
211          *                      with the exception message mentioning the precise problem
212          */
213         public FileHeader getFile(Long folderId, String name) throws ObjectNotFoundException;
214
215         /**
216          * Retrieve the folder with the supplied name that is contained
217          * in a folder with the specified ID.
218          *
219          * @param parentId the ID of the parent folder
220          * @param name the name of the folder
221          * @return the folder found
222          * @throws ObjectNotFoundException if the folder or parent was not found,
223          *                      with the exception message mentioning the precise problem
224          */
225         public Folder getFolder(Long parentId, String name) throws ObjectNotFoundException;
226
227         /**
228          * Search the system for a user with the specified username.
229          * If no such user is found, the method returns null.
230          *
231          * @param username the username to search for
232          * @return the User object with the specified username
233          */
234         public User findUser(String username);
235
236         /**
237          * Search the system for a user with the specified email address.
238          * If no such user is found, the method returns null.
239          */
240         public User findUserByEmail(String email);
241
242         /**
243          * Returns a list of users matching specified username
244          *
245          * @param username the email of the User
246          * @return List<User>
247          */
248         public List<User> getUsersByUserNameLike(String username);
249
250         /**
251          * Returns a list of users matching specified username or email
252          * @param query
253          * @return List<User>
254          */
255         public List<User> getUsersByUserNameOrEmailLike(String query);
256
257         /**
258          * Returns a list of All Shared root folders of a user.
259          *
260          * @param userId the ID of the User
261          * @return the list of shared root folders
262          * @throws ObjectNotFoundException if the user cannot be found
263          */
264         public List<Folder> getSharedRootFolders(Long userId) throws ObjectNotFoundException;
265
266         /**
267          * Returns a list of all shared files of a user, not contained in a shared folder.
268          *
269          * @param userId the ID of the User
270          * @return the list of shared files
271          * @throws ObjectNotFoundException if the user cannot be found
272          */
273         public List<FileHeader> getSharedFilesNotInSharedFolders(Long userId) throws ObjectNotFoundException;
274
275         /**
276          * Returns a list of all shared files of a user.
277          *
278          * @param userId the ID of the User
279          * @return the list of shared files
280          * @throws ObjectNotFoundException if the user cannot be found
281          */
282         public List<FileHeader> getSharedFiles(Long userId) throws ObjectNotFoundException;
283
284         /**
285          * Returns a list of all shared folders of a user.
286          *
287          * @param userId the ID of the User
288          * @return the list of shared folders
289          * @throws ObjectNotFoundException if the user cannot be found
290          */
291         public List<Folder> getSharedFolders(Long userId) throws ObjectNotFoundException;
292
293         /**
294          * Returns a list of folders of user with permissions for specified group
295          *
296          * @param userId the ID of the User
297          * @return the list of shared root folders
298          * @param groupId
299          * @throws ObjectNotFoundException if the user cannot be found
300          */
301         public List<Folder> getFoldersPermittedForGroup(Long userId, Long groupId) throws ObjectNotFoundException;
302
303         /**
304          * Returns a list of users sharing files to specified user
305          *
306          * @param userId the ID of the User
307          * @return the list of users sharing files to selected user
308          * @throws ObjectNotFoundException if the user cannot be found
309          */
310         public List<User> getUsersSharingFoldersForUser(Long userId) throws ObjectNotFoundException;
311
312         /**
313          * Returns a list of users sharing files to specified user
314          *
315          * @param userId the ID of the User
316          * @return the list of users sharing files to selected user
317          * @throws ObjectNotFoundException if the user cannot be found
318          */
319         public List<User> getUsersSharingFilesForUser(Long userId) throws ObjectNotFoundException;
320
321         /**
322          * Returns a list of All Shared root folders of a user that calling user has permissions to read them at least.
323          *
324          * @param userId the ID of the User
325          * @param callingUserId
326          * @return the list of shared root folders
327          * @throws ObjectNotFoundException if the user cannot be found
328          */
329         public List<Folder> getSharedRootFolders(Long userId, Long callingUserId) throws ObjectNotFoundException;
330
331         /**
332          * Returns a list of All Shared files of a user not contained in a shared folder that calling user has permissions.
333          *
334          * @param userId the ID of the User
335          * @param callingUserId
336          * @return the list of shared files
337          * @throws ObjectNotFoundException if the user cannot be found
338          */
339         public List<FileHeader> getSharedFiles(Long userId, Long callingUserId) throws ObjectNotFoundException;
340
341         /**
342          * Search Files
343          * @param userId
344          * @param query
345          * @return list of files that match query
346          * @throws ObjectNotFoundException
347          */
348         public List<FileHeader> searchFiles(Long userId, String query) throws ObjectNotFoundException;
349
350         /**
351          * Find the nonce object for the specified encoded nonce, that should be
352          * associated with the specified user.
353          *
354          * @param nonce the issued nonce in Base64 encoding
355          * @param userId the ID of the user for whom this nonce should have been issued
356          * @return the retrieved nonce object
357          * @throws ObjectNotFoundException if the nonce or user were not found
358          */
359         public Nonce getNonce(String nonce, Long userId) throws ObjectNotFoundException;
360
361         /**
362          * Calculates total file size of user.
363          *
364          * @param userId the ID of the user
365          * @return the aggregate size of all the user's files
366          */
367         public Long getFileSize(Long userId);
368
369         /**
370          * Calculates total file count of user.
371          *
372          * @param userId the ID of the user
373          * @return the total number of files in the user's namespace
374          */
375         public Long getFileCount(Long userId);
376
377         /**
378          * This method returns all file ids for rebuilding the search index
379          *
380          * @return a list of Long file ids
381          */
382         public List<Long> getAllFileIds();
383
384         public FileUploadStatus getFileUploadStatus(Long userId, String fileName);
385
386         /**
387          * Fetch the file body with the specified version number.
388          *
389          * @param fileId the ID of the file header
390          * @param version the version number
391          * @return the file body
392          * @throws ObjectNotFoundException if the file body was not found
393          */
394         public FileBody getFileVersion(Long fileId, int version) throws ObjectNotFoundException;
395
396         /**
397          * Update accounting info for given user.
398          * Adds bandwidth used to appropriate time period bucket.
399          * Bucket is created if needed.
400          *
401          * @param user The user to update
402          * @param date Date of transaction
403          * @param bandwidthDiff Bandwidth used; positive for addition,
404          * negative for subtraction (e.g. to rollback)
405          */
406         public void updateAccounting(User user, Date date, long bandwidthDiff);
407
408         /**
409          * Retrieves available user classes.
410          *
411          */
412         public List<UserClass> getUserClasses();
413
414         /**
415          * Find the invite for the specified invitation code.
416          *
417          * @param code the invitation code
418          * @return the Invitation or null if not found
419          */
420         public Invitation findInvite(String code);
421
422         /**
423          * Retrieve the user class for coupon-bearing users.
424          */
425         public UserClass findCouponUserClass();
426
427         /**
428          * Gets the user count.
429          *
430          * @param userClass the user class to use or null to retrieve system statistics
431          * @return the user count
432          */
433         public Long getUserCount(UserClass userClass);
434
435         /**
436          * Gets the file count.
437          *
438          * @param userClass the user class to use or null to retrieve system statistics
439          * @return the file count
440          */
441         public Long getFileCount(UserClass userClass);
442
443         /**
444          * Gets the file size.
445          *
446          * @param userClass the user class to use or null to retrieve system statistics
447          * @return the file size
448          */
449         public Long getFileSize(UserClass userClass);
450
451         public List<User> getUsersByLastLogin(Date lastLoginDate);
452
453         public List<User> getUsersByLastLogin(Date lastLoginDate, int firstResult, int maxResult);
454
455         public Long getCountUsersByLastLogin(Date lastLoginDate);
456
457         public List<User> getInactiveUsers();
458
459         public List<FileHeader> searchFileByFilename(String filename);
460
461         public Long getBandwithUsed(UserClass userClass, Date date);
462
463         public List<AccountingInfo> getAccountingInfo(User user);
464
465         public AccountingInfo getAccountingInfo(User user, Date date);
466
467         /**
468          * Returns a list of files of user with permissions for specified group
469          *
470          * @param userId the ID of the User
471          * @return the list of shared root files
472          * @param groupId
473          * @throws ObjectNotFoundException if the user cannot be found
474          */
475         public List<FileHeader> getFilesPermittedForGroup(Long userId, Long groupId) throws ObjectNotFoundException;
476
477     /**
478      * Gets a file with tags initialized, cause indexing does not always run within a transaction (e.g. during rebuild)
479      * 
480      * @param id
481      * @return
482      * @throws ObjectNotFoundException
483      */
484     public FileHeader getFileForIndexing(Long id) throws ObjectNotFoundException;
485
486         /**
487          * @param userId
488          * @return
489          */
490         List<FileHeader> getSharingFilesForUser(Long userId);
491
492         /**
493          * @param userId
494          * @return
495          */
496         List<Folder> getSharingFoldersForUser(Long userId);
497
498         /**
499          * @param userId
500          * @return
501          */
502         List<Group> getGroupsContainingUser(Long userId);
503
504         /**
505          * @param userId
506          * @return
507          */
508         List<FileUploadStatus> getUploadStatus(Long userId);
509
510         /**
511          * @param userId
512          * @return
513          */
514         int deletePermissionsNotCorrespondingToFilesAndFolders(Long userId);
515         
516         /**
517          * Returns a list of the top two entries related to the date that a user logged in the service. 
518          * The first entry is related to the current session user login 
519          * and the latter is related to the user's last login
520          *  
521          * @param userId
522          * @return a list of last user login and the current session user login
523          */
524         public List<UserLogin> getLoginsForUser (Long userId);
525
526         /**
527          * Returns a list of all entries related to the date that a user logged in the service. 
528          *  
529          * @param userId
530          * @return a list of last user login and the current session user login
531          */
532         public List<UserLogin> getAllLoginsForUser (Long userId);
533         
534         /**
535          * Returns the user matching with the specified username
536          *
537          * @param username the email of the User
538          * @return User
539          */
540         public User getUserByUserName(String username);
541
542 }