1
14
15 package com.liferay.portlet.messageboards.model.impl;
16
17 import com.liferay.portal.PortalException;
18 import com.liferay.portal.SystemException;
19 import com.liferay.portal.model.CompanyConstants;
20 import com.liferay.portlet.messageboards.model.MBCategory;
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 static long DEFAULT_PARENT_CATEGORY_ID = 0;
34
35 public MBCategoryImpl() {
36 }
37
38 public List<Long> getAncestorCategoryIds()
39 throws PortalException, SystemException {
40
41 List<Long> ancestorCategoryIds = new ArrayList<Long>();
42
43 MBCategory category = this;
44
45 while (true) {
46 if (!category.isRoot()) {
47 category = MBCategoryLocalServiceUtil.getCategory(
48 category.getParentCategoryId());
49
50 ancestorCategoryIds.add(category.getCategoryId());
51 }
52 else {
53 break;
54 }
55 }
56
57 return ancestorCategoryIds;
58 }
59
60 public List<MBCategory> getAncestors()
61 throws PortalException, SystemException {
62
63 List<MBCategory> ancestors = new ArrayList<MBCategory>();
64
65 MBCategory category = this;
66
67 while (true) {
68 if (!category.isRoot()) {
69 category = MBCategoryLocalServiceUtil.getCategory(
70 category.getParentCategoryId());
71
72 ancestors.add(category);
73 }
74 else {
75 break;
76 }
77 }
78
79 return ancestors;
80 }
81
82 public boolean isDiscussion() {
83 if (getCategoryId() == CompanyConstants.SYSTEM) {
84 return true;
85 }
86 else {
87 return false;
88 }
89 }
90
91 public boolean isRoot() {
92 if (getParentCategoryId() == DEFAULT_PARENT_CATEGORY_ID) {
93 return true;
94 }
95 else {
96 return false;
97 }
98 }
99
100 }