001
014
015 package com.liferay.portlet.documentlibrary.service.impl;
016
017 import com.liferay.portal.kernel.dao.orm.QueryDefinition;
018 import com.liferay.portal.kernel.exception.PortalException;
019 import com.liferay.portal.kernel.exception.SystemException;
020 import com.liferay.portal.kernel.log.Log;
021 import com.liferay.portal.kernel.log.LogFactoryUtil;
022 import com.liferay.portal.kernel.util.ObjectValuePair;
023 import com.liferay.portal.kernel.util.OrderByComparator;
024 import com.liferay.portal.kernel.util.ParamUtil;
025 import com.liferay.portal.kernel.util.StringPool;
026 import com.liferay.portal.kernel.util.UnicodeProperties;
027 import com.liferay.portal.kernel.workflow.WorkflowConstants;
028 import com.liferay.portal.model.Group;
029 import com.liferay.portal.model.ResourceConstants;
030 import com.liferay.portal.model.User;
031 import com.liferay.portal.repository.liferayrepository.model.LiferayFolder;
032 import com.liferay.portal.service.ServiceContext;
033 import com.liferay.portlet.asset.util.AssetUtil;
034 import com.liferay.portlet.documentlibrary.DuplicateFileException;
035 import com.liferay.portlet.documentlibrary.DuplicateFolderNameException;
036 import com.liferay.portlet.documentlibrary.FolderNameException;
037 import com.liferay.portlet.documentlibrary.NoSuchDirectoryException;
038 import com.liferay.portlet.documentlibrary.NoSuchFileEntryException;
039 import com.liferay.portlet.documentlibrary.model.DLFileEntryTypeConstants;
040 import com.liferay.portlet.documentlibrary.model.DLFolder;
041 import com.liferay.portlet.documentlibrary.model.DLFolderConstants;
042 import com.liferay.portlet.documentlibrary.service.base.DLFolderLocalServiceBaseImpl;
043 import com.liferay.portlet.documentlibrary.store.DLStoreUtil;
044 import com.liferay.portlet.trash.util.TrashUtil;
045
046 import java.io.Serializable;
047
048 import java.util.ArrayList;
049 import java.util.Collections;
050 import java.util.Date;
051 import java.util.List;
052 import java.util.Map;
053
054
058 public class DLFolderLocalServiceImpl extends DLFolderLocalServiceBaseImpl {
059
060 public DLFolder addFolder(
061 long userId, long groupId, long repositoryId, boolean mountPoint,
062 long parentFolderId, String name, String description,
063 boolean hidden, ServiceContext serviceContext)
064 throws PortalException, SystemException {
065
066
067
068 User user = userPersistence.findByPrimaryKey(userId);
069 parentFolderId = getParentFolderId(groupId, parentFolderId);
070 Date now = new Date();
071
072 validateFolder(groupId, parentFolderId, name);
073
074 long folderId = counterLocalService.increment();
075
076 DLFolder dlFolder = dlFolderPersistence.create(folderId);
077
078 dlFolder.setUuid(serviceContext.getUuid());
079 dlFolder.setGroupId(groupId);
080 dlFolder.setCompanyId(user.getCompanyId());
081 dlFolder.setUserId(user.getUserId());
082 dlFolder.setCreateDate(serviceContext.getCreateDate(now));
083 dlFolder.setModifiedDate(serviceContext.getModifiedDate(now));
084 dlFolder.setRepositoryId(repositoryId);
085 dlFolder.setMountPoint(mountPoint);
086 dlFolder.setParentFolderId(parentFolderId);
087 dlFolder.setName(name);
088 dlFolder.setDescription(description);
089 dlFolder.setHidden(hidden);
090 dlFolder.setOverrideFileEntryTypes(false);
091 dlFolder.setExpandoBridgeAttributes(serviceContext);
092
093 dlFolderPersistence.update(dlFolder);
094
095
096
097 if (serviceContext.isAddGroupPermissions() ||
098 serviceContext.isAddGuestPermissions()) {
099
100 addFolderResources(
101 dlFolder, serviceContext.isAddGroupPermissions(),
102 serviceContext.isAddGuestPermissions());
103 }
104 else {
105 if (serviceContext.isDeriveDefaultPermissions()) {
106 serviceContext.deriveDefaultPermissions(
107 repositoryId, DLFolderConstants.getClassName());
108 }
109
110 addFolderResources(
111 dlFolder, serviceContext.getGroupPermissions(),
112 serviceContext.getGuestPermissions());
113 }
114
115
116
117 if (parentFolderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
118 DLFolder parentDLFolder = dlFolderPersistence.findByPrimaryKey(
119 parentFolderId);
120
121 parentDLFolder.setLastPostDate(now);
122
123 dlFolderPersistence.update(parentDLFolder);
124 }
125
126
127
128 dlAppHelperLocalService.addFolder(
129 new LiferayFolder(dlFolder), serviceContext);
130
131 return dlFolder;
132 }
133
134
139 public DLFolder addFolder(
140 long userId, long groupId, long repositoryId, boolean mountPoint,
141 long parentFolderId, String name, String description,
142 ServiceContext serviceContext)
143 throws PortalException, SystemException {
144
145 return addFolder(
146 userId, groupId, repositoryId, mountPoint, parentFolderId, name,
147 description, false, serviceContext);
148 }
149
150 public void deleteAll(long groupId)
151 throws PortalException, SystemException {
152
153 Group group = groupLocalService.getGroup(groupId);
154
155 List<DLFolder> dlFolders = dlFolderPersistence.findByG_P(
156 groupId, DLFolderConstants.DEFAULT_PARENT_FOLDER_ID);
157
158 for (DLFolder dlFolder : dlFolders) {
159 deleteFolder(dlFolder);
160 }
161
162 dlFileEntryLocalService.deleteFileEntries(
163 groupId, DLFolderConstants.DEFAULT_PARENT_FOLDER_ID);
164
165 dlFileShortcutLocalService.deleteFileShortcuts(
166 groupId, DLFolderConstants.DEFAULT_PARENT_FOLDER_ID);
167
168 try {
169 DLStoreUtil.deleteDirectory(
170 group.getCompanyId(), groupId, StringPool.BLANK);
171 }
172 catch (NoSuchDirectoryException nsde) {
173 if (_log.isDebugEnabled()) {
174 _log.debug(nsde.getMessage());
175 }
176 }
177 }
178
179 public void deleteFolder(long folderId)
180 throws PortalException, SystemException {
181
182 deleteFolder(folderId, true);
183 }
184
185 public void deleteFolder(long folderId, boolean includeTrashedEntries)
186 throws PortalException, SystemException {
187
188 DLFolder dlFolder = dlFolderPersistence.findByPrimaryKey(folderId);
189
190 deleteFolder(dlFolder, includeTrashedEntries);
191 }
192
193 public DLFolder fetchFolder(long groupId, long parentFolderId, String name)
194 throws SystemException {
195
196 return dlFolderPersistence.fetchByG_P_N(groupId, parentFolderId, name);
197 }
198
199 public List<DLFolder> getCompanyFolders(long companyId, int start, int end)
200 throws SystemException {
201
202 return dlFolderPersistence.findByCompanyId(companyId, start, end);
203 }
204
205 public int getCompanyFoldersCount(long companyId) throws SystemException {
206 return dlFolderPersistence.countByCompanyId(companyId);
207 }
208
209
213 public List<Object> getFileEntriesAndFileShortcuts(
214 long groupId, long folderId, int status, int start, int end)
215 throws SystemException {
216
217 QueryDefinition queryDefinition = new QueryDefinition(
218 status, start, end, null);
219
220 return getFileEntriesAndFileShortcuts(
221 groupId, folderId, queryDefinition);
222 }
223
224 public List<Object> getFileEntriesAndFileShortcuts(
225 long groupId, long folderId, QueryDefinition queryDefinition)
226 throws SystemException {
227
228 return dlFolderFinder.findFE_FS_ByG_F(
229 groupId, folderId, queryDefinition);
230 }
231
232
236 public int getFileEntriesAndFileShortcutsCount(
237 long groupId, long folderId, int status)
238 throws SystemException {
239
240 QueryDefinition queryDefinition = new QueryDefinition(status);
241
242 return getFileEntriesAndFileShortcutsCount(
243 groupId, folderId, queryDefinition);
244 }
245
246 public int getFileEntriesAndFileShortcutsCount(
247 long groupId, long folderId, QueryDefinition queryDefinition)
248 throws SystemException {
249
250 return dlFolderFinder.countFE_FS_ByG_F(
251 groupId, folderId, queryDefinition);
252 }
253
254 public DLFolder getFolder(long folderId)
255 throws PortalException, SystemException {
256
257 return dlFolderPersistence.findByPrimaryKey(folderId);
258 }
259
260 public DLFolder getFolder(long groupId, long parentFolderId, String name)
261 throws PortalException, SystemException {
262
263 return dlFolderPersistence.findByG_P_N(groupId, parentFolderId, name);
264 }
265
266 public long getFolderId(long companyId, long folderId)
267 throws SystemException {
268
269 if (folderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
270
271
272
273 DLFolder dlFolder = dlFolderPersistence.fetchByPrimaryKey(folderId);
274
275 if ((dlFolder == null) || (companyId != dlFolder.getCompanyId())) {
276 folderId = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID;
277 }
278 }
279
280 return folderId;
281 }
282
283 public List<DLFolder> getFolders(long groupId, long parentFolderId)
284 throws SystemException {
285
286 return getFolders(groupId, parentFolderId, true);
287 }
288
289 public List<DLFolder> getFolders(
290 long groupId, long parentFolderId, boolean includeMountfolders)
291 throws SystemException {
292
293 if (includeMountfolders) {
294 return dlFolderPersistence.findByG_P(groupId, parentFolderId);
295 }
296 else {
297 return dlFolderPersistence.findByG_M_P_H(
298 groupId, false, parentFolderId, false);
299 }
300 }
301
302 public List<DLFolder> getFolders(
303 long groupId, long parentFolderId, boolean includeMountfolders,
304 int start, int end, OrderByComparator obc)
305 throws SystemException {
306
307 if (includeMountfolders) {
308 return dlFolderPersistence.findByG_P(
309 groupId, parentFolderId, start, end, obc);
310 }
311 else {
312 return dlFolderPersistence.findByG_M_P_H(
313 groupId, false, parentFolderId, false, start, end, obc);
314 }
315 }
316
317 public List<DLFolder> getFolders(
318 long groupId, long parentFolderId, int start, int end,
319 OrderByComparator obc)
320 throws SystemException {
321
322 return getFolders(groupId, parentFolderId, true, start, end, obc);
323 }
324
325
330 public List<Object> getFoldersAndFileEntriesAndFileShortcuts(
331 long groupId, long folderId, int status,
332 boolean includeMountFolders, int start, int end,
333 OrderByComparator obc)
334 throws SystemException {
335
336 QueryDefinition queryDefinition = new QueryDefinition(
337 status, start, end, obc);
338
339 return getFoldersAndFileEntriesAndFileShortcuts(
340 groupId, folderId, null, includeMountFolders, queryDefinition);
341 }
342
343
348 public List<Object> getFoldersAndFileEntriesAndFileShortcuts(
349 long groupId, long folderId, int status, String[] mimeTypes,
350 boolean includeMountFolders, int start, int end,
351 OrderByComparator obc)
352 throws SystemException {
353
354 QueryDefinition queryDefinition = new QueryDefinition(
355 status, start, end, obc);
356
357 return getFoldersAndFileEntriesAndFileShortcuts(
358 groupId, folderId, mimeTypes, includeMountFolders, queryDefinition);
359 }
360
361 public List<Object> getFoldersAndFileEntriesAndFileShortcuts(
362 long groupId, long folderId, String[] mimeTypes,
363 boolean includeMountFolders, QueryDefinition queryDefinition)
364 throws SystemException {
365
366 return dlFolderFinder.findF_FE_FS_ByG_F_M_M(
367 groupId, folderId, mimeTypes, includeMountFolders, queryDefinition);
368 }
369
370
375 public int getFoldersAndFileEntriesAndFileShortcutsCount(
376 long groupId, long folderId, int status,
377 boolean includeMountFolders)
378 throws SystemException {
379
380 QueryDefinition queryDefinition = new QueryDefinition(status);
381
382 return getFoldersAndFileEntriesAndFileShortcutsCount(
383 groupId, folderId, null, includeMountFolders, queryDefinition);
384 }
385
386
391 public int getFoldersAndFileEntriesAndFileShortcutsCount(
392 long groupId, long folderId, int status, String[] mimeTypes,
393 boolean includeMountFolders)
394 throws SystemException {
395
396 QueryDefinition queryDefinition = new QueryDefinition(status);
397
398 return getFoldersAndFileEntriesAndFileShortcutsCount(
399 groupId, folderId, mimeTypes, includeMountFolders, queryDefinition);
400 }
401
402 public int getFoldersAndFileEntriesAndFileShortcutsCount(
403 long groupId, long folderId, String[] mimeTypes,
404 boolean includeMountFolders, QueryDefinition queryDefinition)
405 throws SystemException {
406
407 return dlFolderFinder.countF_FE_FS_ByG_F_M_M(
408 groupId, folderId, mimeTypes, includeMountFolders, queryDefinition);
409 }
410
411 public int getFoldersCount(long groupId, long parentFolderId)
412 throws SystemException {
413
414 return getFoldersCount(groupId, parentFolderId, true);
415 }
416
417 public int getFoldersCount(
418 long groupId, long parentFolderId, boolean includeMountfolders)
419 throws SystemException {
420
421 if (includeMountfolders) {
422 return dlFolderPersistence.countByG_P(groupId, parentFolderId);
423 }
424 else {
425 return dlFolderPersistence.countByG_M_P_H(
426 groupId, false, parentFolderId, false);
427 }
428 }
429
430 public DLFolder getMountFolder(long repositoryId)
431 throws PortalException, SystemException {
432
433 return dlFolderPersistence.findByRepositoryId(repositoryId);
434 }
435
436 public List<DLFolder> getMountFolders(
437 long groupId, long parentFolderId, int start, int end,
438 OrderByComparator obc)
439 throws SystemException {
440
441 return dlFolderPersistence.findByG_M_P_H(
442 groupId, true, parentFolderId, false, start, end, obc);
443 }
444
445 public int getMountFoldersCount(long groupId, long parentFolderId)
446 throws SystemException {
447
448 return dlFolderPersistence.countByG_M_P_H(
449 groupId, true, parentFolderId, false);
450 }
451
452 public void getSubfolderIds(
453 List<Long> folderIds, long groupId, long folderId)
454 throws SystemException {
455
456 List<DLFolder> dlFolders = dlFolderPersistence.findByG_P(
457 groupId, folderId);
458
459 for (DLFolder dlFolder : dlFolders) {
460 folderIds.add(dlFolder.getFolderId());
461
462 getSubfolderIds(
463 folderIds, dlFolder.getGroupId(), dlFolder.getFolderId());
464 }
465 }
466
467 public DLFolder moveFolder(
468 long folderId, long parentFolderId, ServiceContext serviceContext)
469 throws PortalException, SystemException {
470
471 DLFolder dlFolder = dlFolderPersistence.findByPrimaryKey(folderId);
472
473 parentFolderId = getParentFolderId(dlFolder, parentFolderId);
474
475 validateFolder(
476 dlFolder.getFolderId(), dlFolder.getGroupId(), parentFolderId,
477 dlFolder.getName());
478
479 dlFolder.setModifiedDate(serviceContext.getModifiedDate(null));
480 dlFolder.setParentFolderId(parentFolderId);
481 dlFolder.setExpandoBridgeAttributes(serviceContext);
482
483 dlFolderPersistence.update(dlFolder);
484
485 dlAppHelperLocalService.moveFolder(new LiferayFolder(dlFolder));
486
487 return dlFolder;
488 }
489
490 public DLFolder updateFolder(
491 long folderId, long parentFolderId, String name, String description,
492 long defaultFileEntryTypeId, List<Long> fileEntryTypeIds,
493 boolean overrideFileEntryTypes, ServiceContext serviceContext)
494 throws PortalException, SystemException {
495
496
497
498 DLFolder dlFolder = null;
499
500 if (folderId > DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
501 dlFolder = dlFolderLocalService.updateFolderAndFileEntryTypes(
502 folderId, parentFolderId, name, description,
503 defaultFileEntryTypeId, fileEntryTypeIds,
504 overrideFileEntryTypes, serviceContext);
505
506 dlFileEntryTypeLocalService.cascadeFileEntryTypes(
507 serviceContext.getUserId(), dlFolder);
508 }
509
510
511
512 List<ObjectValuePair<Long, String>> workflowDefinitionOVPs =
513 new ArrayList<ObjectValuePair<Long, String>>();
514
515 if (fileEntryTypeIds.isEmpty()) {
516 fileEntryTypeIds.add(
517 DLFileEntryTypeConstants.FILE_ENTRY_TYPE_ID_ALL);
518 }
519 else {
520 workflowDefinitionOVPs.add(
521 new ObjectValuePair<Long, String>(
522 DLFileEntryTypeConstants.FILE_ENTRY_TYPE_ID_ALL,
523 StringPool.BLANK));
524 }
525
526 for (long fileEntryTypeId : fileEntryTypeIds) {
527 String workflowDefinition = ParamUtil.getString(
528 serviceContext, "workflowDefinition" + fileEntryTypeId);
529
530 workflowDefinitionOVPs.add(
531 new ObjectValuePair<Long, String>(
532 fileEntryTypeId, workflowDefinition));
533 }
534
535 workflowDefinitionLinkLocalService.updateWorkflowDefinitionLinks(
536 serviceContext.getUserId(), serviceContext.getCompanyId(),
537 serviceContext.getScopeGroupId(), DLFolder.class.getName(),
538 folderId, workflowDefinitionOVPs);
539
540 return dlFolder;
541 }
542
543 public DLFolder updateFolder(
544 long folderId, String name, String description,
545 long defaultFileEntryTypeId, List<Long> fileEntryTypeIds,
546 boolean overrideFileEntryTypes, ServiceContext serviceContext)
547 throws PortalException, SystemException {
548
549 return updateFolder(
550 folderId, folderId, name, description, defaultFileEntryTypeId,
551 fileEntryTypeIds, overrideFileEntryTypes, serviceContext);
552 }
553
554 public DLFolder updateFolderAndFileEntryTypes(
555 long folderId, long parentFolderId, String name, String description,
556 long defaultFileEntryTypeId, List<Long> fileEntryTypeIds,
557 boolean overrideFileEntryTypes, ServiceContext serviceContext)
558 throws PortalException, SystemException {
559
560
561
562 if (!overrideFileEntryTypes) {
563 fileEntryTypeIds = Collections.emptyList();
564 }
565
566 DLFolder dlFolder = dlFolderPersistence.findByPrimaryKey(folderId);
567
568 parentFolderId = getParentFolderId(dlFolder, parentFolderId);
569
570 validateFolder(folderId, dlFolder.getGroupId(), parentFolderId, name);
571
572 dlFolder.setModifiedDate(serviceContext.getModifiedDate(null));
573 dlFolder.setParentFolderId(parentFolderId);
574 dlFolder.setName(name);
575 dlFolder.setDescription(description);
576 dlFolder.setExpandoBridgeAttributes(serviceContext);
577 dlFolder.setOverrideFileEntryTypes(overrideFileEntryTypes);
578 dlFolder.setDefaultFileEntryTypeId(defaultFileEntryTypeId);
579
580 dlFolderPersistence.update(dlFolder);
581
582
583
584 if (fileEntryTypeIds != null) {
585 dlFileEntryTypeLocalService.updateFolderFileEntryTypes(
586 dlFolder, fileEntryTypeIds, defaultFileEntryTypeId,
587 serviceContext);
588 }
589
590
591
592 dlAppHelperLocalService.updateFolder(
593 new LiferayFolder(dlFolder), serviceContext);
594
595 return dlFolder;
596 }
597
598 public void updateLastPostDate(long folderId, Date lastPostDate)
599 throws PortalException, SystemException {
600
601 DLFolder dlFolder = dlFolderPersistence.findByPrimaryKey(folderId);
602
603 dlFolder.setLastPostDate(lastPostDate);
604
605 dlFolderPersistence.update(dlFolder);
606 }
607
608 public DLFolder updateStatus(
609 long userId, long folderId, int status,
610 Map<String, Serializable> workflowContext,
611 ServiceContext serviceContext)
612 throws PortalException, SystemException {
613
614
615
616 User user = userPersistence.findByPrimaryKey(userId);
617
618 DLFolder dlFolder = dlFolderPersistence.findByPrimaryKey(folderId);
619
620 if (dlFolder.isInTrash() &&
621 (status == WorkflowConstants.STATUS_APPROVED)) {
622
623 dlFolder.setName(TrashUtil.getOriginalTitle(dlFolder.getName()));
624 }
625
626 dlFolder.setStatus(status);
627 dlFolder.setStatusByUserId(user.getUserId());
628 dlFolder.setStatusByUserName(user.getFullName());
629 dlFolder.setStatusDate(new Date());
630
631 dlFolderPersistence.update(dlFolder);
632
633
634
635 QueryDefinition queryDefinition = new QueryDefinition(
636 WorkflowConstants.STATUS_ANY);
637
638 List<Object> foldersAndFileEntriesAndFileShortcuts =
639 getFoldersAndFileEntriesAndFileShortcuts(
640 dlFolder.getGroupId(), folderId, null, false, queryDefinition);
641
642 dlAppHelperLocalService.updateDependentStatus(
643 user, foldersAndFileEntriesAndFileShortcuts, status);
644
645
646
647 if (status == WorkflowConstants.STATUS_IN_TRASH) {
648 UnicodeProperties typeSettingsProperties = new UnicodeProperties();
649
650 typeSettingsProperties.put("title", dlFolder.getName());
651
652 trashEntryLocalService.addTrashEntry(
653 userId, dlFolder.getGroupId(), DLFolderConstants.getClassName(),
654 dlFolder.getFolderId(), WorkflowConstants.STATUS_APPROVED, null,
655 typeSettingsProperties);
656 }
657
658 return dlFolder;
659 }
660
661 protected void addFolderResources(
662 DLFolder dlFolder, boolean addGroupPermissions,
663 boolean addGuestPermissions)
664 throws PortalException, SystemException {
665
666 resourceLocalService.addResources(
667 dlFolder.getCompanyId(), dlFolder.getGroupId(),
668 dlFolder.getUserId(), DLFolder.class.getName(),
669 dlFolder.getFolderId(), false, addGroupPermissions,
670 addGuestPermissions);
671 }
672
673 protected void addFolderResources(
674 DLFolder dlFolder, String[] groupPermissions,
675 String[] guestPermissions)
676 throws PortalException, SystemException {
677
678 resourceLocalService.addModelResources(
679 dlFolder.getCompanyId(), dlFolder.getGroupId(),
680 dlFolder.getUserId(), DLFolder.class.getName(),
681 dlFolder.getFolderId(), groupPermissions, guestPermissions);
682 }
683
684 protected void addFolderResources(
685 long folderId, boolean addGroupPermissions,
686 boolean addGuestPermissions)
687 throws PortalException, SystemException {
688
689 DLFolder dlFolder = dlFolderPersistence.findByPrimaryKey(folderId);
690
691 addFolderResources(dlFolder, addGroupPermissions, addGuestPermissions);
692 }
693
694 protected void addFolderResources(
695 long folderId, String[] groupPermissions, String[] guestPermissions)
696 throws PortalException, SystemException {
697
698 DLFolder dlFolder = dlFolderPersistence.findByPrimaryKey(folderId);
699
700 addFolderResources(dlFolder, groupPermissions, guestPermissions);
701 }
702
703 protected void deleteFolder(DLFolder dlFolder)
704 throws PortalException, SystemException {
705
706 deleteFolder(dlFolder, true);
707 }
708
709 protected void deleteFolder(
710 DLFolder dlFolder, boolean includeTrashedEntries)
711 throws PortalException, SystemException {
712
713
714
715 List<DLFolder> dlFolders = dlFolderPersistence.findByG_P(
716 dlFolder.getGroupId(), dlFolder.getFolderId());
717
718 for (DLFolder curDLFolder : dlFolders) {
719 if (includeTrashedEntries || !curDLFolder.isInTrash()) {
720 deleteFolder(curDLFolder, includeTrashedEntries);
721 }
722 }
723
724
725
726 resourceLocalService.deleteResource(
727 dlFolder.getCompanyId(), DLFolder.class.getName(),
728 ResourceConstants.SCOPE_INDIVIDUAL, dlFolder.getFolderId());
729
730
731
732 webDAVPropsLocalService.deleteWebDAVProps(
733 DLFolder.class.getName(), dlFolder.getFolderId());
734
735
736
737 dlFileEntryLocalService.deleteFileEntries(
738 dlFolder.getGroupId(), dlFolder.getFolderId(),
739 includeTrashedEntries);
740
741
742
743 dlFileEntryTypeLocalService.unsetFolderFileEntryTypes(
744 dlFolder.getFolderId());
745
746
747
748 dlFileShortcutLocalService.deleteFileShortcuts(
749 dlFolder.getGroupId(), dlFolder.getFolderId(),
750 includeTrashedEntries);
751
752
753
754 expandoValueLocalService.deleteValues(
755 DLFolder.class.getName(), dlFolder.getFolderId());
756
757
758
759 dlAppHelperLocalService.deleteFolder(new LiferayFolder(dlFolder));
760
761
762
763 dlFolderPersistence.remove(dlFolder);
764
765
766
767 try {
768 DLStoreUtil.deleteDirectory(
769 dlFolder.getCompanyId(), dlFolder.getFolderId(),
770 StringPool.BLANK);
771 }
772 catch (NoSuchDirectoryException nsde) {
773 if (_log.isDebugEnabled()) {
774 _log.debug(nsde.getMessage());
775 }
776 }
777 }
778
779 protected long getParentFolderId(DLFolder dlFolder, long parentFolderId)
780 throws SystemException {
781
782 if (parentFolderId == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
783 return parentFolderId;
784 }
785
786 if (dlFolder.getFolderId() == parentFolderId) {
787 return dlFolder.getParentFolderId();
788 }
789 else {
790 DLFolder parentDLFolder = dlFolderPersistence.fetchByPrimaryKey(
791 parentFolderId);
792
793 if ((parentDLFolder == null) ||
794 (dlFolder.getGroupId() != parentDLFolder.getGroupId())) {
795
796 return dlFolder.getParentFolderId();
797 }
798
799 List<Long> subfolderIds = new ArrayList<Long>();
800
801 getSubfolderIds(
802 subfolderIds, dlFolder.getGroupId(), dlFolder.getFolderId());
803
804 if (subfolderIds.contains(parentFolderId)) {
805 return dlFolder.getParentFolderId();
806 }
807
808 return parentFolderId;
809 }
810 }
811
812 protected long getParentFolderId(long groupId, long parentFolderId)
813 throws SystemException {
814
815 if (parentFolderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
816 DLFolder parentDLFolder = dlFolderPersistence.fetchByPrimaryKey(
817 parentFolderId);
818
819 if ((parentDLFolder == null) ||
820 (groupId != parentDLFolder.getGroupId())) {
821
822 parentFolderId = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID;
823 }
824 }
825
826 return parentFolderId;
827 }
828
829 protected void validateFolder(
830 long folderId, long groupId, long parentFolderId, String name)
831 throws PortalException, SystemException {
832
833 validateFolderName(name);
834
835 try {
836 dlFileEntryLocalService.getFileEntry(groupId, parentFolderId, name);
837
838 throw new DuplicateFileException(name);
839 }
840 catch (NoSuchFileEntryException nsfee) {
841 }
842
843 DLFolder dlFolder = dlFolderPersistence.fetchByG_P_N(
844 groupId, parentFolderId, name);
845
846 if ((dlFolder != null) && (dlFolder.getFolderId() != folderId)) {
847 throw new DuplicateFolderNameException(name);
848 }
849 }
850
851 protected void validateFolder(
852 long groupId, long parentFolderId, String name)
853 throws PortalException, SystemException {
854
855 long folderId = 0;
856
857 validateFolder(folderId, groupId, parentFolderId, name);
858 }
859
860 protected void validateFolderName(String name) throws PortalException {
861 if (!AssetUtil.isValidWord(name)) {
862 throw new FolderNameException();
863 }
864 }
865
866 private static Log _log = LogFactoryUtil.getLog(
867 DLFolderLocalServiceImpl.class);
868
869 }