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