001
014
015 package com.liferay.portal.repository.liferayrepository;
016
017 import com.liferay.portal.kernel.exception.PortalException;
018 import com.liferay.portal.kernel.exception.SystemException;
019 import com.liferay.portal.kernel.repository.Repository;
020 import com.liferay.portal.kernel.repository.model.FileEntry;
021 import com.liferay.portal.kernel.repository.model.FileVersion;
022 import com.liferay.portal.kernel.repository.model.Folder;
023 import com.liferay.portal.kernel.search.BooleanQuery;
024 import com.liferay.portal.kernel.search.Hits;
025 import com.liferay.portal.kernel.search.Indexer;
026 import com.liferay.portal.kernel.search.IndexerRegistryUtil;
027 import com.liferay.portal.kernel.search.Query;
028 import com.liferay.portal.kernel.search.SearchContext;
029 import com.liferay.portal.kernel.search.SearchEngineUtil;
030 import com.liferay.portal.kernel.search.SearchException;
031 import com.liferay.portal.kernel.util.OrderByComparator;
032 import com.liferay.portal.kernel.util.ParamUtil;
033 import com.liferay.portal.kernel.util.SortedArrayList;
034 import com.liferay.portal.model.Lock;
035 import com.liferay.portal.repository.liferayrepository.model.LiferayFileEntry;
036 import com.liferay.portal.repository.liferayrepository.model.LiferayFileVersion;
037 import com.liferay.portal.repository.liferayrepository.model.LiferayFolder;
038 import com.liferay.portal.service.RepositoryService;
039 import com.liferay.portal.service.ServiceContext;
040 import com.liferay.portlet.documentlibrary.model.DLFileEntry;
041 import com.liferay.portlet.documentlibrary.model.DLFileEntryConstants;
042 import com.liferay.portlet.documentlibrary.model.DLFileVersion;
043 import com.liferay.portlet.documentlibrary.model.DLFolder;
044 import com.liferay.portlet.documentlibrary.service.DLAppHelperLocalService;
045 import com.liferay.portlet.documentlibrary.service.DLFileEntryLocalService;
046 import com.liferay.portlet.documentlibrary.service.DLFileEntryService;
047 import com.liferay.portlet.documentlibrary.service.DLFileVersionLocalService;
048 import com.liferay.portlet.documentlibrary.service.DLFileVersionService;
049 import com.liferay.portlet.documentlibrary.service.DLFolderLocalService;
050 import com.liferay.portlet.documentlibrary.service.DLFolderService;
051 import com.liferay.portlet.dynamicdatamapping.storage.Fields;
052
053 import java.io.File;
054 import java.io.InputStream;
055
056 import java.util.List;
057 import java.util.Map;
058
059
062 public class LiferayRepository
063 extends LiferayRepositoryBase implements Repository {
064
065 public LiferayRepository(
066 RepositoryService repositoryService,
067 DLAppHelperLocalService dlAppHelperLocalService,
068 DLFileEntryLocalService dlFileEntryLocalService,
069 DLFileEntryService dlFileEntryService,
070 DLFileVersionLocalService dlFileVersionLocalService,
071 DLFileVersionService dlFileVersionService,
072 DLFolderLocalService dlFolderLocalService,
073 DLFolderService dlFolderService, long repositoryId) {
074
075 super(
076 repositoryService, dlAppHelperLocalService, dlFileEntryLocalService,
077 dlFileEntryService, dlFileVersionLocalService, dlFileVersionService,
078 dlFolderLocalService, dlFolderService, repositoryId);
079 }
080
081 public LiferayRepository(
082 RepositoryService repositoryService,
083 DLAppHelperLocalService dlAppHelperLocalService,
084 DLFileEntryLocalService dlFileEntryLocalService,
085 DLFileEntryService dlFileEntryService,
086 DLFileVersionLocalService dlFileVersionLocalService,
087 DLFileVersionService dlFileVersionService,
088 DLFolderLocalService dlFolderLocalService,
089 DLFolderService dlFolderService, long folderId,
090 long fileEntryId, long fileVersionId) {
091
092 super(
093 repositoryService, dlAppHelperLocalService, dlFileEntryLocalService,
094 dlFileEntryService, dlFileVersionLocalService, dlFileVersionService,
095 dlFolderLocalService, dlFolderService, folderId, fileEntryId,
096 fileVersionId);
097 }
098
099 public FileEntry addFileEntry(
100 long folderId, String sourceFileName, String mimeType, String title,
101 String description, String changeLog, File file,
102 ServiceContext serviceContext)
103 throws PortalException, SystemException {
104
105 long fileEntryTypeId = ParamUtil.getLong(
106 serviceContext, "fileEntryTypeId", -1L);
107 Map<String, Fields> fieldsMap = getFieldsMap(
108 serviceContext, fileEntryTypeId);
109 long size = 0;
110
111 if (file != null) {
112 size = file.length();
113 }
114
115 DLFileEntry dlFileEntry = dlFileEntryService.addFileEntry(
116 getGroupId(), getRepositoryId(), toFolderId(folderId),
117 sourceFileName, mimeType, title, description, changeLog,
118 fileEntryTypeId, fieldsMap, file, null, size, serviceContext);
119
120 addFileEntryResources(dlFileEntry, serviceContext);
121
122 return new LiferayFileEntry(dlFileEntry);
123 }
124
125 public FileEntry addFileEntry(
126 long folderId, String sourceFileName, String mimeType, String title,
127 String description, String changeLog, InputStream is, long size,
128 ServiceContext serviceContext)
129 throws PortalException, SystemException {
130
131 long fileEntryTypeId = ParamUtil.getLong(
132 serviceContext, "fileEntryTypeId", -1L);
133 Map<String, Fields> fieldsMap = getFieldsMap(
134 serviceContext, fileEntryTypeId);
135
136 DLFileEntry dlFileEntry = dlFileEntryService.addFileEntry(
137 getGroupId(), getRepositoryId(), toFolderId(folderId),
138 sourceFileName, mimeType, title, description, changeLog,
139 fileEntryTypeId, fieldsMap, null, is, size, serviceContext);
140
141 addFileEntryResources(dlFileEntry, serviceContext);
142
143 return new LiferayFileEntry(dlFileEntry);
144 }
145
146 public Folder addFolder(
147 long parentFolderId, String title, String description,
148 ServiceContext serviceContext)
149 throws PortalException, SystemException {
150
151 boolean mountPoint = ParamUtil.getBoolean(serviceContext, "mountPoint");
152
153 DLFolder dlFolder = dlFolderService.addFolder(
154 getGroupId(), getRepositoryId(), mountPoint,
155 toFolderId(parentFolderId), title, description, serviceContext);
156
157 return new LiferayFolder(dlFolder);
158 }
159
160 public void cancelCheckOut(long fileEntryId)
161 throws PortalException, SystemException {
162
163 dlFileEntryService.cancelCheckOut(fileEntryId);
164 }
165
166 public void checkInFileEntry(
167 long fileEntryId, boolean major, String changeLog,
168 ServiceContext serviceContext)
169 throws PortalException, SystemException {
170
171 dlFileEntryService.checkInFileEntry(
172 fileEntryId, major, changeLog, serviceContext);
173 }
174
175 public void checkInFileEntry(long fileEntryId, String lockUuid)
176 throws PortalException, SystemException {
177
178 dlFileEntryService.checkInFileEntry(fileEntryId, lockUuid);
179 }
180
181 public FileEntry checkOutFileEntry(long fileEntryId)
182 throws PortalException, SystemException {
183
184 DLFileEntry dlFileEntry = dlFileEntryService.checkOutFileEntry(
185 fileEntryId);
186
187 return new LiferayFileEntry(dlFileEntry);
188 }
189
190 public FileEntry checkOutFileEntry(
191 long fileEntryId, String owner, long expirationTime)
192 throws PortalException, SystemException {
193
194 DLFileEntry dlFileEntry = dlFileEntryService.checkOutFileEntry(
195 fileEntryId, owner, expirationTime);
196
197 return new LiferayFileEntry(dlFileEntry);
198 }
199
200 public FileEntry copyFileEntry(
201 long groupId, long fileEntryId, long destFolderId,
202 ServiceContext serviceContext)
203 throws PortalException, SystemException {
204
205 DLFileEntry dlFileEntry = dlFileEntryService.copyFileEntry(
206 groupId, getRepositoryId(), fileEntryId, destFolderId,
207 serviceContext);
208
209 return new LiferayFileEntry(dlFileEntry);
210 }
211
212 public void deleteFileEntry(long fileEntryId)
213 throws PortalException, SystemException {
214
215 dlFileEntryService.deleteFileEntry(fileEntryId);
216 }
217
218 public void deleteFileEntry(long folderId, String title)
219 throws PortalException, SystemException {
220
221 dlFileEntryService.deleteFileEntry(
222 getGroupId(), toFolderId(folderId), title);
223 }
224
225 public void deleteFolder(long folderId)
226 throws PortalException, SystemException {
227
228 dlFolderService.deleteFolder(folderId);
229 }
230
231 public void deleteFolder(long parentFolderId, String title)
232 throws PortalException, SystemException {
233
234 dlFolderService.deleteFolder(
235 getGroupId(), toFolderId(parentFolderId), title);
236 }
237
238 public List<FileEntry> getFileEntries(
239 long folderId, int start, int end, OrderByComparator obc)
240 throws SystemException {
241
242 List<DLFileEntry> dlFileEntries = dlFileEntryService.getFileEntries(
243 getGroupId(), toFolderId(folderId), start, end, obc);
244
245 return toFileEntries(dlFileEntries);
246 }
247
248 public List<FileEntry> getFileEntries(
249 long folderId, long fileEntryTypeId, int start, int end,
250 OrderByComparator obc)
251 throws SystemException {
252
253 List<DLFileEntry> dlFileEntries = dlFileEntryService.getFileEntries(
254 getGroupId(), toFolderId(folderId), fileEntryTypeId, start, end,
255 obc);
256
257 return toFileEntries(dlFileEntries);
258 }
259
260 public List<Object> getFileEntriesAndFileShortcuts(
261 long folderId, int status, int start, int end)
262 throws SystemException {
263
264 List<Object> dlFileEntriesAndFileShortcuts =
265 dlFolderService.getFileEntriesAndFileShortcuts(
266 getGroupId(), toFolderId(folderId), status, start, end);
267
268 return toFileEntriesAndFolders(dlFileEntriesAndFileShortcuts);
269 }
270
271 public int getFileEntriesAndFileShortcutsCount(long folderId, int status)
272 throws SystemException {
273
274 return dlFolderService.getFileEntriesAndFileShortcutsCount(
275 getGroupId(), toFolderId(folderId), status);
276 }
277
278 public int getFileEntriesCount(long folderId) throws SystemException {
279 return dlFileEntryService.getFileEntriesCount(
280 getGroupId(), toFolderId(folderId));
281 }
282
283 public int getFileEntriesCount(long folderId, long fileEntryTypeId)
284 throws SystemException {
285
286 return dlFileEntryService.getFileEntriesCount(
287 getGroupId(), toFolderId(folderId), fileEntryTypeId);
288 }
289
290 public FileEntry getFileEntry(long fileEntryId)
291 throws PortalException, SystemException {
292
293 DLFileEntry dlFileEntry = dlFileEntryService.getFileEntry(
294 fileEntryId);
295
296 return new LiferayFileEntry(dlFileEntry);
297 }
298
299 public FileEntry getFileEntry(long folderId, String title)
300 throws PortalException, SystemException {
301
302 DLFileEntry dlFileEntry = dlFileEntryService.getFileEntry(
303 getGroupId(), toFolderId(folderId), title);
304
305 return new LiferayFileEntry(dlFileEntry);
306 }
307
308 public FileEntry getFileEntryByUuid(String uuid)
309 throws PortalException, SystemException {
310
311 DLFileEntry dlFileEntry =
312 dlFileEntryService.getFileEntryByUuidAndGroupId(uuid, getGroupId());
313
314 return new LiferayFileEntry(dlFileEntry);
315 }
316
317 public Lock getFileEntryLock(long fileEntryId) {
318 return dlFileEntryService.getFileEntryLock(fileEntryId);
319 }
320
321 public FileVersion getFileVersion(long fileVersionId)
322 throws PortalException, SystemException {
323
324 DLFileVersion dlFileVersion = dlFileVersionService.getFileVersion(
325 fileVersionId);
326
327 return new LiferayFileVersion(dlFileVersion);
328 }
329
330 public Folder getFolder(long folderId)
331 throws PortalException, SystemException {
332
333 DLFolder dlFolder = dlFolderService.getFolder(toFolderId(folderId));
334
335 return new LiferayFolder(dlFolder);
336 }
337
338 public Folder getFolder(long parentFolderId, String title)
339 throws PortalException, SystemException {
340
341 DLFolder dlFolder = dlFolderService.getFolder(
342 getGroupId(), toFolderId(parentFolderId), title);
343
344 return new LiferayFolder(dlFolder);
345 }
346
347 public List<Folder> getFolders(
348 long parentFolderId, boolean includeMountfolders, int start,
349 int end, OrderByComparator obc)
350 throws SystemException {
351
352 List<DLFolder> dlFolders = dlFolderService.getFolders(
353 getGroupId(), toFolderId(parentFolderId), includeMountfolders,
354 start, end, obc);
355
356 return toFolders(dlFolders);
357 }
358
359 public List<Object> getFoldersAndFileEntriesAndFileShortcuts(
360 long folderId, int status, boolean includeMountFolders, int start,
361 int end, OrderByComparator obc)
362 throws SystemException {
363
364 List<Object> dlFoldersAndFileEntriesAndFileShortcuts =
365 dlFolderService.getFoldersAndFileEntriesAndFileShortcuts(
366 getGroupId(), toFolderId(folderId), status, includeMountFolders,
367 start, end, obc);
368
369 return toFileEntriesAndFolders(dlFoldersAndFileEntriesAndFileShortcuts);
370 }
371
372 public List<Object> getFoldersAndFileEntriesAndFileShortcuts(
373 long folderId, int status, String[] mimeTypes,
374 boolean includeMountFolders, int start, int end,
375 OrderByComparator obc)
376 throws SystemException {
377
378 List<Object> dlFoldersAndFileEntriesAndFileShortcuts =
379 dlFolderService.getFoldersAndFileEntriesAndFileShortcuts(
380 getGroupId(), toFolderId(folderId), status, mimeTypes,
381 includeMountFolders, start, end, obc);
382
383 return toFileEntriesAndFolders(dlFoldersAndFileEntriesAndFileShortcuts);
384 }
385
386 public int getFoldersAndFileEntriesAndFileShortcutsCount(
387 long folderId, int status, boolean includeMountFolders)
388 throws SystemException {
389
390 return dlFolderService.getFoldersAndFileEntriesAndFileShortcutsCount(
391 getGroupId(), toFolderId(folderId), status, includeMountFolders);
392 }
393
394 public int getFoldersAndFileEntriesAndFileShortcutsCount(
395 long folderId, int status, String[] mimeTypes,
396 boolean includeMountFolders)
397 throws SystemException {
398
399 return dlFolderService.getFoldersAndFileEntriesAndFileShortcutsCount(
400 getGroupId(), toFolderId(folderId), status, mimeTypes,
401 includeMountFolders);
402 }
403
404 public int getFoldersCount(long parentFolderId) throws SystemException {
405 return getFoldersCount(parentFolderId, true);
406 }
407
408 public int getFoldersCount(long parentFolderId, boolean includeMountfolders)
409 throws SystemException {
410
411 return dlFolderService.getFoldersCount(
412 getGroupId(), toFolderId(parentFolderId), includeMountfolders);
413 }
414
415 public int getFoldersFileEntriesCount(List<Long> folderIds, int status)
416 throws SystemException {
417
418 return dlFileEntryService.getFoldersFileEntriesCount(
419 getGroupId(), toFolderIds(folderIds), status);
420 }
421
422 public List<Folder> getMountFolders(
423 long parentFolderId, int start, int end, OrderByComparator obc)
424 throws SystemException {
425
426 List<DLFolder> dlFolders = dlFolderService.getMountFolders(
427 getGroupId(), toFolderId(parentFolderId), start, end, obc);
428
429 return toFolders(dlFolders);
430 }
431
432 public int getMountFoldersCount(long parentFolderId)
433 throws SystemException {
434
435 return dlFolderService.getMountFoldersCount(
436 getGroupId(), toFolderId(parentFolderId));
437 }
438
439 public List<FileEntry> getRepositoryFileEntries(
440 long userId, long rootFolderId, int start, int end,
441 OrderByComparator obc)
442 throws SystemException {
443
444 List<DLFileEntry> dlFileEntries =
445 dlFileEntryService.getGroupFileEntries(
446 getGroupId(), userId, toFolderId(rootFolderId), start, end,
447 obc);
448
449 return toFileEntries(dlFileEntries);
450 }
451
452 public int getRepositoryFileEntriesCount(long userId, long rootFolderId)
453 throws SystemException {
454
455 return dlFileEntryService.getGroupFileEntriesCount(
456 getGroupId(), userId, toFolderId(rootFolderId));
457 }
458
459 public void getSubfolderIds(List<Long> folderIds, long folderId)
460 throws SystemException {
461
462 dlFolderService.getSubfolderIds(
463 folderIds, getGroupId(), toFolderId(folderId));
464 }
465
466 public List<Long> getSubfolderIds(long folderId, boolean recurse)
467 throws SystemException {
468
469 return dlFolderService.getSubfolderIds(
470 getGroupId(), toFolderId(folderId), recurse);
471 }
472
473 public Lock lockFolder(long folderId)
474 throws PortalException, SystemException {
475
476 return dlFolderService.lockFolder(toFolderId(folderId));
477 }
478
479 public Lock lockFolder(
480 long folderId, String owner, boolean inheritable,
481 long expirationTime)
482 throws PortalException, SystemException {
483
484 return dlFolderService.lockFolder(
485 toFolderId(folderId), owner, inheritable, expirationTime);
486 }
487
488 public FileEntry moveFileEntry(
489 long fileEntryId, long newFolderId, ServiceContext serviceContext)
490 throws PortalException, SystemException {
491
492 DLFileEntry dlFileEntry = dlFileEntryService.moveFileEntry(
493 fileEntryId, toFolderId(newFolderId), serviceContext);
494
495 return new LiferayFileEntry(dlFileEntry);
496 }
497
498 public Folder moveFolder(
499 long folderId, long parentFolderId, ServiceContext serviceContext)
500 throws PortalException, SystemException {
501
502 DLFolder dlFolder = dlFolderService.moveFolder(
503 toFolderId(folderId), toFolderId(parentFolderId), serviceContext);
504
505 return new LiferayFolder(dlFolder);
506 }
507
508 public Lock refreshFileEntryLock(String lockUuid, long expirationTime)
509 throws PortalException, SystemException {
510
511 return dlFileEntryService.refreshFileEntryLock(
512 lockUuid, expirationTime);
513 }
514
515 public Lock refreshFolderLock(String lockUuid, long expirationTime)
516 throws PortalException, SystemException {
517
518 return dlFolderService.refreshFolderLock(lockUuid, expirationTime);
519 }
520
521 public void revertFileEntry(
522 long fileEntryId, String version, ServiceContext serviceContext)
523 throws PortalException, SystemException {
524
525 dlFileEntryService.revertFileEntry(
526 fileEntryId, version, serviceContext);
527 }
528
529 public Hits search(SearchContext searchContext) throws SearchException {
530 Indexer indexer = IndexerRegistryUtil.getIndexer(
531 DLFileEntryConstants.getClassName());
532
533 BooleanQuery fullQuery = indexer.getFullQuery(searchContext);
534
535 return SearchEngineUtil.search(searchContext, fullQuery);
536 }
537
538 public Hits search(SearchContext searchContext, Query query)
539 throws SearchException {
540
541 return SearchEngineUtil.search(searchContext, query);
542 }
543
544 public void unlockFolder(long folderId, String lockUuid)
545 throws PortalException, SystemException {
546
547 dlFolderService.unlockFolder(
548 getGroupId(), toFolderId(folderId), lockUuid);
549 }
550
551 public void unlockFolder(long parentFolderId, String title, String lockUuid)
552 throws PortalException, SystemException {
553
554 dlFolderService.unlockFolder(
555 getGroupId(), toFolderId(parentFolderId), title, lockUuid);
556 }
557
558 public FileEntry updateFileEntry(
559 long fileEntryId, String sourceFileName, String mimeType,
560 String title, String description, String changeLog,
561 boolean majorVersion, File file, ServiceContext serviceContext)
562 throws PortalException, SystemException {
563
564 long fileEntryTypeId = ParamUtil.getLong(
565 serviceContext, "fileEntryTypeId", -1L);
566 Map<String, Fields> fieldsMap = getFieldsMap(
567 serviceContext, fileEntryTypeId);
568 long size = 0;
569
570 if (file != null) {
571 size = file.length();
572 }
573
574 DLFileEntry dlFileEntry = dlFileEntryService.updateFileEntry(
575 fileEntryId, sourceFileName, mimeType, title, description,
576 changeLog, majorVersion, fileEntryTypeId, fieldsMap, file, null,
577 size, serviceContext);
578
579 return new LiferayFileEntry(dlFileEntry);
580 }
581
582 public FileEntry updateFileEntry(
583 long fileEntryId, String sourceFileName, String mimeType,
584 String title, String description, String changeLog,
585 boolean majorVersion, InputStream is, long size,
586 ServiceContext serviceContext)
587 throws PortalException, SystemException {
588
589 long fileEntryTypeId = ParamUtil.getLong(
590 serviceContext, "fileEntryTypeId", -1L);
591 Map<String, Fields> fieldsMap = getFieldsMap(
592 serviceContext, fileEntryTypeId);
593
594 DLFileEntry dlFileEntry = dlFileEntryService.updateFileEntry(
595 fileEntryId, sourceFileName, mimeType, title, description,
596 changeLog, majorVersion, fileEntryTypeId, fieldsMap, null, is, size,
597 serviceContext);
598
599 return new LiferayFileEntry(dlFileEntry);
600 }
601
602 public Folder updateFolder(
603 long folderId, String title, String description,
604 ServiceContext serviceContext)
605 throws PortalException, SystemException {
606
607 long defaultFileEntryTypeId = ParamUtil.getLong(
608 serviceContext, "defaultFileEntryTypeId");
609 SortedArrayList<Long> fileEntryTypeIds = getLongList(
610 serviceContext, "fileEntryTypeSearchContainerPrimaryKeys");
611 boolean overrideFileEntryTypes = ParamUtil.getBoolean(
612 serviceContext, "overrideFileEntryTypes");
613
614 DLFolder dlFolder = dlFolderService.updateFolder(
615 toFolderId(folderId), title, description, defaultFileEntryTypeId,
616 fileEntryTypeIds, overrideFileEntryTypes, serviceContext);
617
618 return new LiferayFolder(dlFolder);
619 }
620
621 public boolean verifyFileEntryCheckOut(long fileEntryId, String lockUuid)
622 throws PortalException, SystemException {
623
624 return dlFileEntryService.verifyFileEntryCheckOut(
625 fileEntryId, lockUuid);
626 }
627
628 public boolean verifyInheritableLock(long folderId, String lockUuid)
629 throws PortalException, SystemException {
630
631 return dlFolderService.verifyInheritableLock(
632 toFolderId(folderId), lockUuid);
633 }
634
635 }