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