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