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