Coverage Report - org.kuali.rice.location.api.campus.Campus
 
Classes in this File Line Coverage Branch Coverage Complexity
Campus
100%
30/30
100%
2/2
1.222
Campus$1
N/A
N/A
1.222
Campus$Builder
100%
41/41
100%
6/6
1.222
Campus$Cache
0%
0/1
N/A
1.222
Campus$Constants
0%
0/1
N/A
1.222
Campus$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.location.api.campus;
 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.location.api.LocationConstants;
 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  
  * An immutable representation of a {@link CampusContract}.
 35  
  *
 36  
  * <p>To construct an instance of a Campus, use the {@link Campus.Builder} class.
 37  
  *
 38  
  * @see CampusContract
 39  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 40  
  */
 41  5
 @XmlRootElement(name = Campus.Constants.ROOT_ELEMENT_NAME)
 42  
 @XmlAccessorType(XmlAccessType.NONE)
 43  
 @XmlType(name = Campus.Constants.TYPE_NAME, propOrder = {
 44  
         Campus.Elements.CODE,
 45  
         Campus.Elements.NAME,
 46  
         Campus.Elements.SHORT_NAME,
 47  
         Campus.Elements.CAMPUS_TYPE,
 48  
         Campus.Elements.ACTIVE,
 49  
         CoreConstants.CommonElements.VERSION_NUMBER,
 50  
         CoreConstants.CommonElements.OBJECT_ID,
 51  
         CoreConstants.CommonElements.FUTURE_ELEMENTS
 52  
 })
 53  4
 public final class Campus extends AbstractDataTransferObject implements CampusContract {
 54  
         private static final long serialVersionUID = 2288194493838509380L;
 55  
 
 56  
         @XmlElement(name = Elements.CODE, required=true)
 57  
         private final String code;
 58  
 
 59  
         @XmlElement(name = Elements.NAME, required=false)
 60  
         private final String name;
 61  
 
 62  
         @XmlElement(name = Elements.SHORT_NAME, required=false)
 63  
         private final String shortName;
 64  
 
 65  
         @XmlElement(name = Elements.CAMPUS_TYPE, required=false)
 66  
         private final CampusType campusType;
 67  
 
 68  
         @XmlElement(name = Elements.ACTIVE, required=false)
 69  
         private final boolean active;
 70  
 
 71  
     @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
 72  
     private final Long versionNumber;
 73  
     
 74  
         @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false)
 75  
         private final String objectId;
 76  
         
 77  7
         @SuppressWarnings("unused")
 78  
     @XmlAnyElement
 79  
     private final Collection<Element> _futureElements = null;
 80  
         
 81  
         
 82  
          /** 
 83  
      * This constructor should never be called.  It is only present for use during JAXB unmarshalling. 
 84  
      */
 85  
     @SuppressWarnings("unused")
 86  3
     private Campus() {
 87  3
             this.code = null;
 88  3
             this.name = null;
 89  3
             this.shortName = null;
 90  3
             this.campusType = null;
 91  3
             this.active = false;
 92  3
         this.versionNumber = null;
 93  3
         this.objectId = null;
 94  3
     }
 95  
     
 96  
     /**
 97  
          * Constructs a Campus from the given builder.  This constructor is private and should only
 98  
          * ever be invoked from the builder.
 99  
          * 
 100  
          * @param builder the Builder from which to construct the campus
 101  
          */
 102  4
     private Campus(Builder builder) {
 103  4
         this.code = builder.getCode();
 104  4
         this.name = builder.getName();
 105  4
         this.shortName = builder.getShortName();
 106  4
         if (builder.campusType != null) {
 107  2
                 this.campusType = builder.getCampusType().build();
 108  
         } else {
 109  2
             this.campusType = null;
 110  
         }
 111  4
         this.active = builder.isActive();
 112  4
         this.versionNumber = builder.getVersionNumber();
 113  4
         this.objectId = builder.getObjectId();
 114  4
     }
 115  
 
 116  
         /** {@inheritDoc} */
 117  
         @Override
 118  
         public String getCode() {
 119  1
                 return this.code;
 120  
         }
 121  
 
 122  
         /** {@inheritDoc} */
 123  
         @Override
 124  
         public String getName() {
 125  1
                 return this.name;
 126  
         }
 127  
 
 128  
         /** {@inheritDoc} */
 129  
         @Override
 130  
         public String getShortName() {
 131  1
                 return this.shortName;
 132  
         }
 133  
 
 134  
         /** {@inheritDoc} */
 135  
         @Override
 136  
         public CampusType getCampusType() {
 137  5
                 return this.campusType;
 138  
         }
 139  
 
 140  
         /** {@inheritDoc} */
 141  
         @Override
 142  
         public boolean isActive() {
 143  1
                 return this.active;
 144  
         }
 145  
 
 146  
     /** {@inheritDoc} */
 147  
     @Override
 148  
     public Long getVersionNumber() {
 149  1
         return versionNumber;
 150  
     }
 151  
         
 152  
         /** {@inheritDoc} */
 153  
         @Override
 154  
         public String getObjectId() {
 155  1
                 return objectId;
 156  
         }
 157  
 
 158  
         /**
 159  
      * This builder is used to construct instances of Campus.  It enforces the constraints of the {@link CampusContract}.
 160  
      */
 161  9
     public static class Builder implements CampusContract, ModelBuilder, Serializable {
 162  
                 private static final long serialVersionUID = -3130728718673871762L;
 163  
                 private String code;
 164  
         private String name;
 165  
         private String shortName;
 166  
         private CampusType.Builder campusType;
 167  
         private boolean active;
 168  
         private Long versionNumber;
 169  
         private String objectId;
 170  
 
 171  
                 /**
 172  
                  * Private constructor for creating a builder with all of it's required attributes.
 173  
                  */
 174  6
         private Builder(String code) {
 175  6
             setCode(code);
 176  5
                         setActive(true);
 177  5
         }
 178  
 
 179  
         /**
 180  
          * Creates a builder from the given campus code.
 181  
          * 
 182  
          * @param code the campus code
 183  
          * @return an instance of the builder with the code already populated
 184  
          * @throws IllegalArgumentException if the code is null or blank
 185  
          */
 186  
         public static Builder create(String code) {
 187  3
             return new Builder(code);
 188  
         }
 189  
 
 190  
         /**
 191  
          * Creates a builder by populating it with data from the given {@link CampusContract}.
 192  
          * 
 193  
          * @param contract the contract from which to populate this builder
 194  
          * @return an instance of the builder populated with data from the contract
 195  
          */
 196  
         public static Builder create(CampusContract contract) {
 197  4
                 if (contract == null) {
 198  1
                 throw new IllegalArgumentException("contract is null");
 199  
             }
 200  3
             Builder builder =  new Builder(contract.getCode());
 201  3
             builder.setName(contract.getName());
 202  3
             builder.setShortName(contract.getShortName());
 203  3
             if (contract.getCampusType() != null) {
 204  2
                     builder.setCampusType(CampusType.Builder.create(contract.getCampusType()));
 205  
             }
 206  3
             builder.setActive(contract.isActive());
 207  3
             builder.setVersionNumber(contract.getVersionNumber());
 208  3
             builder.setObjectId(contract.getObjectId());
 209  3
             return builder;
 210  
         }
 211  
 
 212  
                 /**
 213  
                  * Sets the value of the code on this builder to the given value.
 214  
                  * 
 215  
                  * @param code the code value to set, must not be null or blank
 216  
                  * @throws IllegalArgumentException if the code is null or blank
 217  
                  */
 218  
         public void setCode(String code) {
 219  6
             if (StringUtils.isBlank(code)) {
 220  1
                 throw new IllegalArgumentException("code is blank");
 221  
             }
 222  5
             this.code = code;
 223  5
         }
 224  
 
 225  
                 public void setName(String name) {
 226  3
                         this.name = name;
 227  3
                 }
 228  
                 
 229  
                 public void setShortName(String shortName) {
 230  3
                         this.shortName = shortName;
 231  3
                 }
 232  
                 
 233  
                 public void setCampusType(CampusType.Builder campusType) {
 234  2
                         this.campusType = campusType;
 235  2
                 }
 236  
 
 237  
                 public void setActive(boolean active) {
 238  8
                         this.active = active;
 239  8
                 }
 240  
 
 241  
         public void setVersionNumber(Long versionNumber){
 242  3
             this.versionNumber = versionNumber;
 243  3
         }
 244  
         
 245  
         public void setObjectId(String objectId) {
 246  3
                 this.objectId = objectId;
 247  3
         }
 248  
 
 249  
                 @Override
 250  
                 public String getCode() {
 251  5
                         return code;
 252  
                 }
 253  
 
 254  
                 @Override
 255  
                 public String getName() {
 256  5
                         return name;
 257  
                 }
 258  
                 
 259  
                 @Override
 260  
                 public String getShortName() {
 261  5
                         return shortName;
 262  
                 }
 263  
                 
 264  
                 @Override 
 265  
                 public CampusType.Builder getCampusType() {
 266  3
                         return campusType;
 267  
                 }
 268  
                 
 269  
                 @Override
 270  
                 public boolean isActive() {
 271  5
                         return active;
 272  
                 }
 273  
 
 274  
         @Override
 275  
         public Long getVersionNumber() {
 276  5
             return versionNumber;
 277  
         }
 278  
 
 279  
         @Override
 280  
             public String getObjectId() {
 281  5
                     return objectId;
 282  
             }
 283  
 
 284  
                 /**
 285  
                  * Builds an instance of a Campus based on the current state of the builder.
 286  
                  * 
 287  
                  * @return the fully-constructed Campus
 288  
                  */
 289  
         @Override
 290  
         public Campus build() {
 291  4
             return new Campus(this);
 292  
         }
 293  
                 
 294  
     }
 295  
 
 296  
         /**
 297  
          * Defines some internal constants used on this class.
 298  
          */
 299  0
         static class Constants {
 300  
                 final static String ROOT_ELEMENT_NAME = "campus";
 301  
                 final static String TYPE_NAME = "CampusType";
 302  
         }
 303  
         
 304  
         /**
 305  
      * A private class which exposes constants which define the XML element names to use
 306  
      * when this object is marshalled to XML.
 307  
      */
 308  0
     static class Elements {
 309  
         final static String CODE = "code";
 310  
         final static String NAME = "name";
 311  
         final static String SHORT_NAME = "shortName";
 312  
         final static String CAMPUS_TYPE = "campusType";
 313  
         final static String ACTIVE = "active";
 314  
     }
 315  
 
 316  0
     public static class Cache {
 317  
         public static final String NAME = LocationConstants.Namespaces.LOCATION_NAMESPACE_2_0 + "/" + Campus.Constants.TYPE_NAME;
 318  
     }
 319  
 }