| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| GroupBo |
|
| 0.0;0 |
| 1 | /** | |
| 2 | * Copyright 2005-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 | package org.kuali.rice.kim.impl.group | |
| 17 | ||
| 18 | import javax.persistence.CascadeType | |
| 19 | import javax.persistence.Column | |
| 20 | import javax.persistence.Entity | |
| 21 | import javax.persistence.FetchType | |
| 22 | import javax.persistence.Id | |
| 23 | import javax.persistence.OneToMany | |
| 24 | import javax.persistence.Table | |
| 25 | import javax.persistence.Transient | |
| 26 | import org.hibernate.annotations.Fetch | |
| 27 | import org.hibernate.annotations.FetchMode | |
| 28 | import org.hibernate.annotations.Type | |
| 29 | import org.joda.time.DateTime | |
| 30 | import org.kuali.rice.kim.api.KimConstants.KimGroupMemberTypes | |
| 31 | import org.kuali.rice.kim.api.group.Group | |
| 32 | import org.kuali.rice.kim.api.group.GroupContract | |
| 33 | import org.kuali.rice.kim.api.identity.Person | |
| 34 | import org.kuali.rice.kim.api.services.KimApiServiceLocator | |
| 35 | import org.kuali.rice.kim.impl.common.attribute.KimAttributeDataBo | |
| 36 | import org.kuali.rice.kim.impl.type.KimTypeBo | |
| 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<Group> memberGroups | |
| 77 | ||
| 78 | @Transient | |
| 79 | Map<String,String> attributes | |
| 80 | ||
| 81 | Map<String,String> getAttributes() { | |
| 82 | 0 | 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 | 0 | if (bo == null) { |
| 92 | 0 | return null |
| 93 | } | |
| 94 | ||
| 95 | 0 | 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 | 0 | if (im == null) { |
| 105 | 0 | return null |
| 106 | } | |
| 107 | ||
| 108 | 0 | GroupBo bo = new GroupBo() |
| 109 | 0 | bo.id = im.id |
| 110 | 0 | bo.namespaceCode = im.namespaceCode |
| 111 | 0 | bo.name = im.name |
| 112 | 0 | bo.description = im.description |
| 113 | 0 | bo.active = im.active |
| 114 | 0 | bo.kimTypeId = im.kimTypeId |
| 115 | 0 | bo.attributes = im.attributes |
| 116 | //bo.attributeDetails = KimAttributeDataBo.createFrom(GroupAttributeBo.class, im.attributes, im.kimTypeId ) | |
| 117 | 0 | bo.versionNumber = im.versionNumber |
| 118 | 0 | bo.objectId = im.objectId; |
| 119 | ||
| 120 | 0 | 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(new DateTime())) { |
| 139 | 0 | if ( KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE.equals(groupMember.getType())) { |
| 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 (KimGroupMemberTypes.GROUP_MEMBER_TYPE.equals(groupMember.getType())) { |
| 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 | 0 | List<String> principalIds = new ArrayList<String>() |
| 164 | 0 | if (getMembers() != null) { |
| 165 | 0 | for ( GroupMemberBo groupMember : getMembers() ) { |
| 166 | 0 | if (groupMember.isActive(new DateTime())) { |
| 167 | 0 | if ( KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE.equals(groupMember.getType())) { |
| 168 | 0 | principalIds.add(groupMember.getMemberId()); |
| 169 | } | |
| 170 | } | |
| 171 | } | |
| 172 | } | |
| 173 | 0 | return principalIds; |
| 174 | } | |
| 175 | ||
| 176 | public List<String> getMemberGroupIds() { | |
| 177 | 0 | List<String> principalIds = new ArrayList<String>() |
| 178 | 0 | if (getMembers() != null) { |
| 179 | 0 | for ( GroupMemberBo groupMember : getMembers() ) { |
| 180 | 0 | if (groupMember.isActive(new DateTime())) { |
| 181 | 0 | if ( KimGroupMemberTypes.GROUP_MEMBER_TYPE.equals(groupMember.getType())) { |
| 182 | 0 | principalIds.add(groupMember.getMemberId()); |
| 183 | } | |
| 184 | } | |
| 185 | } | |
| 186 | } | |
| 187 | 0 | 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 | } |