root / src / gr / ebs / gss / server / ejb / GSSDAO.java @ 623:66f69a7348ed
History | View | Annotate | Download (14.1 kB)
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 |
|
33 |
import java.util.Date; |
34 |
import java.util.List; |
35 |
import java.util.Set; |
36 |
|
37 |
import javax.ejb.Local; |
38 |
|
39 |
/**
|
40 |
* This class serves as a facade in front of the persistence library so client
|
41 |
* classes can be independent of the persistence implementation.
|
42 |
*
|
43 |
* @author past
|
44 |
*/
|
45 |
@Local
|
46 |
public interface GSSDAO { |
47 |
|
48 |
/**
|
49 |
* Creates the given object in the persistent storage.
|
50 |
*
|
51 |
* @param obj The object to be saved or updated
|
52 |
*/
|
53 |
public void create(Object obj); |
54 |
|
55 |
/**
|
56 |
* Updates by re-attaching the given object to the persistence context.
|
57 |
*
|
58 |
* @param obj The object to be updated
|
59 |
*/
|
60 |
public void update(Object obj); |
61 |
|
62 |
/**
|
63 |
* Refreshes an object by re-attaching it to the persistence context.
|
64 |
*
|
65 |
* @param obj the supplied object
|
66 |
*/
|
67 |
public void refresh(Object obj); |
68 |
|
69 |
/**
|
70 |
* Deletes the specified entity from the persistent storage.
|
71 |
*
|
72 |
* @param entity the object to be deleted
|
73 |
*/
|
74 |
public void delete(Object entity); |
75 |
|
76 |
/**
|
77 |
* Returns an Entity of the specified class with the specified id
|
78 |
*
|
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
|
84 |
*/
|
85 |
public <T> T getEntityById(Class<T> _class, Object _id) throws ObjectNotFoundException; |
86 |
|
87 |
/**
|
88 |
* Returns the list of Groups that belong to a particular User.
|
89 |
*
|
90 |
* @param userId the ID of the specified User
|
91 |
* @return a List of Group objects
|
92 |
* @throws ObjectNotFoundException
|
93 |
*/
|
94 |
public List<Group> getGroups(Long userId) throws ObjectNotFoundException; |
95 |
|
96 |
/**
|
97 |
* Retrieves the root folder for the specified user. The caller must ensure
|
98 |
* that the userId exists.
|
99 |
*
|
100 |
* @param userId
|
101 |
* @return Folder
|
102 |
* @throws ObjectNotFoundException if no Folder was found
|
103 |
*/
|
104 |
public Folder getRootFolder(Long userId) throws gr.ebs.gss.client.exceptions.ObjectNotFoundException; |
105 |
|
106 |
/**
|
107 |
* Retrieves the user for the requested username.
|
108 |
*
|
109 |
* @param username the username specified
|
110 |
* @return the user object
|
111 |
* @throws ObjectNotFoundException if no user was found
|
112 |
*/
|
113 |
public User getUser(final String username) throws ObjectNotFoundException; |
114 |
|
115 |
/**
|
116 |
* Returns a list of files contained in the folder specified by its id, CAUTION: it does not return files marked as deleted
|
117 |
*
|
118 |
* @param folderId
|
119 |
* @param userId
|
120 |
* @param ignoreDeleted
|
121 |
* @return List<FileHeader>
|
122 |
* @throws ObjectNotFoundException
|
123 |
*/
|
124 |
@SuppressWarnings("unchecked") |
125 |
public List<FileHeader> getFiles(Long folderId, Long userId, boolean ignoreDeleted) throws ObjectNotFoundException; |
126 |
|
127 |
/**
|
128 |
* Returns a list of deleted files of user specified by userId
|
129 |
*
|
130 |
* @param userId
|
131 |
* @return List<FileHeader>
|
132 |
* @throws ObjectNotFoundException
|
133 |
*/
|
134 |
@SuppressWarnings("unchecked") |
135 |
public List<FileHeader> getDeletedFiles(Long userId) throws ObjectNotFoundException; |
136 |
|
137 |
/**
|
138 |
* Returns a list of deleted root folders of user specified by userId
|
139 |
*
|
140 |
* @param userId
|
141 |
* @return List<Folder>
|
142 |
* @throws ObjectNotFoundException
|
143 |
*/
|
144 |
@SuppressWarnings("unchecked") |
145 |
public List<Folder> getDeletedRootFolders(Long userId) throws ObjectNotFoundException; |
146 |
|
147 |
/**
|
148 |
* Returns a list of users for the specified group
|
149 |
*
|
150 |
* @param groupId
|
151 |
* @return List<User>
|
152 |
* @throws ObjectNotFoundException
|
153 |
*/
|
154 |
public List<User> getUsers(Long groupId) throws ObjectNotFoundException; |
155 |
|
156 |
/**
|
157 |
* Checks if a folder or file with the specified name exists under the
|
158 |
* specified parent.
|
159 |
*
|
160 |
* @param parentId
|
161 |
* @param name
|
162 |
* @return boolean
|
163 |
* @throws ObjectNotFoundException
|
164 |
* @throws ObjectNotFoundException
|
165 |
*/
|
166 |
public boolean existsFolderOrFile(Long parentId, String name) throws ObjectNotFoundException; |
167 |
|
168 |
/**
|
169 |
* Checks if a folder with the specified name exists for the specified user.
|
170 |
*
|
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
|
175 |
*/
|
176 |
public boolean existsGroup(Long userId, String name) throws ObjectNotFoundException; |
177 |
|
178 |
/**
|
179 |
* Retrieves all tags defined by the specified user
|
180 |
*
|
181 |
* @param userId
|
182 |
* @return Set<String> A set of string tags
|
183 |
* @throws ObjectNotFoundException if the user was null
|
184 |
*/
|
185 |
public Set<String> getUserTags(final Long userId) throws ObjectNotFoundException; |
186 |
|
187 |
/**
|
188 |
* Flushes the persistence context
|
189 |
*/
|
190 |
public void flush(); |
191 |
|
192 |
/**
|
193 |
* Retrieve the file with the supplied name that is contained
|
194 |
* in a folder with the specified ID.
|
195 |
*
|
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
|
201 |
*/
|
202 |
public FileHeader getFile(Long folderId, String name) throws ObjectNotFoundException; |
203 |
|
204 |
/**
|
205 |
* Retrieve the folder with the supplied name that is contained
|
206 |
* in a folder with the specified ID.
|
207 |
*
|
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
|
213 |
*/
|
214 |
public Folder getFolder(Long parentId, String name) throws ObjectNotFoundException; |
215 |
|
216 |
/**
|
217 |
* Search the system for a user with the specified username.
|
218 |
* If no such user is found, the method returns null.
|
219 |
*
|
220 |
* @param username the username to search for
|
221 |
* @return the User object with the specified username
|
222 |
*/
|
223 |
public User findUser(String username); |
224 |
|
225 |
/**
|
226 |
* Search the system for a user with the specified email address.
|
227 |
* If no such user is found, the method returns null.
|
228 |
*/
|
229 |
public User findUserByEmail(String email); |
230 |
|
231 |
/**
|
232 |
* Returns a list of users matching specified username
|
233 |
*
|
234 |
* @param username the email of the User
|
235 |
* @return List<User>
|
236 |
*/
|
237 |
public List<User> getUsersByUserNameLike(String username); |
238 |
|
239 |
/**
|
240 |
* Returns a list of users matching specified username or email
|
241 |
* @param query
|
242 |
* @return List<User>
|
243 |
*/
|
244 |
public List<User> getUsersByUserNameOrEmailLike(String query); |
245 |
|
246 |
/**
|
247 |
* Returns a list of All Shared root folders of a user.
|
248 |
*
|
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
|
252 |
*/
|
253 |
public List<Folder> getSharedRootFolders(Long userId) throws ObjectNotFoundException; |
254 |
|
255 |
/**
|
256 |
* Returns a list of all shared files of a user, not contained in a shared folder.
|
257 |
*
|
258 |
* @param userId the ID of the User
|
259 |
* @return the list of shared files
|
260 |
* @throws ObjectNotFoundException if the user cannot be found
|
261 |
*/
|
262 |
public List<FileHeader> getSharedFilesNotInSharedFolders(Long userId) throws ObjectNotFoundException; |
263 |
|
264 |
/**
|
265 |
* Returns a list of all shared files of a user.
|
266 |
*
|
267 |
* @param userId the ID of the User
|
268 |
* @return the list of shared files
|
269 |
* @throws ObjectNotFoundException if the user cannot be found
|
270 |
*/
|
271 |
public List<FileHeader> getSharedFiles(Long userId) throws ObjectNotFoundException; |
272 |
|
273 |
/**
|
274 |
* Returns a list of all shared folders of a user.
|
275 |
*
|
276 |
* @param userId the ID of the User
|
277 |
* @return the list of shared folders
|
278 |
* @throws ObjectNotFoundException if the user cannot be found
|
279 |
*/
|
280 |
public List<Folder> getSharedFolders(Long userId) throws ObjectNotFoundException; |
281 |
|
282 |
/**
|
283 |
* Returns a list of folders of user with permissions for specified group
|
284 |
*
|
285 |
* @param userId the ID of the User
|
286 |
* @return the list of shared root folders
|
287 |
* @param groupId
|
288 |
* @throws ObjectNotFoundException if the user cannot be found
|
289 |
*/
|
290 |
public List<Folder> getFoldersPermittedForGroup(Long userId, Long groupId) throws ObjectNotFoundException; |
291 |
|
292 |
/**
|
293 |
* Returns a list of users sharing files to specified user
|
294 |
*
|
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
|
298 |
*/
|
299 |
public List<User> getUsersSharingFoldersForUser(Long userId) throws ObjectNotFoundException; |
300 |
|
301 |
/**
|
302 |
* Returns a list of users sharing files to specified user
|
303 |
*
|
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
|
307 |
*/
|
308 |
public List<User> getUsersSharingFilesForUser(Long userId) throws ObjectNotFoundException; |
309 |
|
310 |
/**
|
311 |
* Returns a list of All Shared root folders of a user that calling user has permissions to read them at least.
|
312 |
*
|
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
|
317 |
*/
|
318 |
public List<Folder> getSharedRootFolders(Long userId, Long callingUserId) throws ObjectNotFoundException; |
319 |
|
320 |
/**
|
321 |
* Returns a list of All Shared files of a user not contained in a shared folder that calling user has permissions.
|
322 |
*
|
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
|
327 |
*/
|
328 |
public List<FileHeader> getSharedFiles(Long userId, Long callingUserId) throws ObjectNotFoundException; |
329 |
|
330 |
/**
|
331 |
* Search Files
|
332 |
* @param userId
|
333 |
* @param query
|
334 |
* @return list of files that match query
|
335 |
* @throws ObjectNotFoundException
|
336 |
*/
|
337 |
public List<FileHeader> searchFiles(Long userId, String query) throws ObjectNotFoundException; |
338 |
|
339 |
/**
|
340 |
* Find the nonce object for the specified encoded nonce, that should be
|
341 |
* associated with the specified user.
|
342 |
*
|
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
|
347 |
*/
|
348 |
public Nonce getNonce(String nonce, Long userId) throws ObjectNotFoundException; |
349 |
|
350 |
/**
|
351 |
* Loads the file for indexing. That means the file is loaded with the lazy fields needed for inedexing, initialized.
|
352 |
* For now only the tags need to be initialized
|
353 |
*
|
354 |
* @param id
|
355 |
* @return the {@link FileHeader} with initialized tags
|
356 |
* @throws ObjectNotFoundException when a file with the specified id does not exist
|
357 |
*/
|
358 |
public FileHeader getFileForIndexing(Long id) throws ObjectNotFoundException; |
359 |
|
360 |
/**
|
361 |
* Calculates total file size of user.
|
362 |
*
|
363 |
* @param userId the ID of the user
|
364 |
* @return the aggregate size of all the user's files
|
365 |
*/
|
366 |
public Long getFileSize(Long userId); |
367 |
|
368 |
/**
|
369 |
* Calculates total file count of user.
|
370 |
*
|
371 |
* @param userId the ID of the user
|
372 |
* @return the total number of files in the user's namespace
|
373 |
*/
|
374 |
public Long getFileCount(Long userId); |
375 |
|
376 |
/**
|
377 |
* This method returns all file ids for rebuilding the search index
|
378 |
*
|
379 |
* @return a list of Long file ids
|
380 |
*/
|
381 |
public List<Long> getAllFileIds(); |
382 |
|
383 |
public FileUploadStatus getFileUploadStatus(Long userId, String fileName); |
384 |
|
385 |
/**
|
386 |
* Fetch the file body with the specified version number.
|
387 |
*
|
388 |
* @param fileId the ID of the file header
|
389 |
* @param version the version number
|
390 |
* @return the file body
|
391 |
* @throws ObjectNotFoundException if the file body was not found
|
392 |
*/
|
393 |
public FileBody getFileVersion(Long fileId, int version) throws ObjectNotFoundException; |
394 |
|
395 |
/**
|
396 |
* Update accounting info for given user.
|
397 |
* Adds bandwidth used to appropriate time period bucket.
|
398 |
* Bucket is created if needed.
|
399 |
*
|
400 |
* @param user The user to update
|
401 |
* @param date Date of transaction
|
402 |
* @param bandwidthDiff Bandwidth used; positive for addition,
|
403 |
* negative for subtraction (e.g. to rollback)
|
404 |
*/
|
405 |
public void updateAccounting(User user, Date date, long bandwidthDiff); |
406 |
|
407 |
/**
|
408 |
* Retrieves available user classes.
|
409 |
*
|
410 |
*/
|
411 |
public List<UserClass> getUserClasses(); |
412 |
|
413 |
/**
|
414 |
* Find the invite for the specified invitation code.
|
415 |
*
|
416 |
* @param code the invitation code
|
417 |
* @return the Invitation or null if not found
|
418 |
*/
|
419 |
public Invitation findInvite(String code); |
420 |
|
421 |
/**
|
422 |
* Retrieve the user class for coupon-bearing users.
|
423 |
*/
|
424 |
public UserClass findCouponUserClass();
|
425 |
|
426 |
/**
|
427 |
* Gets the user count.
|
428 |
*
|
429 |
* @param userClass the user class to use or null to retrieve system statistics
|
430 |
* @return the user count
|
431 |
*/
|
432 |
public Long getUserCount(UserClass userClass); |
433 |
|
434 |
/**
|
435 |
* Gets the file count.
|
436 |
*
|
437 |
* @param userClass the user class to use or null to retrieve system statistics
|
438 |
* @return the file count
|
439 |
*/
|
440 |
public Long getFileCount(UserClass userClass); |
441 |
|
442 |
/**
|
443 |
* Gets the file size.
|
444 |
*
|
445 |
* @param userClass the user class to use or null to retrieve system statistics
|
446 |
* @return the file size
|
447 |
*/
|
448 |
public Long getFileSize(UserClass userClass); |
449 |
|
450 |
public List<User> getUsersByLastLogin(Date lastLoginDate); |
451 |
|
452 |
public List<User> getUsersByLastLogin(Date lastLoginDate, int firstResult, int maxResult); |
453 |
|
454 |
public Long getCountUsersByLastLogin(Date lastLoginDate); |
455 |
|
456 |
public List<User> getInactiveUsers(); |
457 |
|
458 |
public List<FileHeader> searchFileByFilename(String filename); |
459 |
|
460 |
public Long getBandwithUsed(UserClass userClass, Date date); |
461 |
|
462 |
public List<AccountingInfo> getAccountingInfo(User user); |
463 |
|
464 |
public AccountingInfo getAccountingInfo(User user, Date date); |
465 |
} |