Coverage Report - org.kuali.rice.kim.impl.group.GroupBo
 
Classes in this File Line Coverage Branch Coverage Complexity
GroupBo
54%
30/55
36%
19/52
0
 
 1  
 /*
 2  
  * Copyright 2006-2011 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  
 
 17  
 package org.kuali.rice.kim.impl.group
 18  
 
 19  
 import javax.persistence.CascadeType
 20  
 import javax.persistence.Column
 21  
 import javax.persistence.Entity
 22  
 import javax.persistence.FetchType
 23  
 import javax.persistence.Id
 24  
 import javax.persistence.OneToMany
 25  
 import javax.persistence.Table
 26  
 import javax.persistence.Transient
 27  
 import org.hibernate.annotations.Fetch
 28  
 import org.hibernate.annotations.FetchMode
 29  
 import org.hibernate.annotations.Type
 30  
 import org.kuali.rice.kim.api.group.Group
 31  
 import org.kuali.rice.kim.api.group.GroupContract
 32  
 import org.kuali.rice.kim.api.services.KimApiServiceLocator
 33  
 import org.kuali.rice.kim.bo.Person
 34  
 import org.kuali.rice.kim.impl.common.attribute.KimAttributeDataBo
 35  
 import org.kuali.rice.kim.impl.type.KimTypeBo
 36  
 import org.kuali.rice.kim.util.KimConstants.KimGroupMemberTypes
 37  
 import org.kuali.rice.krad.bo.PersistableBusinessObjectBase
 38  
 
 39  
 @Entity
 40  
 @Table(name="KRIM_GRP_T")
 41  
 public class GroupBo extends PersistableBusinessObjectBase implements GroupContract {
 42  
     private static final long serialVersionUID = 1L;
 43  
 
 44  
     @Id
 45  
         @Column(name="GRP_ID")
 46  
         String id
 47  
 
 48  
     @Column(name="GRP_NM")
 49  
         String name
 50  
 
 51  
     @Column(name="GRP_DESC",length=4000)
 52  
         String description
 53  
 
 54  
         @Column(name="ACTV_IND")
 55  
         @Type(type="yes_no")
 56  
         boolean active
 57  
 
 58  
         @Column(name="KIM_TYP_ID")
 59  
         String kimTypeId
 60  
 
 61  
     @Column(name="NMSPC_CD")
 62  
         String namespaceCode
 63  
 
 64  
         @OneToMany(targetEntity=GroupMemberBo.class,cascade=[CascadeType.ALL],fetch=FetchType.EAGER,mappedBy="id")
 65  
         @Fetch(value = FetchMode.SELECT)
 66  
         List<GroupMemberBo> members
 67  
 
 68  
         @OneToMany(targetEntity=GroupAttributeBo.class,cascade=[CascadeType.ALL],fetch=FetchType.EAGER,mappedBy="id")
 69  
         @Fetch(value = FetchMode.SELECT)
 70  
         List<GroupAttributeBo> attributeDetails
 71  
 
 72  
     @Transient
 73  
     private List<Person> memberPersons
 74  
 
 75  
     @Transient
 76  
     private List<GroupBo> memberGroups
 77  
 
 78  
     @Transient
 79  
     Map<String,String> attributes
 80  
 
 81  
     Map<String,String> getAttributes() {
 82  43
         return attributeDetails != null ? KimAttributeDataBo.toAttributes(attributeDetails) : attributes
 83  
     }
 84  
 
 85  
     /**
 86  
      * Converts a mutable bo to its immutable counterpart
 87  
      * @param bo the mutable business object
 88  
      * @return the immutable object
 89  
      */
 90  
     static Group to(GroupBo bo) {
 91  22
         if (bo == null) {
 92  1
             return null
 93  
         }
 94  
 
 95  21
         return Group.Builder.create(bo).build();
 96  
     }
 97  
 
 98  
     /**
 99  
      * Converts a immutable object to its mutable counterpart
 100  
      * @param im immutable object
 101  
      * @return the mutable bo
 102  
      */
 103  
     static GroupBo from(Group im) {
 104  1
         if (im == null) {
 105  0
             return null
 106  
         }
 107  
 
 108  1
         GroupBo bo = new GroupBo()
 109  1
         bo.id = im.id
 110  1
         bo.namespaceCode = im.namespaceCode
 111  1
         bo.name = im.name
 112  1
         bo.description = im.description
 113  1
         bo.active = im.active
 114  1
         bo.kimTypeId = im.kimTypeId
 115  1
         bo.attributes = im.attributes
 116  
         //bo.attributeDetails = KimAttributeDataBo.createFrom(GroupAttributeBo.class, im.attributes, im.kimTypeId )
 117  1
         bo.versionNumber = im.versionNumber
 118  1
                 bo.objectId = im.objectId;
 119  
 
 120  1
         return bo
 121  
     }
 122  
 
 123  
     //helper function to get Attribute Value with specific id
 124  
     public String getGroupAttributeValueById(String attributeId) {
 125  0
             for (GroupAttributeBo gad : getAttributeDetails()) {
 126  0
                 if (gad.getKimAttributeId().equals(attributeId.trim())) {
 127  0
                     return gad.getAttributeValue();
 128  
                 }
 129  
             }
 130  0
             return null;
 131  
         }
 132  
 
 133  
     private void splitMembersToTypes() {
 134  0
         memberPersons = new ArrayList<Person>()
 135  0
         memberGroups = new ArrayList<Group>()
 136  0
         if (getMembers() != null) {
 137  0
             for ( GroupMemberBo groupMember : getMembers() ) {
 138  0
                 if (groupMember.isActive()) {
 139  0
                     if ( groupMember.getTypeCode().equals ( KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE )) {
 140  0
                         Person tempPerson =  KimApiServiceLocator.getPersonService().getPerson(groupMember.getMemberId())
 141  0
                         if (tempPerson != null && tempPerson.isActive()) {
 142  0
                             memberPersons.add(tempPerson)
 143  
                         }
 144  0
                     } else if (groupMember.getTypeCode().equals ( KimGroupMemberTypes.GROUP_MEMBER_TYPE ) ) {
 145  0
                         Group tempGroup =  KimApiServiceLocator.getGroupService().getGroup(groupMember.getMemberId())
 146  0
                         if (tempGroup != null && tempGroup.isActive()) {
 147  0
                             memberGroups.add(tempGroup)
 148  
                         }
 149  
                     }
 150  
                 }
 151  
             }
 152  
         }
 153  
     }
 154  
 
 155  
     public List<Person> getMemberPersons() {
 156  0
         if (this.memberPersons == null) {
 157  0
             splitMembersToTypes()
 158  
         }
 159  0
         return this.memberPersons
 160  
     }
 161  
 
 162  
     public List<String> getMemberPrincipalIds() {
 163  2
         List<String> principalIds = new ArrayList<String>()
 164  2
         if (getMembers() != null) {
 165  1
             for ( GroupMemberBo groupMember : getMembers() ) {
 166  3
                 if (groupMember.isActive()) {
 167  3
                     if ( groupMember.getTypeCode().equals ( KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE )) {
 168  2
                         principalIds.add(groupMember.getMemberId());
 169  
                     }
 170  
                 }
 171  
             }
 172  
         }
 173  2
         return principalIds;
 174  
     }
 175  
 
 176  
     public List<String> getMemberGroupIds() {
 177  4
         List<String> principalIds = new ArrayList<String>()
 178  4
         if (getMembers() != null) {
 179  2
             for ( GroupMemberBo groupMember : getMembers() ) {
 180  6
                 if (groupMember.isActive()) {
 181  6
                     if ( groupMember.getTypeCode().equals ( KimGroupMemberTypes.GROUP_MEMBER_TYPE )) {
 182  2
                         principalIds.add(groupMember.getMemberId());
 183  
                     }
 184  
                 }
 185  
             }
 186  
         }
 187  4
         return principalIds;
 188  
     }
 189  
 
 190  
     public List<Group> getMemberGroups() {
 191  0
         if (this.memberGroups == null) {
 192  0
             splitMembersToTypes()
 193  
         }
 194  0
         return this.memberGroups
 195  
     }
 196  
 
 197  
     public KimTypeBo getKimTypeInfo() {
 198  0
         return KimTypeBo.from(KimApiServiceLocator.getKimTypeInfoService().getKimType(this.kimTypeId))
 199  
     }
 200  
 }