001
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
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 int getFoldersCount(long parentFolderId, boolean includeMountfolders)
303 throws PortalException {
304
305 return documentRepository.getFoldersCount(
306 parentFolderId, includeMountfolders);
307 }
308
309 @Override
310 public int getFoldersCount(
311 long parentFolderId, int status, boolean includeMountfolders)
312 throws PortalException {
313
314 return documentRepository.getFoldersCount(
315 parentFolderId, status, includeMountfolders);
316 }
317
318 @Override
319 public List<FileEntry> getRepositoryFileEntries(
320 long userId, long rootFolderId, int start, int end,
321 OrderByComparator<FileEntry> obc)
322 throws PortalException {
323
324 checkDocumentRepository();
325
326 return documentRepository.getRepositoryFileEntries(
327 userId, rootFolderId, start, end, obc);
328 }
329
330 @Override
331 public long getRepositoryId() {
332 checkDocumentRepository();
333
334 return documentRepository.getRepositoryId();
335 }
336
337 @Override
338 public <C extends Capability> boolean isCapabilityProvided(
339 Class<C> capabilityClass) {
340
341 checkDocumentRepository();
342
343 return documentRepository.isCapabilityProvided(capabilityClass);
344 }
345
346 @Override
347 public FileEntry moveFileEntry(
348 long userId, long fileEntryId, long newFolderId,
349 ServiceContext serviceContext)
350 throws PortalException {
351
352 checkDocumentRepository();
353
354 return documentRepository.moveFileEntry(
355 userId, fileEntryId, newFolderId, serviceContext);
356 }
357
358 @Override
359 public Folder moveFolder(
360 long userId, long folderId, long parentFolderId,
361 ServiceContext serviceContext)
362 throws PortalException {
363
364 checkDocumentRepository();
365
366 return documentRepository.moveFolder(
367 userId, folderId, parentFolderId, serviceContext);
368 }
369
370 @Override
371 public void revertFileEntry(
372 long userId, long fileEntryId, String version,
373 ServiceContext serviceContext)
374 throws PortalException {
375
376 checkDocumentRepository();
377
378 documentRepository.revertFileEntry(
379 userId, fileEntryId, version, serviceContext);
380 }
381
382 public void setDocumentRepository(T documentRepository) {
383 if (this.documentRepository != null) {
384 throw new IllegalStateException(
385 "Unable to initialize an initialized document repository");
386 }
387
388 this.documentRepository = documentRepository;
389 }
390
391 @Override
392 public FileEntry updateFileEntry(
393 long userId, long fileEntryId, String sourceFileName,
394 String mimeType, String title, String description, String changeLog,
395 boolean majorVersion, File file, ServiceContext serviceContext)
396 throws PortalException {
397
398 checkDocumentRepository();
399
400 return documentRepository.updateFileEntry(
401 userId, fileEntryId, sourceFileName, mimeType, title, description,
402 changeLog, majorVersion, file, serviceContext);
403 }
404
405 @Override
406 public FileEntry updateFileEntry(
407 long userId, long fileEntryId, String sourceFileName,
408 String mimeType, String title, String description, String changeLog,
409 boolean majorVersion, InputStream is, long size,
410 ServiceContext serviceContext)
411 throws PortalException {
412
413 checkDocumentRepository();
414
415 return documentRepository.updateFileEntry(
416 userId, fileEntryId, sourceFileName, mimeType, title, description,
417 changeLog, majorVersion, is, size, serviceContext);
418 }
419
420 @Override
421 public FileShortcut updateFileShortcut(
422 long userId, long fileShortcutId, long folderId, long toFileEntryId,
423 ServiceContext serviceContext)
424 throws PortalException {
425
426 checkDocumentRepository();
427
428 return documentRepository.updateFileShortcut(
429 userId, fileShortcutId, folderId, toFileEntryId, serviceContext);
430 }
431
432 @Override
433 public void updateFileShortcuts(
434 long oldToFileEntryId, long newToFileEntryId)
435 throws PortalException {
436
437 checkDocumentRepository();
438
439 documentRepository.updateFileShortcuts(
440 oldToFileEntryId, newToFileEntryId);
441 }
442
443 @Override
444 public Folder updateFolder(
445 long folderId, long parentFolderId, String name, String description,
446 ServiceContext serviceContext)
447 throws PortalException {
448
449 checkDocumentRepository();
450
451 return documentRepository.updateFolder(
452 folderId, parentFolderId, name, description, serviceContext);
453 }
454
455 protected void checkDocumentRepository() {
456 if (documentRepository == null) {
457 throw new IllegalStateException(
458 "Document repositry is not initialized");
459 }
460 }
461
462 protected T documentRepository;
463
464 }