Coverage Report - org.kuali.rice.kim.web.struts.form.IdentityManagementRoleDocumentForm
 
Classes in this File Line Coverage Branch Coverage Complexity
IdentityManagementRoleDocumentForm
0%
0/100
0%
0/40
2.062
 
 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.web.struts.form;
 17  
 
 18  
 import org.apache.commons.lang.StringUtils;
 19  
 import org.kuali.rice.core.api.membership.MemberType;
 20  
 import org.kuali.rice.core.web.format.DateDisplayTimestampObjectFormatter;
 21  
 import org.kuali.rice.kim.api.KimConstants;
 22  
 import org.kuali.rice.kim.api.type.KimType;
 23  
 import org.kuali.rice.kim.bo.ui.KimDocumentRoleMember;
 24  
 import org.kuali.rice.kim.bo.ui.KimDocumentRolePermission;
 25  
 import org.kuali.rice.kim.bo.ui.KimDocumentRoleQualifier;
 26  
 import org.kuali.rice.kim.bo.ui.KimDocumentRoleResponsibility;
 27  
 import org.kuali.rice.kim.bo.ui.RoleDocumentDelegationMember;
 28  
 import org.kuali.rice.kim.bo.ui.RoleDocumentDelegationMemberQualifier;
 29  
 import org.kuali.rice.kim.document.IdentityManagementRoleDocument;
 30  
 import org.kuali.rice.kim.impl.group.GroupBo;
 31  
 import org.kuali.rice.kim.impl.identity.PersonImpl;
 32  
 import org.kuali.rice.kim.impl.role.RoleBo;
 33  
 import org.kuali.rice.kns.util.TableRenderUtil;
 34  
 
 35  
 import java.util.List;
 36  
 
 37  
 /**
 38  
  * This is a description of what this class does - shyu don't forget to fill this in. 
 39  
  * 
 40  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 41  
  *
 42  
  */
 43  
 public class IdentityManagementRoleDocumentForm extends IdentityManagementDocumentFormBase {
 44  
         protected static final long serialVersionUID = 7099079353241080483L;
 45  
         {
 46  0
                 requiredNonEditableProperties.add("methodToCall");
 47  0
                 requiredNonEditableProperties.add("roleCommand");
 48  
         }
 49  
         
 50  
         protected String delegationMemberRoleMemberId;
 51  
         protected String dmrmi;
 52  0
         protected boolean canAssignRole = true;
 53  0
         protected boolean canModifyAssignees = true;
 54  
         protected KimType kimType;
 55  
         protected KimDocumentRoleMember member;
 56  
         {
 57  0
                 member = new KimDocumentRoleMember();
 58  0
                 member.getQualifiers().add(new KimDocumentRoleQualifier());
 59  
         }
 60  
         protected KimDocumentRolePermission permission;
 61  
         protected KimDocumentRoleResponsibility responsibility;
 62  
         protected RoleDocumentDelegationMember delegationMember;
 63  
         {
 64  0
                 delegationMember = new RoleDocumentDelegationMember();
 65  0
                 delegationMember.getQualifiers().add(new RoleDocumentDelegationMemberQualifier());
 66  
         }
 67  
         protected String roleId;
 68  
 
 69  
 
 70  
         public IdentityManagementRoleDocumentForm() {
 71  0
         super();
 72  0
         setFormatterType("document.members.activeFromDate", DateDisplayTimestampObjectFormatter.class);
 73  0
         setFormatterType("document.delegationMembers.activeFromDate", DateDisplayTimestampObjectFormatter.class);
 74  0
         setFormatterType("document.members.activeToDate", DateDisplayTimestampObjectFormatter.class);
 75  0
         setFormatterType("document.delegationMembers.activeToDate", DateDisplayTimestampObjectFormatter.class);
 76  0
     }
 77  
         
 78  
     /**
 79  
          * @return the delegationMember
 80  
          */
 81  
         public RoleDocumentDelegationMember getDelegationMember() {
 82  0
                 return this.delegationMember;
 83  
         }
 84  
 
 85  
         /**
 86  
          * @param delegationMember the delegationMember to set
 87  
          */
 88  
         public void setDelegationMember(RoleDocumentDelegationMember delegationMember) {
 89  0
                 this.delegationMember = delegationMember;
 90  0
         }
 91  
 
 92  
         @Override
 93  
         public String getDefaultDocumentTypeName(){
 94  0
                 return "IdentityManagementRoleDocument";
 95  
         }
 96  
         
 97  
         public IdentityManagementRoleDocument getRoleDocument() {
 98  0
         return (IdentityManagementRoleDocument) this.getDocument();
 99  
     }
 100  
 
 101  
         /**
 102  
          * @return the member
 103  
          */
 104  
         public KimDocumentRoleMember getMember() {
 105  0
                 return this.member;
 106  
         }
 107  
 
 108  
         /**
 109  
          * @param member the member to set
 110  
          */
 111  
         public void setMember(KimDocumentRoleMember member) {
 112  0
                 this.member = member;
 113  0
         }
 114  
 
 115  
         /**
 116  
          * @return the permission
 117  
          */
 118  
         public KimDocumentRolePermission getPermission() {
 119  0
                 return this.permission;
 120  
         }
 121  
 
 122  
         /**
 123  
          * @param permission the permission to set
 124  
          */
 125  
         public void setPermission(KimDocumentRolePermission permission) {
 126  0
                 this.permission = permission;
 127  0
         }
 128  
 
 129  
         /**
 130  
          * @return the responsibility
 131  
          */
 132  
         public KimDocumentRoleResponsibility getResponsibility() {
 133  0
                 return this.responsibility;
 134  
         }
 135  
 
 136  
         /**
 137  
          * @param responsibility the responsibility to set
 138  
          */
 139  
         public void setResponsibility(KimDocumentRoleResponsibility responsibility) {
 140  0
                 this.responsibility = responsibility;
 141  0
         }
 142  
 
 143  
         public String getMemberFieldConversions(){
 144  0
                 if(member==null) {
 145  0
                         return "";
 146  
         }
 147  0
                 return getMemberFieldConversions(member.getMemberTypeCode());
 148  
         }
 149  
 
 150  
         public String getMemberBusinessObjectName(){
 151  0
                 if(member==null) {
 152  0
                         return "";
 153  
         }
 154  0
                 return getMemberBusinessObjectName(member.getMemberTypeCode());
 155  
         }
 156  
 
 157  
         public String getDelegationMemberFieldConversions(){
 158  0
                 if(getDelegationMember()==null) {
 159  0
                         return "";
 160  
         }
 161  0
                 String memberTypeCode = getDelegationMember().getMemberTypeCode();
 162  0
                 if(MemberType.PRINCIPAL.getCode().equals(memberTypeCode)) {
 163  0
                         return "principalId:delegationMember.memberId,principalName:delegationMember.memberName";
 164  
         }
 165  0
                 else if(MemberType.ROLE.getCode().equals(memberTypeCode)) {
 166  0
                         return "roleId:delegationMember.memberId,roleName:delegationMember.memberName,namespaceCode:delegationMember.memberNamespaceCode";
 167  
         }
 168  0
                 else if(MemberType.GROUP.getCode().equals(memberTypeCode)) {
 169  0
                         return "groupId:delegationMember.memberId,groupName:delegationMember.memberName,namespaceCode:delegationMember.memberNamespaceCode";
 170  
         }
 171  0
                 return "";
 172  
         }
 173  
 
 174  
         public String getDelegationMemberBusinessObjectName(){
 175  0
                 if(getDelegationMember()==null) {
 176  0
                         return "";
 177  
         }
 178  0
                 return getMemberBusinessObjectName(getDelegationMember().getMemberTypeCode());
 179  
         }
 180  
 
 181  
         protected String getMemberFieldConversions(String memberTypeCode){
 182  0
                 if(MemberType.PRINCIPAL.getCode().equals(memberTypeCode)) {
 183  0
                         return "principalId:member.memberId,principalName:member.memberName";
 184  
         }
 185  0
                 else if(MemberType.ROLE.getCode().equals(memberTypeCode)) {
 186  0
                         return "roleId:member.memberId,roleName:member.memberName,namespaceCode:member.memberNamespaceCode";
 187  
         }
 188  0
                 else if(MemberType.GROUP.getCode().equals(memberTypeCode)) {
 189  0
                         return "groupId:member.memberId,groupName:member.memberName,namespaceCode:member.memberNamespaceCode";
 190  
         }
 191  0
                 return "";
 192  
         }
 193  
 
 194  
         protected String getMemberBusinessObjectName(String memberTypeCode){
 195  0
                 if(MemberType.PRINCIPAL.getCode().equals(memberTypeCode)) {
 196  0
                         return PersonImpl.class.getName();
 197  
         }
 198  0
                 else if(MemberType.ROLE.getCode().equals(memberTypeCode)) {
 199  0
                         return RoleBo.class.getName();
 200  
         }
 201  0
                 else if(MemberType.GROUP.getCode().equals(memberTypeCode)) {
 202  0
                         return GroupBo.class.getName();
 203  
         }
 204  0
                 return "";
 205  
         }
 206  
 
 207  
         /**
 208  
          * @return the kimType
 209  
          */
 210  
         public KimType getKimType() {
 211  0
                 return this.kimType;
 212  
         }
 213  
 
 214  
         /**
 215  
          * @param kimType the kimType to set
 216  
          */
 217  
         public void setKimType(KimType kimType) {
 218  0
                 this.kimType = kimType;
 219  0
                 if ( kimType != null && getRoleDocument() != null ) {
 220  0
                         getRoleDocument().setKimType(kimType);
 221  
                 }
 222  0
         }
 223  
 
 224  
         /**
 225  
          * @return the canAssignRole
 226  
          */
 227  
         public boolean isCanAssignRole() {
 228  0
                 return this.canAssignRole;
 229  
         }
 230  
 
 231  
         /**
 232  
          * @param canAssignRole the canAssignRole to set
 233  
          */
 234  
         public void setCanAssignRole(boolean canAssignRole) {
 235  0
                 this.canAssignRole = canAssignRole;
 236  0
         }
 237  
 
 238  
         /**
 239  
          * @return the canModifyAssignees
 240  
          */
 241  
         public boolean isCanModifyAssignees() {
 242  0
                 return this.canModifyAssignees;
 243  
         }
 244  
 
 245  
         /**
 246  
          * @param canModifyAssignees the canModifyAssignees to set
 247  
          */
 248  
         public void setCanModifyAssignees(boolean canModifyAssignees) {
 249  0
                 this.canModifyAssignees = canModifyAssignees;
 250  0
         }
 251  
         
 252  
         public List<KimDocumentRoleMember> getMemberRows() {
 253  0
                 return getRoleDocument().getMembers();
 254  
         }
 255  
 
 256  
         public int getIndexOfRoleMemberFromMemberRows(String roleMemberId){
 257  0
                 int index = 0;
 258  0
                 for(KimDocumentRoleMember roleMember: getMemberRows()){
 259  0
                         if(StringUtils.equals(roleMember.getRoleMemberId(), roleMemberId)){
 260  0
                                 break;
 261  
                         }
 262  0
                         index++;
 263  
                 }
 264  0
                 return index;
 265  
         }
 266  
 
 267  
         public int getPageNumberOfRoleMemberId(String roleMemberId){
 268  0
                 if(StringUtils.isEmpty(roleMemberId)) {return 1;}
 269  0
                 int index = getIndexOfRoleMemberFromMemberRows(roleMemberId);
 270  0
                 return TableRenderUtil.computeTotalNumberOfPages(index + 1, getRecordsPerPage())-1;
 271  
         }
 272  
         
 273  
         /**
 274  
          * @return the roleId
 275  
          */
 276  
         public String getRoleId() {
 277  0
                 return this.roleId;
 278  
         }
 279  
 
 280  
         /**
 281  
          * @param roleId the roleId to set
 282  
          */
 283  
         public void setRoleId(String roleId) {
 284  0
                 this.roleId = roleId;
 285  0
         }
 286  
 
 287  
         /**
 288  
          * @return the delegationMemberRoleMemberId
 289  
          */
 290  
         public String getDelegationMemberRoleMemberId() {
 291  0
                 return this.delegationMemberRoleMemberId;
 292  
         }
 293  
 
 294  
         /**
 295  
          * @param delegationMemberRoleMemberId the delegationMemberRoleMemberId to set
 296  
          */
 297  
         public void setDelegationMemberRoleMemberId(String delegationMemberRoleMemberId) {
 298  0
                 this.delegationMemberRoleMemberId = delegationMemberRoleMemberId;
 299  0
                 getDelegationMember().setRoleMemberId(delegationMemberRoleMemberId);
 300  0
                 KimDocumentRoleMember roleMember = getRoleDocument().getMember(delegationMemberRoleMemberId);
 301  0
                 if(roleMember!=null){
 302  0
                         delegationMember.setRoleMemberId(roleMember.getRoleMemberId());
 303  0
                         delegationMember.setRoleMemberName(roleMember.getMemberName());
 304  0
                         delegationMember.setRoleMemberNamespaceCode(roleMember.getMemberNamespaceCode());
 305  
                         RoleDocumentDelegationMemberQualifier delegationMemberQualifier;
 306  0
                         for(KimDocumentRoleQualifier roleQualifier: roleMember.getQualifiers()){
 307  0
                                 delegationMemberQualifier = getDelegationMember().getQualifier(roleQualifier.getKimAttrDefnId());
 308  0
                                 delegationMemberQualifier.setAttrVal(roleQualifier.getAttrVal());
 309  
                         }
 310  
                 }
 311  0
         }
 312  
 
 313  
         /**
 314  
          * @return the dmrmi
 315  
          */
 316  
         public String getDmrmi() {
 317  0
                 return this.dmrmi;
 318  
         }
 319  
 
 320  
         /**
 321  
          * @param dmrmi the dmrmi to set
 322  
          */
 323  
         public void setDmrmi(String dmrmi) {
 324  0
                 this.dmrmi = dmrmi;
 325  0
         }
 326  
 
 327  
 }