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