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