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