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