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