Coverage Report - org.kuali.rice.kim.document.IdentityManagementGroupDocument
 
Classes in this File Line Coverage Branch Coverage Complexity
IdentityManagementGroupDocument
0%
0/107
0%
0/42
1.719
 
 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.document;
 17  
 
 18  
 import org.apache.commons.lang.StringUtils;
 19  
 import org.apache.log4j.Logger;
 20  
 import org.hibernate.annotations.Fetch;
 21  
 import org.hibernate.annotations.FetchMode;
 22  
 import org.hibernate.annotations.Type;
 23  
 import org.kuali.rice.kew.dto.DocumentRouteStatusChangeDTO;
 24  
 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
 25  
 import org.kuali.rice.kim.api.type.KimType;
 26  
 import org.kuali.rice.kim.bo.types.dto.AttributeDefinitionMap;
 27  
 import org.kuali.rice.kim.bo.ui.GroupDocumentMember;
 28  
 import org.kuali.rice.kim.bo.ui.GroupDocumentQualifier;
 29  
 import org.kuali.rice.kim.impl.type.IdentityManagementTypeAttributeTransactionalDocument;
 30  
 import org.kuali.rice.kim.service.KIMServiceLocatorInternal;
 31  
 import org.kuali.rice.kim.util.KimConstants;
 32  
 import org.kuali.rice.krad.service.SequenceAccessorService;
 33  
 import org.springframework.util.AutoPopulatingList;
 34  
 
 35  
 import javax.persistence.AttributeOverride;
 36  
 import javax.persistence.AttributeOverrides;
 37  
 import javax.persistence.CascadeType;
 38  
 import javax.persistence.Column;
 39  
 import javax.persistence.Entity;
 40  
 import javax.persistence.FetchType;
 41  
 import javax.persistence.JoinColumn;
 42  
 import javax.persistence.OneToMany;
 43  
 import javax.persistence.Table;
 44  
 import javax.persistence.Transient;
 45  
 import java.util.ArrayList;
 46  
 import java.util.HashMap;
 47  
 import java.util.List;
 48  
 import java.util.Map;
 49  
 
 50  
 
 51  
 /**
 52  
  * This is a description of what this class does - bhargavp don't forget to fill this in.
 53  
  *
 54  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 55  
  *
 56  
  */
 57  
 @Entity
 58  
 @AttributeOverrides({
 59  
         @AttributeOverride(name="documentNumber",column=@Column(name="FDOC_NBR"))
 60  
 })
 61  
 @Table(name="KRIM_GRP_DOCUMENT_T")
 62  
 public class IdentityManagementGroupDocument extends IdentityManagementTypeAttributeTransactionalDocument {
 63  0
         private static final Logger LOG = Logger.getLogger(IdentityManagementGroupDocument.class);
 64  
         
 65  
         private static final long serialVersionUID = 1L;
 66  
         
 67  
         // principal data
 68  
         @Column(name="GRP_ID")
 69  
         protected String groupId;
 70  
         @Column(name="KIM_TYP_ID")
 71  
         protected String groupTypeId;
 72  
         @Transient
 73  
         protected String groupTypeName;
 74  
         @Column(name="GRP_NMSPC")
 75  
         protected String groupNamespace;
 76  
         @Column(name="GRP_NM")
 77  
         protected String groupName;
 78  
         @Column(name="GRP_DESC")
 79  
         protected String groupDescription;
 80  0
         @Type(type="yes_no")
 81  
         @Column(name="ACTV_IND")
 82  
         protected boolean active = true;
 83  
 
 84  
         @Transient
 85  
         protected boolean editing;
 86  
 
 87  0
         @OneToMany(targetEntity = GroupDocumentMember.class, fetch = FetchType.EAGER, cascade=CascadeType.ALL)
 88  
         @Fetch(value = FetchMode.SELECT)
 89  
         @JoinColumn(name="FDOC_NBR", insertable = false, updatable = false)
 90  
         private List<GroupDocumentMember> members = new AutoPopulatingList(GroupDocumentMember.class);
 91  0
         @OneToMany(targetEntity = GroupDocumentQualifier.class, fetch = FetchType.EAGER, cascade=CascadeType.ALL)
 92  
         @Fetch(value = FetchMode.SELECT)
 93  
         @JoinColumn(name="FDOC_NBR", insertable = false, updatable = false)
 94  
         private List<GroupDocumentQualifier> qualifiers = new AutoPopulatingList(GroupDocumentQualifier.class);
 95  
 
 96  0
         public IdentityManagementGroupDocument() {
 97  0
         }
 98  
         
 99  
         /**
 100  
          * @return the active
 101  
          */
 102  
         public boolean isActive() {
 103  0
                 return this.active;
 104  
         }
 105  
 
 106  
         /**
 107  
          * @param active the active to set
 108  
          */
 109  
         public void setActive(boolean active) {
 110  0
                 this.active = active;
 111  0
         }
 112  
 
 113  
         /**
 114  
          * @param groupId the groupId to set
 115  
          */
 116  
         public void setRoleId(String groupId) {
 117  0
                 this.groupId = groupId;
 118  0
         }
 119  
 
 120  
         /**
 121  
          * @param member the members to set
 122  
          */
 123  
         public void addMember(GroupDocumentMember member) {
 124  0
                getMembers().add(member);
 125  0
         }
 126  
 
 127  
         /**
 128  
          * @return the kimType
 129  
          */
 130  
         public KimType getKimType() {
 131  0
         if (getGroupTypeId() != null) {
 132  0
                     return KimApiServiceLocator.getKimTypeInfoService().getKimType(getGroupTypeId());
 133  
         }
 134  0
         return null;
 135  
         }
 136  
         
 137  
         public GroupDocumentMember getBlankMember() {
 138  0
                 return new GroupDocumentMember();
 139  
         }
 140  
 
 141  
         /**
 142  
          * @see org.kuali.rice.krad.document.DocumentBase#doRouteStatusChange(org.kuali.rice.kew.dto.DocumentRouteStatusChangeDTO)
 143  
          */
 144  
         @Override
 145  
         public void doRouteStatusChange(DocumentRouteStatusChangeDTO statusChangeEvent) {
 146  0
                 super.doRouteStatusChange(statusChangeEvent);
 147  0
                 if (getDocumentHeader().getWorkflowDocument().isProcessed()) {
 148  0
                         KIMServiceLocatorInternal.getUiDocumentService().saveGroup(this);
 149  
                 }
 150  0
         }
 151  
 
 152  
         @Override
 153  
         public void prepareForSave(){
 154  
                 String groupId;
 155  0
                 if(StringUtils.isBlank(getGroupId())){
 156  0
                         SequenceAccessorService sas = getSequenceAccessorService();
 157  0
                         Long nextSeq = sas.getNextAvailableSequenceNumber(
 158  
                                         "KRIM_GRP_ID_S", this.getClass());
 159  0
                         groupId = nextSeq.toString();
 160  0
                         setGroupId(groupId);
 161  0
                 } else{
 162  0
                         groupId = getGroupId();
 163  
                 }
 164  0
                 if(getMembers()!=null){
 165  
                         String groupMemberId;
 166  0
                         for(GroupDocumentMember member: getMembers()){
 167  0
                                 member.setGroupId(getGroupId());
 168  0
                                 if(StringUtils.isBlank(member.getGroupMemberId())){
 169  0
                                         SequenceAccessorService sas = getSequenceAccessorService();
 170  0
                                         Long nextSeq = sas.getNextAvailableSequenceNumber(
 171  
                                                         "KRIM_GRP_MBR_ID_S", this.getClass());
 172  0
                                         groupMemberId = nextSeq.toString();
 173  0
                                         member.setGroupMemberId(groupMemberId);
 174  
                                 }
 175  0
                                 if (StringUtils.isBlank(member.getDocumentNumber())) {
 176  0
                                         member.setDocumentNumber(getDocumentNumber());
 177  
                                 }
 178  
                          }
 179  
                 }
 180  0
                 int index = 0;
 181  
                 // this needs to be checked - are all qualifiers present?
 182  0
                 if(getDefinitions()!=null){
 183  0
                         for(String key : getDefinitions().keySet()) {
 184  0
                                 if ( getQualifiers().size() > index ) {
 185  0
                                         GroupDocumentQualifier qualifier = getQualifiers().get(index);
 186  0
                                         qualifier.setKimAttrDefnId(getKimAttributeDefnId(getDefinitions().get(key)));
 187  0
                                         qualifier.setKimTypId(getKimType().getId());
 188  0
                                         qualifier.setGroupId(groupId);
 189  
                                 }
 190  0
                                 index++;
 191  
                 }
 192  
                 }
 193  0
         }
 194  
 
 195  
         public void initializeDocumentForNewGroup() {
 196  0
                 if(StringUtils.isBlank(this.groupId)){
 197  0
                         SequenceAccessorService sas = getSequenceAccessorService();
 198  0
                         Long nextSeq = sas.getNextAvailableSequenceNumber(
 199  
                                         KimConstants.SequenceNames.KRIM_GROUP_ID_S, this.getClass());
 200  0
                         this.groupId = nextSeq.toString();
 201  
                 }
 202  0
                 if(StringUtils.isBlank(this.groupTypeId)) {
 203  0
                         this.groupTypeId = "1";
 204  
                 }
 205  0
         }
 206  
         
 207  
         public String getGroupId(){
 208  
 //                if(StringUtils.isBlank(this.groupId)){
 209  
 //                        initializeDocumentForNewGroup();
 210  
 //                }
 211  0
                 return groupId;
 212  
         }
 213  
 
 214  
         /**
 215  
          * @param groupId the groupId to set
 216  
          */
 217  
         public void setGroupId(String groupId) {
 218  0
                 this.groupId = groupId;
 219  0
         }
 220  
 
 221  
         /**
 222  
          * @return the groupName
 223  
          */
 224  
         public String getGroupName() {
 225  0
                 return this.groupName;
 226  
         }
 227  
 
 228  
         /**
 229  
          * @param groupName the groupName to set
 230  
          */
 231  
         public void setGroupName(String groupName) {
 232  0
                 this.groupName = groupName;
 233  0
         }
 234  
 
 235  
         public String getGroupDescription() {
 236  0
                 return this.groupDescription;
 237  
         }
 238  
 
 239  
         public void setGroupDescription(String groupDescription) {
 240  0
                 this.groupDescription = groupDescription;
 241  0
         }
 242  
         
 243  
         /**
 244  
          * @return the groupNamespace
 245  
          */
 246  
         public String getGroupNamespace() {
 247  0
                 return this.groupNamespace;
 248  
         }
 249  
 
 250  
         /**
 251  
          * @param groupNamespace the groupNamespace to set
 252  
          */
 253  
         public void setGroupNamespace(String groupNamespace) {
 254  0
                 this.groupNamespace = groupNamespace;
 255  0
         }
 256  
 
 257  
         /**
 258  
          * @return the groupTypeId
 259  
          */
 260  
         public String getGroupTypeId() {
 261  0
                 return this.groupTypeId;
 262  
         }
 263  
 
 264  
         /**
 265  
          * @param groupTypeId the groupTypeId to set
 266  
          */
 267  
         public void setGroupTypeId(String groupTypeId) {
 268  0
                 this.groupTypeId = groupTypeId;
 269  0
         }
 270  
 
 271  
         /**
 272  
          * @return the groupTypeName
 273  
          */
 274  
         public String getGroupTypeName() {
 275  0
                 return this.groupTypeName;
 276  
         }
 277  
 
 278  
         /**
 279  
          * @param groupTypeName the groupTypeName to set
 280  
          */
 281  
         public void setGroupTypeName(String groupTypeName) {
 282  0
                 this.groupTypeName = groupTypeName;
 283  0
         }
 284  
 
 285  
         /**
 286  
          * @return the members
 287  
          */
 288  
         public List<GroupDocumentMember> getMembers() {
 289  0
                 return this.members;
 290  
         }
 291  
 
 292  
         /**
 293  
          * @param members the members to set
 294  
          */
 295  
         public void setMembers(List<GroupDocumentMember> members) {
 296  0
                 this.members = members;
 297  0
         }
 298  
 
 299  
         /**
 300  
          * @return the qualifiers
 301  
          */
 302  
         public List<GroupDocumentQualifier> getQualifiers() {
 303  0
                 return this.qualifiers;
 304  
         }
 305  
 
 306  
         /**
 307  
          * @param qualifiers the qualifiers to set
 308  
          */
 309  
         public void setQualifiers(List<GroupDocumentQualifier> qualifiers) {
 310  0
                 this.qualifiers = qualifiers;
 311  0
         }
 312  
 
 313  
         public GroupDocumentQualifier getQualifier(String kimAttributeDefnId) {
 314  0
                 for(GroupDocumentQualifier qualifier: qualifiers){
 315  0
                         if(qualifier.getKimAttrDefnId().equals(kimAttributeDefnId))
 316  0
                                 return qualifier;
 317  
                 }
 318  0
                 return null;
 319  
         }
 320  
 
 321  
         public Map<String, String> getQualifiersAsAttributes() {
 322  0
         Map<String, String> attributes = new HashMap<String, String>();
 323  0
                 for(GroupDocumentQualifier qualifier: qualifiers){
 324  0
                         if ( qualifier.getKimAttribute() != null ) {
 325  0
                                 attributes.put(qualifier.getKimAttribute().getAttributeName(), qualifier.getAttrVal());
 326  
                         } else {
 327  0
                                 LOG.warn( "Unknown attribute ID on group: " + qualifier.getKimAttrDefnId() + " / value=" + qualifier.getAttrVal());
 328  0
                                 attributes.put("Unknown Attribute ID: " + qualifier.getKimAttrDefnId(), qualifier.getAttrVal());
 329  
                         }
 330  
                 }
 331  0
                 return attributes;
 332  
         }
 333  
         
 334  
         public void setDefinitions(AttributeDefinitionMap definitions) {
 335  0
                 super.setDefinitions(definitions);
 336  0
                 if(getQualifiers()==null || getQualifiers().size()<1){
 337  
                         GroupDocumentQualifier qualifier;
 338  0
                         setQualifiers(new ArrayList<GroupDocumentQualifier>());
 339  0
                         if(getDefinitions()!=null){
 340  0
                                 for(String key : getDefinitions().keySet()) {
 341  0
                                         qualifier = new GroupDocumentQualifier();
 342  0
                                 qualifier.setKimAttrDefnId(getKimAttributeDefnId(getDefinitions().get(key)));
 343  0
                                 getQualifiers().add(qualifier);
 344  
                         }
 345  
                         }
 346  
                 }
 347  0
         }
 348  
 
 349  
         /**
 350  
          * @return the editing
 351  
          */
 352  
         public boolean isEditing() {
 353  0
                 return this.editing;
 354  
         }
 355  
 
 356  
         /**
 357  
          * @param editing the editing to set
 358  
          */
 359  
         public void setEditing(boolean editing) {
 360  0
                 this.editing = editing;
 361  0
         }
 362  
 
 363  
         public void setKimType(KimType kimType) {
 364  0
                 super.setKimType(kimType);
 365  0
                 if (kimType != null){
 366  0
                         setGroupTypeId(kimType.getId());
 367  0
                         setGroupTypeName(kimType.getName());
 368  
                 }
 369  0
         }
 370  
 }