ec5f95eac57f68c3f0b7c47c7a734eb53efd218e
[pithos] / gss / src / gr / ebs / gss / server / ejb / ExternalAPI.java
1 /*
2  * Copyright 2007, 2008, 2009 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.DuplicateNameException;
22 import gr.ebs.gss.client.exceptions.GSSIOException;
23 import gr.ebs.gss.client.exceptions.InsufficientPermissionsException;
24 import gr.ebs.gss.client.exceptions.ObjectNotFoundException;
25 import gr.ebs.gss.client.exceptions.QuotaExceededException;
26 import gr.ebs.gss.server.domain.FileUploadStatus;
27 import gr.ebs.gss.server.domain.Nonce;
28 import gr.ebs.gss.server.domain.User;
29 import gr.ebs.gss.server.domain.dto.FileBodyDTO;
30 import gr.ebs.gss.server.domain.dto.FileHeaderDTO;
31 import gr.ebs.gss.server.domain.dto.FolderDTO;
32 import gr.ebs.gss.server.domain.dto.GroupDTO;
33 import gr.ebs.gss.server.domain.dto.PermissionDTO;
34 import gr.ebs.gss.server.domain.dto.StatsDTO;
35 import gr.ebs.gss.server.domain.dto.UserDTO;
36
37 import java.io.File;
38 import java.io.IOException;
39 import java.io.InputStream;
40 import java.util.Date;
41 import java.util.List;
42 import java.util.Set;
43
44 import javax.ejb.Local;
45 import javax.ejb.TransactionAttribute;
46 import javax.ejb.TransactionAttributeType;
47
48 /**
49  * The External API for GSS clients.
50  *
51  * @author past
52  */
53 @Local
54 public interface ExternalAPI {
55
56         /**
57          * Retrieves the root folder for the specified user. The caller must ensure
58          * that the userId exists.
59          *
60          * @param userId
61          * @return Folder
62          * @throws ObjectNotFoundException if no Folder or user was found
63          */
64         public FolderDTO getRootFolder(Long userId) throws ObjectNotFoundException;
65
66         /**
67          * Retrieve the folder with the specified ID.
68          *
69          * @param userId the ID of the current user
70          * @param folderId the ID of the folder to retrieve
71          * @return the folder found
72          * @throws ObjectNotFoundException if the folder or the user was not found
73          * @throws InsufficientPermissionsException if ther user does not have read permissions for folder
74          */
75         public FolderDTO getFolder(Long userId, Long folderId) throws ObjectNotFoundException,
76                         InsufficientPermissionsException;
77
78         /**
79          * Returns the user with the specified ID.
80          *
81          * @param userId The ID of the User to be found
82          * @return The User object
83          * @throws ObjectNotFoundException if the user cannot be found
84          */
85         public User getUser(Long userId) throws ObjectNotFoundException;
86
87         /**
88          * Returns the user with the specified ID.
89          *
90          * @param userId The ID of the User to be found
91          * @return The User object
92          * @throws ObjectNotFoundException if the user cannot be found
93          */
94         public UserDTO getUserDTO(Long userId) throws ObjectNotFoundException;
95
96         /**
97          * Returns the group with the specified ID.
98          *
99          * @param groupId The ID of the Group to be found
100          * @return The Group object
101          * @throws ObjectNotFoundException if the group cannot be found
102          */
103         public GroupDTO getGroup(Long groupId) throws ObjectNotFoundException;
104
105         /**
106          * Returns the group with the specified name that belongs to the
107          * specified user.
108          *
109          * @param userId the ID of the user
110          * @param name the name of the group
111          * @return The Group object
112          * @throws ObjectNotFoundException if the group cannot be found
113          */
114         public GroupDTO getGroup(Long userId, String name) throws ObjectNotFoundException;
115
116         /**
117          * Retrieve the list of groups for a particular user.
118          *
119          * @param userId the ID of the User
120          * @return a List of Groups that belong to the specified User
121          * @throws ObjectNotFoundException if the user was not found
122          */
123         public List<GroupDTO> getGroups(Long userId) throws ObjectNotFoundException;
124
125         /**
126          * Returns a list of files contained in the folder specified by its id.
127          *
128          * @param userId the ID of the User
129          * @param folderId the ID of the folder containing the files
130          * @param ignoreDeleted
131          * @return the list of file header objects
132          * @throws ObjectNotFoundException if the user or the folder cannot be found
133          * @throws InsufficientPermissionsException
134          */
135         public List<FileHeaderDTO> getFiles(Long userId, Long folderId, boolean ignoreDeleted) throws ObjectNotFoundException,
136                         InsufficientPermissionsException;
137
138         /**
139          * Returns a list of users for the specified group
140          *
141          * @param userId the ID of the User
142          * @param groupId the ID of the requested group
143          * @return List<UserDTO>
144          * @throws ObjectNotFoundException if the user or group was not found, with
145          *             the exception message mentioning the precise problem
146          */
147         public List<UserDTO> getUsers(Long userId, Long groupId) throws ObjectNotFoundException;
148
149         /**
150          * Returns a list of users matching the specified username
151          *
152          * @param username the username of the User
153          * @return List<UserDTO>
154          */
155         public List<UserDTO> getUsersByUserNameLike(String username);
156
157         /**
158          * Creates a new folder with the specified owner, parent folder and name.
159          * New folder has the same permissions as its parent
160          *
161          * @param userId
162          * @param parentId
163          * @param name
164          * @throws DuplicateNameException if the specified name already exists in
165          *             the parent folder, as either a folder or file
166          * @throws ObjectNotFoundException if the user or parent folder was not
167          *             found, with the exception message mentioning the precise
168          *             problem
169          * @throws InsufficientPermissionsException
170          */
171         public void createFolder(Long userId, Long parentId, String name) throws DuplicateNameException,
172                         ObjectNotFoundException, InsufficientPermissionsException;
173
174         /**
175          * Deletes the specified folder, if the specified user has the appropriate
176          * permission.
177          *
178          * @param userId the ID of the current user
179          * @param folderId the ID of the folder to delete
180          * @throws InsufficientPermissionsException if the user does not have the
181          *             appropriate privileges
182          * @throws ObjectNotFoundException if the user or folder was not found, with
183          *             the exception message mentioning the precise problem
184          */
185         public void deleteFolder(Long userId, Long folderId)
186                         throws InsufficientPermissionsException, ObjectNotFoundException;
187
188         /**
189          * Retrieve the subfolders of the specified folder.
190          *
191          * @param userId the ID of the current user
192          * @param folderId the ID of the folder to retrieve
193          * @return the list of subfolders found
194          * @throws ObjectNotFoundException if the folder or user was not found
195          * @throws InsufficientPermissionsException
196          */
197         public List<FolderDTO> getSubfolders(Long userId, Long folderId)
198                         throws ObjectNotFoundException, InsufficientPermissionsException;
199
200         /**
201          * Retrieve the folder with the specified ID with subfolders.
202          *
203          * @param userId the ID of the current user
204          * @param folderId the ID of the folder to retrieve
205          * @return the folder found
206          * @throws ObjectNotFoundException if the folder or the user was not found
207          * @throws InsufficientPermissionsException if ther user does not have read permissions for folder
208          */
209         public FolderDTO getFolderWithSubfolders(Long userId, Long folderId)
210                         throws ObjectNotFoundException, InsufficientPermissionsException;
211
212         /**
213          * Retrieve the folder with the specified ID with subfolders.
214          *
215          * @param userId the ID of the current user
216          * @param callingUserId the ID of the user requesting this operation
217          * @param folderId the ID of the folder to retrieve
218          * @return the folder found
219          * @throws ObjectNotFoundException if the folder or the user was not found
220          * @throws InsufficientPermissionsException if ther user does not have read permissions for folder
221          */
222         public FolderDTO getFolderWithSubfolders(Long userId, Long callingUserId, Long folderId)
223                         throws ObjectNotFoundException, InsufficientPermissionsException;
224         /**
225          * Retrieve the subfolders of the specified folder that are shared to others.
226          *
227          * @param userId the ID of the current user
228          * @param folderId the ID of the folder to retrieve
229          * @return the list of subfolders found
230          * @throws ObjectNotFoundException if the folder or user was not found
231          */
232         public List<FolderDTO> getSharedSubfolders(Long userId, Long folderId) throws ObjectNotFoundException;
233
234         /**
235          * Retrieve the subfolders of the specified folder that are shared to others.
236          *
237          * @param userId the ID of the current user
238          * @param callingUserId the id of the user requesting this operation
239          * @param folderId the ID of the folder to retrieve
240          * @return the list of subfolders found
241          * @throws ObjectNotFoundException if the folder or user was not found
242          */
243         public List<FolderDTO> getSharedSubfolders(Long userId, Long callingUserId, Long folderId) throws ObjectNotFoundException;
244         /**
245          * Modifies the specified folder if the specified user has the appropriate
246          * permission.
247          *
248          * @param userId the ID of the current user
249          * @param folderId the ID of the folder to retrieve
250          * @param folderName
251          * @throws InsufficientPermissionsException if the user does not have the
252          *             appropriate privileges
253          * @throws ObjectNotFoundException if the user or folder was not found, with
254          *             the exception message mentioning the precise problem
255          * @throws DuplicateNameException if the specified name already exists in
256          *             the parent folder, as either a folder or file
257          */
258         public void modifyFolder(Long userId, Long folderId, String folderName)
259                         throws InsufficientPermissionsException, ObjectNotFoundException, DuplicateNameException;
260
261         /**
262          * Adds a user to the specified group
263          *
264          * @param userId the ID of the current user
265          * @param groupId the id of the new group
266          * @param userToAddId the id of the user to add
267          * @throws DuplicateNameException if the user already exists in group
268          * @throws ObjectNotFoundException if the user or group was not found, with
269          *             the exception message mentioning the precise problem
270          * @throws InsufficientPermissionsException
271          */
272         public void addUserToGroup(Long userId, Long groupId, Long userToAddId)
273                         throws ObjectNotFoundException, DuplicateNameException, InsufficientPermissionsException;
274
275         /**
276          * Creates a new group with the specified owner and name.
277          *
278          * @param userId the ID of the current user
279          * @param name the name of the new group
280          * @throws DuplicateNameException if the new group name already exists
281          * @throws ObjectNotFoundException if the user or group was not found, with
282          *             the exception message mentioning the precise problem
283          */
284         public void createGroup(Long userId, String name) throws ObjectNotFoundException, DuplicateNameException;
285
286         /**
287          * Deletes the specified group in the specified user's namespace.
288          *
289          * @param userId the ID of the current user
290          * @param groupId the ID of the group to delete
291          * @throws ObjectNotFoundException if the user or group was not found, with
292          *             the exception message mentioning the precise problem
293          * @throws InsufficientPermissionsException
294          */
295         public void deleteGroup(Long userId, Long groupId) throws ObjectNotFoundException, InsufficientPermissionsException;
296
297         /**
298          * Creates a new file with the specified owner, parent folder and name. The
299          * new file has the same permissions as its parent folder. The file contents
300          * are read from the input stream to a new File object.
301          *
302          * @param userId the ID of the current user
303          * @param folderId the ID of the parent folder
304          * @param name the name of the new file
305          * @param mimeType the MIME type of the file
306          * @param stream the input stream with the file contents
307          * @return The FileHeaderDTO created
308          * @throws DuplicateNameException if the specified name already exists in
309          *             the parent folder, as either a folder or file
310          * @throws ObjectNotFoundException if the user or parent folder was not
311          *             found, with the exception message mentioning the precise
312          *             problem
313          * @throws GSSIOException if there was an error while storing the file contents
314          * @throws InsufficientPermissionsException
315          * @throws QuotaExceededException
316          */
317         public FileHeaderDTO createFile(Long userId, Long folderId, String name, String mimeType,
318                                 InputStream stream) throws DuplicateNameException, ObjectNotFoundException,
319                                 GSSIOException, InsufficientPermissionsException, QuotaExceededException;
320
321         /**
322          * Deletes the specified file, provided the specified user has
323          * the necessary permissions.
324          *
325          * @param userId the ID of the current user
326          * @param fileId the ID of the file to delete
327          * @throws ObjectNotFoundException if the user or file was not found, with
328          *             the exception message mentioning the precise problem
329          * @throws InsufficientPermissionsException if the user does not have the
330          *             appropriate privileges
331          */
332         public void deleteFile(Long userId, Long fileId) throws ObjectNotFoundException, InsufficientPermissionsException;
333
334         /**
335          * Deletes the specified file in the specified user's namespace.
336          *
337          * @param userId the ID of the current user
338          * @param fileIds the IDs of the files to delete
339          * @throws ObjectNotFoundException if the user or file was not found, with
340          *             the exception message mentioning the precise problem
341          * @throws InsufficientPermissionsException if the user does not have the
342          *             appropriate privileges
343          */
344         public void deleteFiles(Long userId, List<Long> fileIds)
345                         throws ObjectNotFoundException, InsufficientPermissionsException;
346
347         /**
348          * Creates a new tag for the specified user and file.
349          *
350          * @param userId the creator of the tag
351          * @param fileHeaderId the file that is tagged
352          * @param tag the tag
353          * @throws ObjectNotFoundException if the user or the file was not found
354          */
355         public void createTag(Long userId, Long fileHeaderId, String tag) throws ObjectNotFoundException;
356
357         /**
358          * Returns all tags defined by the specified user
359          *
360          * @param userId
361          * @return Set<String>
362          * @throws ObjectNotFoundException if the user was null
363          */
364         public Set<String> getUserTags(final Long userId) throws ObjectNotFoundException;
365
366         /**
367          * Updates name and tags for the specified file
368          *
369          * @param userId
370          * @param fileId
371          * @param name
372          * @param tagSet a String that contains tags separated by comma
373          * @throws ObjectNotFoundException
374          * @throws InsufficientPermissionsException
375          */
376         public void updateFile(Long userId, Long fileId, String name, String tagSet)
377                         throws ObjectNotFoundException, InsufficientPermissionsException;
378
379         /**
380          * Retrieve the contents of the current body for the file
381          * with the specified FileHeader ID. The file contents
382          * are provided as an InputStream from which the caller can
383          * retrieve the raw bytes.
384          *
385          * @param userId the ID of the current user
386          * @param fileId the ID of the file to retrieve
387          * @return an InputStream from the current file body contents
388          * @throws ObjectNotFoundException if the file or the user was not found
389          * @throws InsufficientPermissionsException  if the user does not have the
390          *             appropriate privileges
391          */
392         public InputStream getFileContents(Long userId, Long fileId)
393                         throws ObjectNotFoundException, InsufficientPermissionsException;
394
395         /**
396          * Retrieve the contents of the  body identified by bodyId for the file
397          * with the specified FileHeader ID. The file contents
398          * are provided as an InputStream from which the caller can
399          * retrieve the raw bytes.
400          *
401          * @param userId the ID of the current user
402          * @param fileId the ID of the file to retrieve
403          * @param bodyId the body ID
404          * @return an InputStream from the current file body contents
405          * @throws ObjectNotFoundException if the file or the user was not found
406          * @throws InsufficientPermissionsException  if the user does not have the
407          *             appropriate privileges
408          */
409         public InputStream getFileContents(Long userId, Long fileId, Long bodyId)
410                         throws ObjectNotFoundException, InsufficientPermissionsException;
411
412         /**
413          * Retrieve the file with the specified ID.
414          *
415          * @param userId the ID of the current user
416          * @param fileId the ID of the file to retrieve
417          * @return the file found
418          * @throws ObjectNotFoundException if the file or the user was not found, with
419          *                      the exception message mentioning the precise problem
420          * @throws InsufficientPermissionsException
421          */
422         public FileHeaderDTO getFile(Long userId, Long fileId) throws ObjectNotFoundException,
423                         InsufficientPermissionsException;
424
425         /**
426          * Retrieve the filebody with the specified ID.
427          *
428          * @param userId the ID of the current user
429          * @param fileId the ID of the file to retrieve
430          * @param bodyId the ID of the body
431          * @return the file found
432          * @throws ObjectNotFoundException if the file or the user was not found, with
433          *                      the exception message mentioning the precise problem
434          * @throws InsufficientPermissionsException
435          */
436         public FileBodyDTO getFileBody(Long userId, Long fileId, Long bodyId)
437                         throws ObjectNotFoundException, InsufficientPermissionsException;
438
439         /**
440          * Get the resource (file or folder) at the specified path in
441          * the specified user's namespace. The returned object will be of type
442          * FileHeaderDTO or FolderDTO.<p><strong>Note:</strong> this method does not
443          * receive the current user as a parameter, therefore it is unable to perform
444          * the necessary permission checks and should <strong>NOT</strong> be directly
445          * exposed to remote clients. It is the caller's responsibility to verify that
446          * the calling user has the required privileges for performing any subsequent
447          * action on the resource through one of the other ExternalAPI methods.
448          *
449          * @param ownerId the ID of the user owning the namespace
450          * @param path the absolute path in the user's namespace
451          * @param ignoreDeleted if true, resources that have been moved to the trash
452          *                      will be ignored
453          * @throws ObjectNotFoundException if the user or resource was not found, with
454          *                      the exception message mentioning the precise problem
455          * @return the resource found
456          */
457         public Object getResourceAtPath(Long ownerId, String path, boolean ignoreDeleted)
458                         throws ObjectNotFoundException;
459
460         /**
461          * Copy the provided file to the specified destination.
462          *
463          * @param userId the ID of the current user
464          * @param fileId the IF of the provided file
465          * @param dest the path of the new resource
466          * @throws ObjectNotFoundException if the user, file or destination was not
467          *                      found, with     the exception message mentioning the precise problem
468          * @throws DuplicateNameException if the specified name already exists in
469          *          the destination folder, as either a folder or file
470          * @throws GSSIOException if there was an error while accessing the file contents
471          * @throws InsufficientPermissionsException
472          * @throws QuotaExceededException
473          */
474         public void copyFile(Long userId, Long fileId, String dest) throws ObjectNotFoundException,
475                         DuplicateNameException, GSSIOException, InsufficientPermissionsException, QuotaExceededException;
476
477         /**
478          * Copy the provided file to the specified destination.
479          *
480          * @param userId the ID of the current user
481          * @param ownerId the ID of the owner of the destination namespace
482          * @param fileId the IF of the provided file
483          * @param dest the path of the new resource
484          * @throws ObjectNotFoundException if the user, file or destination was not
485          *                      found, with     the exception message mentioning the precise problem
486          * @throws DuplicateNameException if the specified name already exists in
487          *          the destination folder, as either a folder or file
488          * @throws GSSIOException if there was an error while accessing the file contents
489          * @throws InsufficientPermissionsException
490          * @throws QuotaExceededException
491          */
492         public void copyFileToPath(Long userId, Long ownerId, Long fileId, String dest) throws ObjectNotFoundException,
493                         DuplicateNameException, GSSIOException, InsufficientPermissionsException, QuotaExceededException;
494
495         /**
496          * Copy the provided file to the specified destination.
497          *
498          * @param userId the ID of the current user
499          * @param fileIds the IDs of the provided files
500          * @param destId the ID of the destination folder
501          * @throws ObjectNotFoundException if the user, file or destination was not
502          *                      found, with     the exception message mentioning the precise problem
503          * @throws GSSIOException if there was an error while accessing the file contents
504          * @throws DuplicateNameException if the specified name already exists in
505          *          the destination folder, as either a folder or file
506          * @throws InsufficientPermissionsException
507          * @throws QuotaExceededException
508          */
509         public void copyFiles(Long userId, List<Long> fileIds, Long destId)
510                         throws ObjectNotFoundException, DuplicateNameException, GSSIOException,
511                         InsufficientPermissionsException, QuotaExceededException;
512
513         /**
514          * Copy the provided file to the specified destination.
515          *
516          * @param userId the ID of the current user
517          * @param fileId the IF of the provided file
518          * @param destId the ID of the destination folder
519          * @param destName the name of the new file
520          * @throws ObjectNotFoundException if the user, file or destination was not
521          *                      found, with     the exception message mentioning the precise problem
522          * @throws GSSIOException if there was an error while accessing the file contents
523          * @throws DuplicateNameException if the specified name already exists in
524          *          the destination folder, as either a folder or file
525          * @throws InsufficientPermissionsException
526          * @throws QuotaExceededException
527          */
528         public void copyFile(Long userId, Long fileId, Long destId, String destName)
529                         throws ObjectNotFoundException, DuplicateNameException, GSSIOException,
530                         InsufficientPermissionsException, QuotaExceededException;
531
532         /**
533          * Copy the provided folder to the specified destination.
534          *
535          * @param userId the ID of the current user
536          * @param folderId the IF of the provided folder
537          * @param dest the path of the new folder
538          * @throws ObjectNotFoundException if the user, folder or destination was not
539          *                      found, with     the exception message mentioning the precise problem
540          * @throws DuplicateNameException if the specified name already exists in
541          *          the destination folder, as either a folder or file
542          * @throws InsufficientPermissionsException InsufficientPermissionsException if the user does not have the
543          *          appropriate privileges
544          */
545         public void copyFolder(Long userId, Long folderId, String dest) throws ObjectNotFoundException,
546                         DuplicateNameException, InsufficientPermissionsException;
547
548         /**
549          * Copy the provided folder to the specified destination.
550          *
551          * @param userId the ID of the current user
552          * @param folderId the IF of the provided folder
553          * @param destId the ID of the destination folder
554          * @param destName the name of the new folder
555          * @throws ObjectNotFoundException if the user, folder or destination was not
556          *                      found, with     the exception message mentioning the precise problem
557          * @throws DuplicateNameException if the specified name already exists in
558          *          the destination folder, as either a folder or file
559          * @throws InsufficientPermissionsException InsufficientPermissionsException
560          *                      if the user does not have the appropriate privileges
561          */
562         public void copyFolder(Long userId, Long folderId, Long destId, String destName)
563                         throws ObjectNotFoundException, DuplicateNameException, InsufficientPermissionsException;
564
565         /**
566          * Copy the provided folder and all its subfolders and files to the specified destination.
567          *
568          * @param userId the ID of the current user
569          * @param ownerId the ID of the owner of the destination namespace
570          * @param folderId the IF of the provided folder
571          * @param dest the path of the new folder
572          * @throws ObjectNotFoundException if the user, folder or destination was not
573          *                      found, with     the exception message mentioning the precise problem
574          * @throws DuplicateNameException if the specified name already exists in
575          *          the destination folder, as either a folder or file
576          * @throws InsufficientPermissionsException InsufficientPermissionsException if the user does not have the
577          *          appropriate privileges
578          * @throws QuotaExceededException if the user quota limit would be exceeded
579          * @throws GSSIOException if there was an error while accessing the file contents
580          */
581         public void copyFolderStructureToPath(Long userId, Long ownerId, Long folderId, String dest) throws ObjectNotFoundException,
582                         DuplicateNameException, InsufficientPermissionsException, GSSIOException, QuotaExceededException;
583
584         /**
585          * Copy the provided folder and all its subfolders and files to the specified destination.
586          *
587          * @param userId the ID of the current user
588          * @param folderId the IF of the provided folder
589          * @param destId the ID of the destination folder
590          * @param destName the name of the new folder
591          * @throws ObjectNotFoundException if the user, folder or destination was not
592          *                      found, with     the exception message mentioning the precise problem
593          * @throws DuplicateNameException if the specified name already exists in
594          *          the destination folder, as either a folder or file
595          * @throws InsufficientPermissionsException InsufficientPermissionsException
596          *                      if the user does not have the appropriate privileges
597          * @throws GSSIOException if there was an error while accessing the file contents
598          * @throws QuotaExceededException if the user quota limit would be exceeded
599          */
600         public void copyFolderStructure(Long userId, Long folderId, Long destId, String destName)
601                         throws ObjectNotFoundException, DuplicateNameException, InsufficientPermissionsException,
602                         GSSIOException, QuotaExceededException;
603
604         /**
605          * Marks  the specified file as deleted in the specified user's namespace.
606          *
607          * @param userId the ID of the current user
608          * @param fileId the ID of the file to delete
609          * @throws ObjectNotFoundException if the user or file was not found, with
610          *             the exception message mentioning the precise problem
611          * @throws InsufficientPermissionsException if the user does not have the
612          *             appropriate privileges
613          */
614         public void moveFileToTrash(Long userId, Long fileId) throws ObjectNotFoundException,
615                         InsufficientPermissionsException;
616
617         /**
618          * Marks  the specified deleted file as undeleted in the specified user's namespace.
619          *
620          * @param userId the ID of the current user
621          * @param fileId the ID of the file to undelete
622          * @throws ObjectNotFoundException if the user or file was not found, with
623          *             the exception message mentioning the precise problem
624          * @throws InsufficientPermissionsException if the user does not have the
625          *             appropriate privileges
626          *
627          */
628         public void removeFileFromTrash(Long userId, Long fileId) throws ObjectNotFoundException, InsufficientPermissionsException;
629
630         /**
631          * Marks  the specified files as deleted in the specified user's namespace.
632          *
633          * @param userId the ID of the current user
634          * @param fileIds the IDs of the file to delete
635          * @throws ObjectNotFoundException if the user or file was not found, with
636          *             the exception message mentioning the precise problem
637          * @throws InsufficientPermissionsException if the user does not have the
638          *             appropriate privileges
639          */
640         public void moveFilesToTrash(Long userId, List<Long> fileIds)
641                         throws ObjectNotFoundException, InsufficientPermissionsException;
642
643         /**
644          * Marks  the specified deleted files as undeleted in the specified user's namespace.
645          *
646          * @param userId the ID of the current user
647          * @param fileIds the IDs of the file to undelete
648          * @throws ObjectNotFoundException if the user or file was not found, with
649          *             the exception message mentioning the precise problem
650          * @throws InsufficientPermissionsException if the user does not have the
651          *             appropriate privileges
652          */
653         public void removeFilesFromTrash(Long userId, List<Long> fileIds) throws ObjectNotFoundException, InsufficientPermissionsException;
654
655         /**
656          * Marks  the specified folder as deleted in the specified user's namespace.
657          *
658          * @param userId the ID of the current user
659          * @param folderId the ID of the folder to delete
660          * @throws ObjectNotFoundException if the user or file was not found, with
661          *             the exception message mentioning the precise problem
662          * @throws InsufficientPermissionsException if the user does not have the
663          *             appropriate privileges
664          */
665         public void moveFolderToTrash(Long userId, Long folderId)
666                         throws ObjectNotFoundException, InsufficientPermissionsException;
667
668         /**
669          * Marks  the specified deleted folder as undeleted in the specified user's namespace.
670          *
671          * @param userId the ID of the current user
672          * @param folderId the ID of the folder to undelete
673          * @throws ObjectNotFoundException if the user or file was not found, with
674          *             the exception message mentioning the precise problem
675          * @throws InsufficientPermissionsException if the user does not have the
676          *          appropriate privileges
677          *
678          */
679         public void removeFolderFromTrash(Long userId, Long folderId) throws ObjectNotFoundException, InsufficientPermissionsException;
680
681         /**
682          * Move the provided folder and all its subfolders and files to the specified destination.
683          *
684          * @param userId the ID of the current user
685          * @param folderId the IF of the provided folder
686          * @param destId the ID of the destination folder
687          * @param destName the name of the new folder
688          * @throws ObjectNotFoundException if the user, folder or destination was not
689          *                      found, with     the exception message mentioning the precise problem
690          * @throws DuplicateNameException if the specified name already exists in
691          *          the destination folder, as either a folder or file
692          * @throws InsufficientPermissionsException if the user does not have the
693          *          appropriate privileges
694          * @throws GSSIOException
695          * @throws QuotaExceededException
696          */
697         public void moveFolder(Long userId, Long folderId, Long destId, String destName)
698                         throws ObjectNotFoundException, DuplicateNameException, InsufficientPermissionsException,
699                         GSSIOException, QuotaExceededException;
700
701         /**
702          * Move the provided folder and all its subfolders and files to the specified destination.
703          *
704          * @param userId the ID of the current user
705          * @param ownerId the owner of the destination namespace
706          * @param folderId the IF of the provided folder
707          * @param dest the path of the new folder
708          * @throws ObjectNotFoundException if the user, folder or destination was not
709          *                      found, with     the exception message mentioning the precise problem
710          * @throws DuplicateNameException if the specified name already exists in
711          *          the destination folder, as either a folder or file
712          * @throws InsufficientPermissionsException InsufficientPermissionsException if the user does not have the
713          *          appropriate privileges
714          * @throws GSSIOException
715          * @throws QuotaExceededException
716          */
717         public void moveFolderToPath(Long userId, Long ownerId, Long folderId, String dest) throws ObjectNotFoundException,
718                         DuplicateNameException, InsufficientPermissionsException, GSSIOException, QuotaExceededException;
719
720         /**
721          * Move the provided file to the specified destination.
722          *
723          * @param userId the ID of the current user
724          * @param fileId the IF of the provided file
725          * @param destId the ID of the destination folder
726          * @param destName the name of the new file
727          * @throws InsufficientPermissionsException
728          * @throws ObjectNotFoundException if the user, file or destination was not
729          *                      found, with     the exception message mentioning the precise problem
730          * @throws GSSIOException if there was an error while accessing the file contents
731          * @throws DuplicateNameException if the specified name already exists in
732          *          the destination folder, as either a folder or file
733          * @throws QuotaExceededException
734          */
735         public void moveFile(Long userId, Long fileId, Long destId, String destName)
736                         throws InsufficientPermissionsException, ObjectNotFoundException,
737                         DuplicateNameException, GSSIOException, QuotaExceededException;
738
739         /**
740          * Move the provided file to the specified destination.
741          *
742          * @param userId the ID of the current user
743          * @param ownerId the owner of the destination namespace
744          * @param fileId the IF of the provided file
745          * @param dest the path of the new file
746          * @throws InsufficientPermissionsException
747          * @throws ObjectNotFoundException if the user, file or destination was not
748          *                      found, with     the exception message mentioning the precise problem
749          * @throws GSSIOException if there was an error while accessing the file contents
750          * @throws DuplicateNameException if the specified name already exists in
751          *          the destination folder, as either a folder or file
752          * @throws QuotaExceededException
753          */
754         public void moveFileToPath(Long userId, Long ownerId, Long fileId, String dest) throws ObjectNotFoundException, InsufficientPermissionsException, DuplicateNameException, GSSIOException, QuotaExceededException;
755
756         /**
757          * move the provided file to the specified destination.
758          *
759          * @param userId the ID of the current user
760          * @param fileIds the IDs of the provided files
761          * @param destId the ID of the destination folder
762          * @throws InsufficientPermissionsException
763          * @throws ObjectNotFoundException if the user, file or destination was not
764          *                      found, with     the exception message mentioning the precise problem
765          * @throws GSSIOException if there was an error while accessing the file contents
766          * @throws DuplicateNameException if the specified name already exists in
767          *          the destination folder, as either a folder or file
768          * @throws QuotaExceededException
769          */
770         public void moveFiles(Long userId, List<Long> fileIds, Long destId)
771                         throws InsufficientPermissionsException, ObjectNotFoundException,
772                         DuplicateNameException, GSSIOException, QuotaExceededException;
773
774         /**
775          * Returns a list of All deleted files of a user.
776          *
777          * @param userId the ID of the User
778          *       * @return the list of deleted file header objects
779          * @throws ObjectNotFoundException if the user cannot be found
780          */
781         public List<FileHeaderDTO> getDeletedFiles(Long userId) throws ObjectNotFoundException;
782
783         /**
784          * Returns a list of All deleted root folders of a user.
785          *
786          * @param userId the ID of the User
787          *       * @return the list of deleted file header objects
788          * @throws ObjectNotFoundException if the user cannot be found
789          */
790         public List<FolderDTO> getDeletedRootFolders(Long userId) throws ObjectNotFoundException;
791
792         /**
793          * Empty Trash by deleting all marked as deleted files and folders
794          * @param userId
795          * @throws ObjectNotFoundException if something goes wrong in the delete process
796          * @throws InsufficientPermissionsException if something goes wrong in the delete process
797          */
798         public void emptyTrash(Long userId) throws ObjectNotFoundException, InsufficientPermissionsException;
799
800         /**
801          * Restores All Trashed Items by undeleting all marked as deleted files and folders
802          * @param userId
803          * @throws ObjectNotFoundException if something goes wrong in the delete process
804          * @throws InsufficientPermissionsException
805          */
806         public void restoreTrash(Long userId) throws ObjectNotFoundException, InsufficientPermissionsException;
807
808         /**
809          * Search the system for a user with the specified username.
810          * If no such user is found, the method returns null.
811          *
812          * @param username the username to search for
813          * @return the User object with the specified username
814          */
815         public User findUser(String username);
816
817         /**
818          * Create a new user with the specified name, username and e-mail address.
819          *
820          * @param username the username of the new user
821          * @param name the full name of the new user
822          * @param mail the e-mail of the new user
823          * @return the newly-created User object
824          * @throws DuplicateNameException if a user with the same username already exists
825          * @throws ObjectNotFoundException if no username was provided
826          */
827         public User createUser(String username, String name, String mail)
828                         throws DuplicateNameException, ObjectNotFoundException;
829
830         /**
831          * Update the user with the specified username with the provoded name
832          * and e-mail address.
833          *
834          * @param username the username of the user
835          * @param name the modified full name of the user
836          * @param mail the modified e-mail of the user
837          * @return the updated User object
838          * @throws ObjectNotFoundException if no username was provided
839          */
840         public User updateUser(String username, String name, String mail) throws ObjectNotFoundException;
841
842         /**
843          * Updates the authentication token for the specified user.
844          *
845          * @param userId the ID of the user whose token should be updated
846          * @return the updated user
847          * @throws ObjectNotFoundException if the user could not be found
848          */
849         public User updateUserToken(Long userId) throws ObjectNotFoundException;
850
851         /**
852          * Updates the policy acceptance flag for the specified user.
853          *
854          * @param userId the ID of the user whose flag should be updated
855          * @param isAccepted the new value of the flag
856          * @return the updated user
857          * @throws ObjectNotFoundException if the user could not be found
858          */
859         public User updateUserPolicyAcceptance(Long userId, boolean isAccepted) throws ObjectNotFoundException;
860
861         /**
862          * Invalidates the authentication token for the specified user.
863          *
864          * @param userId the ID of the user whose token should be updated
865          * @throws ObjectNotFoundException if the user could not be found
866          */
867         public void invalidateUserToken(Long userId) throws ObjectNotFoundException;
868
869         /**
870          * Retrieve folder user and group permissions
871          *
872          * @param userId the ID of the user whose token should be updated
873          * @param folderId the ID of the folder
874          * @return the Set of permissions from requested folder
875          * @throws ObjectNotFoundException if the user or folder could not be found
876          * @throws InsufficientPermissionsException
877          */
878         public Set<PermissionDTO> getFolderPermissions(Long userId, Long folderId)
879                         throws ObjectNotFoundException, InsufficientPermissionsException;
880
881         /**
882          * update folder permissions
883          * @param userId
884          * @param folderId
885          * @param permissions
886          * @throws ObjectNotFoundException
887          * @throws InsufficientPermissionsException
888          */
889         public void setFolderPermissions(Long userId, Long folderId, Set<PermissionDTO> permissions)
890                         throws ObjectNotFoundException, InsufficientPermissionsException;
891
892         /**
893          * Retrieve file user and group permissions
894          *
895          * @param userId the ID of the user whose token should be updated
896          * @param fileId the ID of the folder
897          * @return the Set of permissions from requested folder
898          * @throws ObjectNotFoundException if the user or folder could not be found
899          * @throws InsufficientPermissionsException
900          */
901         public Set<PermissionDTO> getFilePermissions(Long userId, Long fileId)
902                         throws ObjectNotFoundException, InsufficientPermissionsException;
903
904
905         /**
906          * update file permissions
907          * @param userId
908          * @param fileId
909          * @param readForAll
910          * @param permissions
911          * @throws ObjectNotFoundException
912          * @throws InsufficientPermissionsException
913          */
914         public void setFilePermissions(Long userId, Long fileId, Boolean readForAll,
915                                 Set<PermissionDTO> permissions)
916                         throws ObjectNotFoundException, InsufficientPermissionsException;
917
918         /**
919          * Returns a list of all shared root folders of a user.
920          *
921          * @param userId the ID of the User
922          * @return the list of shared root folders
923          * @throws ObjectNotFoundException if the user cannot be found
924          */
925         public List<FolderDTO> getSharedRootFolders(Long userId) throws ObjectNotFoundException;
926
927         /**
928          * Returns a list of all shared files of a user that are not
929          * inside other shared folders.
930          *
931          * @param userId the ID of the User
932          * @return the list of shared files
933          * @throws ObjectNotFoundException if the user cannot be found
934          */
935         public List<FileHeaderDTO> getSharedFilesNotInSharedFolders(Long userId) throws ObjectNotFoundException;
936
937         /**
938          * Returns a list of all shared files of a user.
939          *
940          * @param userId the ID of the User
941          * @return the list of shared files
942          * @throws ObjectNotFoundException if the user cannot be found
943          */
944         public List<FileHeaderDTO> getSharedFiles(Long userId) throws ObjectNotFoundException;
945
946         /**
947          * Returns a list of all shared folders of a user.
948          *
949          * @param userId the ID of the User
950          * @return the list of shared folders
951          * @throws ObjectNotFoundException if the user cannot be found
952          */
953         public List<FolderDTO> getSharedFolders(Long userId) throws ObjectNotFoundException;
954
955         /**
956          * Returns a list of all shared root folders of a user that calling
957          * user has at least read permissions.
958          *
959          * @param ownerId the ID of the User
960          * @return the list of shared root folders
961          * @param callingUserId
962          *
963          * @throws ObjectNotFoundException if the user cannot be found
964          */
965         public List<FolderDTO> getSharedRootFolders(Long ownerId, Long callingUserId)
966                         throws ObjectNotFoundException;
967
968         /**
969          * Returns a list of all shared  files of a user that calling user has
970          * at least read permissions..
971          *
972          * @param ownerId the ID of the User
973          * @return the list of shared files
974          * @param callingUserId
975          * @throws ObjectNotFoundException if the user cannot be found
976          */
977         public List<FileHeaderDTO> getSharedFiles(Long ownerId, Long callingUserId)
978                         throws ObjectNotFoundException;
979
980         /**
981          * Remove a user member from a group
982          *
983          * @param userId the ID of the User owning the group
984          * @param groupId the ID of the requested group
985          * @param memberId the ID of the member to be removed
986          *
987          * @throws ObjectNotFoundException if the user or group was not found, with
988          *             the exception message mentioning the precise problem
989          * @throws InsufficientPermissionsException
990          */
991         public void removeMemberFromGroup(Long userId, Long groupId, Long memberId)
992                         throws ObjectNotFoundException, InsufficientPermissionsException;
993
994         /**
995          * Retrieves the list of users sharing files to user identified by user id
996          * @param userId
997          * @return the List of users sharing files to user
998          * @throws ObjectNotFoundException
999          */
1000         public List<UserDTO> getUsersSharingFoldersForUser(Long userId) throws ObjectNotFoundException;
1001
1002         /**
1003          * Search Files
1004          *
1005          * @param userId
1006          * @param query
1007          * @return list of files that match query
1008          * @throws ObjectNotFoundException if no user or query was specified
1009          */
1010         public List<FileHeaderDTO> searchFiles(Long userId, String query) throws ObjectNotFoundException;
1011
1012         /**
1013          * Creates a nonce for the specified user.
1014          *
1015          * @param userId the ID of the user
1016          * @return the new nonce
1017          * @throws ObjectNotFoundException if the user could not be found
1018          */
1019         public Nonce createNonce(Long userId) throws ObjectNotFoundException;
1020
1021         /**
1022          * Find the nonce object for the specified encoded nonce, that should be
1023          * associated with the specified user.
1024          *
1025          * @param nonce the issued nonce in Base64 encoding
1026          * @param userId the ID of the user for whom this nonce should have been issued
1027          * @return the retrieved nonce object
1028          * @throws ObjectNotFoundException if the nonce or user were not found
1029          */
1030         public Nonce getNonce(String nonce, Long userId) throws ObjectNotFoundException;
1031
1032         /**
1033          * Remove the specified nonce from the persistent store.
1034          *
1035          * @param id the ID of the nonce
1036          * @throws ObjectNotFoundException if the specified nonce could not be found
1037          */
1038         public void removeNonce(Long id) throws ObjectNotFoundException;
1039
1040         /**
1041          * Activate the supplied nonce for the specified user.
1042          *
1043          * @param userId the ID of the user
1044          * @param nonce the nonce to activate
1045          * @param nonceExpiryDate the expiry date of the nonce
1046          * @throws ObjectNotFoundException
1047          */
1048         public void activateUserNonce(Long userId, String nonce, Date nonceExpiryDate) throws ObjectNotFoundException;
1049
1050         /**
1051          * Retrieves user statistics.
1052          *
1053          * @param userId the ID of the user
1054          * @return the statistics
1055          * @throws ObjectNotFoundException
1056          *
1057          */
1058         public StatsDTO getUserStatistics(Long userId) throws ObjectNotFoundException;
1059
1060         /**
1061          * Retrieves file versions
1062          *
1063          * @param userId the ID of the user
1064          * @param fileId the ID of the file
1065          * @return the list of filebodies
1066          * @throws ObjectNotFoundException
1067          * @throws InsufficientPermissionsException
1068          *
1069          */
1070         public List<FileBodyDTO> getVersions(Long userId, Long fileId)
1071                         throws ObjectNotFoundException, InsufficientPermissionsException;
1072
1073         /**
1074          * Restore the file contents to the specified version.
1075          *
1076          * @param userId the ID of the user
1077          * @param fileId the ID of the file
1078          * @param version the version number of the desired file contents
1079          * @throws ObjectNotFoundException if the user or file was not
1080          *                      found, with     the exception message mentioning the precise problem
1081          * @throws InsufficientPermissionsException if the user does not have the
1082          *          appropriate privileges
1083          * @throws QuotaExceededException if the user quota limit would be exceeded
1084          * @throws GSSIOException if there was an error while accessing the file contents
1085          */
1086         public void restoreVersion(Long userId, Long fileId, int version)
1087                         throws ObjectNotFoundException, InsufficientPermissionsException,  GSSIOException, QuotaExceededException;
1088
1089         /**
1090          * Remove file version identified by bodyId
1091          *
1092          * @param userId the ID of the user
1093          * @param fileId the ID of the file
1094          * @param bodyId the ID of the body
1095          *
1096          * @throws ObjectNotFoundException
1097          * @throws InsufficientPermissionsException
1098          *
1099          */
1100         public void removeVersion(Long userId, Long fileId, Long bodyId)
1101                         throws ObjectNotFoundException, InsufficientPermissionsException;
1102
1103         /**
1104          * Removes all old file versions for specified file keeping only the current revision
1105          *
1106          * @param userId the ID of the user
1107          * @param fileId the ID of the file
1108          *
1109          * @throws ObjectNotFoundException
1110          * @throws InsufficientPermissionsException
1111          *
1112          */
1113         public void removeOldVersions(Long userId, Long fileId)
1114                         throws ObjectNotFoundException, InsufficientPermissionsException;
1115
1116         /**
1117          * Toggle between file being versioned or not.
1118          *
1119          * @param userId the ID of the user
1120          * @param fileId the ID of the file
1121          * @param versioned the new value of the flag
1122          *
1123          * @throws ObjectNotFoundException
1124          * @throws InsufficientPermissionsException
1125          *
1126          */
1127         public void toggleFileVersioning(Long userId, Long fileId, boolean versioned)
1128                         throws ObjectNotFoundException, InsufficientPermissionsException;
1129
1130         /**
1131          * It is used by the Solr mbean to rebuild the index.
1132          */
1133         public void rebuildSolrIndex();
1134
1135         /**
1136          * Creates a new file with the specified owner, parent folder and name. The
1137          * new file has the same permissions as its parent folder. The file contents
1138          * are already uploaded outside of externalAPI and the uploaded file is used as a parameter.
1139          *
1140          * @param userId the ID of the current user
1141          * @param folderId the ID of the parent folder
1142          * @param name the name of the new file
1143          * @param mimeType the MIME type of the file
1144          * @param uploadedFile the uploaded file
1145          * @return The FileHeaderDTO created
1146          * @throws DuplicateNameException if the specified name already exists in
1147          *             the parent folder, as either a folder or file
1148          * @throws ObjectNotFoundException if the user or parent folder was not
1149          *             found, with the exception message mentioning the precise
1150          *             problem
1151          * @throws GSSIOException if there was an error while storing the file contents
1152          * @throws InsufficientPermissionsException
1153          * @throws QuotaExceededException
1154          */
1155         public FileHeaderDTO createFile(Long userId, Long folderId, String name, String mimeType, File uploadedFile)
1156                         throws DuplicateNameException, ObjectNotFoundException, GSSIOException,
1157                         InsufficientPermissionsException, QuotaExceededException;
1158
1159         /**
1160          * Create a new FileBody with the supplied uploaded file as contents and make it the current body
1161          * of the file.
1162          *
1163          * @param userId the ID of the current user
1164          * @param fileId the ID of the file header object
1165          * @param mimeType the content type of the file
1166          * @param uploadedFile the already uploadedFile
1167          * @return The FileHeaderDTO updated
1168          * @throws ObjectNotFoundException if the user or file was not found, with
1169          *                      the exception message mentioning the precise problem
1170          * @throws GSSIOException when an IO exception occurs
1171          * @throws InsufficientPermissionsException
1172          * @throws QuotaExceededException
1173          */
1174         public FileHeaderDTO updateFileContents(Long userId, Long fileId, String mimeType,
1175                                 File uploadedFile) throws ObjectNotFoundException, GSSIOException,
1176                                 InsufficientPermissionsException, QuotaExceededException;
1177
1178         /**
1179          * Create a file based on inputstream without using transaction.
1180          *
1181          * @param stream
1182          * @param userId
1183          * @return the file
1184          * @throws IOException
1185          * @throws ObjectNotFoundException
1186          */
1187         @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
1188         public File uploadFile(InputStream stream, Long userId)
1189                         throws IOException, ObjectNotFoundException;
1190
1191         public void createFileUploadProgress(Long userId, String filename,
1192                                 Long bytesTransfered, Long fileSize) throws ObjectNotFoundException;
1193
1194         public FileUploadStatus getFileUploadStatus(Long userId, String fileName);
1195
1196         public void removeFileUploadProgress(Long userId, String filename)
1197                         throws ObjectNotFoundException;
1198
1199         /**
1200          * Fetch the file body with the specified version number.
1201          *
1202          * @param userId the ID of the current user
1203          * @param fileId the ID of the file header
1204          * @param version the version number
1205          * @return the file body
1206          * @throws ObjectNotFoundException if the user file or version
1207          *                      were not found
1208          * @throws InsufficientPermissionsException if the user does not
1209          *                      have enough privileges for reading this file
1210          */
1211         public FileBodyDTO getFileVersion(Long userId, Long fileId, int version) throws ObjectNotFoundException, InsufficientPermissionsException;
1212
1213         /**
1214          * Search the system for a user with the specified email address.
1215          * If no such user is found, the method returns null.
1216          */
1217         public User findUserByEmail(String email);
1218
1219         /**
1220          * Update the user with the values from the supplied object.
1221          */
1222         public void updateUser(User user);
1223
1224         /**
1225          * Update accounting information for given user.
1226          *
1227          * @param user The user to update
1228          * @param date Date of transaction
1229          * @param bandwidthDiff Bandwidth used; positive for addition,
1230          * negative for subtraction (e.g. to rollback)
1231          */
1232         public void updateAccounting(User user, Date date, long bandwidthDiff);
1233
1234         /**
1235          * Check if the user with the specified ID has permission to read the
1236          * folder with the supplied ID.
1237          */
1238         public boolean canReadFolder(Long userId, Long folderId) throws ObjectNotFoundException;
1239 }