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.krms.impl.repository;
17  
18  import org.kuali.rice.krad.data.jpa.PortableSequenceGenerator;
19  import org.kuali.rice.krms.api.repository.proposition.PropositionParameter;
20  import org.kuali.rice.krms.api.repository.proposition.PropositionParameterContract;
21  import org.kuali.rice.krms.api.repository.term.TermDefinition;
22  
23  import javax.persistence.CascadeType;
24  import javax.persistence.Column;
25  import javax.persistence.Entity;
26  import javax.persistence.FetchType;
27  import javax.persistence.GeneratedValue;
28  import javax.persistence.Id;
29  import javax.persistence.JoinColumn;
30  import javax.persistence.ManyToOne;
31  import javax.persistence.Table;
32  import javax.persistence.Transient;
33  import javax.persistence.Version;
34  import java.io.Serializable;
35  import java.util.ArrayList;
36  import java.util.Collections;
37  import java.util.List;
38  
39  @Entity
40  @Table(name = "KRMS_PROP_PARM_T")
41  public class PropositionParameterBo implements PropositionParameterContract, Serializable {
42  
43      private static final long serialVersionUID = 1l;
44  
45      @PortableSequenceGenerator(name = "KRMS_PROP_PARM_S")
46      @GeneratedValue(generator = "KRMS_PROP_PARM_S")
47      @Id
48      @Column(name = "PROP_PARM_ID")
49      private String id;
50  
51      @ManyToOne(fetch = FetchType.LAZY, cascade = { CascadeType.REFRESH, CascadeType.REMOVE, CascadeType.PERSIST })
52      @JoinColumn(name = "PROP_ID")
53      private PropositionBo proposition;
54  
55      @Column(name = "PARM_VAL")
56      private String value;
57  
58      @Column(name = "PARM_TYP_CD")
59      private String parameterType;
60  
61      @Column(name = "SEQ_NO")
62      private Integer sequenceNumber;
63  
64      @Transient
65      private TermDefinition termValue;
66  
67      @Column(name = "VER_NBR")
68      @Version
69      private Long versionNumber;
70  
71      public TermDefinition getTermValue() {
72          return termValue;
73      }
74  
75      public void setTermValue(TermDefinition termValue) {
76          if (termValue != null) {
77              value = termValue.getId();
78          }
79  
80          this.termValue = termValue;
81      }
82  
83      /**
84       * Converts a mutable bo to it's immutable counterpart
85       *
86       * @param bo the mutable business object
87       * @return the immutable object
88       */
89      public static PropositionParameter to(PropositionParameterBo bo) {
90          if (bo == null) {
91              return null;
92          }
93  
94          return PropositionParameter.Builder.create(bo).build();
95      }
96  
97      /**
98       * Converts a list of mutable bos to it's immutable counterpart
99       *
100      * @param bos the list of smutable business objects
101      * @return and immutable list containing the immutable objects
102      */
103     public static List<PropositionParameter> to(List<PropositionParameterBo> bos) {
104         if (bos == null) {
105             return null;
106         }
107 
108         List<PropositionParameter> parms = new ArrayList<PropositionParameter>();
109 
110         for (PropositionParameterBo p : bos) {
111             parms.add(PropositionParameter.Builder.create(p).build());
112         }
113 
114         return Collections.unmodifiableList(parms);
115     }
116 
117     /**
118      * Converts a immutable object to it's mutable bo counterpart
119      *
120      * @param im immutable object
121      * @return the mutable bo
122      */
123     public static PropositionParameterBo from(PropositionParameter im) {
124         if (im == null) {
125             return null;
126         }
127 
128         PropositionParameterBo bo = new PropositionParameterBo();
129         bo.id = im.getId();
130 
131         // we don't set proposition here, it gets set in PropositionBo.from
132 
133         bo.value = im.getValue();
134         bo.setTermValue(im.getTermValue());
135         bo.parameterType = im.getParameterType();
136         bo.sequenceNumber = im.getSequenceNumber();
137         bo.setVersionNumber(im.getVersionNumber());
138 
139         return bo;
140     }
141 
142     public static List<PropositionParameterBo> from(List<PropositionParameter> ims) {
143         if (ims == null) {
144             return null;
145         }
146 
147         List<PropositionParameterBo> bos = new ArrayList<PropositionParameterBo>();
148         for (PropositionParameter im : ims) {
149             PropositionParameterBo bo = new PropositionParameterBo();
150             bo.id = im.getId();
151 
152             // we don't set proposition here, it gets set in PropositionBo.from
153 
154             bo.value = im.getValue();
155             bo.parameterType = im.getParameterType();
156             bo.sequenceNumber = im.getSequenceNumber();
157             bo.setVersionNumber(im.getVersionNumber());
158             bos.add(bo);
159         }
160 
161         return Collections.unmodifiableList(bos);
162     }
163 
164     public String getId() {
165         return id;
166     }
167 
168     public void setId(String id) {
169         this.id = id;
170     }
171 
172     public String getPropId() {
173         if (proposition != null) {
174             return proposition.getId();
175         }
176 
177         return null;
178     }
179 
180     public PropositionBo getProposition() {
181         return proposition;
182     }
183 
184     public void setProposition(PropositionBo proposition) {
185         this.proposition = proposition;
186     }
187 
188     public String getValue() {
189         return value;
190     }
191 
192     public void setValue(String value) {
193         this.value = value;
194     }
195 
196     public String getParameterType() {
197         return parameterType;
198     }
199 
200     public void setParameterType(String parameterType) {
201         this.parameterType = parameterType;
202     }
203 
204     public Integer getSequenceNumber() {
205         return sequenceNumber;
206     }
207 
208     public void setSequenceNumber(Integer sequenceNumber) {
209         this.sequenceNumber = sequenceNumber;
210     }
211 
212     public Long getVersionNumber() {
213         return versionNumber;
214     }
215 
216     public void setVersionNumber(Long versionNumber) {
217         this.versionNumber = versionNumber;
218     }
219 }