001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portlet.messageboards.model.impl;
022:
023: import com.liferay.portal.PortalException;
024: import com.liferay.portal.SystemException;
025: import com.liferay.portal.model.impl.CompanyImpl;
026: import com.liferay.portal.util.PortalUtil;
027: import com.liferay.portlet.messageboards.model.MBCategory;
028: import com.liferay.portlet.messageboards.service.MBCategoryLocalServiceUtil;
029:
030: import java.util.ArrayList;
031: import java.util.List;
032:
033: /**
034: * <a href="MBCategoryImpl.java.html"><b><i>View Source</i></b></a>
035: *
036: * @author Brian Wing Shun Chan
037: *
038: */
039: public class MBCategoryImpl extends MBCategoryModelImpl implements
040: MBCategory {
041:
042: public static long DEFAULT_PARENT_CATEGORY_ID = 0;
043:
044: public MBCategoryImpl() {
045: }
046:
047: public List getAncestorCategoryIds() throws PortalException,
048: SystemException {
049:
050: List ancestorCategoryIds = new ArrayList();
051:
052: MBCategory category = this ;
053:
054: while (true) {
055: if (!category.isRoot()) {
056: category = MBCategoryLocalServiceUtil
057: .getCategory(category.getParentCategoryId());
058:
059: ancestorCategoryIds.add(new Long(category
060: .getCategoryId()));
061: } else {
062: break;
063: }
064: }
065:
066: return ancestorCategoryIds;
067: }
068:
069: public List getAncestors() throws PortalException, SystemException {
070: List ancestors = new ArrayList();
071:
072: MBCategory category = this ;
073:
074: while (true) {
075: if (!category.isRoot()) {
076: category = MBCategoryLocalServiceUtil
077: .getCategory(category.getParentCategoryId());
078:
079: ancestors.add(category);
080: } else {
081: break;
082: }
083: }
084:
085: return ancestors;
086: }
087:
088: public String getUserUuid() throws SystemException {
089: return PortalUtil.getUserValue(getUserId(), "uuid", _userUuid);
090: }
091:
092: public void setUserUuid(String userUuid) {
093: _userUuid = userUuid;
094: }
095:
096: public boolean isRoot() {
097: if (getParentCategoryId() == DEFAULT_PARENT_CATEGORY_ID) {
098: return true;
099: } else {
100: return false;
101: }
102: }
103:
104: public boolean isDiscussion() {
105: if (getCategoryId() == CompanyImpl.SYSTEM) {
106: return true;
107: } else {
108: return false;
109: }
110: }
111:
112: private String _userUuid;
113:
114: }
|