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.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;
34 import java.util.Date;
35 import java.util.List;
38 import javax.ejb.Local;
41 * This class serves as a facade in front of the persistence library so client
42 * classes can be independent of the persistence implementation.
47 public interface GSSDAO {
50 * Creates the given object in the persistent storage.
52 * @param obj The object to be saved or updated
54 public void create(Object obj);
57 * Updates by re-attaching the given object to the persistence context.
59 * @param obj The object to be updated
61 public void update(Object obj);
64 * Refreshes an object by re-attaching it to the persistence context.
66 * @param obj the supplied object
68 public void refresh(Object obj);
71 * Deletes the specified entity from the persistent storage.
73 * @param entity the object to be deleted
75 public void delete(Object entity);
78 * Returns an Entity of the specified class with the specified id
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
86 public <T> T getEntityById(Class<T> _class, Object _id) throws ObjectNotFoundException;
89 * Returns the list of Groups that belong to a particular User.
91 * @param userId the ID of the specified User
92 * @return a List of Group objects
93 * @throws ObjectNotFoundException
95 public List<Group> getGroups(Long userId) throws ObjectNotFoundException;
98 * Retrieves the root folder id for the specified user. The caller must ensure
99 * that the userId exists.
102 * @return Long The id
103 * @throws ObjectNotFoundException if no Folder was found
105 public Long getRootFolderId(final Long userId) throws ObjectNotFoundException;
108 * Retrieves the root folder for the specified user. The caller must ensure
109 * that the userId exists.
113 * @throws ObjectNotFoundException if no Folder was found
115 public Folder getRootFolder(Long userId) throws gr.ebs.gss.client.exceptions.ObjectNotFoundException;
118 * Retrieves the user for the requested username.
120 * @param username the username specified
121 * @return the user object
122 * @throws ObjectNotFoundException if no user was found
124 public User getUser(final String username) throws ObjectNotFoundException;
127 * Returns a list of files contained in the folder specified by its id, CAUTION: it does not return files marked as deleted
131 * @param ignoreDeleted
132 * @return List<FileHeader>
133 * @throws ObjectNotFoundException
135 @SuppressWarnings("unchecked")
136 public List<FileHeader> getFiles(Long folderId, Long userId, boolean ignoreDeleted) throws ObjectNotFoundException;
139 * Returns a list of deleted files of user specified by userId
142 * @return List<FileHeader>
143 * @throws ObjectNotFoundException
145 @SuppressWarnings("unchecked")
146 public List<FileHeader> getDeletedFiles(Long userId) throws ObjectNotFoundException;
149 * Returns a list of deleted root folders of user specified by userId
152 * @return List<Folder>
153 * @throws ObjectNotFoundException
155 @SuppressWarnings("unchecked")
156 public List<Folder> getDeletedRootFolders(Long userId) throws ObjectNotFoundException;
159 * Returns a list of users for the specified group
163 * @throws ObjectNotFoundException
165 public List<User> getUsers(Long groupId) throws ObjectNotFoundException;
168 * Checks if a folder or file with the specified name exists under the
174 * @throws ObjectNotFoundException
175 * @throws ObjectNotFoundException
177 public boolean existsFolderOrFile(Long parentId, String name) throws ObjectNotFoundException;
180 * Checks if a folder with the specified name exists for the specified user.
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
187 public boolean existsGroup(Long userId, String name) throws ObjectNotFoundException;
190 * Retrieves all tags defined by the specified user
193 * @return Set<String> A set of string tags
194 * @throws ObjectNotFoundException if the user was null
196 public Set<String> getUserTags(final Long userId) throws ObjectNotFoundException;
199 * Flushes the persistence context
204 * Retrieve the file with the supplied name that is contained
205 * in a folder with the specified ID.
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
213 public FileHeader getFile(Long folderId, String name) throws ObjectNotFoundException;
216 * Retrieve the folder with the supplied name that is contained
217 * in a folder with the specified ID.
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
225 public Folder getFolder(Long parentId, String name) throws ObjectNotFoundException;
228 * Search the system for a user with the specified username.
229 * If no such user is found, the method returns null.
231 * @param username the username to search for
232 * @return the User object with the specified username
234 public User findUser(String username);
237 * Search the system for a user with the specified email address.
238 * If no such user is found, the method returns null.
240 public User findUserByEmail(String email);
243 * Returns a list of users matching specified username
245 * @param username the email of the User
248 public List<User> getUsersByUserNameLike(String username);
251 * Returns a list of users matching specified username or email
255 public List<User> getUsersByUserNameOrEmailLike(String query);
258 * Returns a list of All Shared root folders of a user.
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
264 public List<Folder> getSharedRootFolders(Long userId) throws ObjectNotFoundException;
267 * Returns a list of all shared files of a user, not contained in a shared folder.
269 * @param userId the ID of the User
270 * @return the list of shared files
271 * @throws ObjectNotFoundException if the user cannot be found
273 public List<FileHeader> getSharedFilesNotInSharedFolders(Long userId) throws ObjectNotFoundException;
276 * Returns a list of all shared files of a user.
278 * @param userId the ID of the User
279 * @return the list of shared files
280 * @throws ObjectNotFoundException if the user cannot be found
282 public List<FileHeader> getSharedFiles(Long userId) throws ObjectNotFoundException;
285 * Returns a list of all shared folders of a user.
287 * @param userId the ID of the User
288 * @return the list of shared folders
289 * @throws ObjectNotFoundException if the user cannot be found
291 public List<Folder> getSharedFolders(Long userId) throws ObjectNotFoundException;
294 * Returns a list of folders of user with permissions for specified group
296 * @param userId the ID of the User
297 * @return the list of shared root folders
299 * @throws ObjectNotFoundException if the user cannot be found
301 public List<Folder> getFoldersPermittedForGroup(Long userId, Long groupId) throws ObjectNotFoundException;
304 * Returns a list of users sharing files to specified user
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
310 public List<User> getUsersSharingFoldersForUser(Long userId) throws ObjectNotFoundException;
313 * Returns a list of users sharing files to specified user
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
319 public List<User> getUsersSharingFilesForUser(Long userId) throws ObjectNotFoundException;
322 * Returns a list of All Shared root folders of a user that calling user has permissions to read them at least.
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
329 public List<Folder> getSharedRootFolders(Long userId, Long callingUserId) throws ObjectNotFoundException;
332 * Returns a list of All Shared files of a user not contained in a shared folder that calling user has permissions.
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
339 public List<FileHeader> getSharedFiles(Long userId, Long callingUserId) throws ObjectNotFoundException;
345 * @return list of files that match query
346 * @throws ObjectNotFoundException
348 public List<FileHeader> searchFiles(Long userId, String query) throws ObjectNotFoundException;
351 * Find the nonce object for the specified encoded nonce, that should be
352 * associated with the specified user.
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
359 public Nonce getNonce(String nonce, Long userId) throws ObjectNotFoundException;
362 * Calculates total file size of user.
364 * @param userId the ID of the user
365 * @return the aggregate size of all the user's files
367 public Long getFileSize(Long userId);
370 * Calculates total file count of user.
372 * @param userId the ID of the user
373 * @return the total number of files in the user's namespace
375 public Long getFileCount(Long userId);
378 * This method returns all file ids for rebuilding the search index
380 * @return a list of Long file ids
382 public List<Long> getAllFileIds();
384 public FileUploadStatus getFileUploadStatus(Long userId, String fileName);
387 * Fetch the file body with the specified version number.
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
394 public FileBody getFileVersion(Long fileId, int version) throws ObjectNotFoundException;
397 * Update accounting info for given user.
398 * Adds bandwidth used to appropriate time period bucket.
399 * Bucket is created if needed.
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)
406 public void updateAccounting(User user, Date date, long bandwidthDiff);
409 * Retrieves available user classes.
412 public List<UserClass> getUserClasses();
415 * Find the invite for the specified invitation code.
417 * @param code the invitation code
418 * @return the Invitation or null if not found
420 public Invitation findInvite(String code);
423 * Retrieve the user class for coupon-bearing users.
425 public UserClass findCouponUserClass();
428 * Gets the user count.
430 * @param userClass the user class to use or null to retrieve system statistics
431 * @return the user count
433 public Long getUserCount(UserClass userClass);
436 * Gets the file count.
438 * @param userClass the user class to use or null to retrieve system statistics
439 * @return the file count
441 public Long getFileCount(UserClass userClass);
444 * Gets the file size.
446 * @param userClass the user class to use or null to retrieve system statistics
447 * @return the file size
449 public Long getFileSize(UserClass userClass);
451 public List<User> getUsersByLastLogin(Date lastLoginDate);
453 public List<User> getUsersByLastLogin(Date lastLoginDate, int firstResult, int maxResult);
455 public Long getCountUsersByLastLogin(Date lastLoginDate);
457 public List<User> getInactiveUsers();
459 public List<FileHeader> searchFileByFilename(String filename);
461 public Long getBandwithUsed(UserClass userClass, Date date);
463 public List<AccountingInfo> getAccountingInfo(User user);
465 public AccountingInfo getAccountingInfo(User user, Date date);
468 * Returns a list of files of user with permissions for specified group
470 * @param userId the ID of the User
471 * @return the list of shared root files
473 * @throws ObjectNotFoundException if the user cannot be found
475 public List<FileHeader> getFilesPermittedForGroup(Long userId, Long groupId) throws ObjectNotFoundException;
478 * Gets a file with tags initialized, cause indexing does not always run within a transaction (e.g. during rebuild)
482 * @throws ObjectNotFoundException
484 public FileHeader getFileForIndexing(Long id) throws ObjectNotFoundException;
490 List<FileHeader> getSharingFilesForUser(Long userId);
496 List<Folder> getSharingFoldersForUser(Long userId);
502 List<Group> getGroupsContainingUser(Long userId);
508 List<FileUploadStatus> getUploadStatus(Long userId);
514 int deletePermissionsNotCorrespondingToFilesAndFolders(Long userId);
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
522 * @return a list of last user login and the current session user login
524 public List<UserLogin> getLoginsForUser (Long userId);
527 * Returns a list of all entries related to the date that a user logged in the service.
530 * @return a list of last user login and the current session user login
532 public List<UserLogin> getAllLoginsForUser (Long userId);