001
014
015 package com.liferay.portlet.wiki.model.impl;
016
017 import com.liferay.portal.kernel.dao.orm.QueryUtil;
018 import com.liferay.portal.kernel.exception.PortalException;
019 import com.liferay.portal.kernel.repository.model.FileEntry;
020 import com.liferay.portal.kernel.repository.model.Folder;
021 import com.liferay.portal.model.Repository;
022 import com.liferay.portal.portletfilerepository.PortletFileRepositoryUtil;
023 import com.liferay.portal.service.ServiceContext;
024 import com.liferay.portal.util.PortletKeys;
025 import com.liferay.portlet.documentlibrary.model.DLFolderConstants;
026 import com.liferay.portlet.wiki.model.WikiPage;
027 import com.liferay.portlet.wiki.service.WikiPageLocalServiceUtil;
028
029 import java.util.ArrayList;
030 import java.util.List;
031
032
035 public class WikiNodeImpl extends WikiNodeBaseImpl {
036
037 @Override
038 public Folder addAttachmentsFolder() throws PortalException {
039 if (_attachmentsFolderId !=
040 DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
041
042 return PortletFileRepositoryUtil.getPortletFolder(
043 _attachmentsFolderId);
044 }
045
046 ServiceContext serviceContext = new ServiceContext();
047
048 serviceContext.setAddGroupPermissions(true);
049 serviceContext.setAddGuestPermissions(true);
050
051 Repository repository = PortletFileRepositoryUtil.addPortletRepository(
052 getGroupId(), PortletKeys.WIKI, serviceContext);
053
054 Folder folder = PortletFileRepositoryUtil.addPortletFolder(
055 getUserId(), repository.getRepositoryId(),
056 DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
057 String.valueOf(getNodeId()), serviceContext);
058
059 _attachmentsFolderId = folder.getFolderId();
060
061 return folder;
062 }
063
064 @Override
065 public long getAttachmentsFolderId() {
066 if (_attachmentsFolderId !=
067 DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
068
069 return _attachmentsFolderId;
070 }
071
072 ServiceContext serviceContext = new ServiceContext();
073
074 serviceContext.setAddGroupPermissions(true);
075 serviceContext.setAddGuestPermissions(true);
076
077 Repository repository =
078 PortletFileRepositoryUtil.fetchPortletRepository(
079 getGroupId(), PortletKeys.WIKI);
080
081 if (repository == null) {
082 return DLFolderConstants.DEFAULT_PARENT_FOLDER_ID;
083 }
084
085 try {
086 Folder folder = PortletFileRepositoryUtil.getPortletFolder(
087 repository.getRepositoryId(),
088 DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
089 String.valueOf(getNodeId()));
090
091 _attachmentsFolderId = folder.getFolderId();
092 }
093 catch (Exception e) {
094 }
095
096 return _attachmentsFolderId;
097 }
098
099 @Override
100 public List<FileEntry> getDeletedAttachmentsFiles() {
101 List<WikiPage> wikiPages = WikiPageLocalServiceUtil.getPages(
102 getNodeId(), true, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
103
104 List<FileEntry> fileEntries = new ArrayList<FileEntry>();
105
106 for (WikiPage wikiPage : wikiPages) {
107 fileEntries.addAll(wikiPage.getDeletedAttachmentsFileEntries());
108 }
109
110 return fileEntries;
111 }
112
113 private long _attachmentsFolderId;
114
115 }