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