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