| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.kim.bo.impl; |
| 17 | |
|
| 18 | |
import java.util.ArrayList; |
| 19 | |
import java.util.LinkedHashMap; |
| 20 | |
import java.util.List; |
| 21 | |
|
| 22 | |
import javax.persistence.CascadeType; |
| 23 | |
import javax.persistence.Column; |
| 24 | |
import javax.persistence.Entity; |
| 25 | |
import javax.persistence.FetchType; |
| 26 | |
import javax.persistence.Id; |
| 27 | |
import javax.persistence.JoinColumn; |
| 28 | |
import javax.persistence.OneToMany; |
| 29 | |
import javax.persistence.Table; |
| 30 | |
import javax.persistence.Transient; |
| 31 | |
|
| 32 | |
import org.apache.commons.lang.builder.EqualsBuilder; |
| 33 | |
import org.apache.commons.lang.builder.HashCodeBuilder; |
| 34 | |
import org.hibernate.annotations.Type; |
| 35 | |
import org.kuali.rice.kim.bo.Group; |
| 36 | |
import org.kuali.rice.kim.bo.Person; |
| 37 | |
import org.kuali.rice.kim.bo.group.dto.GroupInfo; |
| 38 | |
import org.kuali.rice.kim.bo.group.impl.GroupAttributeDataImpl; |
| 39 | |
import org.kuali.rice.kim.bo.group.impl.GroupMemberImpl; |
| 40 | |
import org.kuali.rice.kim.bo.types.dto.AttributeSet; |
| 41 | |
import org.kuali.rice.kim.bo.types.dto.KimTypeInfo; |
| 42 | |
import org.kuali.rice.kim.service.KIMServiceLocator; |
| 43 | |
import org.kuali.rice.kim.util.KimConstants.KimGroupMemberTypes; |
| 44 | |
import org.kuali.rice.kns.bo.PersistableBusinessObjectBase; |
| 45 | |
import org.kuali.rice.kns.util.TypedArrayList; |
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
@Entity |
| 54 | |
@Table(name="KRIM_GRP_T") |
| 55 | 0 | public class GroupImpl extends PersistableBusinessObjectBase implements Group { |
| 56 | |
|
| 57 | |
private static final long serialVersionUID = 1L; |
| 58 | |
|
| 59 | |
@Id |
| 60 | |
@Column(name="GRP_ID") |
| 61 | |
protected String groupId; |
| 62 | |
@Column(name="GRP_NM") |
| 63 | |
protected String groupName; |
| 64 | |
@Column(name="GRP_DESC",length=4000) |
| 65 | |
protected String groupDescription; |
| 66 | |
|
| 67 | |
@Column(name="ACTV_IND") |
| 68 | |
@Type(type="yes_no") |
| 69 | |
protected boolean active; |
| 70 | |
|
| 71 | |
@Column(name="KIM_TYP_ID") |
| 72 | |
protected String kimTypeId; |
| 73 | |
@Column(name="NMSPC_CD") |
| 74 | |
protected String namespaceCode; |
| 75 | |
|
| 76 | |
@OneToMany(targetEntity=GroupMemberImpl.class,cascade={CascadeType.ALL},fetch=FetchType.LAZY) |
| 77 | |
@JoinColumn(name="GRP_ID", insertable=false, updatable=false) |
| 78 | |
protected List<GroupMemberImpl> members; |
| 79 | |
|
| 80 | 0 | @OneToMany(targetEntity=GroupAttributeDataImpl.class,cascade={CascadeType.ALL},fetch=FetchType.LAZY) |
| 81 | |
@JoinColumn(name="GRP_ID", insertable=false, updatable=false) |
| 82 | |
protected List<GroupAttributeDataImpl> groupAttributes = new TypedArrayList(GroupAttributeDataImpl.class); |
| 83 | |
|
| 84 | |
@Transient |
| 85 | |
private List<Person> memberPersons; |
| 86 | |
@Transient |
| 87 | |
private List<GroupInfo> memberGroups; |
| 88 | |
|
| 89 | |
protected AttributeSet attributes; |
| 90 | |
|
| 91 | |
|
| 92 | |
|
| 93 | |
|
| 94 | |
@SuppressWarnings("unchecked") |
| 95 | |
@Override |
| 96 | |
protected LinkedHashMap toStringMapper() { |
| 97 | 0 | LinkedHashMap m = new LinkedHashMap(); |
| 98 | 0 | m.put( "groupId", groupId ); |
| 99 | 0 | m.put( "namespaceCode", namespaceCode ); |
| 100 | 0 | m.put( "groupName", groupName ); |
| 101 | 0 | return m; |
| 102 | |
} |
| 103 | |
|
| 104 | |
public String getKimTypeId() { |
| 105 | 0 | return this.kimTypeId; |
| 106 | |
} |
| 107 | |
|
| 108 | |
public void setKimTypeId(String kimTypeId) { |
| 109 | 0 | this.kimTypeId = kimTypeId; |
| 110 | 0 | } |
| 111 | |
|
| 112 | |
public String getNamespaceCode() { |
| 113 | 0 | return this.namespaceCode; |
| 114 | |
} |
| 115 | |
|
| 116 | |
public void setNamespaceCode(String namespaceCode) { |
| 117 | 0 | this.namespaceCode = namespaceCode; |
| 118 | 0 | } |
| 119 | |
|
| 120 | |
|
| 121 | |
|
| 122 | |
|
| 123 | |
public String getGroupId() { |
| 124 | 0 | return this.groupId; |
| 125 | |
} |
| 126 | |
|
| 127 | |
|
| 128 | |
|
| 129 | |
|
| 130 | |
public void setGroupId(String groupId) { |
| 131 | 0 | this.groupId = groupId; |
| 132 | 0 | } |
| 133 | |
|
| 134 | |
|
| 135 | |
|
| 136 | |
|
| 137 | |
public String getGroupName() { |
| 138 | 0 | return this.groupName; |
| 139 | |
} |
| 140 | |
|
| 141 | |
|
| 142 | |
|
| 143 | |
|
| 144 | |
public void setGroupName(String groupName) { |
| 145 | 0 | this.groupName = groupName; |
| 146 | 0 | } |
| 147 | |
|
| 148 | |
|
| 149 | |
|
| 150 | |
|
| 151 | |
public String getGroupDescription() { |
| 152 | 0 | return this.groupDescription; |
| 153 | |
} |
| 154 | |
|
| 155 | |
|
| 156 | |
|
| 157 | |
|
| 158 | |
public void setGroupDescription(String groupDescription) { |
| 159 | 0 | this.groupDescription = groupDescription; |
| 160 | 0 | } |
| 161 | |
|
| 162 | |
|
| 163 | |
|
| 164 | |
|
| 165 | |
public boolean isActive() { |
| 166 | 0 | return this.active; |
| 167 | |
} |
| 168 | |
|
| 169 | |
|
| 170 | |
|
| 171 | |
|
| 172 | |
public void setActive(boolean active) { |
| 173 | 0 | this.active = active; |
| 174 | 0 | } |
| 175 | |
|
| 176 | |
public AttributeSet getAttributes() { |
| 177 | 0 | AttributeSet attributes = new AttributeSet( groupAttributes.size() ); |
| 178 | 0 | for ( GroupAttributeDataImpl attr : groupAttributes ) { |
| 179 | 0 | if ( attr.getKimAttribute() != null ) { |
| 180 | 0 | attributes.put(attr.getKimAttribute().getAttributeName(), attr.getAttributeValue()); |
| 181 | |
} else { |
| 182 | 0 | attributes.put("Unknown Attribute ID: " + attr.getKimAttributeId(), attr.getAttributeValue()); |
| 183 | |
} |
| 184 | |
} |
| 185 | |
|
| 186 | 0 | return attributes; |
| 187 | |
} |
| 188 | |
|
| 189 | |
|
| 190 | |
|
| 191 | |
|
| 192 | |
public void setAttributes(AttributeSet attributes) { |
| 193 | 0 | this.attributes = attributes; |
| 194 | 0 | } |
| 195 | |
|
| 196 | |
|
| 197 | |
|
| 198 | |
|
| 199 | |
public List<GroupAttributeDataImpl> getGroupAttributes() { |
| 200 | 0 | return this.groupAttributes; |
| 201 | |
} |
| 202 | |
|
| 203 | |
|
| 204 | |
|
| 205 | |
|
| 206 | |
public void setGroupAttributes(List<GroupAttributeDataImpl> groupAttributes) { |
| 207 | 0 | this.groupAttributes = groupAttributes; |
| 208 | 0 | } |
| 209 | |
|
| 210 | |
|
| 211 | |
|
| 212 | |
|
| 213 | |
public List<GroupInfo> getMemberGroups() { |
| 214 | 0 | return this.memberGroups; |
| 215 | |
} |
| 216 | |
|
| 217 | |
|
| 218 | |
|
| 219 | |
|
| 220 | |
protected void setMemberGroups(List<GroupInfo> memberGroups) { |
| 221 | 0 | this.memberGroups = memberGroups; |
| 222 | 0 | } |
| 223 | |
|
| 224 | |
|
| 225 | |
|
| 226 | |
|
| 227 | |
public List<Person> getMemberPersons() { |
| 228 | 0 | return this.memberPersons; |
| 229 | |
} |
| 230 | |
|
| 231 | |
|
| 232 | |
|
| 233 | |
|
| 234 | |
protected void setMemberPersons(List<Person> memberPersons) { |
| 235 | 0 | this.memberPersons = memberPersons; |
| 236 | 0 | } |
| 237 | |
|
| 238 | |
|
| 239 | |
|
| 240 | |
|
| 241 | |
public List<GroupMemberImpl> getMembers() { |
| 242 | 0 | return this.members; |
| 243 | |
} |
| 244 | |
|
| 245 | |
|
| 246 | |
|
| 247 | |
|
| 248 | |
public void setMembers(List<GroupMemberImpl> members) { |
| 249 | 0 | this.members = members; |
| 250 | 0 | } |
| 251 | |
|
| 252 | |
public List<String> getMemberGroupIds() { |
| 253 | 0 | List<String> groupMembers = new ArrayList<String>(); |
| 254 | 0 | if (getMembers() != null) { |
| 255 | 0 | for ( GroupMemberImpl groupMemberImpl : getMembers() ) { |
| 256 | 0 | if ( groupMemberImpl.getMemberTypeCode().equals ( KimGroupMemberTypes.GROUP_MEMBER_TYPE ) |
| 257 | |
&& groupMemberImpl.isActive() ) { |
| 258 | 0 | groupMembers.add( groupMemberImpl.getMemberId() ); |
| 259 | |
} |
| 260 | |
} |
| 261 | |
} |
| 262 | 0 | return groupMembers; |
| 263 | |
} |
| 264 | |
|
| 265 | |
public List<String> getMemberPrincipalIds() { |
| 266 | 0 | List<String> groupMembers = new ArrayList<String>(); |
| 267 | 0 | if (getMembers() != null) { |
| 268 | 0 | for ( GroupMemberImpl groupMemberImpl : getMembers() ) { |
| 269 | 0 | if ( groupMemberImpl.getMemberTypeCode().equals ( KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE ) |
| 270 | |
&& groupMemberImpl.isActive() ) { |
| 271 | 0 | groupMembers.add( groupMemberImpl.getMemberId() ); |
| 272 | |
} |
| 273 | |
} |
| 274 | |
} |
| 275 | 0 | return groupMembers; |
| 276 | |
} |
| 277 | |
|
| 278 | |
public void setMemberPersonsAndGroups() { |
| 279 | 0 | List<Person> personMembers = new ArrayList<Person>(); |
| 280 | 0 | List<GroupInfo> groupMembers = new ArrayList<GroupInfo>(); |
| 281 | 0 | if (getMembers() != null) { |
| 282 | 0 | for ( GroupMemberImpl groupMemberImpl : getMembers() ) { |
| 283 | 0 | if ( groupMemberImpl.getMemberTypeCode().equals ( KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE ) |
| 284 | |
&& groupMemberImpl.isActive() ) { |
| 285 | 0 | personMembers.add( KIMServiceLocator.getPersonService().getPerson(groupMemberImpl.getMemberId()) ); |
| 286 | 0 | } else if (groupMemberImpl.getMemberTypeCode().equals ( KimGroupMemberTypes.GROUP_MEMBER_TYPE ) |
| 287 | |
&& groupMemberImpl.isActive() ) { |
| 288 | 0 | groupMembers.add( |
| 289 | |
KIMServiceLocator.getIdentityManagementService().getGroup(groupMemberImpl.getMemberId()) ); |
| 290 | |
} |
| 291 | |
} |
| 292 | |
} |
| 293 | 0 | setMemberPersons(personMembers); |
| 294 | 0 | setMemberGroups(groupMembers); |
| 295 | 0 | } |
| 296 | |
|
| 297 | |
|
| 298 | |
|
| 299 | |
|
| 300 | |
public boolean equals(Object object) { |
| 301 | 0 | if ( !(object instanceof Group) ) { |
| 302 | 0 | return false; |
| 303 | |
} |
| 304 | 0 | Group rhs = (Group)object; |
| 305 | 0 | return new EqualsBuilder().append( this.groupId, rhs.getGroupId() ).isEquals(); |
| 306 | |
} |
| 307 | |
|
| 308 | |
|
| 309 | |
|
| 310 | |
|
| 311 | |
public int hashCode() { |
| 312 | 0 | return new HashCodeBuilder( -460627871, 746615189 ).append( this.groupId ).toHashCode(); |
| 313 | |
} |
| 314 | |
|
| 315 | |
public GroupAttributeDataImpl getGroupAttributeById(String attributeId) { |
| 316 | 0 | for (GroupAttributeDataImpl gad : getGroupAttributes()) { |
| 317 | 0 | if (gad.getAttributeValue().equals(attributeId.trim())) { |
| 318 | 0 | return gad; |
| 319 | |
} |
| 320 | |
} |
| 321 | 0 | return null; |
| 322 | |
} |
| 323 | |
|
| 324 | |
public String getGroupAttributeValueById(String attributeId) { |
| 325 | 0 | for (GroupAttributeDataImpl gad : getGroupAttributes()) { |
| 326 | 0 | if (gad.getKimAttributeId().equals(attributeId.trim())) { |
| 327 | 0 | return gad.getAttributeValue(); |
| 328 | |
} |
| 329 | |
} |
| 330 | 0 | return null; |
| 331 | |
} |
| 332 | |
|
| 333 | |
public KimTypeInfo getKimTypeInfo() { |
| 334 | 0 | return KIMServiceLocator.getTypeInfoService().getKimType(this.kimTypeId); |
| 335 | |
} |
| 336 | |
|
| 337 | |
} |