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