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.repository;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.repository.DocumentRepository;
019    import com.liferay.portal.kernel.repository.capabilities.Capability;
020    import com.liferay.portal.kernel.repository.model.FileEntry;
021    import com.liferay.portal.kernel.repository.model.FileShortcut;
022    import com.liferay.portal.kernel.repository.model.FileVersion;
023    import com.liferay.portal.kernel.repository.model.Folder;
024    import com.liferay.portal.kernel.util.OrderByComparator;
025    import com.liferay.portal.service.ServiceContext;
026    
027    import java.io.File;
028    import java.io.InputStream;
029    
030    import java.util.List;
031    
032    /**
033     * @author Adolfo P??rez
034     */
035    public abstract class InitializedDocumentRepository
036            <T extends DocumentRepository> implements DocumentRepository {
037    
038            @Override
039            public FileEntry addFileEntry(
040                            long userId, long folderId, String sourceFileName, String mimeType,
041                            String title, String description, String changeLog, File file,
042                            ServiceContext serviceContext)
043                    throws PortalException {
044    
045                    checkDocumentRepository();
046    
047                    return documentRepository.addFileEntry(
048                            userId, folderId, sourceFileName, mimeType, title, description,
049                            changeLog, file, serviceContext);
050            }
051    
052            @Override
053            public FileEntry addFileEntry(
054                            long userId, long folderId, String sourceFileName, String mimeType,
055                            String title, String description, String changeLog, InputStream is,
056                            long size, ServiceContext serviceContext)
057                    throws PortalException {
058    
059                    checkDocumentRepository();
060    
061                    return documentRepository.addFileEntry(
062                            userId, folderId, sourceFileName, mimeType, title, description,
063                            changeLog, is, size, serviceContext);
064            }
065    
066            @Override
067            public FileShortcut addFileShortcut(
068                            long userId, long folderId, long toFileEntryId,
069                            ServiceContext serviceContext)
070                    throws PortalException {
071    
072                    checkDocumentRepository();
073    
074                    return documentRepository.addFileShortcut(
075                            userId, folderId, toFileEntryId, serviceContext);
076            }
077    
078            @Override
079            public Folder addFolder(
080                            long userId, long parentFolderId, String name, String description,
081                            ServiceContext serviceContext)
082                    throws PortalException {
083    
084                    checkDocumentRepository();
085    
086                    return documentRepository.addFolder(
087                            userId, parentFolderId, name, description, serviceContext);
088            }
089    
090            @Override
091            public void checkInFileEntry(
092                            long userId, long fileEntryId, boolean major, String changeLog,
093                            ServiceContext serviceContext)
094                    throws PortalException {
095    
096                    checkDocumentRepository();
097    
098                    documentRepository.checkInFileEntry(
099                            userId, fileEntryId, major, changeLog, serviceContext);
100            }
101    
102            @Override
103            public void checkInFileEntry(
104                            long userId, long fileEntryId, String lockUuid,
105                            ServiceContext serviceContext)
106                    throws PortalException {
107    
108                    checkDocumentRepository();
109    
110                    documentRepository.checkInFileEntry(
111                            userId, fileEntryId, lockUuid, serviceContext);
112            }
113    
114            @Override
115            public FileEntry copyFileEntry(
116                            long userId, long groupId, long fileEntryId, long destFolderId,
117                            ServiceContext serviceContext)
118                    throws PortalException {
119    
120                    checkDocumentRepository();
121    
122                    return documentRepository.copyFileEntry(
123                            userId, groupId, fileEntryId, destFolderId, serviceContext);
124            }
125    
126            @Override
127            public void deleteAll() throws PortalException {
128                    checkDocumentRepository();
129    
130                    documentRepository.deleteAll();
131            }
132    
133            @Override
134            public void deleteFileEntry(long fileEntryId) throws PortalException {
135                    checkDocumentRepository();
136    
137                    documentRepository.deleteFileEntry(fileEntryId);
138            }
139    
140            @Override
141            public void deleteFileShortcut(long fileShortcutId) throws PortalException {
142                    checkDocumentRepository();
143    
144                    documentRepository.deleteFileShortcut(fileShortcutId);
145            }
146    
147            @Override
148            public void deleteFileShortcuts(long toFileEntryId) throws PortalException {
149                    checkDocumentRepository();
150    
151                    documentRepository.deleteFileShortcuts(toFileEntryId);
152            }
153    
154            @Override
155            public void deleteFolder(long folderId) throws PortalException {
156                    checkDocumentRepository();
157    
158                    documentRepository.deleteFolder(folderId);
159            }
160    
161            @Override
162            public <C extends Capability> C getCapability(Class<C> capabilityClass) {
163                    checkDocumentRepository();
164    
165                    return documentRepository.getCapability(capabilityClass);
166            }
167    
168            @Override
169            public List<FileEntry> getFileEntries(
170                            long folderId, int status, int start, int end,
171                            OrderByComparator<FileEntry> obc)
172                    throws PortalException {
173    
174                    checkDocumentRepository();
175    
176                    return documentRepository.getFileEntries(
177                            folderId, status, start, end, obc);
178            }
179    
180            @Override
181            public List<FileEntry> getFileEntries(
182                            long folderId, int start, int end, OrderByComparator<FileEntry> obc)
183                    throws PortalException {
184    
185                    checkDocumentRepository();
186    
187                    return documentRepository.getFileEntries(folderId, start, end, obc);
188            }
189    
190            @Override
191            public int getFileEntriesCount(long folderId) throws PortalException {
192                    checkDocumentRepository();
193    
194                    return documentRepository.getFileEntriesCount(folderId);
195            }
196    
197            @Override
198            public int getFileEntriesCount(long folderId, int status)
199                    throws PortalException {
200    
201                    checkDocumentRepository();
202    
203                    return documentRepository.getFileEntriesCount(folderId, status);
204            }
205    
206            @Override
207            public FileEntry getFileEntry(long fileEntryId) throws PortalException {
208                    checkDocumentRepository();
209    
210                    return documentRepository.getFileEntry(fileEntryId);
211            }
212    
213            @Override
214            public FileEntry getFileEntry(long folderId, String title)
215                    throws PortalException {
216    
217                    checkDocumentRepository();
218    
219                    return documentRepository.getFileEntry(folderId, title);
220            }
221    
222            @Override
223            public FileEntry getFileEntryByUuid(String uuid) throws PortalException {
224                    checkDocumentRepository();
225    
226                    return documentRepository.getFileEntryByUuid(uuid);
227            }
228    
229            @Override
230            public FileShortcut getFileShortcut(long fileShortcutId)
231                    throws PortalException {
232    
233                    checkDocumentRepository();
234    
235                    return documentRepository.getFileShortcut(fileShortcutId);
236            }
237    
238            @Override
239            public FileVersion getFileVersion(long fileVersionId)
240                    throws PortalException {
241    
242                    checkDocumentRepository();
243    
244                    return documentRepository.getFileVersion(fileVersionId);
245            }
246    
247            @Override
248            public Folder getFolder(long folderId) throws PortalException {
249                    checkDocumentRepository();
250    
251                    return documentRepository.getFolder(folderId);
252            }
253    
254            @Override
255            public Folder getFolder(long parentFolderId, String name)
256                    throws PortalException {
257    
258                    checkDocumentRepository();
259    
260                    return documentRepository.getFolder(parentFolderId, name);
261            }
262    
263            @Override
264            public List<FileEntry> getRepositoryFileEntries(
265                            long userId, long rootFolderId, int start, int end,
266                            OrderByComparator<FileEntry> obc)
267                    throws PortalException {
268    
269                    checkDocumentRepository();
270    
271                    return documentRepository.getRepositoryFileEntries(
272                            userId, rootFolderId, start, end, obc);
273            }
274    
275            @Override
276            public long getRepositoryId() {
277                    checkDocumentRepository();
278    
279                    return documentRepository.getRepositoryId();
280            }
281    
282            @Override
283            public <C extends Capability> boolean isCapabilityProvided(
284                    Class<C> capabilityClass) {
285    
286                    checkDocumentRepository();
287    
288                    return documentRepository.isCapabilityProvided(capabilityClass);
289            }
290    
291            @Override
292            public FileEntry moveFileEntry(
293                            long userId, long fileEntryId, long newFolderId,
294                            ServiceContext serviceContext)
295                    throws PortalException {
296    
297                    checkDocumentRepository();
298    
299                    return documentRepository.moveFileEntry(
300                            userId, fileEntryId, newFolderId, serviceContext);
301            }
302    
303            @Override
304            public Folder moveFolder(
305                            long userId, long folderId, long parentFolderId,
306                            ServiceContext serviceContext)
307                    throws PortalException {
308    
309                    checkDocumentRepository();
310    
311                    return documentRepository.moveFolder(
312                            userId, folderId, parentFolderId, serviceContext);
313            }
314    
315            @Override
316            public void revertFileEntry(
317                            long userId, long fileEntryId, String version,
318                            ServiceContext serviceContext)
319                    throws PortalException {
320    
321                    checkDocumentRepository();
322    
323                    documentRepository.revertFileEntry(
324                            userId, fileEntryId, version, serviceContext);
325            }
326    
327            public void setDocumentRepository(T documentRepository) {
328                    if (this.documentRepository != null) {
329                            throw new IllegalStateException(
330                                    "Unable to initialize an initialized document repository");
331                    }
332    
333                    this.documentRepository = documentRepository;
334            }
335    
336            @Override
337            public FileEntry updateFileEntry(
338                            long userId, long fileEntryId, String sourceFileName,
339                            String mimeType, String title, String description, String changeLog,
340                            boolean majorVersion, File file, ServiceContext serviceContext)
341                    throws PortalException {
342    
343                    checkDocumentRepository();
344    
345                    return documentRepository.updateFileEntry(
346                            userId, fileEntryId, sourceFileName, mimeType, title, description,
347                            changeLog, majorVersion, file, serviceContext);
348            }
349    
350            @Override
351            public FileEntry updateFileEntry(
352                            long userId, long fileEntryId, String sourceFileName,
353                            String mimeType, String title, String description, String changeLog,
354                            boolean majorVersion, InputStream is, long size,
355                            ServiceContext serviceContext)
356                    throws PortalException {
357    
358                    checkDocumentRepository();
359    
360                    return documentRepository.updateFileEntry(
361                            userId, fileEntryId, sourceFileName, mimeType, title, description,
362                            changeLog, majorVersion, is, size, serviceContext);
363            }
364    
365            @Override
366            public FileShortcut updateFileShortcut(
367                            long userId, long fileShortcutId, long folderId, long toFileEntryId,
368                            ServiceContext serviceContext)
369                    throws PortalException {
370    
371                    checkDocumentRepository();
372    
373                    return documentRepository.updateFileShortcut(
374                            userId, fileShortcutId, folderId, toFileEntryId, serviceContext);
375            }
376    
377            @Override
378            public void updateFileShortcuts(
379                            long oldToFileEntryId, long newToFileEntryId)
380                    throws PortalException {
381    
382                    checkDocumentRepository();
383    
384                    documentRepository.updateFileShortcuts(
385                            oldToFileEntryId, newToFileEntryId);
386            }
387    
388            @Override
389            public Folder updateFolder(
390                            long folderId, long parentFolderId, String name, String description,
391                            ServiceContext serviceContext)
392                    throws PortalException {
393    
394                    checkDocumentRepository();
395    
396                    return documentRepository.updateFolder(
397                            folderId, parentFolderId, name, description, serviceContext);
398            }
399    
400            protected void checkDocumentRepository() {
401                    if (documentRepository == null) {
402                            throw new IllegalStateException(
403                                    "Document repositry is not initialized");
404                    }
405            }
406    
407            protected T documentRepository;
408    
409    }