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;
33 import java.util.Date;
34 import java.util.List;
37 import javax.ejb.Local;
40 * This class serves as a facade in front of the persistence library so client
41 * classes can be independent of the persistence implementation.
46 public interface GSSDAO {
49 * Creates the given object in the persistent storage.
51 * @param obj The object to be saved or updated
53 public void create(Object obj);
56 * Updates by re-attaching the given object to the persistence context.
58 * @param obj The object to be updated
60 public void update(Object obj);
63 * Refreshes an object by re-attaching it to the persistence context.
65 * @param obj the supplied object
67 public void refresh(Object obj);
70 * Deletes the specified entity from the persistent storage.
72 * @param entity the object to be deleted
74 public void delete(Object entity);
77 * Returns an Entity of the specified class with the specified id
79 * @param <T> The type of the entity
80 * @param _class the Class of the entity
81 * @param _id the id of the entity
82 * @return the Object found
83 * @throws ObjectNotFoundException if the Object was not found
85 public <T> T getEntityById(Class<T> _class, Object _id) throws ObjectNotFoundException;
88 * Returns the list of Groups that belong to a particular User.
90 * @param userId the ID of the specified User
91 * @return a List of Group objects
92 * @throws ObjectNotFoundException
94 public List<Group> getGroups(Long userId) throws ObjectNotFoundException;
97 * Retrieves the root folder for the specified user. The caller must ensure
98 * that the userId exists.
102 * @throws ObjectNotFoundException if no Folder was found
104 public Folder getRootFolder(Long userId) throws gr.ebs.gss.client.exceptions.ObjectNotFoundException;
107 * Retrieves the user for the requested username.
109 * @param username the username specified
110 * @return the user object
111 * @throws ObjectNotFoundException if no user was found
113 public User getUser(final String username) throws ObjectNotFoundException;
116 * Returns a list of files contained in the folder specified by its id, CAUTION: it does not return files marked as deleted
120 * @param ignoreDeleted
121 * @return List<FileHeader>
122 * @throws ObjectNotFoundException
124 @SuppressWarnings("unchecked")
125 public List<FileHeader> getFiles(Long folderId, Long userId, boolean ignoreDeleted) throws ObjectNotFoundException;
128 * Returns a list of deleted files of user specified by userId
131 * @return List<FileHeader>
132 * @throws ObjectNotFoundException
134 @SuppressWarnings("unchecked")
135 public List<FileHeader> getDeletedFiles(Long userId) throws ObjectNotFoundException;
138 * Returns a list of deleted root folders of user specified by userId
141 * @return List<Folder>
142 * @throws ObjectNotFoundException
144 @SuppressWarnings("unchecked")
145 public List<Folder> getDeletedRootFolders(Long userId) throws ObjectNotFoundException;
148 * Returns a list of users for the specified group
152 * @throws ObjectNotFoundException
154 public List<User> getUsers(Long groupId) throws ObjectNotFoundException;
157 * Checks if a folder or file with the specified name exists under the
163 * @throws ObjectNotFoundException
164 * @throws ObjectNotFoundException
166 public boolean existsFolderOrFile(Long parentId, String name) throws ObjectNotFoundException;
169 * Checks if a folder with the specified name exists for the specified user.
171 * @param userId the owner of the group
172 * @param name the name of the group
173 * @return true if a group with the same name exists
174 * @throws ObjectNotFoundException
176 public boolean existsGroup(Long userId, String name) throws ObjectNotFoundException;
179 * Retrieves all tags defined by the specified user
182 * @return Set<String> A set of string tags
183 * @throws ObjectNotFoundException if the user was null
185 public Set<String> getUserTags(final Long userId) throws ObjectNotFoundException;
188 * Flushes the persistence context
193 * Retrieve the file with the supplied name that is contained
194 * in a folder with the specified ID.
196 * @param folderId the ID of the parent folder
197 * @param name the name of the file
198 * @return the file found
199 * @throws ObjectNotFoundException if the file or parent folder was not found,
200 * with the exception message mentioning the precise problem
202 public FileHeader getFile(Long folderId, String name) throws ObjectNotFoundException;
205 * Retrieve the folder with the supplied name that is contained
206 * in a folder with the specified ID.
208 * @param parentId the ID of the parent folder
209 * @param name the name of the folder
210 * @return the folder found
211 * @throws ObjectNotFoundException if the folder or parent was not found,
212 * with the exception message mentioning the precise problem
214 public Folder getFolder(Long parentId, String name) throws ObjectNotFoundException;
217 * Search the system for a user with the specified username.
218 * If no such user is found, the method returns null.
220 * @param username the username to search for
221 * @return the User object with the specified username
223 public User findUser(String username);
226 * Search the system for a user with the specified email address.
227 * If no such user is found, the method returns null.
229 public User findUserByEmail(String email);
232 * Returns a list of users matching specified username
234 * @param username the email of the User
237 public List<User> getUsersByUserNameLike(String username);
240 * Returns a list of users matching specified username or email
244 public List<User> getUsersByUserNameOrEmailLike(String query);
247 * Returns a list of All Shared root folders of a user.
249 * @param userId the ID of the User
250 * @return the list of shared root folders
251 * @throws ObjectNotFoundException if the user cannot be found
253 public List<Folder> getSharedRootFolders(Long userId) throws ObjectNotFoundException;
256 * Returns a list of all shared files of a user, not contained in a shared folder.
258 * @param userId the ID of the User
259 * @return the list of shared files
260 * @throws ObjectNotFoundException if the user cannot be found
262 public List<FileHeader> getSharedFilesNotInSharedFolders(Long userId) throws ObjectNotFoundException;
265 * Returns a list of all shared files of a user.
267 * @param userId the ID of the User
268 * @return the list of shared files
269 * @throws ObjectNotFoundException if the user cannot be found
271 public List<FileHeader> getSharedFiles(Long userId) throws ObjectNotFoundException;
274 * Returns a list of all shared folders of a user.
276 * @param userId the ID of the User
277 * @return the list of shared folders
278 * @throws ObjectNotFoundException if the user cannot be found
280 public List<Folder> getSharedFolders(Long userId) throws ObjectNotFoundException;
283 * Returns a list of folders of user with permissions for specified group
285 * @param userId the ID of the User
286 * @return the list of shared root folders
288 * @throws ObjectNotFoundException if the user cannot be found
290 public List<Folder> getFoldersPermittedForGroup(Long userId, Long groupId) throws ObjectNotFoundException;
293 * Returns a list of users sharing files to specified user
295 * @param userId the ID of the User
296 * @return the list of users sharing files to selected user
297 * @throws ObjectNotFoundException if the user cannot be found
299 public List<User> getUsersSharingFoldersForUser(Long userId) throws ObjectNotFoundException;
302 * Returns a list of users sharing files to specified user
304 * @param userId the ID of the User
305 * @return the list of users sharing files to selected user
306 * @throws ObjectNotFoundException if the user cannot be found
308 public List<User> getUsersSharingFilesForUser(Long userId) throws ObjectNotFoundException;
311 * Returns a list of All Shared root folders of a user that calling user has permissions to read them at least.
313 * @param userId the ID of the User
314 * @param callingUserId
315 * @return the list of shared root folders
316 * @throws ObjectNotFoundException if the user cannot be found
318 public List<Folder> getSharedRootFolders(Long userId, Long callingUserId) throws ObjectNotFoundException;
321 * Returns a list of All Shared files of a user not contained in a shared folder that calling user has permissions.
323 * @param userId the ID of the User
324 * @param callingUserId
325 * @return the list of shared files
326 * @throws ObjectNotFoundException if the user cannot be found
328 public List<FileHeader> getSharedFiles(Long userId, Long callingUserId) throws ObjectNotFoundException;
334 * @return list of files that match query
335 * @throws ObjectNotFoundException
337 public List<FileHeader> searchFiles(Long userId, String query) throws ObjectNotFoundException;
340 * Find the nonce object for the specified encoded nonce, that should be
341 * associated with the specified user.
343 * @param nonce the issued nonce in Base64 encoding
344 * @param userId the ID of the user for whom this nonce should have been issued
345 * @return the retrieved nonce object
346 * @throws ObjectNotFoundException if the nonce or user were not found
348 public Nonce getNonce(String nonce, Long userId) throws ObjectNotFoundException;
351 * Calculates total file size of user.
353 * @param userId the ID of the user
354 * @return the aggregate size of all the user's files
356 public Long getFileSize(Long userId);
359 * Calculates total file count of user.
361 * @param userId the ID of the user
362 * @return the total number of files in the user's namespace
364 public Long getFileCount(Long userId);
367 * This method returns all file ids for rebuilding the search index
369 * @return a list of Long file ids
371 public List<Long> getAllFileIds();
373 public FileUploadStatus getFileUploadStatus(Long userId, String fileName);
376 * Fetch the file body with the specified version number.
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
383 public FileBody getFileVersion(Long fileId, int version) throws ObjectNotFoundException;
386 * Update accounting info for given user.
387 * Adds bandwidth used to appropriate time period bucket.
388 * Bucket is created if needed.
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)
395 public void updateAccounting(User user, Date date, long bandwidthDiff);
398 * Retrieves available user classes.
401 public List<UserClass> getUserClasses();
404 * Find the invite for the specified invitation code.
406 * @param code the invitation code
407 * @return the Invitation or null if not found
409 public Invitation findInvite(String code);
412 * Retrieve the user class for coupon-bearing users.
414 public UserClass findCouponUserClass();
417 * Gets the user count.
419 * @param userClass the user class to use or null to retrieve system statistics
420 * @return the user count
422 public Long getUserCount(UserClass userClass);
425 * Gets the file count.
427 * @param userClass the user class to use or null to retrieve system statistics
428 * @return the file count
430 public Long getFileCount(UserClass userClass);
433 * Gets the file size.
435 * @param userClass the user class to use or null to retrieve system statistics
436 * @return the file size
438 public Long getFileSize(UserClass userClass);
440 public List<User> getUsersByLastLogin(Date lastLoginDate);
442 public List<User> getUsersByLastLogin(Date lastLoginDate, int firstResult, int maxResult);
444 public Long getCountUsersByLastLogin(Date lastLoginDate);
446 public List<User> getInactiveUsers();
448 public List<FileHeader> searchFileByFilename(String filename);
450 public Long getBandwithUsed(UserClass userClass, Date date);
452 public List<AccountingInfo> getAccountingInfo(User user);
454 public AccountingInfo getAccountingInfo(User user, Date date);
457 * Returns a list of files of user with permissions for specified group
459 * @param userId the ID of the User
460 * @return the list of shared root files
462 * @throws ObjectNotFoundException if the user cannot be found
464 public List<FileHeader> getFilesPermittedForGroup(Long userId, Long groupId) throws ObjectNotFoundException;
467 * Gets a file with tags initialized, cause indexing does not always run within a transaction (e.g. during rebuild)
471 * @throws ObjectNotFoundException
473 public FileHeader getFileForIndexing(Long id) throws ObjectNotFoundException;
479 List<FileHeader> getSharingFilesForUser(Long userId);
485 List<Folder> getSharingFoldersForUser(Long userId);
491 List<Group> getGroupsContainingUser(Long userId);
497 List<FileUploadStatus> getUploadStatus(Long userId);
503 int deletePermissionsNotCorrespondingToFilesAndFolders(Long userId);