View Javadoc
1   /**
2    * Copyright 2005-2014 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  package org.kuali.rice.kim.impl.identity.address;
17  
18  import javax.persistence.CascadeType;
19  import javax.persistence.Column;
20  import javax.persistence.Entity;
21  import javax.persistence.GeneratedValue;
22  import javax.persistence.Id;
23  import javax.persistence.JoinColumn;
24  import javax.persistence.ManyToOne;
25  import javax.persistence.Table;
26  
27  import org.kuali.rice.kim.api.identity.address.EntityAddress;
28  import org.kuali.rice.krad.data.jpa.PortableSequenceGenerator;
29  
30  /**
31   * @author Kuali Rice Team (rice.collab@kuali.org)
32   */
33  @Entity
34  @Table(name = "KRIM_ENTITY_ADDR_T")
35  public class EntityAddressBo extends EntityAddressBase {
36  
37      private static final long serialVersionUID = 0L;
38  
39      @PortableSequenceGenerator(name = "KRIM_ENTITY_ADDR_ID_S")
40      @GeneratedValue(generator = "KRIM_ENTITY_ADDR_ID_S")
41      @Id
42      @Column(name = "ENTITY_ADDR_ID")
43      private String id;
44  
45      @ManyToOne(targetEntity = EntityAddressTypeBo.class, cascade = { CascadeType.REFRESH })
46      @JoinColumn(name = "ADDR_TYP_CD", referencedColumnName = "ADDR_TYP_CD", insertable = false, updatable = false)
47      private EntityAddressTypeBo addressType;
48  
49      public static EntityAddress to(EntityAddressBo bo) {
50          if (bo == null) {
51              return null;
52          }
53          return EntityAddress.Builder.create(bo).build();
54      }
55  
56      /**
57       * Creates a EntityAddressBo business object from an immutable representation of a EntityAddress.
58       *
59       * @param immutable an immutable EntityAddress
60       * @return a EntityAddressBo
61       */
62      public static EntityAddressBo from(EntityAddress immutable) {
63          if (immutable == null) {
64              return null;
65          }
66          EntityAddressBo bo = new EntityAddressBo();
67          bo.setActive(immutable.isActive());
68          bo.setEntityTypeCode(immutable.getEntityTypeCode());
69          if (immutable.getAddressType() != null) {
70              bo.setAddressTypeCode(immutable.getAddressType().getCode());
71          }
72          bo.setAddressType(EntityAddressTypeBo.from(immutable.getAddressType()));
73          bo.setDefaultValue(immutable.isDefaultValue());
74          bo.setAttentionLine(immutable.getAttentionLineUnmasked());
75          bo.setLine1(immutable.getLine1Unmasked());
76          bo.setLine2(immutable.getLine2Unmasked());
77          bo.setLine3(immutable.getLine3Unmasked());
78          bo.setCity(immutable.getCityUnmasked());
79          bo.setStateProvinceCode(immutable.getStateProvinceCodeUnmasked());
80          bo.setCountryCode(immutable.getCountryCodeUnmasked());
81          bo.setPostalCode(immutable.getPostalCodeUnmasked());
82          bo.setAddressFormat(immutable.getAddressFormat());
83          bo.setModifiedDate(immutable.getModifiedDate());
84          bo.setValidatedDate(immutable.getValidatedDate());
85          bo.setValidated(immutable.isValidated());
86          bo.setNoteMessage(immutable.getNoteMessage());
87          bo.setId(immutable.getId());
88          bo.setEntityId(immutable.getEntityId());
89          bo.setActive(immutable.isActive());
90          bo.setVersionNumber(immutable.getVersionNumber());
91          return bo;
92      }
93  
94      @Override
95      public EntityAddressTypeBo getAddressType() {
96          return addressType;
97      }
98  
99      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 }