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