View Javadoc
1   /**
2    * Copyright 2005-2016 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.core.api.mo.common.Versioned;
19  import org.kuali.rice.krad.data.jpa.PortableSequenceGenerator;
20  import org.kuali.rice.krms.api.repository.function.FunctionParameterDefinition;
21  import org.kuali.rice.krms.api.repository.function.FunctionParameterDefinitionContract;
22  
23  import javax.persistence.Column;
24  import javax.persistence.Entity;
25  import javax.persistence.FetchType;
26  import javax.persistence.GeneratedValue;
27  import javax.persistence.Id;
28  import javax.persistence.JoinColumn;
29  import javax.persistence.ManyToOne;
30  import javax.persistence.Table;
31  import javax.persistence.Transient;
32  import java.io.Serializable;
33  import java.util.ArrayList;
34  import java.util.Collections;
35  import java.util.List;
36  
37  @Entity
38  @Table(name = "KRMS_FUNC_PARM_T")
39  public class FunctionParameterBo implements FunctionParameterDefinitionContract, Serializable {
40  
41      private static final long serialVersionUID = 1l;
42  
43      @PortableSequenceGenerator(name = "KRMS_FUNC_S")
44      @GeneratedValue(generator = "KRMS_FUNC_S")
45      @Id
46      @Column(name = "FUNC_PARM_ID")
47      private String id;
48  
49      @Column(name = "NM")
50      private String name;
51  
52      @Column(name = "DESC_TXT")
53      private String description;
54  
55      @ManyToOne(fetch = FetchType.LAZY)
56      @JoinColumn(name="FUNC_ID")
57      private FunctionBo function;
58  
59      @Column(name = "TYP")
60      private String parameterType;
61  
62      @Column(name = "SEQ_NO")
63      private Integer sequenceNumber;
64  
65      @Transient
66      protected Long versionNumber;
67  
68      /**
69       * Converts a mutable bo to it's immutable counterpart
70       *
71       * @param bo the mutable business object
72       * @return the immutable object
73       */
74      public static FunctionParameterDefinition to(FunctionParameterBo bo) {
75          if (bo == null) {
76              return null;
77          }
78  
79          return FunctionParameterDefinition.Builder.create(bo).build();
80      }
81  
82      /**
83       * Converts a list of mutable bos to it's immutable counterpart
84       *
85       * @param bos the list of mutable business objects
86       * @return and immutable list containing the immutable objects
87       */
88      public static List<FunctionParameterDefinition> to(List<FunctionParameterBo> bos) {
89          if (bos == null) {
90              return null;
91          }
92  
93          List<FunctionParameterDefinition> parms = new ArrayList<FunctionParameterDefinition>();
94  
95          for (FunctionParameterBo p : bos) {
96              parms.add(FunctionParameterDefinition.Builder.create(p).build());
97          }
98  
99          return Collections.unmodifiableList(parms);
100     }
101 
102     /**
103      * Converts a immutable object to it's mutable bo counterpart
104      *
105      * @param im immutable object
106      * @return the mutable bo
107      */
108     public static FunctionParameterBo from(FunctionParameterDefinition im) {
109         if (im == null) {
110             return null;
111         }
112         FunctionParameterBo bo = new FunctionParameterBo();
113         bo.id = im.getId();
114         bo.name = im.getName();
115         bo.description = im.getDescription();
116 
117         // not setting function here, it will be set in FunctionBo.from
118 
119         bo.parameterType = im.getParameterType();
120         bo.sequenceNumber = im.getSequenceNumber();
121         bo.setVersionNumber(im.getVersionNumber());
122         return bo;
123     }
124 
125     public static List<FunctionParameterBo> from(List<FunctionParameterDefinition> ims) {
126         if (ims == null) {
127             return null;
128         }
129 
130         List<FunctionParameterBo> bos = new ArrayList<FunctionParameterBo>();
131         for (FunctionParameterDefinition im : ims) {
132             FunctionParameterBo bo = FunctionParameterBo.from(im);
133             ((ArrayList<FunctionParameterBo>) bos).add(bo);
134         }
135 
136         return Collections.unmodifiableList(bos);
137     }
138 
139     public String getId() {
140         return id;
141     }
142 
143     public void setId(String id) {
144         this.id = id;
145     }
146 
147     public String getName() {
148         return name;
149     }
150 
151     public void setName(String name) {
152         this.name = name;
153     }
154 
155     public String getDescription() {
156         return description;
157     }
158 
159     public void setDescription(String description) {
160         this.description = description;
161     }
162 
163     public String getFunctionId() {
164         if (function != null){
165             return function.getId();
166         }
167 
168         return null;
169     }
170 
171     public FunctionBo getFunction() {
172         return function;
173     }
174 
175     public void setFunction(FunctionBo function) {
176         this.function = function;
177     }
178 
179     public String getParameterType() {
180         return parameterType;
181     }
182 
183     public void setParameterType(String parameterType) {
184         this.parameterType = parameterType;
185     }
186 
187     public Integer getSequenceNumber() {
188         return sequenceNumber;
189     }
190 
191     public void setSequenceNumber(Integer sequenceNumber) {
192         this.sequenceNumber = sequenceNumber;
193     }
194 
195     public Long getVersionNumber() {
196         return versionNumber;
197     }
198 
199     public void setVersionNumber(Long versionNumber) {
200         this.versionNumber = versionNumber;
201     }
202 }