001    /**
002     * Copyright (c) 2000-present 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.portletfilerepository;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.kernel.exception.PortalException;
020    import com.liferay.portal.kernel.repository.model.FileEntry;
021    import com.liferay.portal.kernel.repository.model.Folder;
022    import com.liferay.portal.kernel.search.Hits;
023    import com.liferay.portal.kernel.search.SearchContext;
024    import com.liferay.portal.kernel.security.pacl.permission.PortalRuntimePermission;
025    import com.liferay.portal.kernel.util.ObjectValuePair;
026    import com.liferay.portal.kernel.util.OrderByComparator;
027    import com.liferay.portal.model.Repository;
028    import com.liferay.portal.service.ServiceContext;
029    import com.liferay.portal.theme.ThemeDisplay;
030    
031    import java.io.File;
032    import java.io.InputStream;
033    
034    import java.util.List;
035    
036    /**
037     * @author Eudaldo Alonso
038     * @author Alexander Chow
039     */
040    @ProviderType
041    public class PortletFileRepositoryUtil {
042    
043            public static void addPortletFileEntries(
044                            long groupId, long userId, String className, long classPK,
045                            String portletId, long folderId,
046                            List<ObjectValuePair<String, InputStream>> inputStreamOVPs)
047                    throws PortalException {
048    
049                    getPortletFileRepository().addPortletFileEntries(
050                            groupId, userId, className, classPK, portletId, folderId,
051                            inputStreamOVPs);
052            }
053    
054            public static FileEntry addPortletFileEntry(
055                            long groupId, long userId, String className, long classPK,
056                            String portletId, long folderId, File file, String fileName,
057                            String mimeType, boolean indexingEnabled)
058                    throws PortalException {
059    
060                    return getPortletFileRepository().addPortletFileEntry(
061                            groupId, userId, className, classPK, portletId, folderId, file,
062                            fileName, mimeType, indexingEnabled);
063            }
064    
065            public static FileEntry addPortletFileEntry(
066                            long groupId, long userId, String className, long classPK,
067                            String portletId, long folderId, InputStream inputStream,
068                            String fileName, String mimeType, boolean indexingEnabled)
069                    throws PortalException {
070    
071                    return getPortletFileRepository().addPortletFileEntry(
072                            groupId, userId, className, classPK, portletId, folderId,
073                            inputStream, fileName, mimeType, indexingEnabled);
074            }
075    
076            public static Folder addPortletFolder(
077                            long userId, long repositoryId, long parentFolderId,
078                            String folderName, ServiceContext serviceContext)
079                    throws PortalException {
080    
081                    return getPortletFileRepository().addPortletFolder(
082                            userId, repositoryId, parentFolderId, folderName, serviceContext);
083            }
084    
085            public static Folder addPortletFolder(
086                            long groupId, long userId, String portletId, long parentFolderId,
087                            String folderName, ServiceContext serviceContext)
088                    throws PortalException {
089    
090                    return getPortletFileRepository().addPortletFolder(
091                            groupId, userId, portletId, parentFolderId, folderName,
092                            serviceContext);
093            }
094    
095            public static Repository addPortletRepository(
096                            long groupId, String portletId, ServiceContext serviceContext)
097                    throws PortalException {
098    
099                    return getPortletFileRepository().addPortletRepository(
100                            groupId, portletId, serviceContext);
101            }
102    
103            /**
104             * @deprecated As of 7.0.0, replaced by {@link #deletePortletFolder}
105             */
106            @Deprecated
107            public static void deleteFolder(long folderId) throws PortalException {
108                    getPortletFileRepository().deleteFolder(folderId);
109            }
110    
111            public static void deletePortletFileEntries(long groupId, long folderId)
112                    throws PortalException {
113    
114                    getPortletFileRepository().deletePortletFileEntries(groupId, folderId);
115            }
116    
117            public static void deletePortletFileEntries(
118                            long groupId, long folderId, int status)
119                    throws PortalException {
120    
121                    getPortletFileRepository().deletePortletFileEntries(
122                            groupId, folderId, status);
123            }
124    
125            public static void deletePortletFileEntry(long fileEntryId)
126                    throws PortalException {
127    
128                    getPortletFileRepository().deletePortletFileEntry(fileEntryId);
129            }
130    
131            public static void deletePortletFileEntry(
132                            long groupId, long folderId, String fileName)
133                    throws PortalException {
134    
135                    getPortletFileRepository().deletePortletFileEntry(
136                            groupId, folderId, fileName);
137            }
138    
139            public static void deletePortletFolder(long folderId)
140                    throws PortalException {
141    
142                    getPortletFileRepository().deletePortletFolder(folderId);
143            }
144    
145            public static void deletePortletRepository(long groupId, String portletId)
146                    throws PortalException {
147    
148                    getPortletFileRepository().deletePortletRepository(groupId, portletId);
149            }
150    
151            public static Repository fetchPortletRepository(
152                    long groupId, String portletId) {
153    
154                    return getPortletFileRepository().fetchPortletRepository(
155                            groupId, portletId);
156            }
157    
158            public static String getDownloadPortletFileEntryURL(
159                    ThemeDisplay themeDisplay, FileEntry fileEntry, String queryString) {
160    
161                    return getPortletFileRepository().getDownloadPortletFileEntryURL(
162                            themeDisplay, fileEntry, queryString);
163            }
164    
165            public static String getDownloadPortletFileEntryURL(
166                    ThemeDisplay themeDisplay, FileEntry fileEntry, String queryString,
167                    boolean absoluteURL) {
168    
169                    return getPortletFileRepository().getDownloadPortletFileEntryURL(
170                            themeDisplay, fileEntry, queryString, absoluteURL);
171            }
172    
173            public static List<FileEntry> getPortletFileEntries(
174                            long groupId, long folderId)
175                    throws PortalException {
176    
177                    return getPortletFileRepository().getPortletFileEntries(
178                            groupId, folderId);
179            }
180    
181            public static List<FileEntry> getPortletFileEntries(
182                            long groupId, long folderId, int status)
183                    throws PortalException {
184    
185                    return getPortletFileRepository().getPortletFileEntries(
186                            groupId, folderId, status);
187            }
188    
189            public static List<FileEntry> getPortletFileEntries(
190                            long groupId, long folderId, int status, int start, int end,
191                            OrderByComparator<FileEntry> obc)
192                    throws PortalException {
193    
194                    return getPortletFileRepository().getPortletFileEntries(
195                            groupId, folderId, status, start, end, obc);
196            }
197    
198            public static List<FileEntry> getPortletFileEntries(
199                            long groupId, long folderId, OrderByComparator<FileEntry> obc)
200                    throws PortalException {
201    
202                    return getPortletFileRepository().getPortletFileEntries(
203                            groupId, folderId, obc);
204            }
205    
206            public static int getPortletFileEntriesCount(long groupId, long folderId)
207                    throws PortalException {
208    
209                    return getPortletFileRepository().getPortletFileEntriesCount(
210                            groupId, folderId);
211            }
212    
213            public static int getPortletFileEntriesCount(
214                            long groupId, long folderId, int status)
215                    throws PortalException {
216    
217                    return getPortletFileRepository().getPortletFileEntriesCount(
218                            groupId, folderId, status);
219            }
220    
221            public static FileEntry getPortletFileEntry(long fileEntryId)
222                    throws PortalException {
223    
224                    return getPortletFileRepository().getPortletFileEntry(fileEntryId);
225            }
226    
227            public static FileEntry getPortletFileEntry(
228                            long groupId, long folderId, String fileName)
229                    throws PortalException {
230    
231                    return getPortletFileRepository().getPortletFileEntry(
232                            groupId, folderId, fileName);
233            }
234    
235            public static FileEntry getPortletFileEntry(String uuid, long groupId)
236                    throws PortalException {
237    
238                    return getPortletFileRepository().getPortletFileEntry(uuid, groupId);
239            }
240    
241            public static String getPortletFileEntryURL(
242                    ThemeDisplay themeDisplay, FileEntry fileEntry, String queryString) {
243    
244                    return getPortletFileRepository().getPortletFileEntryURL(
245                            themeDisplay, fileEntry, queryString);
246            }
247    
248            public static String getPortletFileEntryURL(
249                    ThemeDisplay themeDisplay, FileEntry fileEntry, String queryString,
250                    boolean absoluteURL) {
251    
252                    return getPortletFileRepository().getPortletFileEntryURL(
253                            themeDisplay, fileEntry, queryString, absoluteURL);
254            }
255    
256            public static PortletFileRepository getPortletFileRepository() {
257                    PortalRuntimePermission.checkGetBeanProperty(
258                            PortletFileRepositoryUtil.class);
259    
260                    return _portletFileRepository;
261            }
262    
263            public static Folder getPortletFolder(long folderId)
264                    throws PortalException {
265    
266                    return getPortletFileRepository().getPortletFolder(folderId);
267            }
268    
269            public static Folder getPortletFolder(
270                            long repositoryId, long parentFolderId, String folderName)
271                    throws PortalException {
272    
273                    return getPortletFileRepository().getPortletFolder(
274                            repositoryId, parentFolderId, folderName);
275            }
276    
277            public static Repository getPortletRepository(
278                            long groupId, String portletId)
279                    throws PortalException {
280    
281                    return getPortletFileRepository().getPortletRepository(
282                            groupId, portletId);
283            }
284    
285            public static FileEntry movePortletFileEntryToTrash(
286                            long userId, long fileEntryId)
287                    throws PortalException {
288    
289                    return getPortletFileRepository().movePortletFileEntryToTrash(
290                            userId, fileEntryId);
291            }
292    
293            public static FileEntry movePortletFileEntryToTrash(
294                            long groupId, long userId, long folderId, String fileName)
295                    throws PortalException {
296    
297                    return getPortletFileRepository().movePortletFileEntryToTrash(
298                            groupId, userId, folderId, fileName);
299            }
300    
301            public static void restorePortletFileEntryFromTrash(
302                            long userId, long fileEntryId)
303                    throws PortalException {
304    
305                    getPortletFileRepository().restorePortletFileEntryFromTrash(
306                            userId, fileEntryId);
307            }
308    
309            public static void restorePortletFileEntryFromTrash(
310                            long groupId, long userId, long folderId, String fileName)
311                    throws PortalException {
312    
313                    getPortletFileRepository().restorePortletFileEntryFromTrash(
314                            groupId, userId, folderId, fileName);
315            }
316    
317            public static Hits searchPortletFileEntries(
318                            long repositoryId, SearchContext searchContext)
319                    throws PortalException {
320    
321                    return getPortletFileRepository().searchPortletFileEntries(
322                            repositoryId, searchContext);
323            }
324    
325            public void setPortletFileRepository(
326                    PortletFileRepository portletFileRepository) {
327    
328                    PortalRuntimePermission.checkSetBeanProperty(getClass());
329    
330                    _portletFileRepository = portletFileRepository;
331            }
332    
333            private static PortletFileRepository _portletFileRepository;
334    
335    }