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.log.Log;
020 import com.liferay.portal.kernel.log.LogFactoryUtil;
021 import com.liferay.portal.kernel.repository.LocalRepository;
022 import com.liferay.portal.kernel.repository.model.FileEntry;
023 import com.liferay.portal.kernel.repository.model.FileVersion;
024 import com.liferay.portal.kernel.repository.model.Folder;
025 import com.liferay.portal.kernel.util.OrderByComparator;
026 import com.liferay.portal.kernel.util.ParamUtil;
027 import com.liferay.portal.kernel.util.SortedArrayList;
028 import com.liferay.portal.kernel.util.UnicodeProperties;
029 import com.liferay.portal.model.Repository;
030 import com.liferay.portal.repository.liferayrepository.model.LiferayFileEntry;
031 import com.liferay.portal.repository.liferayrepository.model.LiferayFileVersion;
032 import com.liferay.portal.repository.liferayrepository.model.LiferayFolder;
033 import com.liferay.portal.service.RepositoryLocalService;
034 import com.liferay.portal.service.RepositoryService;
035 import com.liferay.portal.service.ResourceLocalService;
036 import com.liferay.portal.service.ServiceContext;
037 import com.liferay.portlet.documentlibrary.NoSuchFileEntryException;
038 import com.liferay.portlet.documentlibrary.NoSuchFileVersionException;
039 import com.liferay.portlet.documentlibrary.NoSuchFolderException;
040 import com.liferay.portlet.documentlibrary.model.DLFileEntry;
041 import com.liferay.portlet.documentlibrary.model.DLFileVersion;
042 import com.liferay.portlet.documentlibrary.model.DLFolder;
043 import com.liferay.portlet.documentlibrary.service.DLAppHelperLocalService;
044 import com.liferay.portlet.documentlibrary.service.DLFileEntryLocalService;
045 import com.liferay.portlet.documentlibrary.service.DLFileEntryService;
046 import com.liferay.portlet.documentlibrary.service.DLFileVersionLocalService;
047 import com.liferay.portlet.documentlibrary.service.DLFileVersionService;
048 import com.liferay.portlet.documentlibrary.service.DLFolderLocalService;
049 import com.liferay.portlet.documentlibrary.service.DLFolderService;
050 import com.liferay.portlet.dynamicdatamapping.storage.Fields;
051
052 import java.io.File;
053 import java.io.InputStream;
054
055 import java.util.List;
056 import java.util.Map;
057
058
061 public class LiferayLocalRepository
062 extends LiferayRepositoryBase implements LocalRepository {
063
064 public LiferayLocalRepository(
065 RepositoryLocalService repositoryLocalService,
066 RepositoryService repositoryService,
067 DLAppHelperLocalService dlAppHelperLocalService,
068 DLFileEntryLocalService dlFileEntryLocalService,
069 DLFileEntryService dlFileEntryService,
070 DLFileVersionLocalService dlFileVersionLocalService,
071 DLFileVersionService dlFileVersionService,
072 DLFolderLocalService dlFolderLocalService,
073 DLFolderService dlFolderService,
074 ResourceLocalService resourceLocalService, long repositoryId) {
075
076 super(
077 repositoryLocalService, repositoryService, dlAppHelperLocalService,
078 dlFileEntryLocalService, dlFileEntryService,
079 dlFileVersionLocalService, dlFileVersionService,
080 dlFolderLocalService, dlFolderService, resourceLocalService,
081 repositoryId);
082 }
083
084 public LiferayLocalRepository(
085 RepositoryLocalService repositoryLocalService,
086 RepositoryService repositoryService,
087 DLAppHelperLocalService dlAppHelperLocalService,
088 DLFileEntryLocalService dlFileEntryLocalService,
089 DLFileEntryService dlFileEntryService,
090 DLFileVersionLocalService dlFileVersionLocalService,
091 DLFileVersionService dlFileVersionService,
092 DLFolderLocalService dlFolderLocalService,
093 DLFolderService dlFolderService,
094 ResourceLocalService resourceLocalService, long folderId,
095 long fileEntryId, long fileVersionId) {
096
097 super(
098 repositoryLocalService, repositoryService, dlAppHelperLocalService,
099 dlFileEntryLocalService, dlFileEntryService,
100 dlFileVersionLocalService, dlFileVersionService,
101 dlFolderLocalService, dlFolderService, resourceLocalService,
102 folderId, fileEntryId, fileVersionId);
103 }
104
105 @Override
106 public FileEntry addFileEntry(
107 long userId, long folderId, String sourceFileName, String mimeType,
108 String title, String description, String changeLog, File file,
109 ServiceContext serviceContext)
110 throws PortalException, SystemException {
111
112 long fileEntryTypeId = ParamUtil.getLong(
113 serviceContext, "fileEntryTypeId", -1L);
114 Map<String, Fields> fieldsMap = getFieldsMap(
115 serviceContext, fileEntryTypeId);
116 long size = 0;
117
118 if (file != null) {
119 size = file.length();
120 }
121
122 DLFileEntry dlFileEntry = dlFileEntryLocalService.addFileEntry(
123 userId, getGroupId(), getRepositoryId(), toFolderId(folderId),
124 sourceFileName, mimeType, title, description, changeLog,
125 fileEntryTypeId, fieldsMap, file, null, size, serviceContext);
126
127 addFileEntryResources(dlFileEntry, serviceContext);
128
129 return new LiferayFileEntry(dlFileEntry);
130 }
131
132 @Override
133 public FileEntry addFileEntry(
134 long userId, long folderId, String sourceFileName, String mimeType,
135 String title, String description, String changeLog, InputStream is,
136 long size, ServiceContext serviceContext)
137 throws PortalException, SystemException {
138
139 long fileEntryTypeId = ParamUtil.getLong(
140 serviceContext, "fileEntryTypeId", -1L);
141 Map<String, Fields> fieldsMap = getFieldsMap(
142 serviceContext, fileEntryTypeId);
143
144 DLFileEntry dlFileEntry = dlFileEntryLocalService.addFileEntry(
145 userId, getGroupId(), getRepositoryId(), toFolderId(folderId),
146 sourceFileName, mimeType, title, description, changeLog,
147 fileEntryTypeId, fieldsMap, null, is, size, serviceContext);
148
149 addFileEntryResources(dlFileEntry, serviceContext);
150
151 return new LiferayFileEntry(dlFileEntry);
152 }
153
154 @Override
155 public Folder addFolder(
156 long userId, long parentFolderId, String title, String description,
157 ServiceContext serviceContext)
158 throws PortalException, SystemException {
159
160 boolean mountPoint = ParamUtil.getBoolean(serviceContext, "mountPoint");
161
162 DLFolder dlFolder = dlFolderLocalService.addFolder(
163 userId, getGroupId(), getRepositoryId(), mountPoint,
164 toFolderId(parentFolderId), title, description, serviceContext);
165
166 return new LiferayFolder(dlFolder);
167 }
168
169 public void addRepository(
170 long groupId, String name, String description, String portletKey,
171 UnicodeProperties typeSettingsProperties) {
172 }
173
174 @Override
175 public void deleteAll() throws PortalException, SystemException {
176 dlFolderLocalService.deleteAll(getGroupId());
177 }
178
179 @Override
180 public void deleteFileEntry(long fileEntryId)
181 throws PortalException, SystemException {
182
183 dlFileEntryLocalService.deleteFileEntry(fileEntryId);
184 }
185
186 @Override
187 public void deleteFolder(long folderId)
188 throws PortalException, SystemException {
189
190 dlFolderLocalService.deleteFolder(folderId);
191 }
192
193 @Override
194 public List<FileEntry> getFileEntries(
195 long folderId, int start, int end, OrderByComparator obc)
196 throws SystemException {
197
198 List<DLFileEntry> dlFileEntries =
199 dlFileEntryLocalService.getFileEntries(
200 getGroupId(), toFolderId(folderId), start, end, obc);
201
202 return toFileEntries(dlFileEntries);
203 }
204
205 @Override
206 public List<Object> getFileEntriesAndFileShortcuts(
207 long folderId, int status, int start, int end)
208 throws SystemException {
209
210 List<Object> dlFileEntriesAndFileShortcuts =
211 dlFolderLocalService.getFileEntriesAndFileShortcuts(
212 getGroupId(), toFolderId(folderId), status, start, end);
213
214 return toFileEntriesAndFolders(dlFileEntriesAndFileShortcuts);
215 }
216
217 @Override
218 public int getFileEntriesAndFileShortcutsCount(long folderId, int status)
219 throws SystemException {
220
221 return dlFolderLocalService.getFileEntriesAndFileShortcutsCount(
222 getGroupId(), toFolderId(folderId), status);
223 }
224
225 @Override
226 public int getFileEntriesCount(long folderId) throws SystemException {
227 return dlFileEntryLocalService.getFileEntriesCount(
228 getGroupId(), toFolderId(folderId));
229 }
230
231 @Override
232 public FileEntry getFileEntry(long fileEntryId)
233 throws PortalException, SystemException {
234
235 DLFileEntry dlFileEntry = dlFileEntryLocalService.getFileEntry(
236 fileEntryId);
237
238 return new LiferayFileEntry(dlFileEntry);
239 }
240
241 @Override
242 public FileEntry getFileEntry(long folderId, String title)
243 throws PortalException, SystemException {
244
245 DLFileEntry dlFileEntry = dlFileEntryLocalService.getFileEntry(
246 getGroupId(), toFolderId(folderId), title);
247
248 return new LiferayFileEntry(dlFileEntry);
249 }
250
251 @Override
252 public FileEntry getFileEntryByUuid(String uuid)
253 throws PortalException, SystemException {
254
255 DLFileEntry dlFileEntry =
256 dlFileEntryLocalService.getFileEntryByUuidAndGroupId(
257 uuid, getGroupId());
258
259 return new LiferayFileEntry(dlFileEntry);
260 }
261
262 @Override
263 public FileVersion getFileVersion(long fileVersionId)
264 throws PortalException, SystemException {
265
266 DLFileVersion dlFileVersion = dlFileVersionLocalService.getFileVersion(
267 fileVersionId);
268
269 return new LiferayFileVersion(dlFileVersion);
270 }
271
272 @Override
273 public Folder getFolder(long folderId)
274 throws PortalException, SystemException {
275
276 DLFolder dlFolder = dlFolderLocalService.getFolder(folderId);
277
278 return new LiferayFolder(dlFolder);
279 }
280
281 @Override
282 public Folder getFolder(long parentFolderId, String title)
283 throws PortalException, SystemException {
284
285 DLFolder dlFolder = dlFolderLocalService.getFolder(
286 getGroupId(), toFolderId(parentFolderId), title);
287
288 return new LiferayFolder(dlFolder);
289 }
290
291 @Override
292 public List<Folder> getFolders(
293 long parentFolderId, boolean includeMountfolders, int start,
294 int end, OrderByComparator obc)
295 throws SystemException {
296
297 List<DLFolder> dlFolders = dlFolderLocalService.getFolders(
298 getGroupId(), toFolderId(parentFolderId), includeMountfolders,
299 start, end, obc);
300
301 return toFolders(dlFolders);
302 }
303
304 @Override
305 public List<Object> getFoldersAndFileEntriesAndFileShortcuts(
306 long folderId, int status, boolean includeMountFolders, int start,
307 int end, OrderByComparator obc)
308 throws SystemException {
309
310 List<Object> dlFoldersAndFileEntriesAndFileShortcuts =
311 dlFolderLocalService.getFoldersAndFileEntriesAndFileShortcuts(
312 getGroupId(), toFolderId(folderId), status, includeMountFolders,
313 start, end, obc);
314
315 return toFileEntriesAndFolders(dlFoldersAndFileEntriesAndFileShortcuts);
316 }
317
318 @Override
319 public List<Object> getFoldersAndFileEntriesAndFileShortcuts(
320 long folderId, int status, String[] mimeTypes,
321 boolean includeMountFolders, int start, int end,
322 OrderByComparator obc)
323 throws SystemException {
324
325 List<Object> dlFoldersAndFileEntriesAndFileShortcuts =
326 dlFolderLocalService.getFoldersAndFileEntriesAndFileShortcuts(
327 getGroupId(), toFolderId(folderId), status, mimeTypes,
328 includeMountFolders, start, end, obc);
329
330 return toFileEntriesAndFolders(dlFoldersAndFileEntriesAndFileShortcuts);
331 }
332
333 @Override
334 public int getFoldersAndFileEntriesAndFileShortcutsCount(
335 long folderId, int status, boolean includeMountFolders)
336 throws SystemException {
337
338 return dlFolderLocalService.
339 getFoldersAndFileEntriesAndFileShortcutsCount(
340 getGroupId(), toFolderId(folderId), status,
341 includeMountFolders);
342 }
343
344 @Override
345 public int getFoldersAndFileEntriesAndFileShortcutsCount(
346 long folderId, int status, String[] mimeTypes,
347 boolean includeMountFolders)
348 throws SystemException {
349
350 return dlFolderLocalService.
351 getFoldersAndFileEntriesAndFileShortcutsCount(
352 getGroupId(), toFolderId(folderId), status, mimeTypes,
353 includeMountFolders);
354 }
355
356 @Override
357 public int getFoldersCount(long parentFolderId, boolean includeMountfolders)
358 throws SystemException {
359
360 return dlFolderLocalService.getFoldersCount(
361 getGroupId(), toFolderId(parentFolderId), includeMountfolders);
362 }
363
364 @Override
365 public int getFoldersFileEntriesCount(List<Long> folderIds, int status)
366 throws SystemException {
367
368 return dlFolderLocalService.getFoldersFileEntriesCount(
369 getGroupId(), toFolderIds(folderIds), status);
370 }
371
372 @Override
373 public List<Folder> getMountFolders(
374 long parentFolderId, int start, int end, OrderByComparator obc)
375 throws SystemException {
376
377 List<DLFolder> dlFolders = dlFolderLocalService.getMountFolders(
378 getGroupId(), toFolderId(parentFolderId), start, end, obc);
379
380 return toFolders(dlFolders);
381 }
382
383 @Override
384 public int getMountFoldersCount(long parentFolderId)
385 throws SystemException {
386
387 return dlFolderLocalService.getMountFoldersCount(
388 getGroupId(), toFolderId(parentFolderId));
389 }
390
391 @Override
392 public FileEntry moveFileEntry(
393 long userId, long fileEntryId, long newFolderId,
394 ServiceContext serviceContext)
395 throws PortalException, SystemException {
396
397 DLFileEntry dlFileEntry = dlFileEntryLocalService.moveFileEntry(
398 userId, fileEntryId, toFolderId(newFolderId), serviceContext);
399
400 return new LiferayFileEntry(dlFileEntry);
401 }
402
403 @Override
404 public void updateAsset(
405 long userId, FileEntry fileEntry, FileVersion fileVersion,
406 long[] assetCategoryIds, String[] assetTagNames,
407 long[] assetLinkEntryIds)
408 throws PortalException, SystemException {
409
410 dlAppHelperLocalService.updateAsset(
411 userId, fileEntry, fileVersion, assetCategoryIds, assetTagNames,
412 assetLinkEntryIds);
413 }
414
415 @Override
416 public FileEntry updateFileEntry(
417 long userId, long fileEntryId, String sourceFileName,
418 String mimeType, String title, String description, String changeLog,
419 boolean majorVersion, File file, ServiceContext serviceContext)
420 throws PortalException, SystemException {
421
422 long fileEntryTypeId = ParamUtil.getLong(
423 serviceContext, "fileEntryTypeId", -1L);
424 Map<String, Fields> fieldsMap = getFieldsMap(
425 serviceContext, fileEntryTypeId);
426 long size = 0;
427
428 if (file != null) {
429 size = file.length();
430 }
431
432 DLFileEntry dlFileEntry = dlFileEntryLocalService.updateFileEntry(
433 userId, fileEntryId, sourceFileName, mimeType, title, description,
434 changeLog, majorVersion, fileEntryTypeId, fieldsMap, file, null,
435 size, serviceContext);
436
437 return new LiferayFileEntry(dlFileEntry);
438 }
439
440 @Override
441 public FileEntry updateFileEntry(
442 long userId, long fileEntryId, String sourceFileName,
443 String mimeType, String title, String description, String changeLog,
444 boolean majorVersion, InputStream is, long size,
445 ServiceContext serviceContext)
446 throws PortalException, SystemException {
447
448 long fileEntryTypeId = ParamUtil.getLong(
449 serviceContext, "fileEntryTypeId", -1L);
450 Map<String, Fields> fieldsMap = getFieldsMap(
451 serviceContext, fileEntryTypeId);
452
453 DLFileEntry dlFileEntry = dlFileEntryLocalService.updateFileEntry(
454 userId, fileEntryId, sourceFileName, mimeType, title, description,
455 changeLog, majorVersion, fileEntryTypeId, fieldsMap, null, is, size,
456 serviceContext);
457
458 return new LiferayFileEntry(dlFileEntry);
459 }
460
461 @Override
462 public Folder updateFolder(
463 long folderId, long parentFolderId, String title,
464 String description, ServiceContext serviceContext)
465 throws PortalException, SystemException {
466
467 long defaultFileEntryTypeId = ParamUtil.getLong(
468 serviceContext, "defaultFileEntryTypeId");
469 SortedArrayList<Long> fileEntryTypeIds = getLongList(
470 serviceContext, "dlFileEntryTypesSearchContainerPrimaryKeys");
471 boolean overrideFileEntryTypes = ParamUtil.getBoolean(
472 serviceContext, "overrideFileEntryTypes");
473
474 DLFolder dlFolder = dlFolderLocalService.updateFolder(
475 toFolderId(folderId), toFolderId(parentFolderId), title,
476 description, defaultFileEntryTypeId, fileEntryTypeIds,
477 overrideFileEntryTypes, serviceContext);
478
479 return new LiferayFolder(dlFolder);
480 }
481
482 public UnicodeProperties updateRepository(
483 UnicodeProperties typeSettingsProperties) {
484
485 return typeSettingsProperties;
486 }
487
488 @Override
489 protected void initByFileEntryId(long fileEntryId) {
490 try {
491 DLFileEntry dlFileEntry = dlFileEntryLocalService.getFileEntry(
492 fileEntryId);
493
494 initByRepositoryId(dlFileEntry.getRepositoryId());
495 }
496 catch (Exception e) {
497 if (_log.isTraceEnabled()) {
498 if (e instanceof NoSuchFileEntryException) {
499 _log.trace(e.getMessage());
500 }
501 else {
502 _log.trace(e, e);
503 }
504 }
505 }
506 }
507
508 @Override
509 protected void initByFileVersionId(long fileVersionId) {
510 try {
511 DLFileVersion dlFileVersion =
512 dlFileVersionLocalService.getFileVersion(fileVersionId);
513
514 initByRepositoryId(dlFileVersion.getRepositoryId());
515 }
516 catch (Exception e) {
517 if (_log.isTraceEnabled()) {
518 if (e instanceof NoSuchFileVersionException) {
519 _log.trace(e.getMessage());
520 }
521 else {
522 _log.trace(e, e);
523 }
524 }
525 }
526 }
527
528 @Override
529 protected void initByFolderId(long folderId) {
530 try {
531 DLFolder dlFolder = dlFolderLocalService.getFolder(folderId);
532
533 initByRepositoryId(dlFolder.getRepositoryId());
534 }
535 catch (Exception e) {
536 if (_log.isTraceEnabled()) {
537 if (e instanceof NoSuchFolderException) {
538 _log.trace(e.getMessage());
539 }
540 else {
541 _log.trace(e, e);
542 }
543 }
544 }
545 }
546
547 @Override
548 protected void initByRepositoryId(long repositoryId) {
549 setGroupId(repositoryId);
550 setRepositoryId(repositoryId);
551
552 try {
553 Repository repository = repositoryLocalService.getRepository(
554 repositoryId);
555
556 setDlFolderId(repository.getDlFolderId());
557 setGroupId(repository.getGroupId());
558 setRepositoryId(repository.getRepositoryId());
559 }
560 catch (Exception e) {
561 }
562 }
563
564 private static Log _log = LogFactoryUtil.getLog(
565 LiferayLocalRepository.class);
566
567 }