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