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;
17  
18  import javax.persistence.Column;
19  import javax.persistence.Id;
20  import javax.persistence.MappedSuperclass;
21  
22  import org.kuali.rice.kim.api.identity.CodedAttribute;
23  import org.kuali.rice.kim.api.identity.CodedAttributeContract;
24  import org.kuali.rice.krad.bo.DataObjectBase;
25  import org.kuali.rice.krad.data.jpa.converters.BooleanYNConverter;
26  
27  @MappedSuperclass
28  public abstract class CodedAttributeBo extends DataObjectBase implements CodedAttributeContract {
29      private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(CodedAttributeBo.class);
30      private static final long serialVersionUID = -5023039880648352464L;
31      @Id
32      @Column(name = "CD")
33      private String code;
34      @Column(name = "NM")
35      private String name;
36      @javax.persistence.Convert(converter=BooleanYNConverter.class)
37      @Column(name = "ACTV_IND")
38      private boolean active;
39      @Column(name = "DISPLAY_SORT_CD")
40      private String sortCode;
41  
42      /**
43       * Converts a mutable extension CodedAttributeBo to an immutable CodedAttribute representation.
44       *
45       * @param bo
46       * @return an immutable EntityCitizenshipChangeType
47       */
48      public static <T extends CodedAttributeBo>CodedAttribute to(T bo) {
49          if (bo == null) {
50              return null;
51          }
52  
53          return CodedAttribute.Builder.create(bo).build();
54      }
55  
56      /**
57       * Creates a EntityCitizenshipChangeTypeBo business object from an immutable representation of a
58       * EntityCitizenshipChangeType.
59       *
60       * @param immutable an immutable CodedAttribute
61       * @return an object extending from CodedAttributeBo
62       */
63      public static <T extends CodedAttributeBo> T from(Class<T> type, CodedAttribute immutable) {
64          if (immutable == null) {
65              return null;
66          }
67          T bo = null;
68          try {
69              bo = type.newInstance();
70  
71              bo.setCode(immutable.getCode());
72              bo.setName(immutable.getName());
73              bo.setSortCode(immutable.getSortCode());
74              bo.setActive(immutable.isActive());
75              bo.setVersionNumber(immutable.getVersionNumber());
76              bo.setObjectId(immutable.getObjectId());
77          } catch (InstantiationException e) {
78              LOG.error(e.getMessage(), e);
79          } catch (IllegalAccessException e) {
80              LOG.error(e.getMessage(), e);
81          }
82          return bo;
83      }
84  
85      @Override
86      public String getCode() {
87          return code;
88      }
89  
90      public void setCode(String code) {
91          this.code = code;
92      }
93  
94      @Override
95      public String getName() {
96          return name;
97      }
98  
99      public void setName(String name) {
100         this.name = name;
101     }
102 
103     @Override
104     public boolean isActive() {
105         return active;
106     }
107 
108     public void setActive(boolean active) {
109         this.active = active;
110     }
111 
112     @Override
113     public String getSortCode() {
114         return sortCode;
115     }
116 
117     public void setSortCode(String sortCode) {
118         this.sortCode = sortCode;
119     }
120 
121     public void refresh() {
122     }
123 
124 }