/** * Copyright (c) 2000-present Liferay, Inc. All rights reserved. * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. */ package com.liferay.document.library.web.internal.util; import com.liferay.document.library.kernel.model.DLFileEntryType; import com.liferay.document.library.kernel.model.DLFileEntryTypeConstants; import com.liferay.document.library.kernel.model.DLFolder; import com.liferay.document.library.kernel.model.DLFolderConstants; import com.liferay.document.library.kernel.service.DLAppLocalServiceUtil; import com.liferay.portal.kernel.exception.PortalException; import com.liferay.portal.kernel.repository.model.Folder; import com.liferay.portal.kernel.util.ArrayUtil; import com.liferay.subscription.service.SubscriptionLocalServiceUtil; import java.util.ArrayList; import java.util.List; /** * @author Adolfo PĂ©rez */ public class DLSubscriptionUtil { public static boolean isSubscribedToFileEntryType( long companyId, long groupId, long userId, long fileEntryTypeId) { if (fileEntryTypeId == DLFileEntryTypeConstants.FILE_ENTRY_TYPE_ID_BASIC_DOCUMENT) { fileEntryTypeId = groupId; } return SubscriptionLocalServiceUtil.isSubscribed( companyId, userId, DLFileEntryType.class.getName(), fileEntryTypeId); } public static boolean isSubscribedToFolder( long companyId, long groupId, long userId, long folderId) throws PortalException { return isSubscribedToFolder(companyId, groupId, userId, folderId, true); } public static boolean isSubscribedToFolder( long companyId, long groupId, long userId, long folderId, boolean recursive) throws PortalException { List<Long> ancestorFolderIds = new ArrayList<>(); if (folderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) { Folder folder = DLAppLocalServiceUtil.getFolder(folderId); ancestorFolderIds.add(folderId); if (recursive) { ancestorFolderIds.addAll(folder.getAncestorFolderIds()); ancestorFolderIds.add(groupId); } } else { ancestorFolderIds.add(groupId); } long[] folderIdsArray = ArrayUtil.toLongArray(ancestorFolderIds); return SubscriptionLocalServiceUtil.isSubscribed( companyId, userId, DLFolder.class.getName(), folderIdsArray); } }