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