public static void getFolder(HttpServletRequest request) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); long folderId = ParamUtil.getLong(request, "folderId"); Folder folder = null; if ((folderId > 0) && (folderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID)) { folder = DLAppServiceUtil.getFolder(folderId); if (folder.getModel() instanceof DLFolder) { DLFolder dlFolder = (DLFolder) folder.getModel(); if (dlFolder.isInTrash() || dlFolder.isInTrashContainer()) { throw new NoSuchFolderException(); } } } else { DLPermission.check( themeDisplay.getPermissionChecker(), themeDisplay.getScopeGroupId(), ActionKeys.VIEW); } request.setAttribute(WebKeys.DOCUMENT_LIBRARY_FOLDER, folder); }
@Override protected void doReindex(Object obj) throws Exception { DLFolder dlFolder = (DLFolder) obj; if (!dlFolder.isApproved() && !dlFolder.isInTrash()) { return; } Document document = getDocument(dlFolder); if (document != null) { SearchEngineUtil.updateDocument(getSearchEngineId(), dlFolder.getCompanyId(), document); } }
@Override public List<DLFolder> getAncestors() throws PortalException, SystemException { List<DLFolder> ancestors = new ArrayList<DLFolder>(); DLFolder folder = this; while (!folder.isRoot()) { try { folder = folder.getParentFolder(); ancestors.add(folder); } catch (NoSuchFolderException nsfe) { if (folder.isInTrash()) { break; } throw nsfe; } } return ancestors; }
public void updateStatuses(User user, List<Object> dlFileEntriesAndDLFolders, int status) throws PortalException, SystemException { for (Object object : dlFileEntriesAndDLFolders) { if (object instanceof DLFileEntry) { DLFileEntry dlFileEntry = (DLFileEntry) object; List<DLFileVersion> dlFileVersions = dlFileVersionLocalService.getFileVersions( dlFileEntry.getFileEntryId(), WorkflowConstants.STATUS_ANY); dlFileVersions = ListUtil.copy(dlFileVersions); Collections.sort(dlFileVersions, new FileVersionVersionComparator()); DLFileVersion latestDlFileVersion = dlFileVersions.get(0); if ((status == WorkflowConstants.STATUS_APPROVED) && (latestDlFileVersion.getStatus() == WorkflowConstants.STATUS_IN_TRASH)) { continue; } // Asset if (status == WorkflowConstants.STATUS_APPROVED) { if (latestDlFileVersion.isApproved()) { assetEntryLocalService.updateVisible( DLFileEntryConstants.getClassName(), dlFileEntry.getFileEntryId(), true); } } else { assetEntryLocalService.moveEntryToTrash( DLFileEntryConstants.getClassName(), dlFileEntry.getFileEntryId()); } // Social if (status == WorkflowConstants.STATUS_APPROVED) { socialActivityCounterLocalService.enableActivityCounters( DLFileEntryConstants.getClassName(), dlFileEntry.getFileEntryId()); socialActivityLocalService.addActivity( user.getUserId(), dlFileEntry.getGroupId(), DLFileEntryConstants.getClassName(), dlFileEntry.getFileEntryId(), SocialActivityConstants.TYPE_RESTORE_FROM_TRASH, StringPool.BLANK, 0); } else if (latestDlFileVersion.getStatus() == WorkflowConstants.STATUS_APPROVED) { socialActivityLocalService.addActivity( user.getUserId(), dlFileEntry.getGroupId(), DLFileEntryConstants.getClassName(), dlFileEntry.getFileEntryId(), SocialActivityConstants.TYPE_MOVE_TO_TRASH, StringPool.BLANK, 0); } // Index Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(DLFileEntry.class); if (status == WorkflowConstants.STATUS_APPROVED) { indexer.reindex(dlFileEntry); } else { indexer.delete(dlFileEntry); } // Workflow if (status != WorkflowConstants.STATUS_APPROVED) { for (DLFileVersion dlFileVersion : dlFileVersions) { if (!dlFileVersion.isPending()) { continue; } dlFileVersion.setStatus(WorkflowConstants.STATUS_DRAFT); dlFileVersionPersistence.update(dlFileVersion, false); workflowInstanceLinkLocalService.deleteWorkflowInstanceLink( dlFileVersion.getCompanyId(), dlFileVersion.getGroupId(), DLFileEntryConstants.getClassName(), dlFileVersion.getFileVersionId()); } } } else if (object instanceof DLFolder) { DLFolder dlFolder = (DLFolder) object; if (dlFolder.isInTrash()) { continue; } QueryDefinition queryDefinition = new QueryDefinition(WorkflowConstants.STATUS_ANY); List<Object> foldersAndFileEntriesAndFileShortcuts = dlFolderLocalService.getFoldersAndFileEntriesAndFileShortcuts( dlFolder.getGroupId(), dlFolder.getFolderId(), null, false, queryDefinition); updateStatuses(user, foldersAndFileEntriesAndFileShortcuts, status); } } }
@Indexable(type = IndexableType.DELETE) public DLFolder deleteFolder(DLFolder dlFolder, boolean includeTrashedEntries) throws PortalException, SystemException { // Folders List<DLFolder> dlFolders = dlFolderPersistence.findByG_P(dlFolder.getGroupId(), dlFolder.getFolderId()); for (DLFolder curDLFolder : dlFolders) { if (includeTrashedEntries || !curDLFolder.isInTrash()) { dlFolderLocalService.deleteFolder(curDLFolder, includeTrashedEntries); } } // Resources resourceLocalService.deleteResource( dlFolder.getCompanyId(), DLFolder.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL, dlFolder.getFolderId()); // WebDAVProps webDAVPropsLocalService.deleteWebDAVProps(DLFolder.class.getName(), dlFolder.getFolderId()); // File entries dlFileEntryLocalService.deleteFileEntries( dlFolder.getGroupId(), dlFolder.getFolderId(), includeTrashedEntries); // File entry types dlFileEntryTypeLocalService.unsetFolderFileEntryTypes(dlFolder.getFolderId()); // File shortcuts dlFileShortcutLocalService.deleteFileShortcuts( dlFolder.getGroupId(), dlFolder.getFolderId(), includeTrashedEntries); // Expando expandoValueLocalService.deleteValues(DLFolder.class.getName(), dlFolder.getFolderId()); // App helper dlAppHelperLocalService.deleteFolder(new LiferayFolder(dlFolder)); // Folder dlFolderPersistence.remove(dlFolder); // Directory try { DLStoreUtil.deleteDirectory( dlFolder.getCompanyId(), dlFolder.getFolderId(), StringPool.BLANK); } catch (NoSuchDirectoryException nsde) { if (_log.isDebugEnabled()) { _log.debug(nsde.getMessage()); } } return dlFolder; }