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.portal.model.impl;
022:
023: import com.liferay.portal.PortalException;
024: import com.liferay.portal.SystemException;
025: import com.liferay.portal.model.Address;
026: import com.liferay.portal.model.Group;
027: import com.liferay.portal.model.Organization;
028: import com.liferay.portal.service.AddressLocalServiceUtil;
029: import com.liferay.portal.service.GroupLocalServiceUtil;
030:
031: import java.util.List;
032:
033: import org.apache.commons.logging.Log;
034: import org.apache.commons.logging.LogFactory;
035:
036: /**
037: * <a href="OrganizationImpl.java.html"><b><i>View Source</i></b></a>
038: *
039: * @author Brian Wing Shun Chan
040: *
041: */
042: public class OrganizationImpl extends OrganizationModelImpl implements
043: Organization {
044:
045: public static final int DEFAULT_PARENT_ORGANIZATION_ID = 0;
046:
047: public static final int ANY_PARENT_ORGANIZATION_ID = -1;
048:
049: public static final int ANY_TYPE = -1;
050:
051: public static final int TYPE_REGULAR = 1;
052:
053: public static final String TYPE_REGULAR_LABEL = "regular";
054:
055: public static final int TYPE_LOCATION = 2;
056:
057: public static final String TYPE_LOCATION_LABEL = "location";
058:
059: public static int getType(boolean location) {
060: int type = OrganizationImpl.TYPE_REGULAR;
061:
062: if (location) {
063: type = OrganizationImpl.TYPE_LOCATION;
064: }
065:
066: return type;
067: }
068:
069: public static String getTypeLabel(int type) {
070: if (type == TYPE_LOCATION) {
071: return TYPE_LOCATION_LABEL;
072: } else {
073: return TYPE_REGULAR_LABEL;
074: }
075: }
076:
077: public OrganizationImpl() {
078: }
079:
080: public boolean isRoot() {
081: if (getParentOrganizationId() == DEFAULT_PARENT_ORGANIZATION_ID) {
082: return true;
083: } else {
084: return false;
085: }
086: }
087:
088: public boolean isRegular() {
089: return !isLocation();
090: }
091:
092: public int getType() {
093: if (isLocation()) {
094: return TYPE_LOCATION;
095: } else {
096: return TYPE_REGULAR;
097: }
098: }
099:
100: public String getTypeLabel() {
101: return getTypeLabel(getType());
102: }
103:
104: public Group getGroup() {
105: if (getOrganizationId() > 0) {
106: try {
107: return GroupLocalServiceUtil.getOrganizationGroup(
108: getCompanyId(), getOrganizationId());
109: } catch (Exception e) {
110: _log.error(e);
111: }
112: }
113:
114: return new GroupImpl();
115: }
116:
117: public Address getAddress() {
118: Address address = null;
119:
120: try {
121: List addresses = getAddresses();
122:
123: if (addresses.size() > 0) {
124: address = (Address) addresses.get(0);
125: }
126: } catch (Exception e) {
127: _log.error(e);
128: }
129:
130: if (address == null) {
131: address = new AddressImpl();
132: }
133:
134: return address;
135: }
136:
137: public List getAddresses() throws PortalException, SystemException {
138: return AddressLocalServiceUtil.getAddresses(getCompanyId(),
139: Organization.class.getName(), getOrganizationId());
140: }
141:
142: private static Log _log = LogFactory.getLog(Organization.class);
143:
144: }
|