
com.liferay.wiki.model.impl.WikiNodeImpl Maven / Gradle / Ivy
/**
* SPDX-FileCopyrightText: (c) 2000 Liferay, Inc. https://liferay.com
* SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
*/
package com.liferay.wiki.model.impl;
import com.liferay.document.library.kernel.model.DLFolderConstants;
import com.liferay.portal.kernel.dao.orm.QueryUtil;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.model.Repository;
import com.liferay.portal.kernel.portletfilerepository.PortletFileRepositoryUtil;
import com.liferay.portal.kernel.repository.model.FileEntry;
import com.liferay.portal.kernel.repository.model.Folder;
import com.liferay.portal.kernel.service.ServiceContext;
import com.liferay.wiki.constants.WikiConstants;
import com.liferay.wiki.model.WikiPage;
import com.liferay.wiki.service.WikiPageLocalServiceUtil;
import java.util.ArrayList;
import java.util.List;
/**
* @author Brian Wing Shun Chan
*/
public class WikiNodeImpl extends WikiNodeBaseImpl {
@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(), WikiConstants.SERVICE_NAME, serviceContext);
Folder folder = PortletFileRepositoryUtil.addPortletFolder(
getUserId(), repository.getRepositoryId(),
DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
String.valueOf(getNodeId()), serviceContext);
_attachmentsFolderId = folder.getFolderId();
return folder;
}
@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(), WikiConstants.SERVICE_NAME);
if (repository == null) {
return DLFolderConstants.DEFAULT_PARENT_FOLDER_ID;
}
try {
Folder folder = PortletFileRepositoryUtil.getPortletFolder(
repository.getRepositoryId(),
DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
String.valueOf(getNodeId()));
_attachmentsFolderId = folder.getFolderId();
}
catch (Exception exception) {
if (_log.isDebugEnabled()) {
_log.debug(exception);
}
}
return _attachmentsFolderId;
}
@Override
public List getDeletedAttachmentsFiles() throws PortalException {
List wikiPages = WikiPageLocalServiceUtil.getPages(
getNodeId(), true, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
List fileEntries = new ArrayList<>();
for (WikiPage wikiPage : wikiPages) {
fileEntries.addAll(wikiPage.getDeletedAttachmentsFileEntries());
}
return fileEntries;
}
private static final Log _log = LogFactoryUtil.getLog(WikiNodeImpl.class);
private long _attachmentsFolderId;
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy