001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.trash;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.model.ClassedModel;
020    import com.liferay.portal.model.ContainerModel;
021    import com.liferay.portal.model.SystemEvent;
022    import com.liferay.portal.model.TrashedModel;
023    import com.liferay.portal.security.permission.PermissionChecker;
024    import com.liferay.portal.service.ServiceContext;
025    import com.liferay.portlet.trash.model.TrashEntry;
026    
027    import java.util.List;
028    
029    import javax.portlet.PortletRequest;
030    
031    /**
032     * The interface for managing the basic trash operations of the Recycle Bin,
033     * which include:
034     *
035     * <ul>
036     * <li>
037     * Deleting trash entries
038     * </li>
039     * <li>
040     * Moving trash entries out of the Recycle Bin to new destinations
041     * </li>
042     * <li>
043     * Restoring trash entries to their original locations
044     * </li>
045     * </ul>
046     *
047     * <p>
048     * These operations are supported for the following entities via their
049     * respective trash handlers:
050     * </p>
051     *
052     * <ul>
053     * <li>
054     * BlogsEntry via {@link com.liferay.portlet.blogs.trash.BlogsEntryTrashHandler}
055     * </li>
056     * <li>
057     * BookmarksEntry via {@link
058     * com.liferay.portlet.bookmarks.trash.BookmarksEntryTrashHandler}
059     * </li>
060     * <li>
061     * DLFileEntry via {@link
062     * com.liferay.portlet.documentlibrary.trash.DLFileEntryTrashHandler}
063     * </li>
064     * <li>
065     * DLFileShortcut via {@link
066     * com.liferay.portlet.documentlibrary.trash.DLFileShortcutTrashHandler}
067     * </li>
068     * <li>
069     * DLFolder via {@link
070     * com.liferay.portlet.documentlibrary.trash.DLFolderTrashHandler}
071     * </li>
072     * <li>
073     * MBThread via {@link
074     * com.liferay.portlet.messageboards.trash.MBThreadTrashHandler}
075     * </li>
076     * <li>
077     * WikiNode via {@link
078     * com.liferay.portlet.wiki.trash.WikiNodeTrashHandler}
079     * </li>
080     * <li>
081     * WikiPage via {@link
082     * com.liferay.portlet.wiki.trash.WikiPageTrashHandler}
083     * </li>
084     * </ul>
085     *
086     * @author Alexander Chow
087     * @author Zsolt Berentey
088     */
089    public interface TrashHandler {
090    
091            public SystemEvent addDeletionSystemEvent(
092                            long userId, long groupId, long classPK, String classUuid,
093                            String referrerClassName)
094                    throws PortalException, SystemException;
095    
096            public void checkDuplicateEntry(
097                            long classPK, long containerModelId, String newName)
098                    throws PortalException, SystemException;
099    
100            /**
101             * Checks if a duplicate trash entry already exists in the destination
102             * container.
103             *
104             * <p>
105             * This method is used to check for duplicates when a trash entry is being
106             * restored or moved out of the Recycle Bin.
107             * </p>
108             *
109             * @param  trashEntry the trash entry to check
110             * @param  containerModelId the primary key of the destination (e.g. folder)
111             * @param  newName the new name to be assigned to the trash entry
112             *         (optionally <code>null</code> to forego renaming the trash entry)
113             * @throws PortalException if a duplicate trash entry already existed in the
114             *         destination container
115             * @throws SystemException if a system exception occurred
116             */
117            public void checkDuplicateTrashEntry(
118                            TrashEntry trashEntry, long containerModelId, String newName)
119                    throws PortalException, SystemException;
120    
121            /**
122             * Deletes the model entity with the primary key.
123             *
124             * @param  classPK the primary key of the model entity to delete
125             * @throws PortalException if a model entity with the primary key could not
126             *         be found
127             * @throws SystemException if a system exception occurred
128             */
129            public void deleteTrashEntry(long classPK)
130                    throws PortalException, SystemException;
131    
132            /**
133             * Returns the class name handled by this trash handler.
134             *
135             * @return the class name handled by this trash handler
136             */
137            public String getClassName();
138    
139            /**
140             * Returns the container model with the primary key.
141             *
142             * @param  containerModelId the primary key of the container model
143             * @return the container model with the primary key
144             * @throws PortalException if a container model with the primary key could
145             *         not be found
146             * @throws SystemException if a system exception occurred
147             */
148            public ContainerModel getContainerModel(long containerModelId)
149                    throws PortalException, SystemException;
150    
151            /**
152             * Returns the parent container model's class name.
153             */
154            public String getContainerModelClassName();
155    
156            /**
157             * Returns the name of the container model (e.g. folder name).
158             *
159             * @return the name of the container model
160             */
161            public String getContainerModelName();
162    
163            /**
164             * Returns a range of all the container models that are children of the
165             * parent container model identified by the container model ID. These
166             * container models must be able to contain the model entity identified by
167             * the primary key.
168             *
169             * <p>
170             * This method checks for the view permission when retrieving the container
171             * models.
172             * </p>
173             *
174             * <p>
175             * Useful when paginating results. Returns a maximum of <code>end -
176             * start</code> instances. The <code>start</code> and <code>end</code>
177             * values are not primary keys but, rather, indexes in the result set. Thus,
178             * <code>0</code> refers to the first result in the set. Setting both
179             * <code>start</code> and <code>end</code> to {@link
180             * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
181             * result set.
182             * </p>
183             *
184             * @param  classPK the primary key of a model entity the container models
185             *         must be able to contain
186             * @param  containerModelId the primary key of the parent container model
187             * @param  start the lower bound of the range of results
188             * @param  end the upper bound of the range of results (not inclusive)
189             * @return the range of matching container models
190             * @throws PortalException if a model entity with the primary key could not
191             *         be found
192             * @throws SystemException if a system exception occurred
193             */
194            public List<ContainerModel> getContainerModels(
195                            long classPK, long containerModelId, int start, int end)
196                    throws PortalException, SystemException;
197    
198            /**
199             * Returns the number of container models that are children of the parent
200             * container model identified by the container model ID. These container
201             * models must be able to contain the model entity identified by the primary
202             * key.
203             *
204             * <p>
205             * This method checks for the view permission when counting the container
206             * models.
207             * </p>
208             *
209             * @param  classPK the primary key of a model entity the container models
210             *         must be able to contain
211             * @param  containerModelId the primary key of the parent container model
212             * @return the number of matching container models
213             * @throws PortalException if a model entity with the primary key could not
214             *         be found
215             * @throws SystemException if a system exception occurred
216             */
217            public int getContainerModelsCount(long classPK, long containerModelId)
218                    throws PortalException, SystemException;
219    
220            /**
221             * Returns the language key to the localized message to display next to a
222             * trash entry listed in a search result, indicating that the trash entry
223             * was found in a trashed container (e.g. folder or message board thread)
224             * this trash handler is associated with.
225             *
226             * <p>
227             * If the language key (e.g. <code>found-in-deleted-folder-x</code>) used
228             * accepts a single parameter, the trash framework replaces that parameter
229             * with the trashed container's name.
230             * </p>
231             *
232             * @return the language key to the localized message to display next to a
233             *         trash entry listed in a search result
234             */
235            public String getDeleteMessage();
236    
237            /**
238             * Returns the parent container model of the model entity with the primary
239             * key.
240             *
241             * @param  classPK the primary key of a model entity the container models
242             *         must be able to contain
243             * @return the parent container model of the model entity with the primary
244             *         key
245             * @throws PortalException if a portal exception occurred
246             * @throws SystemException if a system exception occurred
247             */
248            public ContainerModel getParentContainerModel(long classPK)
249                    throws PortalException, SystemException;
250    
251            public ContainerModel getParentContainerModel(TrashedModel trashedModel)
252                    throws PortalException, SystemException;
253    
254            /**
255             * Returns all the parent container models of the model entity with the
256             * primary key ordered by hierarchy.
257             *
258             * <p>
259             * For example, if the primary key is for a file entry inside folder C,
260             * which is inside folder B, which is inside folder A; this method returns
261             * container models for folders A, B, and C.
262             * </p>
263             *
264             * @param  classPK the primary key of a model entity the container models
265             *         must be able to contain
266             * @return all the matching parent container models of the model entity
267             * @throws PortalException if a portal exception occurred
268             * @throws SystemException if a system exception occurred
269             */
270            public List<ContainerModel> getParentContainerModels(long classPK)
271                    throws PortalException, SystemException;
272    
273            public String getRestoreContainedModelLink(
274                            PortletRequest portletRequest, long classPK)
275                    throws PortalException, SystemException;
276    
277            /**
278             * Returns the link to the location to which the model entity was restored.
279             *
280             * @param  portletRequest the portlet request
281             * @param  classPK the primary key of the restored model entity
282             * @return the restore link
283             * @throws PortalException if a model entity with the primary key could not
284             *         be found
285             * @throws SystemException if a system exception occurred
286             */
287            public String getRestoreContainerModelLink(
288                            PortletRequest portletRequest, long classPK)
289                    throws PortalException, SystemException;
290    
291            /**
292             * Returns the message describing the location to which the model entity was
293             * restored.
294             *
295             * @param  portletRequest the portlet request
296             * @param  classPK the primary key of the restored model entity
297             * @return the restore message
298             * @throws PortalException if a model entity with the primary key could not
299             *         be found
300             * @throws SystemException if a system exception occurred
301             */
302            public String getRestoreMessage(PortletRequest portletRequest, long classPK)
303                    throws PortalException, SystemException;
304    
305            /**
306             * Returns the name of the root container (e.g. "home").
307             *
308             * @return the name of the root container
309             */
310            public String getRootContainerModelName();
311    
312            /**
313             * Returns the name of the subcontainer model (e.g. for a folder the
314             * subcontainer model name may be "subfolder").
315             *
316             * @return the name of the subcontainer model
317             */
318            public String getSubcontainerModelName();
319    
320            public String getSystemEventClassName();
321    
322            /**
323             * Returns the name of the contained model.
324             *
325             * <p>
326             * For example, "files" may be the model name for a folder and "pages" may
327             * be the model name for a wiki node.
328             * </p>
329             *
330             * @return the name of the contained model
331             */
332            public String getTrashContainedModelName();
333    
334            /**
335             * Returns the number of model entities (excluding container model entities)
336             * that are children of the parent container model identified by the primary
337             * key.
338             *
339             * <p>
340             * For example, for a folder with subfolders and documents, the number of
341             * documents (excluding those explicitely moved to the recycle bin) is
342             * returned.
343             * </p>
344             *
345             * @param  classPK the primary key of a container model
346             * @return the number of model entities that are children of the parent
347             *         container model identified by the primary key
348             * @throws PortalException if a portal exception occurred
349             * @throws SystemException if a system exception occurred
350             */
351            public int getTrashContainedModelsCount(long classPK)
352                    throws PortalException, SystemException;
353    
354            /**
355             * Returns a range of all the trash renderers of model entities (excluding
356             * container models) that are children of the parent container model
357             * identified by the primary key.
358             *
359             * <p>
360             * For example, for a folder with subfolders and documents, a range of all
361             * the trash renderers of documents (excluding those explicitly moved to the
362             * recycle bin) is returned.
363             * </p>
364             *
365             * <p>
366             * Useful when paginating results. Returns a maximum of <code>end -
367             * start</code> instances. The <code>start</code> and <code>end</code>
368             * values are not primary keys but, rather, indexes in the result set. Thus,
369             * <code>0</code> refers to the first result in the set. Setting both
370             * <code>start</code> and <code>end</code> to {@link
371             * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
372             * result set.
373             * </p>
374             *
375             * @param  classPK the primary key of a container model
376             * @param  start the lower bound of the range of results
377             * @param  end the upper bound of the range of results (not inclusive)
378             * @return the range of trash renderers of model entities (excluding
379             *         container models) that are children of the parent container model
380             *         identified by the primary key
381             * @throws PortalException if a portal exception occurred
382             * @throws SystemException if a system exception occurred
383             */
384            public List<TrashRenderer> getTrashContainedModelTrashRenderers(
385                            long classPK, int start, int end)
386                    throws PortalException, SystemException;
387    
388            /**
389             * Returns the name of the container model.
390             *
391             * <p>
392             * For example, "folder" may be the container model name for a file entry.
393             * </p>
394             *
395             * @return the name of the container model
396             */
397            public String getTrashContainerModelName();
398    
399            /**
400             * Returns the number of container models that are children of the parent
401             * container model identified by the primary key.
402             *
403             * <p>
404             * For example, for a folder with subfolders and documents, the number of
405             * folders (excluding those explicitly moved to the recycle bin) is
406             * returned.
407             * </p>
408             *
409             * @param  classPK the primary key of a container model
410             * @return the number of container models that are children of the parent
411             *         container model identified by the primary key
412             * @throws PortalException if a portal exception occurred
413             * @throws SystemException if a system exception occurred
414             */
415            public int getTrashContainerModelsCount(long classPK)
416                    throws PortalException, SystemException;
417    
418            /**
419             * Returns a range of all the trash renderers of model entities that are
420             * children of the parent container model identified by the primary key.
421             *
422             * <p>
423             * For example, for a folder with subfolders and documents, the range of
424             * renderers representing folders (excluding those explicitly moved to the
425             * recycle bin) is returned.
426             * </p>
427             *
428             * <p>
429             * Useful when paginating results. Returns a maximum of <code>end -
430             * start</code> instances. The <code>start</code> and <code>end</code>
431             * values are not primary keys but, rather, indexes in the result set. Thus,
432             * <code>0</code> refers to the first result in the set. Setting both
433             * <code>start</code> and <code>end</code> to {@link
434             * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
435             * result set.
436             * </p>
437             *
438             * @param  classPK the primary key of a container model
439             * @param  start the lower bound of the range of results
440             * @param  end the upper bound of the range of results (not inclusive)
441             * @return the range of matching trash renderers of model entities
442             * @throws PortalException if a portal exception occurred
443             * @throws SystemException if a system exception occurred
444             */
445            public List<TrashRenderer> getTrashContainerModelTrashRenderers(
446                            long classPK, int start, int end)
447                    throws PortalException, SystemException;
448    
449            public TrashEntry getTrashEntry(long classPK)
450                    throws PortalException, SystemException;
451    
452            /**
453             * Returns the trash renderer associated to the model entity with the
454             * primary key.
455             *
456             * @param  classPK the primary key of the model entity
457             * @return the trash renderer associated to the model entity
458             * @throws PortalException if a model entity with the primary key could not
459             *         be found
460             * @throws SystemException if a system exception occurred
461             */
462            public TrashRenderer getTrashRenderer(long classPK)
463                    throws PortalException, SystemException;
464    
465            /**
466             * Returns <code>true</code> if the user has the required permission to
467             * perform the trash action on the model entity with the primary key.
468             *
469             * <p>
470             * This method is a mapper for special Recycle Bin operations that are not
471             * real permissions. The implementations of this method should translate
472             * these virtual permissions to real permission checks.
473             * </p>
474             *
475             * @param  permissionChecker the permission checker
476             * @param  groupId the primary key of the group
477             * @param  classPK the primary key of the model entity
478             * @param  trashActionId the trash action permission to check
479             * @return <code>true</code> if the user has the required permission;
480             *         <code>false</code> otherwise
481             * @throws PortalException if a model entity with the primary key could not
482             *         be found
483             * @throws SystemException if a system exception occurred
484             */
485            public boolean hasTrashPermission(
486                            PermissionChecker permissionChecker, long groupId, long classPK,
487                            String trashActionId)
488                    throws PortalException, SystemException;
489    
490            /**
491             * Returns <code>true</code> if the entity is a container model.
492             *
493             * @return <code>true</code> if the entity is a container model;
494             *         <code>false</code> otherwise
495             */
496            public boolean isContainerModel();
497    
498            /**
499             * Returns <code>true</code> if the entity can be deleted from the Recycle
500             * Bin.
501             *
502             * @return <code>true</code> if the entity can be deleted from the Recycle
503             *         Bin.
504             */
505            public boolean isDeletable();
506    
507            /**
508             * Returns <code>true</code> if the model entity with the primary key is in
509             * the Recycle Bin.
510             *
511             * @param  classPK the primary key of the model entity
512             * @return <code>true</code> if the model entity is in the Recycle Bin;
513             *         <code>false</code> otherwise
514             * @throws PortalException if a model entity with the primary key could not
515             *         be found in the portal
516             * @throws SystemException if a system exception occurred
517             */
518            public boolean isInTrash(long classPK)
519                    throws PortalException, SystemException;
520    
521            /**
522             * Returns <code>true</code> if the model entity with the primary key is in
523             * a container that is in the Recycle Bin.
524             *
525             * @param  classPK the primary key of the model entity
526             * @return <code>true</code> if the model entity with the primary key is in
527             *         a container that is in the Recycle Bin; <code>false</code>
528             *         otherwise
529             * @throws PortalException if a model entity with the primary key could not
530             *         be found in the portal
531             * @throws SystemException if a system exception occurred
532             */
533            public boolean isInTrashContainer(long classPK)
534                    throws PortalException, SystemException;
535    
536            /**
537             * Returns <code>true</code> if the entity can be moved from one container
538             * model (such as a folder) to another.
539             *
540             * @return <code>true</code> if the entity can be moved from one container
541             *         model to another; <code>false</code> otherwise
542             */
543            public boolean isMovable();
544    
545            /**
546             * Returns <code>true</code> if the model entity can be restored to its
547             * original location.
548             *
549             * <p>
550             * This method usually returns <code>false</code> if the container (e.g.
551             * folder) of the model entity is no longer available (e.g. moved to the
552             * Recycle Bin or deleted).
553             * </p>
554             *
555             * @param  classPK the primary key of the model entity
556             * @return <code>true</code> if the model entity can be restored to its
557             *         original location; <code>false</code> otherwise
558             * @throws PortalException if a model entity with the primary key could not
559             *         be found
560             * @throws SystemException if a system exception occurred
561             */
562            public boolean isRestorable(long classPK)
563                    throws PortalException, SystemException;
564    
565            public boolean isTrashEntry(
566                    TrashEntry trashEntry, ClassedModel classedModel);
567    
568            /**
569             * Moves the entity with the class primary key to the container model with
570             * the class primary key
571             *
572             * @param  userId the user ID
573             * @param  classPK the primary key of the model entity
574             * @param  containerModelId the primary key of the destination container
575             *         model
576             * @param  serviceContext the service context to be applied
577             * @throws PortalException if a model entity with the primary key or the
578             *         destination container model with the primary key could not be
579             *         found
580             * @throws SystemException if a system exception occurred
581             */
582            public void moveEntry(
583                            long userId, long classPK, long containerModelId,
584                            ServiceContext serviceContext)
585                    throws PortalException, SystemException;
586    
587            /**
588             * Moves the model entity with the primary key out of the Recycle Bin to a
589             * new destination identified by the container model ID.
590             *
591             * @param  userId the user ID
592             * @param  classPK the primary key of the model entity
593             * @param  containerModelId the primary key of the destination container
594             *         model
595             * @param  serviceContext the service context to be applied
596             * @throws PortalException if a model entity with the primary key or the
597             *         destination container model with the primary key could not be
598             *         found
599             * @throws SystemException if a system exception occurred
600             */
601            public void moveTrashEntry(
602                            long userId, long classPK, long containerModelId,
603                            ServiceContext serviceContext)
604                    throws PortalException, SystemException;
605    
606            /**
607             * Restores the model entity that is related to the model entity with the
608             * class name and class PK. For example, {@link
609             * com.liferay.portlet.wiki.trash.WikiPageTrashHandler#restoreRelatedTrashEntry(
610             * String, long)} restores the attachment related to the wiki page with the
611             * class name and class PK.
612             *
613             * @param  className the class name of the model entity with a related model
614             *         entity to restore
615             * @param  classPK the primary key of the model entity with a related model
616             *         entity to restore
617             * @throws PortalException if a model entity with the primary key could not
618             *         be found
619             * @throws SystemException if a system exception occurred
620             */
621            public void restoreRelatedTrashEntry(String className, long classPK)
622                    throws PortalException, SystemException;
623    
624            /**
625             * Restores the model entity with the primary key.
626             *
627             * @param  userId the user ID
628             * @param  classPK the primary key of the model entity to restore
629             * @throws PortalException if a model entity with the primary key could not
630             *         be found
631             * @throws SystemException if a system exception occurred
632             */
633            public void restoreTrashEntry(long userId, long classPK)
634                    throws PortalException, SystemException;
635    
636            /**
637             * Updates the title of the model entity with the primary key. This method
638             * is called by {@link com.liferay.portlet.trash.action.EditEntryAction}
639             * before restoring the model entity via its restore rename action.
640             *
641             * @param  classPK the primary key of the model entity
642             * @param  title the title to be assigned
643             * @throws PortalException if a model entity with the primary key could not
644             *         be found
645             * @throws SystemException if a system exception occurred
646             */
647            public void updateTitle(long classPK, String title)
648                    throws PortalException, SystemException;
649    
650    }