2 * Copyright 2007, 2008, 2009 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.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;
30 import java.util.Date;
31 import java.util.List;
34 import javax.ejb.Local;
37 * This class serves as a facade in front of the persistence library so client
38 * classes can be independent of the persistence implementation.
43 public interface GSSDAO {
46 * Creates the given object in the persistent storage.
48 * @param obj The object to be saved or updated
50 public void create(Object obj);
53 * Updates by re-attaching the given object to the persistence context.
55 * @param obj The object to be updated
57 public void update(Object obj);
60 * Refreshes an object by re-attaching it to the persistence context.
62 * @param obj the supplied object
64 public void refresh(Object obj);
67 * Deletes the specified entity from the persistent storage.
69 * @param entity the object to be deleted
71 public void delete(Object entity);
74 * Returns an Entity of the specified class with the specified id
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
82 public <T> T getEntityById(Class<T> _class, Object _id) throws ObjectNotFoundException;
85 * Returns the list of Groups that belong to a particular User.
87 * @param userId the ID of the specified User
88 * @return a List of Group objects
89 * @throws ObjectNotFoundException
91 public List<Group> getGroups(Long userId) throws ObjectNotFoundException;
94 * Retrieves the root folder for the specified user. The caller must ensure
95 * that the userId exists.
99 * @throws ObjectNotFoundException if no Folder was found
101 public Folder getRootFolder(Long userId) throws gr.ebs.gss.client.exceptions.ObjectNotFoundException;
104 * Retrieves the user for the requested username.
106 * @param username the username specified
107 * @return the user object
108 * @throws ObjectNotFoundException if no user was found
110 public User getUser(final String username) throws ObjectNotFoundException;
113 * Returns a list of files contained in the folder specified by its id, CAUTION: it does not return files marked as deleted
117 * @param ignoreDeleted
118 * @return List<FileHeader>
119 * @throws ObjectNotFoundException
121 @SuppressWarnings("unchecked")
122 public List<FileHeader> getFiles(Long folderId, Long userId, boolean ignoreDeleted) throws ObjectNotFoundException;
125 * Returns a list of deleted files of user specified by userId
128 * @return List<FileHeader>
129 * @throws ObjectNotFoundException
131 @SuppressWarnings("unchecked")
132 public List<FileHeader> getDeletedFiles(Long userId) throws ObjectNotFoundException;
135 * Returns a list of deleted root folders of user specified by userId
138 * @return List<Folder>
139 * @throws ObjectNotFoundException
141 @SuppressWarnings("unchecked")
142 public List<Folder> getDeletedRootFolders(Long userId) throws ObjectNotFoundException;
145 * Returns a list of users for the specified group
149 * @throws ObjectNotFoundException
151 public List<User> getUsers(Long groupId) throws ObjectNotFoundException;
154 * Checks if a folder or file with the specified name exists under the
160 * @throws ObjectNotFoundException
161 * @throws ObjectNotFoundException
163 public boolean existsFolderOrFile(Long parentId, String name) throws ObjectNotFoundException;
166 * Checks if a folder with the specified name exists for the specified user.
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
173 public boolean existsGroup(Long userId, String name) throws ObjectNotFoundException;
176 * Retrieves all tags defined by the specified user
179 * @return Set<String> A set of string tags
180 * @throws ObjectNotFoundException if the user was null
182 public Set<String> getUserTags(final Long userId) throws ObjectNotFoundException;
185 * Flushes the persistence context
190 * Retrieve the file with the supplied name that is contained
191 * in a folder with the specified ID.
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
199 public FileHeader getFile(Long folderId, String name) throws ObjectNotFoundException;
202 * Retrieve the folder with the supplied name that is contained
203 * in a folder with the specified ID.
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
211 public Folder getFolder(Long parentId, String name) throws ObjectNotFoundException;
214 * Search the system for a user with the specified username.
215 * If no such user is found, the method returns null.
217 * @param username the username to search for
218 * @return the User object with the specified username
220 public User findUser(String username);
223 * Search the system for a user with the specified email address.
224 * If no such user is found, the method returns null.
226 public User findUserByEmail(String email);
229 * Returns a list of users matching specified username
231 * @param username the email of the User
234 public List<User> getUsersByUserNameLike(String username);
237 * Returns a list of All Shared root folders of a user.
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
243 public List<Folder> getSharedRootFolders(Long userId) throws ObjectNotFoundException;
246 * Returns a list of all shared files of a user, not contained in a shared folder.
248 * @param userId the ID of the User
249 * @return the list of shared files
250 * @throws ObjectNotFoundException if the user cannot be found
252 public List<FileHeader> getSharedFilesNotInSharedFolders(Long userId) throws ObjectNotFoundException;
255 * Returns a list of all shared files of a user.
257 * @param userId the ID of the User
258 * @return the list of shared files
259 * @throws ObjectNotFoundException if the user cannot be found
261 public List<FileHeader> getSharedFiles(Long userId) throws ObjectNotFoundException;
264 * Returns a list of all shared folders of a user.
266 * @param userId the ID of the User
267 * @return the list of shared folders
268 * @throws ObjectNotFoundException if the user cannot be found
270 public List<Folder> getSharedFolders(Long userId) throws ObjectNotFoundException;
273 * Returns a list of folders of user with permissions for specified group
275 * @param userId the ID of the User
276 * @return the list of shared root folders
278 * @throws ObjectNotFoundException if the user cannot be found
280 public List<Folder> getFoldersPermittedForGroup(Long userId, Long groupId) throws ObjectNotFoundException;
283 * Returns a list of users sharing files to specified user
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
289 public List<User> getUsersSharingFoldersForUser(Long userId) throws ObjectNotFoundException;
292 * Returns a list of users sharing files to specified user
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
298 public List<User> getUsersSharingFilesForUser(Long userId) throws ObjectNotFoundException;
301 * Returns a list of All Shared root folders of a user that calling user has permissions to read them at least.
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
308 public List<Folder> getSharedRootFolders(Long userId, Long callingUserId) throws ObjectNotFoundException;
311 * Returns a list of All Shared files of a user not contained in a shared folder that calling user has permissions.
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
318 public List<FileHeader> getSharedFiles(Long userId, Long callingUserId) throws ObjectNotFoundException;
324 * @return list of files that match query
325 * @throws ObjectNotFoundException
327 public List<FileHeader> searchFiles(Long userId, String query) throws ObjectNotFoundException;
330 * Find the nonce object for the specified encoded nonce, that should be
331 * associated with the specified user.
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
338 public Nonce getNonce(String nonce, Long userId) throws ObjectNotFoundException;
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
345 * @return the {@link FileHeader} with initialized tags
346 * @throws ObjectNotFoundException when a file with the specified id does not exist
348 public FileHeader getFileForIndexing(Long id) 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);