Coverage Report - org.kuali.rice.kim.document.IdentityManagementGroupDocument
 
Classes in this File Line Coverage Branch Coverage Complexity
IdentityManagementGroupDocument
0%
0/105
0%
0/40
1.656
 
 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
                 return KimApiServiceLocator.getKimTypeInfoService().getKimType(getGroupTypeId());
 132  
         }
 133  
         
 134  
         public GroupDocumentMember getBlankMember() {
 135  0
                 return new GroupDocumentMember();
 136  
         }
 137  
 
 138  
         /**
 139  
          * @see org.kuali.rice.krad.document.DocumentBase#doRouteStatusChange(org.kuali.rice.kew.dto.DocumentRouteStatusChangeDTO)
 140  
          */
 141  
         @Override
 142  
         public void doRouteStatusChange(DocumentRouteStatusChangeDTO statusChangeEvent) {
 143  0
                 super.doRouteStatusChange(statusChangeEvent);
 144  0
                 if (getDocumentHeader().getWorkflowDocument().isProcessed()) {
 145  0
                         KIMServiceLocatorInternal.getUiDocumentService().saveGroup(this);
 146  
                 }
 147  0
         }
 148  
 
 149  
         @Override
 150  
         public void prepareForSave(){
 151  
                 String groupId;
 152  0
                 if(StringUtils.isBlank(getGroupId())){
 153  0
                         SequenceAccessorService sas = getSequenceAccessorService();
 154  0
                         Long nextSeq = sas.getNextAvailableSequenceNumber(
 155  
                                         "KRIM_GRP_ID_S", this.getClass());
 156  0
                         groupId = nextSeq.toString();
 157  0
                         setGroupId(groupId);
 158  0
                 } else{
 159  0
                         groupId = getGroupId();
 160  
                 }
 161  0
                 if(getMembers()!=null){
 162  
                         String groupMemberId;
 163  0
                         for(GroupDocumentMember member: getMembers()){
 164  0
                                 member.setGroupId(getGroupId());
 165  0
                                 if(StringUtils.isBlank(member.getGroupMemberId())){
 166  0
                                         SequenceAccessorService sas = getSequenceAccessorService();
 167  0
                                         Long nextSeq = sas.getNextAvailableSequenceNumber(
 168  
                                                         "KRIM_GRP_MBR_ID_S", this.getClass());
 169  0
                                         groupMemberId = nextSeq.toString();
 170  0
                                         member.setGroupMemberId(groupMemberId);
 171  
                                 }
 172  0
                                 if (StringUtils.isBlank(member.getDocumentNumber())) {
 173  0
                                         member.setDocumentNumber(getDocumentNumber());
 174  
                                 }
 175  
                          }
 176  
                 }
 177  0
                 int index = 0;
 178  
                 // this needs to be checked - are all qualifiers present?
 179  0
                 if(getDefinitions()!=null){
 180  0
                         for(String key : getDefinitions().keySet()) {
 181  0
                                 if ( getQualifiers().size() > index ) {
 182  0
                                         GroupDocumentQualifier qualifier = getQualifiers().get(index);
 183  0
                                         qualifier.setKimAttrDefnId(getKimAttributeDefnId(getDefinitions().get(key)));
 184  0
                                         qualifier.setKimTypId(getKimType().getId());
 185  0
                                         qualifier.setGroupId(groupId);
 186  
                                 }
 187  0
                                 index++;
 188  
                 }
 189  
                 }
 190  0
         }
 191  
 
 192  
         public void initializeDocumentForNewGroup() {
 193  0
                 if(StringUtils.isBlank(this.groupId)){
 194  0
                         SequenceAccessorService sas = getSequenceAccessorService();
 195  0
                         Long nextSeq = sas.getNextAvailableSequenceNumber(
 196  
                                         KimConstants.SequenceNames.KRIM_GROUP_ID_S, this.getClass());
 197  0
                         this.groupId = nextSeq.toString();
 198  
                 }
 199  0
                 if(StringUtils.isBlank(this.groupTypeId)) {
 200  0
                         this.groupTypeId = "1";
 201  
                 }
 202  0
         }
 203  
         
 204  
         public String getGroupId(){
 205  
 //                if(StringUtils.isBlank(this.groupId)){
 206  
 //                        initializeDocumentForNewGroup();
 207  
 //                }
 208  0
                 return groupId;
 209  
         }
 210  
 
 211  
         /**
 212  
          * @param groupId the groupId to set
 213  
          */
 214  
         public void setGroupId(String groupId) {
 215  0
                 this.groupId = groupId;
 216  0
         }
 217  
 
 218  
         /**
 219  
          * @return the groupName
 220  
          */
 221  
         public String getGroupName() {
 222  0
                 return this.groupName;
 223  
         }
 224  
 
 225  
         /**
 226  
          * @param groupName the groupName to set
 227  
          */
 228  
         public void setGroupName(String groupName) {
 229  0
                 this.groupName = groupName;
 230  0
         }
 231  
 
 232  
         public String getGroupDescription() {
 233  0
                 return this.groupDescription;
 234  
         }
 235  
 
 236  
         public void setGroupDescription(String groupDescription) {
 237  0
                 this.groupDescription = groupDescription;
 238  0
         }
 239  
         
 240  
         /**
 241  
          * @return the groupNamespace
 242  
          */
 243  
         public String getGroupNamespace() {
 244  0
                 return this.groupNamespace;
 245  
         }
 246  
 
 247  
         /**
 248  
          * @param groupNamespace the groupNamespace to set
 249  
          */
 250  
         public void setGroupNamespace(String groupNamespace) {
 251  0
                 this.groupNamespace = groupNamespace;
 252  0
         }
 253  
 
 254  
         /**
 255  
          * @return the groupTypeId
 256  
          */
 257  
         public String getGroupTypeId() {
 258  0
                 return this.groupTypeId;
 259  
         }
 260  
 
 261  
         /**
 262  
          * @param groupTypeId the groupTypeId to set
 263  
          */
 264  
         public void setGroupTypeId(String groupTypeId) {
 265  0
                 this.groupTypeId = groupTypeId;
 266  0
         }
 267  
 
 268  
         /**
 269  
          * @return the groupTypeName
 270  
          */
 271  
         public String getGroupTypeName() {
 272  0
                 return this.groupTypeName;
 273  
         }
 274  
 
 275  
         /**
 276  
          * @param groupTypeName the groupTypeName to set
 277  
          */
 278  
         public void setGroupTypeName(String groupTypeName) {
 279  0
                 this.groupTypeName = groupTypeName;
 280  0
         }
 281  
 
 282  
         /**
 283  
          * @return the members
 284  
          */
 285  
         public List<GroupDocumentMember> getMembers() {
 286  0
                 return this.members;
 287  
         }
 288  
 
 289  
         /**
 290  
          * @param members the members to set
 291  
          */
 292  
         public void setMembers(List<GroupDocumentMember> members) {
 293  0
                 this.members = members;
 294  0
         }
 295  
 
 296  
         /**
 297  
          * @return the qualifiers
 298  
          */
 299  
         public List<GroupDocumentQualifier> getQualifiers() {
 300  0
                 return this.qualifiers;
 301  
         }
 302  
 
 303  
         /**
 304  
          * @param qualifiers the qualifiers to set
 305  
          */
 306  
         public void setQualifiers(List<GroupDocumentQualifier> qualifiers) {
 307  0
                 this.qualifiers = qualifiers;
 308  0
         }
 309  
 
 310  
         public GroupDocumentQualifier getQualifier(String kimAttributeDefnId) {
 311  0
                 for(GroupDocumentQualifier qualifier: qualifiers){
 312  0
                         if(qualifier.getKimAttrDefnId().equals(kimAttributeDefnId))
 313  0
                                 return qualifier;
 314  
                 }
 315  0
                 return null;
 316  
         }
 317  
 
 318  
         public Map<String, String> getQualifiersAsAttributes() {
 319  0
         Map<String, String> attributes = new HashMap<String, String>();
 320  0
                 for(GroupDocumentQualifier qualifier: qualifiers){
 321  0
                         if ( qualifier.getKimAttribute() != null ) {
 322  0
                                 attributes.put(qualifier.getKimAttribute().getAttributeName(), qualifier.getAttrVal());
 323  
                         } else {
 324  0
                                 LOG.warn( "Unknown attribute ID on group: " + qualifier.getKimAttrDefnId() + " / value=" + qualifier.getAttrVal());
 325  0
                                 attributes.put("Unknown Attribute ID: " + qualifier.getKimAttrDefnId(), qualifier.getAttrVal());
 326  
                         }
 327  
                 }
 328  0
                 return attributes;
 329  
         }
 330  
         
 331  
         public void setDefinitions(AttributeDefinitionMap definitions) {
 332  0
                 super.setDefinitions(definitions);
 333  0
                 if(getQualifiers()==null || getQualifiers().size()<1){
 334  
                         GroupDocumentQualifier qualifier;
 335  0
                         setQualifiers(new ArrayList<GroupDocumentQualifier>());
 336  0
                         if(getDefinitions()!=null){
 337  0
                                 for(String key : getDefinitions().keySet()) {
 338  0
                                         qualifier = new GroupDocumentQualifier();
 339  0
                                 qualifier.setKimAttrDefnId(getKimAttributeDefnId(getDefinitions().get(key)));
 340  0
                                 getQualifiers().add(qualifier);
 341  
                         }
 342  
                         }
 343  
                 }
 344  0
         }
 345  
 
 346  
         /**
 347  
          * @return the editing
 348  
          */
 349  
         public boolean isEditing() {
 350  0
                 return this.editing;
 351  
         }
 352  
 
 353  
         /**
 354  
          * @param editing the editing to set
 355  
          */
 356  
         public void setEditing(boolean editing) {
 357  0
                 this.editing = editing;
 358  0
         }
 359  
 
 360  
         public void setKimType(KimType kimType) {
 361  0
                 super.setKimType(kimType);
 362  0
                 if (kimType != null){
 363  0
                         setGroupTypeId(kimType.getId());
 364  0
                         setGroupTypeName(kimType.getName());
 365  
                 }
 366  0
         }
 367  
 }