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