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, byte[] bytes, String fileName,
057                            String mimeType, boolean indexingEnabled)
058                    throws PortalException {
059    
060                    return getPortletFileRepository().addPortletFileEntry(
061                            groupId, userId, className, classPK, portletId, folderId, bytes,
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, File file, String fileName,
068                            String mimeType, boolean indexingEnabled)
069                    throws PortalException {
070    
071                    return getPortletFileRepository().addPortletFileEntry(
072                            groupId, userId, className, classPK, portletId, folderId, file,
073                            fileName, mimeType, indexingEnabled);
074            }
075    
076            public static FileEntry addPortletFileEntry(
077                            long groupId, long userId, String className, long classPK,
078                            String portletId, long folderId, InputStream inputStream,
079                            String fileName, String mimeType, boolean indexingEnabled)
080                    throws PortalException {
081    
082                    return getPortletFileRepository().addPortletFileEntry(
083                            groupId, userId, className, classPK, portletId, folderId,
084                            inputStream, fileName, mimeType, indexingEnabled);
085            }
086    
087            public static Folder addPortletFolder(
088                            long userId, long repositoryId, long parentFolderId,
089                            String folderName, ServiceContext serviceContext)
090                    throws PortalException {
091    
092                    return getPortletFileRepository().addPortletFolder(
093                            userId, repositoryId, parentFolderId, folderName, serviceContext);
094            }
095    
096            public static Folder addPortletFolder(
097                            long groupId, long userId, String portletId, long parentFolderId,
098                            String folderName, ServiceContext serviceContext)
099                    throws PortalException {
100    
101                    return getPortletFileRepository().addPortletFolder(
102                            groupId, userId, portletId, parentFolderId, folderName,
103                            serviceContext);
104            }
105    
106            public static Repository addPortletRepository(
107                            long groupId, String portletId, ServiceContext serviceContext)
108                    throws PortalException {
109    
110                    return getPortletFileRepository().addPortletRepository(
111                            groupId, portletId, serviceContext);
112            }
113    
114            /**
115             * @deprecated As of 7.0.0, replaced by {@link #deletePortletFolder}
116             */
117            @Deprecated
118            public static void deleteFolder(long folderId) throws PortalException {
119                    getPortletFileRepository().deleteFolder(folderId);
120            }
121    
122            public static void deletePortletFileEntries(long groupId, long folderId)
123                    throws PortalException {
124    
125                    getPortletFileRepository().deletePortletFileEntries(groupId, folderId);
126            }
127    
128            public static void deletePortletFileEntries(
129                            long groupId, long folderId, int status)
130                    throws PortalException {
131    
132                    getPortletFileRepository().deletePortletFileEntries(
133                            groupId, folderId, status);
134            }
135    
136            public static void deletePortletFileEntry(long fileEntryId)
137                    throws PortalException {
138    
139                    getPortletFileRepository().deletePortletFileEntry(fileEntryId);
140            }
141    
142            public static void deletePortletFileEntry(
143                            long groupId, long folderId, String fileName)
144                    throws PortalException {
145    
146                    getPortletFileRepository().deletePortletFileEntry(
147                            groupId, folderId, fileName);
148            }
149    
150            public static void deletePortletFolder(long folderId)
151                    throws PortalException {
152    
153                    getPortletFileRepository().deletePortletFolder(folderId);
154            }
155    
156            public static void deletePortletRepository(long groupId, String portletId)
157                    throws PortalException {
158    
159                    getPortletFileRepository().deletePortletRepository(groupId, portletId);
160            }
161    
162            public static Repository fetchPortletRepository(
163                    long groupId, String portletId) {
164    
165                    return getPortletFileRepository().fetchPortletRepository(
166                            groupId, portletId);
167            }
168    
169            public static String getDownloadPortletFileEntryURL(
170                    ThemeDisplay themeDisplay, FileEntry fileEntry, String queryString) {
171    
172                    return getPortletFileRepository().getDownloadPortletFileEntryURL(
173                            themeDisplay, fileEntry, queryString);
174            }
175    
176            public static String getDownloadPortletFileEntryURL(
177                    ThemeDisplay themeDisplay, FileEntry fileEntry, String queryString,
178                    boolean absoluteURL) {
179    
180                    return getPortletFileRepository().getDownloadPortletFileEntryURL(
181                            themeDisplay, fileEntry, queryString, absoluteURL);
182            }
183    
184            public static List<FileEntry> getPortletFileEntries(
185                            long groupId, long folderId)
186                    throws PortalException {
187    
188                    return getPortletFileRepository().getPortletFileEntries(
189                            groupId, folderId);
190            }
191    
192            public static List<FileEntry> getPortletFileEntries(
193                            long groupId, long folderId, int status)
194                    throws PortalException {
195    
196                    return getPortletFileRepository().getPortletFileEntries(
197                            groupId, folderId, status);
198            }
199    
200            public static List<FileEntry> getPortletFileEntries(
201                            long groupId, long folderId, int status, int start, int end,
202                            OrderByComparator<FileEntry> obc)
203                    throws PortalException {
204    
205                    return getPortletFileRepository().getPortletFileEntries(
206                            groupId, folderId, status, start, end, obc);
207            }
208    
209            public static List<FileEntry> getPortletFileEntries(
210                            long groupId, long folderId, OrderByComparator<FileEntry> obc)
211                    throws PortalException {
212    
213                    return getPortletFileRepository().getPortletFileEntries(
214                            groupId, folderId, obc);
215            }
216    
217            public static int getPortletFileEntriesCount(long groupId, long folderId)
218                    throws PortalException {
219    
220                    return getPortletFileRepository().getPortletFileEntriesCount(
221                            groupId, folderId);
222            }
223    
224            public static int getPortletFileEntriesCount(
225                            long groupId, long folderId, int status)
226                    throws PortalException {
227    
228                    return getPortletFileRepository().getPortletFileEntriesCount(
229                            groupId, folderId, status);
230            }
231    
232            public static FileEntry getPortletFileEntry(long fileEntryId)
233                    throws PortalException {
234    
235                    return getPortletFileRepository().getPortletFileEntry(fileEntryId);
236            }
237    
238            public static FileEntry getPortletFileEntry(
239                            long groupId, long folderId, String fileName)
240                    throws PortalException {
241    
242                    return getPortletFileRepository().getPortletFileEntry(
243                            groupId, folderId, fileName);
244            }
245    
246            public static FileEntry getPortletFileEntry(String uuid, long groupId)
247                    throws PortalException {
248    
249                    return getPortletFileRepository().getPortletFileEntry(uuid, groupId);
250            }
251    
252            public static String getPortletFileEntryURL(
253                    ThemeDisplay themeDisplay, FileEntry fileEntry, String queryString) {
254    
255                    return getPortletFileRepository().getPortletFileEntryURL(
256                            themeDisplay, fileEntry, queryString);
257            }
258    
259            public static String getPortletFileEntryURL(
260                    ThemeDisplay themeDisplay, FileEntry fileEntry, String queryString,
261                    boolean absoluteURL) {
262    
263                    return getPortletFileRepository().getPortletFileEntryURL(
264                            themeDisplay, fileEntry, queryString, absoluteURL);
265            }
266    
267            public static PortletFileRepository getPortletFileRepository() {
268                    PortalRuntimePermission.checkGetBeanProperty(
269                            PortletFileRepositoryUtil.class);
270    
271                    return _portletFileRepository;
272            }
273    
274            public static Folder getPortletFolder(long folderId)
275                    throws PortalException {
276    
277                    return getPortletFileRepository().getPortletFolder(folderId);
278            }
279    
280            public static Folder getPortletFolder(
281                            long repositoryId, long parentFolderId, String folderName)
282                    throws PortalException {
283    
284                    return getPortletFileRepository().getPortletFolder(
285                            repositoryId, parentFolderId, folderName);
286            }
287    
288            public static Repository getPortletRepository(
289                            long groupId, String portletId)
290                    throws PortalException {
291    
292                    return getPortletFileRepository().getPortletRepository(
293                            groupId, portletId);
294            }
295    
296            public static String getUniqueFileName(
297                    long groupId, long folderId, String fileName) {
298    
299                    return getPortletFileRepository().getUniqueFileName(
300                            groupId, folderId, fileName);
301            }
302    
303            public static FileEntry movePortletFileEntryToTrash(
304                            long userId, long fileEntryId)
305                    throws PortalException {
306    
307                    return getPortletFileRepository().movePortletFileEntryToTrash(
308                            userId, fileEntryId);
309            }
310    
311            public static FileEntry movePortletFileEntryToTrash(
312                            long groupId, long userId, long folderId, String fileName)
313                    throws PortalException {
314    
315                    return getPortletFileRepository().movePortletFileEntryToTrash(
316                            groupId, userId, folderId, fileName);
317            }
318    
319            public static Folder movePortletFolder(
320                            long groupId, long userId, long folderId, long parentFolderId,
321                            ServiceContext serviceContext)
322                    throws PortalException {
323    
324                    return getPortletFileRepository().movePortletFolder(
325                            groupId, userId, folderId, parentFolderId, serviceContext);
326            }
327    
328            public static void restorePortletFileEntryFromTrash(
329                            long userId, long fileEntryId)
330                    throws PortalException {
331    
332                    getPortletFileRepository().restorePortletFileEntryFromTrash(
333                            userId, fileEntryId);
334            }
335    
336            public static void restorePortletFileEntryFromTrash(
337                            long groupId, long userId, long folderId, String fileName)
338                    throws PortalException {
339    
340                    getPortletFileRepository().restorePortletFileEntryFromTrash(
341                            groupId, userId, folderId, fileName);
342            }
343    
344            public static Hits searchPortletFileEntries(
345                            long repositoryId, SearchContext searchContext)
346                    throws PortalException {
347    
348                    return getPortletFileRepository().searchPortletFileEntries(
349                            repositoryId, searchContext);
350            }
351    
352            public void setPortletFileRepository(
353                    PortletFileRepository portletFileRepository) {
354    
355                    PortalRuntimePermission.checkSetBeanProperty(getClass());
356    
357                    _portletFileRepository = portletFileRepository;
358            }
359    
360            private static PortletFileRepository _portletFileRepository;
361    
362    }