1
22
23 package com.liferay.portal.model.impl;
24
25 import com.liferay.portal.PortalException;
26 import com.liferay.portal.SystemException;
27 import com.liferay.portal.model.Address;
28 import com.liferay.portal.model.Group;
29 import com.liferay.portal.model.Organization;
30 import com.liferay.portal.model.OrganizationConstants;
31 import com.liferay.portal.service.AddressLocalServiceUtil;
32 import com.liferay.portal.service.GroupLocalServiceUtil;
33
34 import java.util.List;
35
36 import org.apache.commons.logging.Log;
37 import org.apache.commons.logging.LogFactory;
38
39
45 public class OrganizationImpl
46 extends OrganizationModelImpl implements Organization {
47
48 public OrganizationImpl() {
49 }
50
51 public boolean isRoot() {
52 if (getParentOrganizationId() ==
53 OrganizationConstants.DEFAULT_PARENT_ORGANIZATION_ID) {
54
55 return true;
56 }
57 else {
58 return false;
59 }
60 }
61
62 public boolean isRegular() {
63 return !isLocation();
64 }
65
66 public int getType() {
67 if (isLocation()) {
68 return OrganizationConstants.TYPE_LOCATION;
69 }
70 else {
71 return OrganizationConstants.TYPE_REGULAR;
72 }
73 }
74
75 public int getType(boolean location) {
76 int type = OrganizationConstants.TYPE_REGULAR;
77
78 if (location) {
79 type = OrganizationConstants.TYPE_LOCATION;
80 }
81
82 return type;
83 }
84
85 public String getTypeLabel() {
86 return getTypeLabel(getType());
87 }
88
89 public String getTypeLabel(int type) {
90 if (type == OrganizationConstants.TYPE_LOCATION) {
91 return OrganizationConstants.TYPE_LOCATION_LABEL;
92 }
93 else {
94 return OrganizationConstants.TYPE_REGULAR_LABEL;
95 }
96 }
97
98 public Group getGroup() {
99 if (getOrganizationId() > 0) {
100 try {
101 return GroupLocalServiceUtil.getOrganizationGroup(
102 getCompanyId(), getOrganizationId());
103 }
104 catch (Exception e) {
105 _log.error(e);
106 }
107 }
108
109 return new GroupImpl();
110 }
111
112 public Address getAddress() {
113 Address address = null;
114
115 try {
116 List<Address> addresses = getAddresses();
117
118 if (addresses.size() > 0) {
119 address = addresses.get(0);
120 }
121 }
122 catch (Exception e) {
123 _log.error(e);
124 }
125
126 if (address == null) {
127 address = new AddressImpl();
128 }
129
130 return address;
131 }
132
133 public List<Address> getAddresses()
134 throws PortalException, SystemException {
135
136 return AddressLocalServiceUtil.getAddresses(
137 getCompanyId(), Organization.class.getName(), getOrganizationId());
138 }
139
140 private static Log _log = LogFactory.getLog(Organization.class);
141
142 }