Coverage Report - org.kuali.rice.kim.bo.impl.GroupImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
GroupImpl
0%
0/77
0%
0/42
1.8
 
 1  
 /*
 2  
  * Copyright 2007-2009 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 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  
  * This class is the implementation of a Kim Group 
 42  
  * 
 43  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 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  
         //@GeneratedValue(generator="KRIM_GRP_ID_S")
 54  
         //@GenericGenerator(name="KRIM_GRP_ID_S",strategy="org.kuali.rice.core.jpa.spring.RiceNumericStringSequenceStyleGenerator",parameters={
 55  
         //                @Parameter(name="sequence_name",value="KRIM_GRP_ID_S"),
 56  
         //                @Parameter(name="value_column",value="id")
 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  
         //@JoinColumn(name="GRP_ID", insertable=false, updatable=false)
 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  
         //@JoinColumn(name="GRP_ID", insertable=false, updatable=false)
 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  
          * @return the groupId
 109  
          */
 110  
         public String getGroupId() {
 111  0
                 return this.groupId;
 112  
         }
 113  
 
 114  
         /**
 115  
          * @param groupId the groupId to set
 116  
          */
 117  
         public void setGroupId(String groupId) {
 118  0
                 this.groupId = groupId;
 119  0
         }
 120  
 
 121  
         /**
 122  
          * @return the groupName
 123  
          */
 124  
         public String getGroupName() {
 125  0
                 return this.groupName;
 126  
         }
 127  
 
 128  
         /**
 129  
          * @param groupName the groupName to set
 130  
          */
 131  
         public void setGroupName(String groupName) {
 132  0
                 this.groupName = groupName;
 133  0
         }
 134  
 
 135  
         /**
 136  
          * @return the groupDescription
 137  
          */
 138  
         public String getGroupDescription() {
 139  0
                 return this.groupDescription;
 140  
         }
 141  
 
 142  
         /**
 143  
          * @param groupDescription the groupDescription to set
 144  
          */
 145  
         public void setGroupDescription(String groupDescription) {
 146  0
                 this.groupDescription = groupDescription;
 147  0
         }
 148  
 
 149  
         /**
 150  
          * @return the active
 151  
          */
 152  
         public boolean isActive() {
 153  0
                 return this.active;
 154  
         }
 155  
 
 156  
         /**
 157  
          * @param active the active to set
 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  
          * @param attributes the attributes to set
 178  
          */
 179  
         public void setAttributes(AttributeSet attributes) {
 180  0
                 this.attributes = attributes;
 181  0
         }
 182  
 
 183  
         /**
 184  
          * @return the groupAttributes
 185  
          */
 186  
         public List<GroupAttributeDataImpl> getGroupAttributes() {
 187  0
                 return this.groupAttributes;
 188  
         }
 189  
 
 190  
         /**
 191  
          * @param groupAttributes the groupAttributes to set
 192  
          */
 193  
         public void setGroupAttributes(List<GroupAttributeDataImpl> groupAttributes) {
 194  0
                 this.groupAttributes = groupAttributes;
 195  0
         }
 196  
 
 197  
         /**
 198  
          * @return the memberGroups
 199  
          */
 200  
         public List<GroupInfo> getMemberGroups() {
 201  0
                 return this.memberGroups;
 202  
         }
 203  
 
 204  
         /**
 205  
          * @param memberGroups the memberGroups to set
 206  
          */
 207  
         protected void setMemberGroups(List<GroupInfo> memberGroups) {
 208  0
                 this.memberGroups = memberGroups;
 209  0
         }
 210  
 
 211  
         /**
 212  
          * @return the memberPersons
 213  
          */
 214  
         public List<Person> getMemberPersons() {
 215  0
                 return this.memberPersons;
 216  
         }
 217  
 
 218  
         /**
 219  
          * @param memberPersons the memberPersons to set
 220  
          */
 221  
         protected void setMemberPersons(List<Person> memberPersons) {
 222  0
                 this.memberPersons = memberPersons;
 223  0
         }
 224  
 
 225  
         /**
 226  
          * @return the members
 227  
          */
 228  
         public List<GroupMemberImpl> getMembers() {
 229  0
                 return this.members;
 230  
         }
 231  
 
 232  
         /**
 233  
          * @param members the members to set
 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  
          * @see java.lang.Object#equals(Object)
 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  
          * @see java.lang.Object#hashCode()
 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  
 }