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