1 package org.kuali.rice.kim.impl.group;
2
3 import org.eclipse.persistence.annotations.Convert;
4 import org.eclipse.persistence.annotations.Customizer;
5 import org.joda.time.DateTime;
6 import org.kuali.rice.kim.api.KimConstants;
7 import org.kuali.rice.kim.api.group.Group;
8 import org.kuali.rice.kim.api.identity.Person;
9 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
10 import org.kuali.rice.kim.framework.group.GroupEbo;
11 import org.kuali.rice.kim.impl.common.attribute.KimAttributeDataBo;
12 import org.kuali.rice.kim.impl.type.KimTypeBo;
13 import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
14 import org.kuali.rice.krad.data.provider.jpa.eclipselink.EclipseLinkSequenceCustomizer;
15
16 import org.kuali.rice.krad.data.platform.generator.Sequence;
17
18 import javax.persistence.CascadeType;
19 import javax.persistence.Column;
20 import javax.persistence.Entity;
21 import javax.persistence.FetchType;
22 import javax.persistence.Id;
23 import javax.persistence.JoinColumn;
24 import javax.persistence.MappedSuperclass;
25 import javax.persistence.OneToMany;
26 import javax.persistence.Table;
27 import javax.persistence.Transient;
28 import java.util.ArrayList;
29 import java.util.List;
30 import java.util.Map;
31
32 @MappedSuperclass
33 public abstract class GroupBase extends PersistableBusinessObjectBase implements GroupEbo {
34 private static final long serialVersionUID = 1L;
35
36
37
38
39 @Column(name="GRP_NM")
40 private String name;
41
42 @Column(name="GRP_DESC",length=4000)
43 private String description;
44
45 @Column(name="ACTV_IND")
46 @javax.persistence.Convert(converter=org.kuali.rice.krad.data.converters.BooleanYNConverter.class)
47 private boolean active;
48
49 @Column(name="KIM_TYP_ID")
50 private String kimTypeId;
51
52 @Column(name="NMSPC_CD")
53 private String namespaceCode;
54
55
56
57
58
59
60
61
62
63 @Transient
64 private List<Person> memberPersons;
65
66 @Transient
67 private List<Group> memberGroups;
68
69 @Transient
70 protected Map<String,String> attributes;
71
72
73 @Override
74 public Map<String,String> getAttributes() {
75 return attributes;
76 }
77
78 public void setAttributes(Map<String, String> attributes) {
79 this.attributes = attributes;
80 }
81
82
83
84
85
86
87
88
89
90
91 @Override
92 public String getName() {
93 return name;
94 }
95
96 public void setName(String name) {
97 this.name = name;
98 }
99
100 @Override
101 public String getDescription() {
102 return description;
103 }
104
105 public void setDescription(String description) {
106 this.description = description;
107 }
108
109 @Override
110 public boolean isActive() {
111 return active;
112 }
113
114 public void setActive(boolean active) {
115 this.active = active;
116 }
117
118 @Override
119 public String getKimTypeId() {
120 return kimTypeId;
121 }
122
123 public void setKimTypeId(String kimTypeId) {
124 this.kimTypeId = kimTypeId;
125 }
126
127 @Override
128 public String getNamespaceCode() {
129 return namespaceCode;
130 }
131
132 public void setNamespaceCode(String namespaceCode) {
133 this.namespaceCode = namespaceCode;
134 }
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153 /* */
154
155
156
157 /*
158 public static Group to(GroupBase bo) {
159 if (bo == null) {
160 return null;
161 }
162
163 return Group.Builder.create(bo).build();
164 }
165
166 */
167
168
169
170 /*
171 public static GroupBase from(Group im) {
172 if (im == null) {
173 return null;
174 }
175
176 GroupBase bo = new GroupBase();
177 bo.setId(im.getId());
178 bo.setNamespaceCode(im.getNamespaceCode());
179 bo.setName(im.getName());
180 bo.setDescription(im.getDescription());
181 bo.setActive(im.isActive());
182 bo.setKimTypeId(im.getKimTypeId());
183 bo.setAttributes(im.getAttributes());
184 bo.setVersionNumber(im.getVersionNumber());
185 bo.setObjectId(im.getObjectId());
186
187 return bo;
188 }
189
190
191 public String getGroupAttributeValueById(String attributeId) {
192 for (GroupAttributeBo gad : getAttributeDetails()) {
193 if (gad.getKimAttributeId().equals(attributeId.trim())) {
194 return gad.getAttributeValue();
195 }
196 }
197 return null;
198 }
199
200 private void splitMembersToTypes() {
201 memberPersons = new ArrayList<Person>();
202 memberGroups = new ArrayList<Group>();
203 if (getMembers() != null) {
204 for ( GroupMemberBo groupMember : getMembers() ) {
205 if (groupMember.isActive(new DateTime())) {
206 if ( KimConstants.KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE.equals(groupMember.getType())) {
207 Person tempPerson = KimApiServiceLocator.getPersonService().getPerson(groupMember.getMemberId());
208 if (tempPerson != null && tempPerson.isActive()) {
209 memberPersons.add(tempPerson);
210 }
211 } else if (KimConstants.KimGroupMemberTypes.GROUP_MEMBER_TYPE.equals(groupMember.getType())) {
212 Group tempGroup = KimApiServiceLocator.getGroupService().getGroup(groupMember.getMemberId());
213 if (tempGroup != null && tempGroup.isActive()) {
214 memberGroups.add(tempGroup);
215 }
216 }
217 }
218 }
219 }
220 }
221
222 public List<Person> getMemberPersons() {
223 if (this.memberPersons == null) {
224 splitMembersToTypes();
225 }
226 return this.memberPersons;
227 }
228
229 public void setMemberPersons(List<Person> memberPersons) {
230 this.memberPersons = memberPersons;
231 }
232
233 public List<String> getMemberPrincipalIds() {
234 List<String> principalIds = new ArrayList<String>();
235 if (getMembers() != null) {
236 for ( GroupMemberBo groupMember : getMembers() ) {
237 if (groupMember.isActive(new DateTime())) {
238 if ( KimConstants.KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE.equals(groupMember.getType())) {
239 principalIds.add(groupMember.getMemberId());
240 }
241 }
242 }
243 }
244 return principalIds;
245 }
246
247 public List<String> getMemberGroupIds() {
248 List<String> principalIds = new ArrayList<String>();
249 if (getMembers() != null) {
250 for ( GroupMemberBo groupMember : getMembers() ) {
251 if (groupMember.isActive(new DateTime())) {
252 if ( KimConstants.KimGroupMemberTypes.GROUP_MEMBER_TYPE.equals(groupMember.getType())) {
253 principalIds.add(groupMember.getMemberId());
254 }
255 }
256 }
257 }
258 return principalIds;
259 }
260
261 public List<Group> getMemberGroups() {
262 if (this.memberGroups == null) {
263 splitMembersToTypes();
264 }
265 return this.memberGroups;
266 }
267
268 public void setMemberGroups(List<Group> memberGroups) {
269 this.memberGroups = memberGroups;
270 }*/
271
272 public KimTypeBo getKimTypeInfo() {
273 return KimTypeBo.from(KimApiServiceLocator.getKimTypeInfoService().getKimType(this.kimTypeId));
274 }
275 }