001
014
015 package com.liferay.portlet.documentlibrary.service.impl;
016
017 import com.liferay.portal.NoSuchGroupException;
018 import com.liferay.portal.kernel.dao.orm.QueryUtil;
019 import com.liferay.portal.kernel.exception.PortalException;
020 import com.liferay.portal.kernel.exception.SystemException;
021 import com.liferay.portal.kernel.io.unsync.UnsyncByteArrayInputStream;
022 import com.liferay.portal.kernel.log.Log;
023 import com.liferay.portal.kernel.log.LogFactoryUtil;
024 import com.liferay.portal.kernel.repository.InvalidRepositoryIdException;
025 import com.liferay.portal.kernel.repository.LocalRepository;
026 import com.liferay.portal.kernel.repository.RepositoryProviderUtil;
027 import com.liferay.portal.kernel.repository.model.FileEntry;
028 import com.liferay.portal.kernel.repository.model.FileShortcut;
029 import com.liferay.portal.kernel.repository.model.FileVersion;
030 import com.liferay.portal.kernel.repository.model.Folder;
031 import com.liferay.portal.kernel.repository.util.RepositoryTrashUtil;
032 import com.liferay.portal.kernel.systemevent.SystemEventHierarchyEntryThreadLocal;
033 import com.liferay.portal.kernel.util.ArrayUtil;
034 import com.liferay.portal.kernel.util.ContentTypes;
035 import com.liferay.portal.kernel.util.FileUtil;
036 import com.liferay.portal.kernel.util.MimeTypesUtil;
037 import com.liferay.portal.kernel.util.StringBundler;
038 import com.liferay.portal.kernel.util.StringPool;
039 import com.liferay.portal.kernel.util.Validator;
040 import com.liferay.portal.kernel.workflow.WorkflowConstants;
041 import com.liferay.portal.model.Repository;
042 import com.liferay.portal.model.UserConstants;
043 import com.liferay.portal.repository.liferayrepository.model.LiferayFolder;
044 import com.liferay.portal.service.ServiceContext;
045 import com.liferay.portlet.documentlibrary.NoSuchFileEntryException;
046 import com.liferay.portlet.documentlibrary.NoSuchFileShortcutException;
047 import com.liferay.portlet.documentlibrary.NoSuchFileVersionException;
048 import com.liferay.portlet.documentlibrary.NoSuchFolderException;
049 import com.liferay.portlet.documentlibrary.model.DLFileEntryType;
050 import com.liferay.portlet.documentlibrary.model.DLFileEntryTypeConstants;
051 import com.liferay.portlet.documentlibrary.model.DLFileRank;
052 import com.liferay.portlet.documentlibrary.model.DLFolder;
053 import com.liferay.portlet.documentlibrary.model.DLFolderConstants;
054 import com.liferay.portlet.documentlibrary.service.base.DLAppLocalServiceBaseImpl;
055 import com.liferay.portlet.documentlibrary.util.DLAppUtil;
056
057 import java.io.File;
058 import java.io.IOException;
059 import java.io.InputStream;
060
061 import java.util.List;
062
063
090 public class DLAppLocalServiceImpl extends DLAppLocalServiceBaseImpl {
091
092 @Override
093 public FileEntry addFileEntry(
094 long userId, long repositoryId, long folderId,
095 String sourceFileName, String mimeType, byte[] bytes,
096 ServiceContext serviceContext)
097 throws PortalException {
098
099 return addFileEntry(
100 userId, repositoryId, folderId, sourceFileName, mimeType, null,
101 StringPool.BLANK, StringPool.BLANK, bytes, serviceContext);
102 }
103
104
134 @Override
135 public FileEntry addFileEntry(
136 long userId, long repositoryId, long folderId,
137 String sourceFileName, String mimeType, String title,
138 String description, String changeLog, byte[] bytes,
139 ServiceContext serviceContext)
140 throws PortalException {
141
142 File file = null;
143
144 try {
145 if (ArrayUtil.isNotEmpty(bytes)) {
146 file = FileUtil.createTempFile(bytes);
147 }
148
149 return addFileEntry(
150 userId, repositoryId, folderId, sourceFileName, mimeType, title,
151 description, changeLog, file, serviceContext);
152 }
153 catch (IOException ioe) {
154 throw new SystemException("Unable to write temporary file", ioe);
155 }
156 finally {
157 FileUtil.delete(file);
158 }
159 }
160
161
191 @Override
192 public FileEntry addFileEntry(
193 long userId, long repositoryId, long folderId,
194 String sourceFileName, String mimeType, String title,
195 String description, String changeLog, File file,
196 ServiceContext serviceContext)
197 throws PortalException {
198
199 if ((file == null) || !file.exists() || (file.length() == 0)) {
200 return addFileEntry(
201 userId, repositoryId, folderId, sourceFileName, mimeType, title,
202 description, changeLog, null, 0, serviceContext);
203 }
204
205 mimeType = DLAppUtil.getMimeType(sourceFileName, mimeType, title, file);
206
207 LocalRepository localRepository = getLocalRepository(repositoryId);
208
209 FileEntry fileEntry = localRepository.addFileEntry(
210 userId, folderId, sourceFileName, mimeType, title, description,
211 changeLog, file, serviceContext);
212
213 return fileEntry;
214 }
215
216
248 @Override
249 public FileEntry addFileEntry(
250 long userId, long repositoryId, long folderId,
251 String sourceFileName, String mimeType, String title,
252 String description, String changeLog, InputStream is, long size,
253 ServiceContext serviceContext)
254 throws PortalException {
255
256 if (is == null) {
257 is = new UnsyncByteArrayInputStream(new byte[0]);
258 size = 0;
259 }
260
261 if (Validator.isNull(mimeType) ||
262 mimeType.equals(ContentTypes.APPLICATION_OCTET_STREAM)) {
263
264 String extension = DLAppUtil.getExtension(title, sourceFileName);
265
266 if (size == 0) {
267 mimeType = MimeTypesUtil.getExtensionContentType(extension);
268 }
269 else {
270 File file = null;
271
272 try {
273 file = FileUtil.createTempFile(is);
274
275 return addFileEntry(
276 userId, repositoryId, folderId, sourceFileName,
277 mimeType, title, description, changeLog, file,
278 serviceContext);
279 }
280 catch (IOException ioe) {
281 throw new SystemException(
282 "Unable to write temporary file", ioe);
283 }
284 finally {
285 FileUtil.delete(file);
286 }
287 }
288 }
289
290 LocalRepository localRepository = getLocalRepository(repositoryId);
291
292 FileEntry fileEntry = localRepository.addFileEntry(
293 userId, folderId, sourceFileName, mimeType, title, description,
294 changeLog, is, size, serviceContext);
295
296 return fileEntry;
297 }
298
299
310 @Override
311 public DLFileRank addFileRank(
312 long repositoryId, long companyId, long userId, long fileEntryId,
313 ServiceContext serviceContext) {
314
315 return dlFileRankLocalService.addFileRank(
316 repositoryId, companyId, userId, fileEntryId, serviceContext);
317 }
318
319
332 @Override
333 public FileShortcut addFileShortcut(
334 long userId, long repositoryId, long folderId, long toFileEntryId,
335 ServiceContext serviceContext)
336 throws PortalException {
337
338 LocalRepository localRepository = getLocalRepository(repositoryId);
339
340 return localRepository.addFileShortcut(
341 userId, folderId, toFileEntryId, serviceContext);
342 }
343
344
358 @Override
359 public Folder addFolder(
360 long userId, long repositoryId, long parentFolderId, String name,
361 String description, ServiceContext serviceContext)
362 throws PortalException {
363
364 LocalRepository localRepository = getLocalRepository(repositoryId);
365
366 Folder folder = localRepository.addFolder(
367 userId, parentFolderId, name, description, serviceContext);
368
369 dlAppHelperLocalService.addFolder(userId, folder, serviceContext);
370
371 return folder;
372 }
373
374
380 @Override
381 public void deleteAll(long repositoryId) throws PortalException {
382 LocalRepository localRepository = getLocalRepository(repositoryId);
383
384 deleteRepository(localRepository);
385 }
386
387 @Override
388 public void deleteAllRepositories(long groupId) throws PortalException {
389 LocalRepository groupLocalRepository =
390 RepositoryProviderUtil.getLocalRepository(groupId);
391
392 deleteRepository(groupLocalRepository);
393
394 List<LocalRepository> localRepositories =
395 RepositoryProviderUtil.getLocalRepositoriesByGroupId(groupId);
396
397 for (LocalRepository localRepository : localRepositories) {
398 if (localRepository.getRepositoryId() !=
399 groupLocalRepository.getRepositoryId()) {
400
401 deleteRepository(localRepository);
402 }
403 }
404 }
405
406
411 @Override
412 public void deleteFileEntry(long fileEntryId) throws PortalException {
413 LocalRepository localRepository = getFileEntryLocalRepository(
414 fileEntryId);
415
416 FileEntry fileEntry = localRepository.getFileEntry(fileEntryId);
417
418 dlAppHelperLocalService.deleteFileEntry(fileEntry);
419
420 localRepository.deleteFileEntry(fileEntryId);
421 }
422
423
429 @Override
430 public void deleteFileRanksByFileEntryId(long fileEntryId) {
431 dlFileRankLocalService.deleteFileRanksByFileEntryId(fileEntryId);
432 }
433
434
440 @Override
441 public void deleteFileRanksByUserId(long userId) {
442 dlFileRankLocalService.deleteFileRanksByUserId(userId);
443 }
444
445
451 @Override
452 public void deleteFileShortcut(FileShortcut fileShortcut)
453 throws PortalException {
454
455 deleteFileShortcut(fileShortcut.getFileShortcutId());
456 }
457
458
464 @Override
465 public void deleteFileShortcut(long fileShortcutId) throws PortalException {
466 LocalRepository localRepository = getFileShortcutLocalRepository(
467 fileShortcutId);
468
469 localRepository.deleteFileShortcut(fileShortcutId);
470 }
471
472
478 @Override
479 public void deleteFileShortcuts(long toFileEntryId) throws PortalException {
480 LocalRepository localRepository = getFileEntryLocalRepository(
481 toFileEntryId);
482
483 localRepository.deleteFileShortcuts(toFileEntryId);
484 }
485
486
491 @Override
492 public void deleteFolder(long folderId) throws PortalException {
493 LocalRepository localRepository = getFolderLocalRepository(folderId);
494
495 List<FileEntry> fileEntries = localRepository.getRepositoryFileEntries(
496 UserConstants.USER_ID_DEFAULT, folderId, QueryUtil.ALL_POS,
497 QueryUtil.ALL_POS, null);
498
499 for (FileEntry fileEntry : fileEntries) {
500 dlAppHelperLocalService.deleteFileEntry(fileEntry);
501 }
502
503 Folder folder = getFolder(folderId);
504
505 localRepository.deleteFolder(folderId);
506
507 dlAppHelperLocalService.deleteFolder(folder);
508 }
509
510
516 @Override
517 public FileEntry getFileEntry(long fileEntryId) throws PortalException {
518 LocalRepository localRepository = getFileEntryLocalRepository(
519 fileEntryId);
520
521 return localRepository.getFileEntry(fileEntryId);
522 }
523
524
532 @Override
533 public FileEntry getFileEntry(long groupId, long folderId, String title)
534 throws PortalException {
535
536 try {
537 LocalRepository localRepository = getLocalRepository(groupId);
538
539 return localRepository.getFileEntry(folderId, title);
540 }
541 catch (NoSuchFileEntryException nsfee) {
542 if (_log.isDebugEnabled()) {
543 _log.debug(nsfee, nsfee);
544 }
545 }
546
547 LocalRepository localRepository = getFolderLocalRepository(folderId);
548
549 return localRepository.getFileEntry(folderId, title);
550 }
551
552
559 @Override
560 public FileEntry getFileEntryByUuidAndGroupId(String uuid, long groupId)
561 throws PortalException {
562
563 try {
564 LocalRepository localRepository = getLocalRepository(groupId);
565
566 return localRepository.getFileEntryByUuid(uuid);
567 }
568 catch (NoSuchFileEntryException nsfee) {
569 if (_log.isDebugEnabled()) {
570 _log.debug(nsfee, nsfee);
571 }
572 }
573
574 List<com.liferay.portal.model.Repository> repositories =
575 repositoryPersistence.findByGroupId(groupId);
576
577 for (Repository repository : repositories) {
578 try {
579 LocalRepository localRepository = getLocalRepository(
580 repository.getRepositoryId());
581
582 return localRepository.getFileEntryByUuid(uuid);
583 }
584 catch (NoSuchFileEntryException nsfee) {
585 if (_log.isDebugEnabled()) {
586 _log.debug(nsfee, nsfee);
587 }
588 }
589 }
590
591 StringBundler msg = new StringBundler(6);
592
593 msg.append("No DLFileEntry exists with the key {");
594 msg.append("uuid=");
595 msg.append(uuid);
596 msg.append(", groupId=");
597 msg.append(groupId);
598 msg.append(StringPool.CLOSE_CURLY_BRACE);
599
600 throw new NoSuchFileEntryException(msg.toString());
601 }
602
603
611 @Override
612 public List<DLFileRank> getFileRanks(long repositoryId, long userId) {
613 return dlFileRankLocalService.getFileRanks(repositoryId, userId);
614 }
615
616
623 @Override
624 public FileShortcut getFileShortcut(long fileShortcutId)
625 throws PortalException {
626
627 LocalRepository localRepository = getFileShortcutLocalRepository(
628 fileShortcutId);
629
630 return localRepository.getFileShortcut(fileShortcutId);
631 }
632
633
639 @Override
640 public FileVersion getFileVersion(long fileVersionId)
641 throws PortalException {
642
643 LocalRepository localRepository = getFileVersionLocalRepository(
644 fileVersionId);
645
646 return localRepository.getFileVersion(fileVersionId);
647 }
648
649
655 @Override
656 public Folder getFolder(long folderId) throws PortalException {
657 LocalRepository localRepository = getFolderLocalRepository(folderId);
658
659 return localRepository.getFolder(folderId);
660 }
661
662
670 @Override
671 public Folder getFolder(long repositoryId, long parentFolderId, String name)
672 throws PortalException {
673
674 LocalRepository localRepository = getLocalRepository(repositoryId);
675
676 return localRepository.getFolder(parentFolderId, name);
677 }
678
679
686 @Override
687 public Folder getMountFolder(long repositoryId) throws PortalException {
688 DLFolder dlFolder = dlFolderLocalService.getMountFolder(repositoryId);
689
690 return new LiferayFolder(dlFolder);
691 }
692
693
702 @Override
703 public FileEntry moveFileEntry(
704 long userId, long fileEntryId, long newFolderId,
705 ServiceContext serviceContext)
706 throws PortalException {
707
708 SystemEventHierarchyEntryThreadLocal.push(FileEntry.class);
709
710 try {
711 LocalRepository fromLocalRepository = getFileEntryLocalRepository(
712 fileEntryId);
713 LocalRepository toLocalRepository = getFolderLocalRepository(
714 newFolderId, serviceContext.getScopeGroupId());
715
716 if (fromLocalRepository.getRepositoryId() ==
717 toLocalRepository.getRepositoryId()) {
718
719
720
721 return fromLocalRepository.moveFileEntry(
722 userId, fileEntryId, newFolderId, serviceContext);
723 }
724
725
726
727 return moveFileEntries(
728 userId, fileEntryId, newFolderId, fromLocalRepository,
729 toLocalRepository, serviceContext);
730 }
731 finally {
732 SystemEventHierarchyEntryThreadLocal.pop(FileEntry.class);
733 }
734 }
735
736
741 @Deprecated
742 @Override
743 public FileEntry moveFileEntryFromTrash(
744 long userId, long fileEntryId, long newFolderId,
745 ServiceContext serviceContext)
746 throws PortalException {
747
748 LocalRepository localRepository = getFileEntryLocalRepository(
749 fileEntryId);
750
751 return RepositoryTrashUtil.moveFileEntryFromTrash(
752 userId, localRepository.getRepositoryId(), fileEntryId, newFolderId,
753 serviceContext);
754 }
755
756
760 @Deprecated
761 @Override
762 public FileEntry moveFileEntryToTrash(long userId, long fileEntryId)
763 throws PortalException {
764
765 LocalRepository localRepository = getFileEntryLocalRepository(
766 fileEntryId);
767
768 return RepositoryTrashUtil.moveFileEntryToTrash(
769 userId, localRepository.getRepositoryId(), fileEntryId);
770 }
771
772 @Override
773 public Folder moveFolder(
774 long userId, long folderId, long parentFolderId,
775 ServiceContext serviceContext)
776 throws PortalException {
777
778 SystemEventHierarchyEntryThreadLocal.push(Folder.class);
779
780 try {
781 LocalRepository sourceLocalRepository = getFolderLocalRepository(
782 folderId);
783
784 LocalRepository destinationLocalRepository =
785 getFolderLocalRepository(
786 parentFolderId, serviceContext.getScopeGroupId());
787
788 if (parentFolderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
789 Folder toFolder = destinationLocalRepository.getFolder(
790 parentFolderId);
791
792 if (toFolder.isMountPoint()) {
793 destinationLocalRepository = getLocalRepository(
794 toFolder.getRepositoryId());
795 }
796 }
797
798 if (sourceLocalRepository.getRepositoryId() ==
799 destinationLocalRepository.getRepositoryId()) {
800
801
802
803 return sourceLocalRepository.moveFolder(
804 userId, folderId, parentFolderId, serviceContext);
805 }
806
807
808
809 return moveFolders(
810 userId, folderId, parentFolderId, sourceLocalRepository,
811 destinationLocalRepository, serviceContext);
812 }
813 finally {
814 SystemEventHierarchyEntryThreadLocal.pop(Folder.class);
815 }
816 }
817
818
823 @Deprecated
824 @Override
825 public void restoreFileEntryFromTrash(long userId, long fileEntryId)
826 throws PortalException {
827
828 LocalRepository localRepository = getFileEntryLocalRepository(
829 fileEntryId);
830
831 RepositoryTrashUtil.restoreFileEntryFromTrash(
832 userId, localRepository.getRepositoryId(), fileEntryId);
833 }
834
835
843 @Override
844 public void subscribeFileEntryType(
845 long userId, long groupId, long fileEntryTypeId)
846 throws PortalException {
847
848 if (fileEntryTypeId ==
849 DLFileEntryTypeConstants.FILE_ENTRY_TYPE_ID_BASIC_DOCUMENT) {
850
851 fileEntryTypeId = groupId;
852 }
853
854 subscriptionLocalService.addSubscription(
855 userId, groupId, DLFileEntryType.class.getName(), fileEntryTypeId);
856 }
857
858
866 @Override
867 public void subscribeFolder(long userId, long groupId, long folderId)
868 throws PortalException {
869
870 if (folderId == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
871 folderId = groupId;
872 }
873
874 subscriptionLocalService.addSubscription(
875 userId, groupId, DLFolder.class.getName(), folderId);
876 }
877
878
886 @Override
887 public void unsubscribeFileEntryType(
888 long userId, long groupId, long fileEntryTypeId)
889 throws PortalException {
890
891 if (fileEntryTypeId ==
892 DLFileEntryTypeConstants.FILE_ENTRY_TYPE_ID_BASIC_DOCUMENT) {
893
894 fileEntryTypeId = groupId;
895 }
896
897 subscriptionLocalService.deleteSubscription(
898 userId, DLFileEntryType.class.getName(), fileEntryTypeId);
899 }
900
901
909 @Override
910 public void unsubscribeFolder(long userId, long groupId, long folderId)
911 throws PortalException {
912
913 if (folderId == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
914 folderId = groupId;
915 }
916
917 subscriptionLocalService.deleteSubscription(
918 userId, DLFolder.class.getName(), folderId);
919 }
920
921
932 @Override
933 public void updateAsset(
934 long userId, FileEntry fileEntry, FileVersion fileVersion,
935 long[] assetCategoryIds, String[] assetTagNames,
936 long[] assetLinkEntryIds)
937 throws PortalException {
938
939 dlAppHelperLocalService.updateAsset(
940 userId, fileEntry, fileVersion, assetCategoryIds, assetTagNames,
941 assetLinkEntryIds);
942 }
943
944
978 @Override
979 public FileEntry updateFileEntry(
980 long userId, long fileEntryId, String sourceFileName,
981 String mimeType, String title, String description, String changeLog,
982 boolean majorVersion, byte[] bytes, ServiceContext serviceContext)
983 throws PortalException {
984
985 File file = null;
986
987 try {
988 if (ArrayUtil.isNotEmpty(bytes)) {
989 file = FileUtil.createTempFile(bytes);
990 }
991
992 return updateFileEntry(
993 userId, fileEntryId, sourceFileName, mimeType, title,
994 description, changeLog, majorVersion, file, serviceContext);
995 }
996 catch (IOException ioe) {
997 throw new SystemException("Unable to write temporary file", ioe);
998 }
999 finally {
1000 FileUtil.delete(file);
1001 }
1002 }
1003
1004
1038 @Override
1039 public FileEntry updateFileEntry(
1040 long userId, long fileEntryId, String sourceFileName,
1041 String mimeType, String title, String description, String changeLog,
1042 boolean majorVersion, File file, ServiceContext serviceContext)
1043 throws PortalException {
1044
1045 if ((file == null) || !file.exists() || (file.length() == 0)) {
1046 return updateFileEntry(
1047 userId, fileEntryId, sourceFileName, mimeType, title,
1048 description, changeLog, majorVersion, null, 0, serviceContext);
1049 }
1050
1051 mimeType = DLAppUtil.getMimeType(sourceFileName, mimeType, title, file);
1052
1053 LocalRepository localRepository = getFileEntryLocalRepository(
1054 fileEntryId);
1055
1056 FileEntry fileEntry = localRepository.updateFileEntry(
1057 userId, fileEntryId, sourceFileName, mimeType, title, description,
1058 changeLog, majorVersion, file, serviceContext);
1059
1060 dlAppHelperLocalService.updateFileEntry(
1061 userId, fileEntry, null, fileEntry.getFileVersion(),
1062 serviceContext);
1063
1064 return fileEntry;
1065 }
1066
1067
1102 @Override
1103 public FileEntry updateFileEntry(
1104 long userId, long fileEntryId, String sourceFileName,
1105 String mimeType, String title, String description, String changeLog,
1106 boolean majorVersion, InputStream is, long size,
1107 ServiceContext serviceContext)
1108 throws PortalException {
1109
1110 if (Validator.isNull(mimeType) ||
1111 mimeType.equals(ContentTypes.APPLICATION_OCTET_STREAM)) {
1112
1113 String extension = DLAppUtil.getExtension(title, sourceFileName);
1114
1115 if (size == 0) {
1116 mimeType = MimeTypesUtil.getExtensionContentType(extension);
1117 }
1118 else {
1119 File file = null;
1120
1121 try {
1122 file = FileUtil.createTempFile(is);
1123
1124 return updateFileEntry(
1125 userId, fileEntryId, sourceFileName, mimeType, title,
1126 description, changeLog, majorVersion, file,
1127 serviceContext);
1128 }
1129 catch (IOException ioe) {
1130 throw new SystemException(
1131 "Unable to write temporary file", ioe);
1132 }
1133 finally {
1134 FileUtil.delete(file);
1135 }
1136 }
1137 }
1138
1139 LocalRepository localRepository = getFileEntryLocalRepository(
1140 fileEntryId);
1141
1142 FileEntry fileEntry = localRepository.updateFileEntry(
1143 userId, fileEntryId, sourceFileName, mimeType, title, description,
1144 changeLog, majorVersion, is, size, serviceContext);
1145
1146 dlAppHelperLocalService.updateFileEntry(
1147 userId, fileEntry, null, fileEntry.getFileVersion(),
1148 serviceContext);
1149
1150 return fileEntry;
1151 }
1152
1153
1164 @Override
1165 public DLFileRank updateFileRank(
1166 long repositoryId, long companyId, long userId, long fileEntryId,
1167 ServiceContext serviceContext) {
1168
1169 return dlFileRankLocalService.updateFileRank(
1170 repositoryId, companyId, userId, fileEntryId, serviceContext);
1171 }
1172
1173
1186 @Override
1187 public FileShortcut updateFileShortcut(
1188 long userId, long fileShortcutId, long folderId, long toFileEntryId,
1189 ServiceContext serviceContext)
1190 throws PortalException {
1191
1192 LocalRepository localRepository = getFileShortcutLocalRepository(
1193 fileShortcutId);
1194
1195 return localRepository.updateFileShortcut(
1196 userId, fileShortcutId, folderId, toFileEntryId, serviceContext);
1197 }
1198
1199
1206 @Override
1207 public void updateFileShortcuts(
1208 long oldToFileEntryId, long newToFileEntryId)
1209 throws PortalException {
1210
1211 LocalRepository localRepository = getFileEntryLocalRepository(
1212 newToFileEntryId);
1213
1214 localRepository.updateFileShortcuts(oldToFileEntryId, newToFileEntryId);
1215 }
1216
1217
1221 @Deprecated
1222 @Override
1223 public void updateFileShortcuts(
1224 long toRepositoryId, long oldToFileEntryId, long newToFileEntryId)
1225 throws PortalException {
1226
1227 updateFileShortcuts(oldToFileEntryId, newToFileEntryId);
1228 }
1229
1230
1251 @Override
1252 public Folder updateFolder(
1253 long folderId, long parentFolderId, String name, String description,
1254 ServiceContext serviceContext)
1255 throws PortalException {
1256
1257 LocalRepository localRepository = getFolderLocalRepository(folderId);
1258
1259 Folder folder = localRepository.updateFolder(
1260 folderId, parentFolderId, name, description, serviceContext);
1261
1262 if (folderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
1263 dlAppHelperLocalService.updateFolder(
1264 serviceContext.getUserId(), folder, serviceContext);
1265 }
1266
1267 return folder;
1268 }
1269
1270 protected FileEntry copyFileEntry(
1271 long userId, LocalRepository toLocalRepository, FileEntry fileEntry,
1272 long newFolderId, ServiceContext serviceContext)
1273 throws PortalException {
1274
1275 List<FileVersion> fileVersions = fileEntry.getFileVersions(
1276 WorkflowConstants.STATUS_ANY);
1277
1278 FileVersion latestFileVersion = fileVersions.get(
1279 fileVersions.size() - 1);
1280
1281 FileEntry destinationFileEntry = toLocalRepository.addFileEntry(
1282 userId, newFolderId, fileEntry.getTitle(),
1283 latestFileVersion.getMimeType(), latestFileVersion.getTitle(),
1284 latestFileVersion.getDescription(), StringPool.BLANK,
1285 latestFileVersion.getContentStream(false),
1286 latestFileVersion.getSize(), serviceContext);
1287
1288 for (int i = fileVersions.size() - 2; i >= 0; i--) {
1289 FileVersion fileVersion = fileVersions.get(i);
1290
1291 FileVersion previousFileVersion = fileVersions.get(i + 1);
1292
1293 try {
1294 destinationFileEntry = toLocalRepository.updateFileEntry(
1295 userId, destinationFileEntry.getFileEntryId(),
1296 fileEntry.getTitle(), destinationFileEntry.getMimeType(),
1297 destinationFileEntry.getTitle(),
1298 destinationFileEntry.getDescription(), StringPool.BLANK,
1299 DLAppUtil.isMajorVersion(fileVersion, previousFileVersion),
1300 fileVersion.getContentStream(false), fileVersion.getSize(),
1301 serviceContext);
1302 }
1303 catch (PortalException pe) {
1304 toLocalRepository.deleteFileEntry(
1305 destinationFileEntry.getFileEntryId());
1306
1307 throw pe;
1308 }
1309 }
1310
1311 return destinationFileEntry;
1312 }
1313
1314 protected void deleteFileEntry(
1315 long oldFileEntryId, long newFileEntryId,
1316 LocalRepository fromLocalRepository,
1317 LocalRepository toLocalRepository)
1318 throws PortalException {
1319
1320 try {
1321 FileEntry fileEntry = fromLocalRepository.getFileEntry(
1322 oldFileEntryId);
1323
1324 fromLocalRepository.deleteFileEntry(oldFileEntryId);
1325
1326 dlAppHelperLocalService.deleteFileEntry(fileEntry);
1327 }
1328 catch (PortalException pe) {
1329 FileEntry fileEntry = toLocalRepository.getFileEntry(
1330 newFileEntryId);
1331
1332 toLocalRepository.deleteFileEntry(newFileEntryId);
1333
1334 dlAppHelperLocalService.deleteFileEntry(fileEntry);
1335
1336 throw pe;
1337 }
1338 }
1339
1340 protected void deleteRepository(LocalRepository localRepository)
1341 throws PortalException {
1342
1343 long repositoryId = localRepository.getRepositoryId();
1344
1345 dlAppHelperLocalService.deleteRepositoryFileEntries(repositoryId);
1346
1347 localRepository.deleteAll();
1348
1349 repositoryLocalService.deleteRepository(repositoryId);
1350 }
1351
1352 protected LocalRepository getFileEntryLocalRepository(long fileEntryId)
1353 throws PortalException {
1354
1355 try {
1356 return RepositoryProviderUtil.getFileEntryLocalRepository(
1357 fileEntryId);
1358 }
1359 catch (InvalidRepositoryIdException irie) {
1360 StringBundler sb = new StringBundler(3);
1361
1362 sb.append("No FileEntry exists with the key {fileEntryId=");
1363 sb.append(fileEntryId);
1364 sb.append("}");
1365
1366 throw new NoSuchFileEntryException(sb.toString(), irie);
1367 }
1368 }
1369
1370 protected LocalRepository getFileShortcutLocalRepository(
1371 long fileShortcutId)
1372 throws PortalException {
1373
1374 try {
1375 return RepositoryProviderUtil.getFileShortcutLocalRepository(
1376 fileShortcutId);
1377 }
1378 catch (InvalidRepositoryIdException irie) {
1379 StringBundler sb = new StringBundler(3);
1380
1381 sb.append("No FileShortcut exists with the key {fileShortcutId=");
1382 sb.append(fileShortcutId);
1383 sb.append("}");
1384
1385 throw new NoSuchFileShortcutException(sb.toString(), irie);
1386 }
1387 }
1388
1389 protected LocalRepository getFileVersionLocalRepository(long fileVersionId)
1390 throws PortalException {
1391
1392 try {
1393 return RepositoryProviderUtil.getFileVersionLocalRepository(
1394 fileVersionId);
1395 }
1396 catch (InvalidRepositoryIdException irie) {
1397 StringBundler sb = new StringBundler(3);
1398
1399 sb.append("No FileVersion exists with the key {fileVersionId=");
1400 sb.append(fileVersionId);
1401 sb.append("}");
1402
1403 throw new NoSuchFileVersionException(sb.toString(), irie);
1404 }
1405 }
1406
1407 protected LocalRepository getFolderLocalRepository(long folderId)
1408 throws PortalException {
1409
1410 try {
1411 return RepositoryProviderUtil.getFolderLocalRepository(folderId);
1412 }
1413 catch (InvalidRepositoryIdException irie) {
1414 StringBundler sb = new StringBundler(3);
1415
1416 sb.append("No Folder exists with the key {folderId=");
1417 sb.append(folderId);
1418 sb.append("}");
1419
1420 throw new NoSuchFolderException(sb.toString(), irie);
1421 }
1422 }
1423
1424 protected LocalRepository getFolderLocalRepository(
1425 long folderId, long groupId)
1426 throws PortalException {
1427
1428 if (folderId == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
1429 return getLocalRepository(groupId);
1430 }
1431
1432 return getFolderLocalRepository(folderId);
1433 }
1434
1435 protected LocalRepository getLocalRepository(long repositoryId)
1436 throws PortalException {
1437
1438 try {
1439 return RepositoryProviderUtil.getLocalRepository(repositoryId);
1440 }
1441 catch (InvalidRepositoryIdException irie) {
1442 StringBundler sb = new StringBundler(3);
1443
1444 sb.append("No Group exists with the key {repositoryId=");
1445 sb.append(repositoryId);
1446 sb.append("}");
1447
1448 throw new NoSuchGroupException(sb.toString(), irie);
1449 }
1450 }
1451
1452 protected FileEntry moveFileEntries(
1453 long userId, long fileEntryId, long newFolderId,
1454 LocalRepository fromLocalRepository,
1455 LocalRepository toLocalRepository, ServiceContext serviceContext)
1456 throws PortalException {
1457
1458 FileEntry sourceFileEntry = fromLocalRepository.getFileEntry(
1459 fileEntryId);
1460
1461 FileEntry destinationFileEntry = copyFileEntry(
1462 userId, toLocalRepository, sourceFileEntry, newFolderId,
1463 serviceContext);
1464
1465 deleteFileEntry(
1466 fileEntryId, destinationFileEntry.getFileEntryId(),
1467 fromLocalRepository, toLocalRepository);
1468
1469 return destinationFileEntry;
1470 }
1471
1472 protected Folder moveFolders(
1473 long userId, long folderId, long parentFolderId,
1474 LocalRepository sourceLocalRepository,
1475 LocalRepository destinationLocalRepository,
1476 ServiceContext serviceContext)
1477 throws PortalException {
1478
1479 Folder sourceFolder = sourceLocalRepository.getFolder(folderId);
1480
1481 Folder destinationFolder = destinationLocalRepository.addFolder(
1482 userId, parentFolderId, sourceFolder.getName(),
1483 sourceFolder.getDescription(), serviceContext);
1484
1485 dlAppHelperLocalService.addFolder(
1486 userId, destinationFolder, serviceContext);
1487
1488 List<Object> foldersAndFileEntriesAndFileShortcuts =
1489 dlAppService.getFoldersAndFileEntriesAndFileShortcuts(
1490 sourceLocalRepository.getRepositoryId(), folderId,
1491 WorkflowConstants.STATUS_ANY, true, QueryUtil.ALL_POS,
1492 QueryUtil.ALL_POS);
1493
1494 try {
1495 for (Object folderAndFileEntryAndFileShortcut :
1496 foldersAndFileEntriesAndFileShortcuts) {
1497
1498 if (folderAndFileEntryAndFileShortcut instanceof FileEntry) {
1499 FileEntry fileEntry =
1500 (FileEntry)folderAndFileEntryAndFileShortcut;
1501
1502 copyFileEntry(
1503 userId, destinationLocalRepository, fileEntry,
1504 destinationFolder.getFolderId(), serviceContext);
1505 }
1506 else if (folderAndFileEntryAndFileShortcut instanceof Folder) {
1507 Folder folder = (Folder)folderAndFileEntryAndFileShortcut;
1508
1509 moveFolders(
1510 userId, folder.getFolderId(),
1511 destinationFolder.getFolderId(), sourceLocalRepository,
1512 destinationLocalRepository, serviceContext);
1513 }
1514 else if (folderAndFileEntryAndFileShortcut
1515 instanceof FileShortcut) {
1516
1517 if (destinationFolder.isSupportsShortcuts()) {
1518 FileShortcut fileShortcut =
1519 (FileShortcut)folderAndFileEntryAndFileShortcut;
1520
1521 destinationLocalRepository.addFileShortcut(
1522 userId, destinationFolder.getFolderId(),
1523 fileShortcut.getToFileEntryId(), serviceContext);
1524 }
1525 }
1526 }
1527 }
1528 catch (PortalException pe) {
1529 destinationLocalRepository.deleteFolder(
1530 destinationFolder.getFolderId());
1531
1532 throw pe;
1533 }
1534
1535 try {
1536 sourceLocalRepository.deleteFolder(folderId);
1537 }
1538 catch (PortalException pe) {
1539 destinationLocalRepository.deleteFolder(
1540 destinationFolder.getFolderId());
1541
1542 throw pe;
1543 }
1544
1545 return destinationFolder;
1546 }
1547
1548 private static final Log _log = LogFactoryUtil.getLog(
1549 DLAppLocalServiceImpl.class);
1550
1551 }