2 * Copyright 2007, 2008, 2009, 2010 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.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.FileLock;
29 import gr.ebs.gss.server.domain.Invitation;
30 import gr.ebs.gss.server.domain.Nonce;
31 import gr.ebs.gss.server.domain.User;
32 import gr.ebs.gss.server.domain.UserClass;
33 import gr.ebs.gss.server.domain.UserLogin;
34 import gr.ebs.gss.server.domain.WebDavNonce;
36 import java.util.Date;
37 import java.util.List;
40 import javax.ejb.Local;
43 * This class serves as a facade in front of the persistence library so client
44 * classes can be independent of the persistence implementation.
49 public interface GSSDAO {
52 * Creates the given object in the persistent storage.
54 * @param obj The object to be saved or updated
56 public void create(Object obj);
59 * Updates by re-attaching the given object to the persistence context.
61 * @param obj The object to be updated
63 public void update(Object obj);
66 * Refreshes an object by re-attaching it to the persistence context.
68 * @param obj the supplied object
70 public void refresh(Object obj);
73 * Deletes the specified entity from the persistent storage.
75 * @param entity the object to be deleted
77 public void delete(Object entity);
80 * Returns an Entity of the specified class with the specified id
82 * @param <T> The type of the entity
83 * @param _class the Class of the entity
84 * @param _id the id of the entity
85 * @return the Object found
86 * @throws ObjectNotFoundException if the Object was not found
88 public <T> T getEntityById(Class<T> _class, Object _id) throws ObjectNotFoundException;
91 * Returns the list of Groups that belong to a particular User.
93 * @param userId the ID of the specified User
94 * @return a List of Group objects
95 * @throws ObjectNotFoundException
97 public List<Group> getGroups(Long userId) throws ObjectNotFoundException;
100 * Retrieves the root folder id for the specified user. The caller must ensure
101 * that the userId exists.
104 * @return Long The id
105 * @throws ObjectNotFoundException if no Folder was found
107 public Long getRootFolderId(final Long userId) throws ObjectNotFoundException;
110 * Retrieves the root folder for the specified user. The caller must ensure
111 * that the userId exists.
115 * @throws ObjectNotFoundException if no Folder was found
117 public Folder getRootFolder(Long userId) throws gr.ebs.gss.client.exceptions.ObjectNotFoundException;
120 * Retrieves the user for the requested username.
122 * @param username the username specified
123 * @return the user object
124 * @throws ObjectNotFoundException if no user was found
126 public User getUser(final String username) throws ObjectNotFoundException;
129 * Returns a list of files contained in the folder specified by its id, CAUTION: it does not return files marked as deleted
133 * @param ignoreDeleted
134 * @return List<FileHeader>
135 * @throws ObjectNotFoundException
137 @SuppressWarnings("unchecked")
138 public List<FileHeader> getFiles(Long folderId, Long userId, boolean ignoreDeleted) throws ObjectNotFoundException;
141 * Returns a list of deleted files of user specified by userId
144 * @return List<FileHeader>
145 * @throws ObjectNotFoundException
147 @SuppressWarnings("unchecked")
148 public List<FileHeader> getDeletedFiles(Long userId) throws ObjectNotFoundException;
151 * Returns a list of deleted root folders of user specified by userId
154 * @return List<Folder>
155 * @throws ObjectNotFoundException
157 @SuppressWarnings("unchecked")
158 public List<Folder> getDeletedRootFolders(Long userId) throws ObjectNotFoundException;
161 * Returns a list of users for the specified group
165 * @throws ObjectNotFoundException
167 public List<User> getUsers(Long groupId) throws ObjectNotFoundException;
170 * Checks if a folder or file with the specified name exists under the
176 * @throws ObjectNotFoundException
177 * @throws ObjectNotFoundException
179 public boolean existsFolderOrFile(Long parentId, String name) throws ObjectNotFoundException;
182 * Checks if a folder with the specified name exists for the specified user.
184 * @param userId the owner of the group
185 * @param name the name of the group
186 * @return true if a group with the same name exists
187 * @throws ObjectNotFoundException
189 public boolean existsGroup(Long userId, String name) throws ObjectNotFoundException;
192 * Retrieves all tags defined by the specified user
195 * @return Set<String> A set of string tags
196 * @throws ObjectNotFoundException if the user was null
198 public Set<String> getUserTags(final Long userId) throws ObjectNotFoundException;
201 * Flushes the persistence context
206 * Retrieve the file with the supplied name that is contained
207 * in a folder with the specified ID.
209 * @param folderId the ID of the parent folder
210 * @param name the name of the file
211 * @return the file found
212 * @throws ObjectNotFoundException if the file or parent folder was not found,
213 * with the exception message mentioning the precise problem
215 public FileHeader getFile(Long folderId, String name) throws ObjectNotFoundException;
218 * Retrieve the folder with the supplied name that is contained
219 * in a folder with the specified ID.
221 * @param parentId the ID of the parent folder
222 * @param name the name of the folder
223 * @return the folder found
224 * @throws ObjectNotFoundException if the folder or parent was not found,
225 * with the exception message mentioning the precise problem
227 public Folder getFolder(Long parentId, String name) throws ObjectNotFoundException;
230 * Search the system for a user with the specified username.
231 * If no such user is found, the method returns null.
233 * @param username the username to search for
234 * @return the User object with the specified username
236 public User findUser(String username);
239 * Search the system for a user with the specified email address.
240 * If no such user is found, the method returns null.
242 public User findUserByEmail(String email);
245 * Returns a list of users matching specified username
247 * @param username the email of the User
250 public List<User> getUsersByUserNameLike(String username);
253 * Returns a list of users matching specified username or email
257 public List<User> getUsersByUserNameOrEmailLike(String query);
260 * Returns a list of All Shared root folders of a user.
262 * @param userId the ID of the User
263 * @return the list of shared root folders
264 * @throws ObjectNotFoundException if the user cannot be found
266 public List<Folder> getSharedRootFolders(Long userId) throws ObjectNotFoundException;
269 * Returns a list of all shared files of a user, not contained in a shared folder.
271 * @param userId the ID of the User
272 * @return the list of shared files
273 * @throws ObjectNotFoundException if the user cannot be found
275 public List<FileHeader> getSharedFilesNotInSharedFolders(Long userId) throws ObjectNotFoundException;
278 * Returns a list of all shared files of a user.
280 * @param userId the ID of the User
281 * @return the list of shared files
282 * @throws ObjectNotFoundException if the user cannot be found
284 public List<FileHeader> getSharedFiles(Long userId) throws ObjectNotFoundException;
287 * Returns a list of all shared folders of a user.
289 * @param userId the ID of the User
290 * @return the list of shared folders
291 * @throws ObjectNotFoundException if the user cannot be found
293 public List<Folder> getSharedFolders(Long userId) throws ObjectNotFoundException;
296 * Returns a list of folders of user with permissions for specified group
298 * @param userId the ID of the User
299 * @return the list of shared root folders
301 * @throws ObjectNotFoundException if the user cannot be found
303 public List<Folder> getFoldersPermittedForGroup(Long userId, Long groupId) throws ObjectNotFoundException;
306 * Returns a list of users sharing files to specified user
308 * @param userId the ID of the User
309 * @return the list of users sharing files to selected user
310 * @throws ObjectNotFoundException if the user cannot be found
312 public List<User> getUsersSharingFoldersForUser(Long userId) throws ObjectNotFoundException;
315 * Returns a list of users sharing files to specified user
317 * @param userId the ID of the User
318 * @return the list of users sharing files to selected user
319 * @throws ObjectNotFoundException if the user cannot be found
321 public List<User> getUsersSharingFilesForUser(Long userId) throws ObjectNotFoundException;
324 * Returns a list of All Shared root folders of a user that calling user has permissions to read them at least.
326 * @param userId the ID of the User
327 * @param callingUserId
328 * @return the list of shared root folders
329 * @throws ObjectNotFoundException if the user cannot be found
331 public List<Folder> getSharedRootFolders(Long userId, Long callingUserId) throws ObjectNotFoundException;
334 * Returns a list of All Shared files of a user not contained in a shared folder that calling user has permissions.
336 * @param userId the ID of the User
337 * @param callingUserId
338 * @return the list of shared files
339 * @throws ObjectNotFoundException if the user cannot be found
341 public List<FileHeader> getSharedFiles(Long userId, Long callingUserId) throws ObjectNotFoundException;
347 * @return list of files that match query
348 * @throws ObjectNotFoundException
350 public List<FileHeader> searchFiles(Long userId, String query) throws ObjectNotFoundException;
353 * Find the nonce object for the specified encoded nonce, that should be
354 * associated with the specified user.
356 * @param nonce the issued nonce in Base64 encoding
357 * @param userId the ID of the user for whom this nonce should have been issued
358 * @return the retrieved nonce object
359 * @throws ObjectNotFoundException if the nonce or user were not found
361 public Nonce getNonce(String nonce, Long userId) throws ObjectNotFoundException;
364 * Calculates total file size of user.
366 * @param userId the ID of the user
367 * @return the aggregate size of all the user's files
369 public Long getFileSize(Long userId);
372 * Calculates total file count of user.
374 * @param userId the ID of the user
375 * @return the total number of files in the user's namespace
377 public Long getFileCount(Long userId);
380 * This method returns all file ids for rebuilding the search index
382 * @return a list of Long file ids
384 public List<Long> getAllFileIds();
386 public FileUploadStatus getFileUploadStatus(Long userId, String fileName);
389 * Fetch the file body with the specified version number.
391 * @param fileId the ID of the file header
392 * @param version the version number
393 * @return the file body
394 * @throws ObjectNotFoundException if the file body was not found
396 public FileBody getFileVersion(Long fileId, int version) throws ObjectNotFoundException;
399 * Update accounting info for given user.
400 * Adds bandwidth used to appropriate time period bucket.
401 * Bucket is created if needed.
403 * @param user The user to update
404 * @param date Date of transaction
405 * @param bandwidthDiff Bandwidth used; positive for addition,
406 * negative for subtraction (e.g. to rollback)
408 public void updateAccounting(User user, Date date, long bandwidthDiff);
411 * Retrieves available user classes.
414 public List<UserClass> getUserClasses();
417 * Find the invite for the specified invitation code.
419 * @param code the invitation code
420 * @return the Invitation or null if not found
422 public Invitation findInvite(String code);
425 * Retrieve the user class for coupon-bearing users.
427 public UserClass findCouponUserClass();
430 * Gets the user count.
432 * @param userClass the user class to use or null to retrieve system statistics
433 * @return the user count
435 public Long getUserCount(UserClass userClass);
438 * Gets the file count.
440 * @param userClass the user class to use or null to retrieve system statistics
441 * @return the file count
443 public Long getFileCount(UserClass userClass);
446 * Gets the file size.
448 * @param userClass the user class to use or null to retrieve system statistics
449 * @return the file size
451 public Long getFileSize(UserClass userClass);
453 public List<User> getUsersByLastLogin(Date lastLoginDate);
455 public List<User> getUsersByLastLogin(Date lastLoginDate, int firstResult, int maxResult);
457 public Long getCountUsersByLastLogin(Date lastLoginDate);
459 public List<User> getInactiveUsers();
461 public List<FileHeader> searchFileByFilename(String filename);
463 public Long getBandwithUsed(UserClass userClass, Date date);
465 public List<AccountingInfo> getAccountingInfo(User user);
467 public AccountingInfo getAccountingInfo(User user, Date date);
470 * Returns a list of files of user with permissions for specified group
472 * @param userId the ID of the User
473 * @return the list of shared root files
475 * @throws ObjectNotFoundException if the user cannot be found
477 public List<FileHeader> getFilesPermittedForGroup(Long userId, Long groupId) throws ObjectNotFoundException;
480 * Gets a file with tags initialized, cause indexing does not always run within a transaction (e.g. during rebuild)
484 * @throws ObjectNotFoundException
486 public FileHeader getFileForIndexing(Long id) throws ObjectNotFoundException;
492 List<FileHeader> getSharingFilesForUser(Long userId);
498 List<Folder> getSharingFoldersForUser(Long userId);
504 List<Group> getGroupsContainingUser(Long userId);
510 List<FileUploadStatus> getUploadStatus(Long userId);
516 int deletePermissionsNotCorrespondingToFilesAndFolders(Long userId);
519 * Returns a list of the top two entries related to the date that a user logged in the service.
520 * The first entry is related to the current session user login
521 * and the latter is related to the user's last login
524 * @return a list of last user login and the current session user login
526 public List<UserLogin> getLoginsForUser (Long userId);
529 * Returns a list of all entries related to the date that a user logged in the service.
532 * @return a list of last user login and the current session user login
534 public List<UserLogin> getAllLoginsForUser (Long userId);
540 User getUserByUserName(String username);
546 FileLock getLockById(String id);
552 FileLock getLockByToken(String tokenId);
557 void removeLock(FileLock lock);
563 FileLock saveOrUpdateLock(FileLock lock);
569 WebDavNonce saveOrUpdateWebDavNonce(WebDavNonce lock);
574 void removeWebDavNonce(WebDavNonce lock);
580 WebDavNonce getWebDavNonce(String tokenId);