001/** 002 * Copyright 2005-2015 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.location.impl.county; 017 018import org.kuali.rice.krad.bo.PersistableBusinessObjectBase; 019import org.kuali.rice.krad.data.jpa.converters.BooleanYNConverter; 020import org.kuali.rice.location.api.county.County; 021import org.kuali.rice.location.framework.county.CountyEbo; 022import org.kuali.rice.location.impl.country.CountryBo; 023import org.kuali.rice.location.impl.state.StateBo; 024 025import javax.persistence.Column; 026import javax.persistence.Convert; 027import javax.persistence.Entity; 028import javax.persistence.FetchType; 029import javax.persistence.Id; 030import javax.persistence.IdClass; 031import javax.persistence.JoinColumn; 032import javax.persistence.JoinColumns; 033import javax.persistence.ManyToOne; 034import javax.persistence.Table; 035 036@IdClass(CountyId.class) 037@Entity 038@Table(name = "KRLC_CNTY_T") 039public class CountyBo extends PersistableBusinessObjectBase implements CountyEbo { 040 041 private static final long serialVersionUID = -5988292910408345009L; 042 043 @Id 044 @Column(name = "COUNTY_CD") 045 private String code; 046 047 @Id 048 @Column(name = "POSTAL_CNTRY_CD") 049 private String countryCode; 050 051 @Id 052 @Column(name = "STATE_CD") 053 private String stateCode; 054 055 @Column(name = "COUNTY_NM") 056 private String name; 057 058 @Column(name = "ACTV_IND") 059 @Convert(converter = BooleanYNConverter.class) 060 private boolean active; 061 062 @ManyToOne(targetEntity = CountryBo.class, fetch = FetchType.EAGER) 063 @JoinColumn(name = "POSTAL_CNTRY_CD", insertable = false, updatable = false) 064 private CountryBo country; 065 066 @ManyToOne(targetEntity = StateBo.class, fetch = FetchType.EAGER) 067 @JoinColumns(value = { 068 @JoinColumn(name = "STATE_CD", referencedColumnName = "POSTAL_STATE_CD", insertable = false, updatable = false), 069 @JoinColumn(name = "POSTAL_CNTRY_CD", referencedColumnName = "POSTAL_CNTRY_CD", insertable = false, updatable = false) 070 }) 071 private StateBo state; 072 073 @Override 074 public String getCode() { 075 return code; 076 } 077 078 public void setCode(String code) { 079 this.code = code; 080 } 081 082 @Override 083 public String getCountryCode() { 084 return countryCode; 085 } 086 087 public void setCountryCode(String countryCode) { 088 this.countryCode = countryCode; 089 } 090 091 @Override 092 public String getStateCode() { 093 return stateCode; 094 } 095 096 public void setStateCode(String stateCode) { 097 this.stateCode = stateCode; 098 } 099 100 @Override 101 public String getName() { 102 return name; 103 } 104 105 public void setName(String name) { 106 this.name = name; 107 } 108 109 @Override 110 public boolean isActive() { 111 return active; 112 } 113 114 @Override 115 public void setActive(boolean active) { 116 this.active = active; 117 } 118 119 public CountryBo getCountry() { 120 return country; 121 } 122 123 public void setCountry(CountryBo country) { 124 this.country = country; 125 } 126 127 public StateBo getState() { 128 return state; 129 } 130 131 public void setState(StateBo state) { 132 this.state = state; 133 } 134 135 /** 136 * Converts a mutable bo to its immutable counterpart 137 * @param bo the mutable business object 138 * @return An immutable County if the passed in mutable is not null. If the mutable reference was null, 139 * then null is returned. 140 */ 141 public static County to(CountyBo bo) { 142 if (bo == null) { 143 return null; 144 } 145 146 return County.Builder.create(bo).build(); 147 } 148 149 /** 150 * Converts a immutable object to its mutable counterpart 151 * @param im immutable object 152 * @return a new mutable CountyBo if the passed in immutable is not null. If the immutable reference was null, 153 * then null is returned. 154 */ 155 public static CountyBo from(County im) { 156 if (im == null) { 157 return null; 158 } 159 160 CountyBo bo = new CountyBo(); 161 bo.code = im.getCode(); 162 bo.name = im.getName(); 163 bo.countryCode = im.getCountryCode(); 164 bo.stateCode = im.getStateCode(); 165 bo.active = im.isActive(); 166 bo.versionNumber = im.getVersionNumber(); 167 168 return bo; 169 } 170} 171