@Override protected void doExportStagedModel(PortletDataContext portletDataContext, Repository repository) throws Exception { Element repositoryElement = portletDataContext.getExportDataElement(repository); Folder folder = DLAppLocalServiceUtil.getFolder(repository.getDlFolderId()); if (folder.getModel() instanceof DLFolder) { DLFolder dlFolder = (DLFolder) folder.getModel(); repositoryElement.addAttribute("hidden", String.valueOf(dlFolder.isHidden())); } portletDataContext.addClassedModel( repositoryElement, ExportImportPathUtil.getModelPath(repository), repository); List<RepositoryEntry> repositoryEntries = RepositoryEntryLocalServiceUtil.getRepositoryEntries(repository.getRepositoryId()); for (RepositoryEntry repositoryEntry : repositoryEntries) { StagedModelDataHandlerUtil.exportReferenceStagedModel( portletDataContext, repository, repositoryEntry, PortletDataContext.REFERENCE_TYPE_CHILD); } }
public Folder moveFolderToTrash(long userId, Folder folder) throws PortalException, SystemException { // Folder DLFolder dlFolder = dlFolderLocalService.updateStatus( userId, folder.getFolderId(), WorkflowConstants.STATUS_IN_TRASH, new HashMap<String, Serializable>(), new ServiceContext()); dlFolder.setName(DLAppUtil.appendTrashNamespace(dlFolder.getName())); dlFolderPersistence.update(dlFolder, false); // File rank dlFileRankLocalService.disableFileRanksByFolderId(folder.getFolderId()); // Trash trashEntryLocalService.addTrashEntry( userId, folder.getGroupId(), DLFolderConstants.getClassName(), folder.getFolderId(), WorkflowConstants.STATUS_APPROVED, null, null); return new LiferayFolder(dlFolder); }
@Override public boolean isSubscribedToFolder( long companyId, long groupId, long userId, long folderId, boolean recursive) throws PortalException, SystemException { List<Long> ancestorFolderIds = new ArrayList<Long>(); if (folderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) { Folder folder = DLAppLocalServiceUtil.getFolder(folderId); if (recursive) { ancestorFolderIds = folder.getAncestorFolderIds(); ancestorFolderIds.add(groupId); } ancestorFolderIds.add(0, folderId); } else { ancestorFolderIds.add(groupId); } long[] folderIdsArray = ArrayUtil.toLongArray(ancestorFolderIds); return SubscriptionLocalServiceUtil.isSubscribed( companyId, userId, Folder.class.getName(), folderIdsArray); }
@Override public String getAbsolutePath(PortletRequest portletRequest, long folderId) throws PortalException, SystemException { ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY); if (folderId == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) { return themeDisplay.translate("home"); } Folder folder = DLAppLocalServiceUtil.getFolder(folderId); List<Folder> folders = folder.getAncestors(); Collections.reverse(folders); StringBundler sb = new StringBundler((folders.size() * 3) + 5); sb.append(themeDisplay.translate("home")); sb.append(StringPool.SPACE); for (Folder curFolder : folders) { sb.append(StringPool.RAQUO); sb.append(StringPool.SPACE); sb.append(curFolder.getName()); } sb.append(StringPool.RAQUO); sb.append(StringPool.SPACE); sb.append(folder.getName()); return sb.toString(); }
public void restoreFolderFromTrash(long userId, Folder folder) throws PortalException, SystemException { // Folder TrashEntry trashEntry = trashEntryLocalService.getEntry(DLFolderConstants.getClassName(), folder.getFolderId()); DLFolder dlFolder = dlFolderLocalService.updateStatus( userId, folder.getFolderId(), WorkflowConstants.STATUS_APPROVED, new HashMap<String, Serializable>(), new ServiceContext()); dlFolder.setName(DLAppUtil.stripTrashNamespace(dlFolder.getName())); dlFolderPersistence.update(dlFolder, false); // File rank dlFileRankLocalService.enableFileRanksByFolderId(folder.getFolderId()); // Trash trashEntryLocalService.deleteEntry(trashEntry.getEntryId()); }
@Override protected FileEntry addFileEntry( long userId, long groupId, long folderId, String fileName, String contentType, InputStream inputStream, long size, ServiceContext serviceContext) throws PortalException { Folder folder = BlogsEntryLocalServiceUtil.addAttachmentsFolder(userId, groupId); return PortletFileRepositoryUtil.addPortletFileEntry( groupId, userId, BlogsEntry.class.getName(), 0, BlogsConstants.SERVICE_NAME, folder.getFolderId(), inputStream, fileName, contentType, true); }
@Override public long getAttachmentsFolderId() { if (_attachmentsFolderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) { return _attachmentsFolderId; } ServiceContext serviceContext = new ServiceContext(); serviceContext.setAddGroupPermissions(true); serviceContext.setAddGuestPermissions(true); Repository repository = PortletFileRepositoryUtil.fetchPortletRepository(getGroupId(), PortletKeys.BACKGROUND_TASK); if (repository == null) { return DLFolderConstants.DEFAULT_PARENT_FOLDER_ID; } try { Folder folder = PortletFileRepositoryUtil.getPortletFolder( repository.getRepositoryId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, String.valueOf(getBackgroundTaskId())); _attachmentsFolderId = folder.getFolderId(); } catch (Exception e) { } return _attachmentsFolderId; }
@Override protected void validateImport( Map<String, List<StagedModel>> dependentStagedModelsMap, Group group) throws Exception { List<StagedModel> ddmStructureDependentStagedModels = dependentStagedModelsMap.get(DDMStructure.class.getSimpleName()); Assert.assertEquals(1, ddmStructureDependentStagedModels.size()); DDMStructure ddmStructure = (DDMStructure) ddmStructureDependentStagedModels.get(0); DDMStructureLocalServiceUtil.getDDMStructureByUuidAndGroupId( ddmStructure.getUuid(), group.getGroupId()); List<StagedModel> dlFileEntryTypesDependentStagedModels = dependentStagedModelsMap.get(DLFileEntryType.class.getSimpleName()); Assert.assertEquals(1, dlFileEntryTypesDependentStagedModels.size()); DLFileEntryType dlFileEntryType = (DLFileEntryType) dlFileEntryTypesDependentStagedModels.get(0); DLFileEntryTypeLocalServiceUtil.getDLFileEntryTypeByUuidAndGroupId( dlFileEntryType.getUuid(), group.getGroupId()); List<StagedModel> folderDependentStagedModels = dependentStagedModelsMap.get(DLFolder.class.getSimpleName()); Assert.assertEquals(1, folderDependentStagedModels.size()); Folder parentFolder = (Folder) folderDependentStagedModels.get(0); DLFolderLocalServiceUtil.getDLFolderByUuidAndGroupId( parentFolder.getUuid(), group.getGroupId()); }
private Folder _getFolder(long groupId, String folderName) throws Exception { DLFolder dlFolder = new DLFolderImpl(); dlFolder.setFolderId(DLFolderConstants.DEFAULT_PARENT_FOLDER_ID); dlFolder.setGroupId(groupId); Folder folder = new LiferayFolder(dlFolder); if (folderName.equals(StringPool.SLASH)) { return folder; } StringTokenizer st = new StringTokenizer(folderName, StringPool.SLASH); while (st.hasMoreTokens()) { String curFolderName = st.nextToken(); List<Folder> folders = DLAppServiceUtil.getFolders(groupId, folder.getFolderId()); for (Folder curFolder : folders) { if (curFolder.getName().equals(curFolderName)) { folder = curFolder; break; } } } return folder; }
@Override public void deleteFolder(long parentFolderId, String name) throws PortalException { Folder folder = getFolder(parentFolderId, name); deleteFolder(folder.getFolderId()); }
@Override public Folder addAttachmentsFolder() throws PortalException, SystemException { if (_attachmentsFolderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) { return PortletFileRepositoryUtil.getPortletFolder(_attachmentsFolderId); } ServiceContext serviceContext = new ServiceContext(); serviceContext.setAddGroupPermissions(true); serviceContext.setAddGuestPermissions(true); Repository repository = PortletFileRepositoryUtil.addPortletRepository( getGroupId(), PortletKeys.MESSAGE_BOARDS, serviceContext); MBThread thread = getThread(); Folder threadFolder = thread.addAttachmentsFolder(); Folder folder = PortletFileRepositoryUtil.addPortletFolder( getUserId(), repository.getRepositoryId(), threadFolder.getFolderId(), String.valueOf(getMessageId()), serviceContext); _attachmentsFolderId = folder.getFolderId(); return folder; }
@Override public Folder addAttachmentsFolder() throws PortalException { if (_attachmentsFolderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) { return PortletFileRepositoryUtil.getPortletFolder(_attachmentsFolderId); } ServiceContext serviceContext = new ServiceContext(); serviceContext.setAddGroupPermissions(true); serviceContext.setAddGuestPermissions(true); Repository repository = PortletFileRepositoryUtil.addPortletRepository( getGroupId(), PortletKeys.BACKGROUND_TASK, serviceContext); Folder folder = PortletFileRepositoryUtil.addPortletFolder( getUserId(), repository.getRepositoryId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, String.valueOf(getBackgroundTaskId()), serviceContext); _attachmentsFolderId = folder.getFolderId(); return folder; }
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); }
protected void moveAttachmentsFolders( MBMessage message, long oldAttachmentsFolderId, MBThread oldThread, MBThread newThread, ServiceContext serviceContext) throws PortalException { if (oldAttachmentsFolderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) { Folder newThreadFolder = newThread.addAttachmentsFolder(); PortletFileRepositoryUtil.movePortletFolder( message.getGroupId(), message.getUserId(), oldAttachmentsFolderId, newThreadFolder.getFolderId(), serviceContext); } List<MBMessage> childMessages = mbMessagePersistence.findByT_P(oldThread.getThreadId(), message.getMessageId()); for (MBMessage childMessage : childMessages) { moveAttachmentsFolders( childMessage, childMessage.getAttachmentsFolderId(), oldThread, newThread, serviceContext); } }
protected void deleteImages(ActionRequest actionRequest) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); long[] deleteFileEntryIds = null; long fileEntryId = ParamUtil.getLong(actionRequest, "fileEntryId"); if (fileEntryId > 0) { deleteFileEntryIds = new long[] {fileEntryId}; } else { deleteFileEntryIds = StringUtil.split(ParamUtil.getString(actionRequest, "deleteFileEntryIds"), 0L); } Folder folder = _blogsEntryLocalService.addAttachmentsFolder( themeDisplay.getUserId(), themeDisplay.getScopeGroupId()); for (long deleteFileEntryId : deleteFileEntryIds) { FileEntry fileEntry = PortletFileRepositoryUtil.getPortletFileEntry(deleteFileEntryId); if (fileEntry.getFolderId() != folder.getFolderId()) { continue; } if ((fileEntry.getUserId() == themeDisplay.getUserId()) || BlogsPermission.contains( themeDisplay.getPermissionChecker(), themeDisplay.getScopeGroupId(), ActionKeys.UPDATE)) { PortletFileRepositoryUtil.deletePortletFileEntry(deleteFileEntryId); } } }
protected String fileUpload( CommandArgument commandArgument, String fileName, File file, String extension) { try { Group group = commandArgument.getCurrentGroup(); Folder folder = _getFolder(group.getGroupId(), commandArgument.getCurrentFolder()); long folderId = folder.getFolderId(); String title = fileName; String description = StringPool.BLANK; String changeLog = StringPool.BLANK; ServiceContext serviceContext = new ServiceContext(); serviceContext.setAddCommunityPermissions(true); serviceContext.setAddGuestPermissions(true); DLAppServiceUtil.addFileEntry( group.getGroupId(), folderId, title, description, changeLog, file, serviceContext); } catch (Exception e) { throw new FCKException(e); } return "0"; }
private void _getFolders(CommandArgument commandArgument, Document document, Node rootNode) throws Exception { Element foldersElement = document.createElement("Folders"); rootNode.appendChild(foldersElement); if (commandArgument.getCurrentFolder().equals(StringPool.SLASH)) { getRootFolders(commandArgument, document, foldersElement); } else { Group group = commandArgument.getCurrentGroup(); Folder folder = _getFolder(group.getGroupId(), commandArgument.getCurrentFolder()); List<Folder> folders = DLAppServiceUtil.getFolders(group.getGroupId(), folder.getFolderId()); for (Folder curFolder : folders) { Element folderElement = document.createElement("Folder"); foldersElement.appendChild(folderElement); folderElement.setAttribute("name", curFolder.getName()); } } }
@Override public void unlockFolder(long parentFolderId, String name, String lockUuid) throws PortalException { Folder folder = getFolder(parentFolderId, name); unlockFolder(folder.getFolderId(), lockUuid); }
protected void deleteEntries(ActionRequest actionRequest, boolean moveToTrash) throws Exception { long[] deleteFolderIds = ParamUtil.getLongValues(actionRequest, "rowIdsFolder"); List<TrashedModel> trashedModels = new ArrayList<>(); for (int i = 0; i < deleteFolderIds.length; i++) { long deleteFolderId = deleteFolderIds[i]; if (moveToTrash) { Folder folder = _dlAppService.moveFolderToTrash(deleteFolderId); if (folder.getModel() instanceof TrashedModel) { trashedModels.add((TrashedModel) folder.getModel()); } } else { _dlAppService.deleteFolder(deleteFolderId); } } // Delete file shortcuts before file entries. See LPS-21348. long[] deleteFileShortcutIds = ParamUtil.getLongValues(actionRequest, "rowIdsDLFileShortcut"); for (int i = 0; i < deleteFileShortcutIds.length; i++) { long deleteFileShortcutId = deleteFileShortcutIds[i]; if (moveToTrash) { FileShortcut fileShortcut = _dlAppService.moveFileShortcutToTrash(deleteFileShortcutId); if (fileShortcut.getModel() instanceof TrashedModel) { trashedModels.add((TrashedModel) fileShortcut.getModel()); } } else { _dlAppService.deleteFileShortcut(deleteFileShortcutId); } } long[] deleteFileEntryIds = ParamUtil.getLongValues(actionRequest, "rowIdsFileEntry"); for (long deleteFileEntryId : deleteFileEntryIds) { if (moveToTrash) { FileEntry fileEntry = _dlAppService.moveFileEntryToTrash(deleteFileEntryId); if (fileEntry.getModel() instanceof TrashedModel) { trashedModels.add((TrashedModel) fileEntry.getModel()); } } else { _dlAppService.deleteFileEntry(deleteFileEntryId); } } if (moveToTrash && !trashedModels.isEmpty()) { TrashUtil.addTrashSessionMessages(actionRequest, trashedModels); hideDefaultSuccessMessage(actionRequest); } }
public static boolean isSupportedFolder(Folder folder) { if (!(folder.getModel() instanceof DLFolder)) { return false; } DLFolder dlFolder = (DLFolder) folder.getModel(); return isSupportedFolder(dlFolder); }
protected boolean isDefaultRepository(long folderId) throws PortalException { if (folderId == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) { return true; } Folder folder = dlAppLocalService.getFolder(folderId); return folder.isDefaultRepository(); }
public static void addPortletBreadcrumbEntries( Folder folder, HttpServletRequest request, PortletURL portletURL) throws Exception { long defaultFolderId = _getDefaultFolderId(request); List<Folder> ancestorFolders = Collections.emptyList(); if ((folder != null) && (folder.getFolderId() != defaultFolderId)) { ancestorFolders = folder.getAncestors(); int indexOfRootFolder = -1; for (int i = 0; i < ancestorFolders.size(); i++) { Folder ancestorFolder = ancestorFolders.get(i); if (defaultFolderId == ancestorFolder.getFolderId()) { indexOfRootFolder = i; } } if (indexOfRootFolder > -1) { ancestorFolders = ancestorFolders.subList(0, indexOfRootFolder); } } Collections.reverse(ancestorFolders); for (Folder ancestorFolder : ancestorFolders) { portletURL.setParameter("folderId", String.valueOf(ancestorFolder.getFolderId())); Map<String, Object> data = new HashMap<String, Object>(); data.put("folder-id", ancestorFolder.getFolderId()); PortalUtil.addPortletBreadcrumbEntry( request, ancestorFolder.getName(), portletURL.toString(), data); } long folderId = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID; if (folder != null) { folderId = folder.getFolderId(); } portletURL.setParameter("folderId", String.valueOf(folderId)); if ((folderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) && (folderId != defaultFolderId)) { Map<String, Object> data = new HashMap<String, Object>(); data.put("folder-id", folderId); PortalUtil.addPortletBreadcrumbEntry(request, folder.getName(), portletURL.toString(), data); } }
@Override protected String doExportData( PortletDataContext portletDataContext, String portletId, PortletPreferences portletPreferences) throws Exception { portletDataContext.addPermissions( "com.liferay.portlet.documentlibrary", portletDataContext.getScopeGroupId()); long rootFolderId = GetterUtil.getLong(portletPreferences.getValue("rootFolderId", null)); Document document = SAXReaderUtil.createDocument(); Element rootElement = document.addElement("documentlibrary-display-data"); Element fileEntryTypesElement = rootElement.addElement("file-entry-types"); Element foldersElement = rootElement.addElement("folders"); Element fileEntriesElement = rootElement.addElement("file-entries"); Element fileShortcutsElement = rootElement.addElement("file-shortcuts"); Element fileRanksElement = rootElement.addElement("file-ranks"); if (rootFolderId == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) { List<Folder> folders = FolderUtil.findByRepositoryId(portletDataContext.getScopeGroupId()); for (Folder folder : folders) { DLPortletDataHandlerImpl.exportFolder( portletDataContext, fileEntryTypesElement, foldersElement, fileEntriesElement, fileShortcutsElement, fileRanksElement, folder, false); } } else { Folder folder = FolderUtil.findByPrimaryKey(rootFolderId); rootElement.addAttribute("root-folder-id", String.valueOf(folder.getFolderId())); DLPortletDataHandlerImpl.exportFolder( portletDataContext, fileEntryTypesElement, foldersElement, fileEntriesElement, fileShortcutsElement, fileRanksElement, folder, true); } return document.formattedString(); }
public static SyncDLObject toSyncDLObject(Folder folder, String event) throws PortalException, SystemException { if (folder.getModel() instanceof DLFolder) { DLFolder dlFolder = (DLFolder) folder.getModel(); return toSyncDLObject(dlFolder, event); } throw new PortalException("Folder must be an instance of DLFolder"); }
public static boolean contains( PermissionChecker permissionChecker, long groupId, long folderId, String actionId) throws PortalException, SystemException { if (folderId == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) { return DLPermission.contains(permissionChecker, groupId, actionId); } else { Folder folder = DLAppLocalServiceUtil.getFolder(folderId); return folder.containsPermission(permissionChecker, actionId); } }
public void moveFolder(Folder folder) throws PortalException, SystemException { if (!isStagingGroup(folder.getGroupId())) { dlSyncLocalService.updateSync( folder.getFolderId(), folder.getParentFolderId(), folder.getName(), folder.getDescription(), DLSyncConstants.EVENT_UPDATE, "-1"); } }
public static void addPortletBreadcrumbEntries( long folderId, HttpServletRequest request, RenderResponse renderResponse) throws Exception { if (folderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) { Folder folder = DLAppLocalServiceUtil.getFolder(folderId); if (folder.getFolderId() != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) { addPortletBreadcrumbEntries(folder, request, renderResponse); } } }
protected Folder addFolder(boolean rootFolder, String name) throws Exception { long parentFolderId = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID; if (!rootFolder) { Folder parentFolder = addFolder(parentFolderId, "Test Folder", true); parentFolderId = parentFolder.getFolderId(); } return addFolder(parentFolderId, name); }
public static void addPortletBreadcrumbEntries( Folder folder, HttpServletRequest request, RenderResponse renderResponse) throws Exception { String mvcRenderCommandName = ParamUtil.getString(request, "mvcRenderCommandName"); PortletURL portletURL = renderResponse.createRenderURL(); if (mvcRenderCommandName.equals("/document_library/select_folder")) { ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); portletURL.setParameter("mvcRenderCommandName", mvcRenderCommandName); portletURL.setWindowState(LiferayWindowState.POP_UP); PortalUtil.addPortletBreadcrumbEntry( request, themeDisplay.translate("home"), portletURL.toString()); } else { portletURL.setParameter("mvcRenderCommandName", "/image_gallery_display/view"); } long defaultFolderId = getDefaultFolderId(request); List<Folder> ancestorFolders = Collections.emptyList(); if ((folder != null) && (folder.getFolderId() != defaultFolderId)) { ancestorFolders = folder.getAncestors(); int indexOfRootFolder = -1; for (int i = 0; i < ancestorFolders.size(); i++) { Folder ancestorFolder = ancestorFolders.get(i); if (defaultFolderId == ancestorFolder.getFolderId()) { indexOfRootFolder = i; } } if (indexOfRootFolder > -1) { ancestorFolders = ancestorFolders.subList(0, indexOfRootFolder); } } Collections.reverse(ancestorFolders); for (Folder ancestorFolder : ancestorFolders) { portletURL.setParameter("folderId", String.valueOf(ancestorFolder.getFolderId())); PortalUtil.addPortletBreadcrumbEntry( request, ancestorFolder.getName(), portletURL.toString()); } portletURL.setParameter("folderId", String.valueOf(folder.getFolderId())); PortalUtil.addPortletBreadcrumbEntry(request, folder.getName(), portletURL.toString()); }
@Test public void testMigrateDLWhenFileEntryInFolder() throws Exception { ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId(), TestPropsValues.getUserId()); Folder folder = DLAppServiceUtil.addFolder( _group.getGroupId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, RandomTestUtil.randomString(), RandomTestUtil.randomString(), serviceContext); testMigrateDL(folder.getFolderId()); }