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