001
014
015 package com.liferay.portlet.journal.model.impl;
016
017 import com.liferay.portal.kernel.exception.PortalException;
018 import com.liferay.portal.kernel.exception.SystemException;
019 import com.liferay.portlet.journal.NoSuchFolderException;
020 import com.liferay.portlet.journal.model.JournalFolder;
021 import com.liferay.portlet.journal.model.JournalFolderConstants;
022 import com.liferay.portlet.journal.service.JournalFolderLocalServiceUtil;
023 import com.liferay.portlet.trash.model.TrashEntry;
024 import com.liferay.portlet.trash.service.TrashEntryLocalServiceUtil;
025
026 import java.util.ArrayList;
027 import java.util.List;
028
029
032 public class JournalFolderImpl extends JournalFolderBaseImpl {
033
034 public JournalFolderImpl() {
035 }
036
037 @Override
038 public List<Long> getAncestorFolderIds()
039 throws PortalException, SystemException {
040
041 List<Long> ancestorFolderIds = new ArrayList<Long>();
042
043 JournalFolder folder = this;
044
045 while (!folder.isRoot()) {
046 try {
047 folder = folder.getParentFolder();
048
049 ancestorFolderIds.add(folder.getFolderId());
050 }
051 catch (NoSuchFolderException nsfe) {
052 if (folder.isInTrash()) {
053 break;
054 }
055
056 throw nsfe;
057 }
058 }
059
060 return ancestorFolderIds;
061 }
062
063 @Override
064 public List<JournalFolder> getAncestors()
065 throws PortalException, SystemException {
066
067 List<JournalFolder> ancestors = new ArrayList<JournalFolder>();
068
069 JournalFolder folder = this;
070
071 while (!folder.isRoot()) {
072 folder = folder.getParentFolder();
073
074 ancestors.add(folder);
075 }
076
077 return ancestors;
078 }
079
080 @Override
081 public JournalFolder getParentFolder()
082 throws PortalException, SystemException {
083
084 if (getParentFolderId() ==
085 JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
086
087 return null;
088 }
089
090 return JournalFolderLocalServiceUtil.getFolder(getParentFolderId());
091 }
092
093 @Override
094 public boolean isInTrashExplicitly() throws SystemException {
095 if (!isInTrash()) {
096 return false;
097 }
098
099 TrashEntry trashEntry = TrashEntryLocalServiceUtil.fetchEntry(
100 getModelClassName(), getTrashEntryClassPK());
101
102 if (trashEntry != null) {
103 return true;
104 }
105
106 return false;
107 }
108
109 @Override
110 public boolean isRoot() {
111 if (getParentFolderId() ==
112 JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
113
114 return true;
115 }
116
117 return false;
118 }
119
120 }