1
19
20 package com.liferay.portal.model.impl;
21
22 import com.liferay.portal.PortalException;
23 import com.liferay.portal.SystemException;
24 import com.liferay.portal.kernel.log.Log;
25 import com.liferay.portal.kernel.log.LogFactoryUtil;
26 import com.liferay.portal.model.Address;
27 import com.liferay.portal.model.Group;
28 import com.liferay.portal.model.Organization;
29 import com.liferay.portal.model.OrganizationConstants;
30 import com.liferay.portal.service.AddressLocalServiceUtil;
31 import com.liferay.portal.service.GroupLocalServiceUtil;
32 import com.liferay.portal.service.OrganizationLocalServiceUtil;
33
34 import java.util.List;
35
36
42 public class OrganizationImpl
43 extends OrganizationModelImpl implements Organization {
44
45 public OrganizationImpl() {
46 }
47
48 public Address getAddress() {
49 Address address = null;
50
51 try {
52 List<Address> addresses = getAddresses();
53
54 if (addresses.size() > 0) {
55 address = addresses.get(0);
56 }
57 }
58 catch (Exception e) {
59 _log.error(e);
60 }
61
62 if (address == null) {
63 address = new AddressImpl();
64 }
65
66 return address;
67 }
68
69 public List<Address> getAddresses() throws SystemException {
70 return AddressLocalServiceUtil.getAddresses(
71 getCompanyId(), Organization.class.getName(), getOrganizationId());
72 }
73
74 public Group getGroup() {
75 if (getOrganizationId() > 0) {
76 try {
77 return GroupLocalServiceUtil.getOrganizationGroup(
78 getCompanyId(), getOrganizationId());
79 }
80 catch (Exception e) {
81 _log.error(e);
82 }
83 }
84
85 return new GroupImpl();
86 }
87
88 public Organization getParentOrganization()
89 throws PortalException, SystemException {
90
91 if (getParentOrganizationId() ==
92 OrganizationConstants.DEFAULT_PARENT_ORGANIZATION_ID) {
93
94 return null;
95 }
96
97 return OrganizationLocalServiceUtil.getOrganization(
98 getParentOrganizationId());
99 }
100
101 public int getPrivateLayoutsPageCount() {
102 try {
103 Group group = getGroup();
104
105 if (group == null) {
106 return 0;
107 }
108 else {
109 return group.getPrivateLayoutsPageCount();
110 }
111 }
112 catch (Exception e) {
113 _log.error(e);
114 }
115
116 return 0;
117 }
118
119 public int getPublicLayoutsPageCount() {
120 try {
121 Group group = getGroup();
122
123 if (group == null) {
124 return 0;
125 }
126 else {
127 return group.getPublicLayoutsPageCount();
128 }
129 }
130 catch (Exception e) {
131 _log.error(e);
132 }
133
134 return 0;
135 }
136
137 public int getType() {
138 if (isLocation()) {
139 return OrganizationConstants.TYPE_LOCATION;
140 }
141 else {
142 return OrganizationConstants.TYPE_REGULAR;
143 }
144 }
145
146 public int getType(boolean location) {
147 int type = OrganizationConstants.TYPE_REGULAR;
148
149 if (location) {
150 type = OrganizationConstants.TYPE_LOCATION;
151 }
152
153 return type;
154 }
155
156 public String getTypeLabel() {
157 return getTypeLabel(getType());
158 }
159
160 public String getTypeLabel(int type) {
161 if (type == OrganizationConstants.TYPE_LOCATION) {
162 return OrganizationConstants.TYPE_LOCATION_LABEL;
163 }
164 else {
165 return OrganizationConstants.TYPE_REGULAR_LABEL;
166 }
167 }
168
169 public boolean hasPrivateLayouts() {
170 if (getPrivateLayoutsPageCount() > 0) {
171 return true;
172 }
173 else {
174 return false;
175 }
176 }
177
178 public boolean hasPublicLayouts() {
179 if (getPublicLayoutsPageCount() > 0) {
180 return true;
181 }
182 else {
183 return false;
184 }
185 }
186
187 public boolean isRegular() {
188 return !isLocation();
189 }
190
191 public boolean isRoot() {
192 if (getParentOrganizationId() ==
193 OrganizationConstants.DEFAULT_PARENT_ORGANIZATION_ID) {
194
195 return true;
196 }
197 else {
198 return false;
199 }
200 }
201
202 private static Log _log = LogFactoryUtil.getLog(Organization.class);
203
204 }