001/**
002 * Copyright 2005-2016 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.country;
017
018import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
019import org.kuali.rice.krad.data.jpa.converters.BooleanYNConverter;
020import org.kuali.rice.location.api.country.Country;
021import org.kuali.rice.location.framework.country.CountryEbo;
022
023import javax.persistence.Column;
024import javax.persistence.Convert;
025import javax.persistence.Entity;
026import javax.persistence.Id;
027import javax.persistence.Table;
028
029@Entity
030@Table(name = "KRLC_CNTRY_T")
031public class CountryBo extends PersistableBusinessObjectBase implements CountryEbo {
032
033    private static final long serialVersionUID = 5725250018402409870L;
034
035    @Id
036    @Column(name = "POSTAL_CNTRY_CD")
037    private String code;
038
039    @Column(name = "ALT_POSTAL_CNTRY_CD")
040    private String alternateCode;
041
042    @Column(name = "POSTAL_CNTRY_NM")
043    private String name;
044
045    @Column(name = "PSTL_CNTRY_RSTRC_IND")
046    @Convert(converter = BooleanYNConverter.class)
047    private boolean restricted;
048
049    @Column(name = "ACTV_IND")
050    @Convert(converter = BooleanYNConverter.class)
051    private boolean active;
052
053    @Override
054    public String getCode() {
055        return code;
056    }
057
058    public void setCode(String code) {
059        this.code = code;
060    }
061
062    @Override
063    public String getAlternateCode() {
064        return alternateCode;
065    }
066
067    public void setAlternateCode(String alternateCode) {
068        this.alternateCode = alternateCode;
069    }
070
071    @Override
072    public String getName() {
073        return name;
074    }
075
076    public void setName(String name) {
077        this.name = name;
078    }
079
080    @Override
081    public boolean isRestricted() {
082        return restricted;
083    }
084
085    public void setRestricted(boolean restricted) {
086        this.restricted = restricted;
087    }
088
089    @Override
090    public boolean isActive() {
091        return active;
092    }
093
094    @Override
095    public void setActive(boolean active) {
096        this.active = active;
097    }
098
099    /**
100     * Converts a mutable CountryBo to an immutable Country representation.
101     * @param bo
102     * @return an immutable Country
103     */
104    public static Country to(CountryBo bo) {
105        if (bo == null) {
106            return null;
107        }
108        return Country.Builder.create(bo).build();
109    }
110
111    /**
112     * Creates a CountryBo business object from an immutable representation of a Country.
113     * @param immutable an immutable Country
114     * @return a CountryBo
115     */
116    public static CountryBo from(Country immutable) {
117        if (immutable == null) {
118            return null;
119        }
120
121        CountryBo bo = new CountryBo();
122        bo.code = immutable.getCode();
123        bo.alternateCode = immutable.getAlternateCode();
124        bo.name = immutable.getName();
125        bo.restricted = immutable.isRestricted();
126        bo.active = immutable.isActive();
127        bo.versionNumber = immutable.getVersionNumber();
128
129        return bo;
130    }
131}