001
014
015 package com.liferay.portlet.messageboards.model.impl;
016
017 import com.liferay.portal.kernel.exception.PortalException;
018 import com.liferay.portal.kernel.exception.SystemException;
019 import com.liferay.portlet.messageboards.model.MBCategory;
020 import com.liferay.portlet.messageboards.model.MBCategoryConstants;
021 import com.liferay.portlet.messageboards.service.MBCategoryLocalServiceUtil;
022
023 import java.util.ArrayList;
024 import java.util.List;
025
026
029 public class MBCategoryImpl extends MBCategoryBaseImpl {
030
031 public MBCategoryImpl() {
032 }
033
034 @Override
035 public List<Long> getAncestorCategoryIds()
036 throws PortalException, SystemException {
037
038 List<Long> ancestorCategoryIds = new ArrayList<Long>();
039
040 MBCategory category = this;
041
042 while (true) {
043 if (!category.isRoot()) {
044 category = MBCategoryLocalServiceUtil.getCategory(
045 category.getParentCategoryId());
046
047 ancestorCategoryIds.add(category.getCategoryId());
048 }
049 else {
050 break;
051 }
052 }
053
054 return ancestorCategoryIds;
055 }
056
057 @Override
058 public List<MBCategory> getAncestors()
059 throws PortalException, SystemException {
060
061 List<MBCategory> ancestors = new ArrayList<MBCategory>();
062
063 MBCategory category = this;
064
065 while (true) {
066 if (!category.isRoot()) {
067 category = MBCategoryLocalServiceUtil.getCategory(
068 category.getParentCategoryId());
069
070 ancestors.add(category);
071 }
072 else {
073 break;
074 }
075 }
076
077 return ancestors;
078 }
079
080 @Override
081 public boolean isRoot() {
082 if (getParentCategoryId() ==
083 MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID) {
084
085 return true;
086 }
087 else {
088 return false;
089 }
090 }
091
092 }