001/**
002 * Copyright 2005-2014 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.kim.impl.identity.address;
017
018import javax.persistence.CascadeType;
019import javax.persistence.Column;
020import javax.persistence.Entity;
021import javax.persistence.GeneratedValue;
022import javax.persistence.Id;
023import javax.persistence.JoinColumn;
024import javax.persistence.ManyToOne;
025import javax.persistence.Table;
026
027import org.kuali.rice.kim.api.identity.address.EntityAddress;
028import org.kuali.rice.krad.data.jpa.PortableSequenceGenerator;
029
030/**
031 * @author Kuali Rice Team (rice.collab@kuali.org)
032 */
033@Entity
034@Table(name = "KRIM_ENTITY_ADDR_T")
035public class EntityAddressBo extends EntityAddressBase {
036
037    private static final long serialVersionUID = 0L;
038
039    @PortableSequenceGenerator(name = "KRIM_ENTITY_ADDR_ID_S")
040    @GeneratedValue(generator = "KRIM_ENTITY_ADDR_ID_S")
041    @Id
042    @Column(name = "ENTITY_ADDR_ID")
043    private String id;
044
045    @ManyToOne(targetEntity = EntityAddressTypeBo.class, cascade = { CascadeType.REFRESH })
046    @JoinColumn(name = "ADDR_TYP_CD", referencedColumnName = "ADDR_TYP_CD", insertable = false, updatable = false)
047    private EntityAddressTypeBo addressType;
048
049    public static EntityAddress to(EntityAddressBo bo) {
050        if (bo == null) {
051            return null;
052        }
053        return EntityAddress.Builder.create(bo).build();
054    }
055
056    /**
057     * Creates a EntityAddressBo business object from an immutable representation of a EntityAddress.
058     *
059     * @param immutable an immutable EntityAddress
060     * @return a EntityAddressBo
061     */
062    public static EntityAddressBo from(EntityAddress immutable) {
063        if (immutable == null) {
064            return null;
065        }
066        EntityAddressBo bo = new EntityAddressBo();
067        bo.setActive(immutable.isActive());
068        bo.setEntityTypeCode(immutable.getEntityTypeCode());
069        if (immutable.getAddressType() != null) {
070            bo.setAddressTypeCode(immutable.getAddressType().getCode());
071        }
072        bo.setAddressType(EntityAddressTypeBo.from(immutable.getAddressType()));
073        bo.setDefaultValue(immutable.isDefaultValue());
074        bo.setAttentionLine(immutable.getAttentionLineUnmasked());
075        bo.setLine1(immutable.getLine1Unmasked());
076        bo.setLine2(immutable.getLine2Unmasked());
077        bo.setLine3(immutable.getLine3Unmasked());
078        bo.setCity(immutable.getCityUnmasked());
079        bo.setStateProvinceCode(immutable.getStateProvinceCodeUnmasked());
080        bo.setCountryCode(immutable.getCountryCodeUnmasked());
081        bo.setPostalCode(immutable.getPostalCodeUnmasked());
082        bo.setAddressFormat(immutable.getAddressFormat());
083        bo.setModifiedDate(immutable.getModifiedDate());
084        bo.setValidatedDate(immutable.getValidatedDate());
085        bo.setValidated(immutable.isValidated());
086        bo.setNoteMessage(immutable.getNoteMessage());
087        bo.setId(immutable.getId());
088        bo.setEntityId(immutable.getEntityId());
089        bo.setActive(immutable.isActive());
090        bo.setVersionNumber(immutable.getVersionNumber());
091        return bo;
092    }
093
094    @Override
095    public EntityAddressTypeBo getAddressType() {
096        return addressType;
097    }
098
099    public void setAddressType(EntityAddressTypeBo addressType) {
100        this.addressType = addressType;
101    }
102
103    @Override
104    public String getId() {
105        return id;
106    }
107
108    public void setId(String id) {
109        this.id = id;
110    }
111}