1
14
15 package com.liferay.portlet.messageboards.model.impl;
16
17 import com.liferay.portal.kernel.exception.PortalException;
18 import com.liferay.portal.kernel.exception.SystemException;
19 import com.liferay.portlet.messageboards.model.MBCategory;
20 import com.liferay.portlet.messageboards.model.MBCategoryConstants;
21 import com.liferay.portlet.messageboards.service.MBCategoryLocalServiceUtil;
22
23 import java.util.ArrayList;
24 import java.util.List;
25
26
31 public class MBCategoryImpl extends MBCategoryModelImpl implements MBCategory {
32
33 public MBCategoryImpl() {
34 }
35
36 public List<Long> getAncestorCategoryIds()
37 throws PortalException, SystemException {
38
39 List<Long> ancestorCategoryIds = new ArrayList<Long>();
40
41 MBCategory category = this;
42
43 while (true) {
44 if (!category.isRoot()) {
45 category = MBCategoryLocalServiceUtil.getCategory(
46 category.getParentCategoryId());
47
48 ancestorCategoryIds.add(category.getCategoryId());
49 }
50 else {
51 break;
52 }
53 }
54
55 return ancestorCategoryIds;
56 }
57
58 public List<MBCategory> getAncestors()
59 throws PortalException, SystemException {
60
61 List<MBCategory> ancestors = new ArrayList<MBCategory>();
62
63 MBCategory category = this;
64
65 while (true) {
66 if (!category.isRoot()) {
67 category = MBCategoryLocalServiceUtil.getCategory(
68 category.getParentCategoryId());
69
70 ancestors.add(category);
71 }
72 else {
73 break;
74 }
75 }
76
77 return ancestors;
78 }
79
80 public boolean isRoot() {
81 if (getParentCategoryId() ==
82 MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID) {
83
84 return true;
85 }
86 else {
87 return false;
88 }
89 }
90
91 }