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.krms.impl.repository;
17  
18  import org.kuali.rice.krad.data.jpa.PortableSequenceGenerator;
19  import org.kuali.rice.krms.api.repository.term.TermParameterDefinition;
20  import org.kuali.rice.krms.api.repository.term.TermParameterDefinitionContract;
21  
22  import javax.persistence.Column;
23  import javax.persistence.Entity;
24  import javax.persistence.GeneratedValue;
25  import javax.persistence.Id;
26  import javax.persistence.JoinColumn;
27  import javax.persistence.ManyToOne;
28  import javax.persistence.Table;
29  import javax.persistence.Version;
30  import java.io.Serializable;
31  
32  @Entity
33  @Table(name = "KRMS_TERM_PARM_T")
34  public class TermParameterBo implements TermParameterDefinitionContract, Serializable {
35  
36      private static final long serialVersionUID = 1l;
37  
38      public static final String TERM_PARM_SEQ_NAME = "KRMS_TERM_PARM_S";
39  
40      @PortableSequenceGenerator(name = TERM_PARM_SEQ_NAME)
41      @GeneratedValue(generator = TERM_PARM_SEQ_NAME)
42      @Id
43      @Column(name = "TERM_PARM_ID")
44      private String id;
45  
46      @Column(name = "NM")
47      private String name;
48  
49      @Column(name = "VAL")
50      private String value;
51  
52      @Version
53      @Column(name="VER_NBR", length=8)
54      protected Long versionNumber;
55  
56      @ManyToOne()
57      @JoinColumn(name = "TERM_ID", referencedColumnName = "TERM_ID")
58      private TermBo term;
59  
60      /**
61       * Converts a mutable bo to it's immutable counterpart
62       *
63       * @param bo the mutable business object
64       * @return the immutable object
65       */
66      public static TermParameterDefinition to(TermParameterBo bo) {
67          if (bo == null) {
68              return null;
69          }
70  
71          return TermParameterDefinition.Builder.create(bo).build();
72      }
73  
74      /**
75       * Converts a immutable object to it's mutable bo counterpart
76       *
77       * @param im immutable object
78       * @return the mutable bo
79       */
80      public static TermParameterBo from(TermParameterDefinition im) {
81          if (im == null) {
82              return null;
83          }
84  
85          TermParameterBo bo = new TermParameterBo();
86          bo.id = im.getId();
87  
88          // we don't set term here, it gets set in TermBo.from
89  
90          bo.name = im.getName();
91          bo.value = im.getValue();
92          bo.setVersionNumber(im.getVersionNumber());
93  
94          return bo;
95      }
96  
97      public String getId() {
98          return id;
99      }
100 
101     public void setId(String id) {
102         this.id = id;
103     }
104 
105     public String getTermId() {
106         if (term != null) {
107             return term.getId();
108         }
109 
110         return null;
111     }
112 
113     public String getName() {
114         return name;
115     }
116 
117     public void setName(String name) {
118         this.name = name;
119     }
120 
121     public String getValue() {
122         return value;
123     }
124 
125     public void setValue(String value) {
126         this.value = value;
127     }
128 
129     public Long getVersionNumber() {
130         return versionNumber;
131     }
132 
133     public void setVersionNumber(Long versionNumber) {
134         this.versionNumber = versionNumber;
135     }
136 
137     public TermBo getTerm() {
138         return term;
139     }
140 
141     public void setTerm(TermBo term) {
142         this.term = term;
143     }
144 }