Coverage Report - org.kuali.rice.kim.api.identity.principal.Principal
 
Classes in this File Line Coverage Branch Coverage Complexity
Principal
93%
28/30
N/A
1.2
Principal$1
N/A
N/A
1.2
Principal$Builder
97%
40/41
83%
5/6
1.2
Principal$Constants
50%
1/2
N/A
1.2
Principal$Elements
0%
0/1
N/A
1.2
 
 1  
 package org.kuali.rice.kim.api.identity.principal;
 2  
 
 3  
 import java.io.Serializable;
 4  
 import java.util.Collection;
 5  
 import javax.xml.bind.annotation.XmlAccessType;
 6  
 import javax.xml.bind.annotation.XmlAccessorType;
 7  
 import javax.xml.bind.annotation.XmlAnyElement;
 8  
 import javax.xml.bind.annotation.XmlElement;
 9  
 import javax.xml.bind.annotation.XmlRootElement;
 10  
 import javax.xml.bind.annotation.XmlType;
 11  
 
 12  
 import org.apache.commons.lang.StringUtils;
 13  
 import org.apache.commons.lang.builder.EqualsBuilder;
 14  
 import org.apache.commons.lang.builder.HashCodeBuilder;
 15  
 import org.apache.commons.lang.builder.ToStringBuilder;
 16  
 import org.kuali.rice.core.api.CoreConstants;
 17  
 import org.kuali.rice.core.api.mo.ModelBuilder;
 18  
 import org.kuali.rice.core.api.mo.ModelObjectComplete;
 19  
 import org.w3c.dom.Element;
 20  
 
 21  
 @XmlRootElement(name = Principal.Constants.ROOT_ELEMENT_NAME)
 22  
 @XmlAccessorType(XmlAccessType.NONE)
 23  
 @XmlType(name = Principal.Constants.TYPE_NAME, propOrder = {
 24  
     Principal.Elements.PRINCIPAL_ID,
 25  
     Principal.Elements.PRINCIPAL_NAME,
 26  
     Principal.Elements.ENTITY_ID,
 27  
     Principal.Elements.PASSWORD,
 28  
     Principal.Elements.ACTIVE,
 29  
     CoreConstants.CommonElements.VERSION_NUMBER,
 30  
     CoreConstants.CommonElements.OBJECT_ID,
 31  
     CoreConstants.CommonElements.FUTURE_ELEMENTS
 32  
 })
 33  3
 public final class Principal
 34  
     implements ModelObjectComplete, PrincipalContract
 35  
 {
 36  
 
 37  
     @XmlElement(name = Elements.PASSWORD, required = false)
 38  
     private final String password;
 39  
     @XmlElement(name = Elements.PRINCIPAL_ID, required = false)
 40  
     private final String principalId;
 41  
     @XmlElement(name = Elements.PRINCIPAL_NAME, required = false)
 42  
     private final String principalName;
 43  
     @XmlElement(name = Elements.ENTITY_ID, required = false)
 44  
     private final String entityId;
 45  
     @XmlElement(name = Elements.ACTIVE, required = false)
 46  
     private final boolean active;
 47  
     @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
 48  
     private final Long versionNumber;
 49  
     @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false)
 50  
     private final String objectId;
 51  5
     @SuppressWarnings("unused")
 52  
     @XmlAnyElement
 53  
     private final Collection<Element> _futureElements = null;
 54  
 
 55  
     /**
 56  
      * Private constructor used only by JAXB.
 57  
      * 
 58  
      */
 59  2
     private Principal() {
 60  2
         this.password = null;
 61  2
         this.principalId = null;
 62  2
         this.principalName = null;
 63  2
         this.entityId = null;
 64  2
         this.active = false;
 65  2
         this.versionNumber = null;
 66  2
         this.objectId = null;
 67  2
     }
 68  
 
 69  3
     private Principal(Builder builder) {
 70  3
         this.password = builder.getPassword();
 71  3
         this.principalId = builder.getPrincipalId();
 72  3
         this.principalName = builder.getPrincipalName();
 73  3
         this.entityId = builder.getEntityId();
 74  3
         this.active = builder.isActive();
 75  3
         this.versionNumber = builder.getVersionNumber();
 76  3
         this.objectId = builder.getObjectId();
 77  3
     }
 78  
 
 79  
     @Override
 80  
     public String getPassword() {
 81  1
         return this.password;
 82  
     }
 83  
 
 84  
     @Override
 85  
     public String getPrincipalId() {
 86  1
         return this.principalId;
 87  
     }
 88  
 
 89  
     @Override
 90  
     public String getPrincipalName() {
 91  1
         return this.principalName;
 92  
     }
 93  
 
 94  
     @Override
 95  
     public String getEntityId() {
 96  1
         return this.entityId;
 97  
     }
 98  
 
 99  
     @Override
 100  
     public boolean isActive() {
 101  1
         return this.active;
 102  
     }
 103  
 
 104  
     @Override
 105  
     public Long getVersionNumber() {
 106  1
         return this.versionNumber;
 107  
     }
 108  
 
 109  
     @Override
 110  
     public String getObjectId() {
 111  1
         return this.objectId;
 112  
     }
 113  
 
 114  
     @Override
 115  
     public int hashCode() {
 116  0
         return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE);
 117  
     }
 118  
 
 119  
     @Override
 120  
     public boolean equals(Object object) {
 121  3
         return EqualsBuilder.reflectionEquals(object, this, Constants.HASH_CODE_EQUALS_EXCLUDE);
 122  
     }
 123  
 
 124  
     @Override
 125  
     public String toString() {
 126  0
         return ToStringBuilder.reflectionToString(this);
 127  
     }
 128  
 
 129  
 
 130  
     /**
 131  
      * A builder which can be used to construct {@link Principal} instances.  Enforces the constraints of the {@link PrincipalContract}.
 132  
      * 
 133  
      */
 134  3
     public final static class Builder
 135  
         implements Serializable, ModelBuilder, PrincipalContract
 136  
     {
 137  
 
 138  
         private String password;
 139  
         private String principalId;
 140  
         private String principalName;
 141  
         private String entityId;
 142  
         private boolean active;
 143  
         private Long versionNumber;
 144  
         private String objectId;
 145  
 
 146  5
         private Builder(String principalName) {
 147  5
             setPrincipalName(principalName);
 148  4
         }
 149  
 
 150  
         public static Builder create(String principalName) {
 151  
             // TODO modify as needed to pass any required values and add them to the signature of the 'create' method
 152  5
             return new Builder(principalName);
 153  
         }
 154  
 
 155  
         public static Builder create(PrincipalContract contract) {
 156  3
             if (contract == null) {
 157  1
                 throw new IllegalArgumentException("contract was null");
 158  
             }
 159  
             // TODO if create() is modified to accept required parameters, this will need to be modified
 160  2
             Builder builder = create(contract.getPrincipalName());
 161  2
             builder.setPassword(contract.getPassword());
 162  2
             builder.setPrincipalId(contract.getPrincipalId());
 163  2
             builder.setEntityId(contract.getEntityId());
 164  2
             builder.setActive(contract.isActive());
 165  2
             builder.setVersionNumber(contract.getVersionNumber());
 166  2
             builder.setObjectId(contract.getObjectId());
 167  2
             return builder;
 168  
         }
 169  
 
 170  
         public Principal build() {
 171  3
             return new Principal(this);
 172  
         }
 173  
 
 174  
         @Override
 175  
         public String getPassword() {
 176  3
             return this.password;
 177  
         }
 178  
 
 179  
         @Override
 180  
         public String getPrincipalId() {
 181  3
             return this.principalId;
 182  
         }
 183  
 
 184  
         @Override
 185  
         public String getPrincipalName() {
 186  3
             return this.principalName;
 187  
         }
 188  
 
 189  
         @Override
 190  
         public String getEntityId() {
 191  3
             return this.entityId;
 192  
         }
 193  
 
 194  
         @Override
 195  
         public boolean isActive() {
 196  3
             return this.active;
 197  
         }
 198  
 
 199  
         @Override
 200  
         public Long getVersionNumber() {
 201  3
             return this.versionNumber;
 202  
         }
 203  
 
 204  
         @Override
 205  
         public String getObjectId() {
 206  3
             return this.objectId;
 207  
         }
 208  
 
 209  
         public void setPassword(String password) {
 210  2
             this.password = password;
 211  2
         }
 212  
 
 213  
         public void setPrincipalId(String principalId) {
 214  2
             if (StringUtils.isWhitespace(principalId)) {
 215  0
                 throw new IllegalArgumentException("principalId is blank");
 216  
             }
 217  2
             this.principalId = principalId;
 218  2
         }
 219  
 
 220  
         public void setPrincipalName(String principalName) {
 221  5
             if (StringUtils.isEmpty(principalName)) {
 222  1
                 throw new IllegalArgumentException("principalName is blank");
 223  
             }
 224  4
             this.principalName = principalName;
 225  4
         }
 226  
 
 227  
         public void setEntityId(String entityId) {
 228  2
             this.entityId = entityId;
 229  2
         }
 230  
 
 231  
         public void setActive(boolean active) {
 232  2
             this.active = active;
 233  2
         }
 234  
 
 235  
         public void setVersionNumber(Long versionNumber) {
 236  2
             this.versionNumber = versionNumber;
 237  2
         }
 238  
 
 239  
         public void setObjectId(String objectId) {
 240  2
             this.objectId = objectId;
 241  2
         }
 242  
 
 243  
     }
 244  
 
 245  
 
 246  
     /**
 247  
      * Defines some internal constants used on this class.
 248  
      * 
 249  
      */
 250  0
     static class Constants {
 251  
 
 252  
         final static String ROOT_ELEMENT_NAME = "principal";
 253  
         final static String TYPE_NAME = "PrincipalType";
 254  1
         final static String[] HASH_CODE_EQUALS_EXCLUDE = new String[] {CoreConstants.CommonElements.FUTURE_ELEMENTS };
 255  
 
 256  
     }
 257  
 
 258  
 
 259  
     /**
 260  
      * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
 261  
      * 
 262  
      */
 263  0
     static class Elements {
 264  
 
 265  
         final static String PASSWORD = "password";
 266  
         final static String PRINCIPAL_ID = "principalId";
 267  
         final static String PRINCIPAL_NAME = "principalName";
 268  
         final static String ENTITY_ID = "entityId";
 269  
         final static String ACTIVE = "active";
 270  
 
 271  
     }
 272  
 
 273  
 }