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 @Override
031 public List<Long> getAncestorCategoryIds() throws PortalException {
032 List<Long> ancestorCategoryIds = new ArrayList<>();
033
034 MBCategory category = this;
035
036 while (!category.isRoot()) {
037 category = MBCategoryLocalServiceUtil.getCategory(
038 category.getParentCategoryId());
039
040 ancestorCategoryIds.add(category.getCategoryId());
041 }
042
043 return ancestorCategoryIds;
044 }
045
046 @Override
047 public List<MBCategory> getAncestors() throws PortalException {
048 List<MBCategory> ancestors = new ArrayList<>();
049
050 MBCategory category = this;
051
052 while (!category.isRoot()) {
053 category = category.getParentCategory();
054
055 ancestors.add(category);
056 }
057
058 return ancestors;
059 }
060
061 @Override
062 public MBCategory getParentCategory() throws PortalException {
063 long parentCategoryId = getParentCategoryId();
064
065 if ((parentCategoryId ==
066 MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID) ||
067 (parentCategoryId == MBCategoryConstants.DISCUSSION_CATEGORY_ID)) {
068
069 return null;
070 }
071
072 return MBCategoryLocalServiceUtil.getCategory(getParentCategoryId());
073 }
074
075 @Override
076 public boolean isRoot() {
077 if (getParentCategoryId() ==
078 MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID) {
079
080 return true;
081 }
082
083 return false;
084 }
085
086 }