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.trash.model.TrashEntry;
028 import com.liferay.portlet.trash.service.TrashEntryLocalServiceUtil;
029 import com.liferay.portlet.wiki.model.WikiPage;
030 import com.liferay.portlet.wiki.service.WikiPageLocalServiceUtil;
031
032 import java.util.ArrayList;
033 import java.util.List;
034
035
038 public class WikiNodeImpl extends WikiNodeBaseImpl {
039
040 public WikiNodeImpl() {
041 }
042
043 @Override
044 public Folder addAttachmentsFolder()
045 throws PortalException, SystemException {
046
047 if (_attachmentsFolderId !=
048 DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
049
050 return PortletFileRepositoryUtil.getPortletFolder(
051 _attachmentsFolderId);
052 }
053
054 ServiceContext serviceContext = new ServiceContext();
055
056 serviceContext.setAddGroupPermissions(true);
057 serviceContext.setAddGuestPermissions(true);
058
059 Repository repository = PortletFileRepositoryUtil.addPortletRepository(
060 getGroupId(), PortletKeys.WIKI, serviceContext);
061
062 Folder folder = PortletFileRepositoryUtil.addPortletFolder(
063 getUserId(), repository.getRepositoryId(),
064 DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
065 String.valueOf(getNodeId()), serviceContext);
066
067 _attachmentsFolderId = folder.getFolderId();
068
069 return folder;
070 }
071
072 @Override
073 public long getAttachmentsFolderId() throws SystemException {
074 if (_attachmentsFolderId !=
075 DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
076
077 return _attachmentsFolderId;
078 }
079
080 ServiceContext serviceContext = new ServiceContext();
081
082 serviceContext.setAddGroupPermissions(true);
083 serviceContext.setAddGuestPermissions(true);
084
085 Repository repository =
086 PortletFileRepositoryUtil.fetchPortletRepository(
087 getGroupId(), PortletKeys.WIKI);
088
089 if (repository == null) {
090 return DLFolderConstants.DEFAULT_PARENT_FOLDER_ID;
091 }
092
093 try {
094 Folder folder = PortletFileRepositoryUtil.getPortletFolder(
095 getUserId(), repository.getRepositoryId(),
096 DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
097 String.valueOf(getNodeId()), serviceContext);
098
099 _attachmentsFolderId = folder.getFolderId();
100 }
101 catch (Exception e) {
102 }
103
104 return _attachmentsFolderId;
105 }
106
107 @Override
108 public List<FileEntry> getDeletedAttachmentsFiles() throws SystemException {
109 List<WikiPage> wikiPages = WikiPageLocalServiceUtil.getPages(
110 getNodeId(), true, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
111
112 List<FileEntry> fileEntries = new ArrayList<FileEntry>();
113
114 for (WikiPage wikiPage : wikiPages) {
115 fileEntries.addAll(wikiPage.getDeletedAttachmentsFileEntries());
116 }
117
118 return fileEntries;
119 }
120
121 @Override
122 public boolean isInTrashExplicitly() throws SystemException {
123 if (!isInTrash()) {
124 return false;
125 }
126
127 TrashEntry trashEntry = TrashEntryLocalServiceUtil.fetchEntry(
128 getModelClassName(), getTrashEntryClassPK());
129
130 if (trashEntry != null) {
131 return true;
132 }
133
134 return false;
135 }
136
137 private long _attachmentsFolderId;
138
139 }