Coverage Report - org.kuali.rice.shareddata.impl.state.StateBo
 
Classes in this File Line Coverage Branch Coverage Complexity
StateBo
91%
11/12
75%
3/4
0
 
 1  
 /*
 2  
  * Copyright 2006-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  
 
 17  
 package org.kuali.rice.shareddata.impl.state
 18  
 
 19  
 import javax.persistence.Column
 20  
 import javax.persistence.Entity
 21  
 import javax.persistence.FetchType
 22  
 import javax.persistence.Id
 23  
 import javax.persistence.IdClass
 24  
 import javax.persistence.JoinColumn
 25  
 import javax.persistence.ManyToOne
 26  
 import javax.persistence.Table
 27  
 import org.hibernate.annotations.Type
 28  
 import org.kuali.rice.krad.bo.MutableInactivatable
 29  
 import org.kuali.rice.krad.bo.PersistableBusinessObjectBase
 30  
 import org.kuali.rice.shareddata.api.state.State
 31  
 import org.kuali.rice.shareddata.api.state.StateContract
 32  
 import org.kuali.rice.shareddata.impl.country.CountryBo
 33  
 
 34  
 @IdClass(StateId.class)
 35  
 @Entity
 36  
 @Table(name = "KRLC_ST_T")
 37  
 class StateBo extends PersistableBusinessObjectBase implements StateContract, MutableInactivatable {
 38  
 
 39  
     @Id
 40  
     @Column(name = "POSTAL_STATE_CD")
 41  
     def String code;
 42  
 
 43  
     @Id
 44  
     @Column(name = "POSTAL_CNTRY_CD")
 45  
     def String countryCode;
 46  
 
 47  
     @Column(name = "POSTAL_STATE_NM")
 48  
     def String name;
 49  
 
 50  
     @Type(type = "yes_no")
 51  
     @Column(name = "ACTV_IND")
 52  
     def boolean active;
 53  
 
 54  
     @ManyToOne(targetEntity = CountryBo.class, fetch = FetchType.EAGER)
 55  
     @JoinColumn(name = "POSTAL_CNTRY_CD", insertable = false, updatable = false)
 56  
     def CountryBo country;
 57  
 
 58  
     /**
 59  
      * Converts a mutable bo to its immutable counterpart
 60  
      * @param bo the mutable business object
 61  
      * @return An immutable State if the passed in mutable is not null.  If the mutable reference was null, then null
 62  
      * is returned.
 63  
      */
 64  
     static State to(StateBo bo) {
 65  9
         if (bo == null) {
 66  5
             return null
 67  
         }
 68  
 
 69  4
         return State.Builder.create(bo).build();
 70  
     }
 71  
 
 72  
     /**
 73  
      * Converts a immutable object to its mutable counterpart
 74  
      * @param im immutable object
 75  
      * @return a new mutable CountryBo if the passed in immutable is not null.  If the immutable reference was null,
 76  
      * then null is returned.
 77  
      */
 78  
     static StateBo from(State im) {
 79  1
         if (im == null) {
 80  0
             return null
 81  
         }
 82  
 
 83  1
         StateBo bo = new StateBo()
 84  1
         bo.code = im.code
 85  1
         bo.countryCode = im.countryCode
 86  1
         bo.name = im.name
 87  1
         bo.active = im.active
 88  1
         bo.versionNumber = im.versionNumber
 89  
 
 90  1
         return bo
 91  
     }
 92  
 }