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.core.api.mo.common.Versioned;
19  import org.kuali.rice.core.api.mo.common.active.MutableInactivatable;
20  import org.kuali.rice.krad.data.jpa.converters.BooleanYNConverter;
21  import org.kuali.rice.krad.data.jpa.PortableSequenceGenerator;
22  import org.kuali.rice.krms.api.repository.category.CategoryDefinition;
23  import org.kuali.rice.krms.api.repository.function.FunctionDefinition;
24  import org.kuali.rice.krms.api.repository.function.FunctionDefinitionContract;
25  import org.kuali.rice.krms.api.repository.function.FunctionParameterDefinition;
26  
27  import javax.persistence.CascadeType;
28  import javax.persistence.Column;
29  import javax.persistence.Convert;
30  import javax.persistence.Entity;
31  import javax.persistence.GeneratedValue;
32  import javax.persistence.Id;
33  import javax.persistence.JoinColumn;
34  import javax.persistence.JoinTable;
35  import javax.persistence.ManyToMany;
36  import javax.persistence.OneToMany;
37  import javax.persistence.Table;
38  import javax.persistence.Version;
39  import java.io.Serializable;
40  import java.util.ArrayList;
41  import java.util.List;
42  
43  @Entity
44  @Table(name = "KRMS_FUNC_T")
45  public class FunctionBo implements MutableInactivatable, FunctionDefinitionContract, Versioned, Serializable {
46  
47      private static final long serialVersionUID = 1l;
48  
49      @PortableSequenceGenerator(name = "KRMS_FUNC_S")
50      @GeneratedValue(generator = "KRMS_FUNC_S")
51      @Id
52      @Column(name = "FUNC_ID")
53      private String id;
54  
55      @Column(name = "NMSPC_CD")
56      private String namespace;
57  
58      @Column(name = "NM")
59      private String name;
60  
61      @Column(name = "DESC_TXT")
62      private String description;
63  
64      @Column(name = "RTRN_TYP")
65      private String returnType;
66  
67      @Column(name = "TYP_ID")
68      private String typeId;
69  
70      @Column(name = "ACTV")
71      @Convert(converter = BooleanYNConverter.class)
72      private boolean active = true;
73  
74      @Version
75      @Column(name="VER_NBR", length=8)
76      protected Long versionNumber;
77  
78      @OneToMany(cascade = CascadeType.ALL, mappedBy = "function")
79      private List<FunctionParameterBo> parameters;
80  
81      @ManyToMany(targetEntity = CategoryBo.class, cascade = { CascadeType.REFRESH })
82      @JoinTable(name = "KRMS_FUNC_CTGRY_T",
83              joinColumns = { @JoinColumn(name = "FUNC_ID", referencedColumnName = "FUNC_ID") },
84              inverseJoinColumns = { @JoinColumn(name = "CTGRY_ID", referencedColumnName = "CTGRY_ID") })
85      private List<CategoryBo> categories;
86  
87      /**
88       * Converts a mutable bo to it's immutable counterpart
89       *
90       * @param bo the mutable business object
91       * @return the immutable object
92       */
93      public static FunctionDefinition to(FunctionBo bo) {
94          if (bo == null) {
95              return null;
96          }
97  
98          return FunctionDefinition.Builder.create(bo).build();
99      }
100 
101     /**
102      * Converts a immutable object to it's mutable bo counterpart
103      *
104      * @param im immutable object
105      * @return the mutable bo
106      */
107     public static FunctionBo from(FunctionDefinition im) {
108         if (im == null) {
109             return null;
110         }
111 
112         FunctionBo bo = new FunctionBo();
113         bo.id = im.getId();
114         bo.namespace = im.getNamespace();
115         bo.name = im.getName();
116         bo.description = im.getDescription();
117         bo.returnType = im.getReturnType();
118         bo.typeId = im.getTypeId();
119         bo.active = im.isActive();
120         bo.setVersionNumber(im.getVersionNumber());
121         bo.parameters = new ArrayList<FunctionParameterBo>();
122 
123         for (FunctionParameterDefinition parm : im.getParameters()) {
124             FunctionParameterBo functionParameterBo = FunctionParameterBo.from(parm);
125             functionParameterBo.setFunction(bo);
126             bo.parameters.add(functionParameterBo);
127         }
128 
129         bo.categories = new ArrayList<CategoryBo>();
130 
131         for (CategoryDefinition category : im.getCategories()) {
132             bo.categories.add(CategoryBo.from(category));
133         }
134 
135         bo.setVersionNumber(im.getVersionNumber());
136         return bo;
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 getNamespace() {
148         return namespace;
149     }
150 
151     public void setNamespace(String namespace) {
152         this.namespace = namespace;
153     }
154 
155     public String getName() {
156         return name;
157     }
158 
159     public void setName(String name) {
160         this.name = name;
161     }
162 
163     public String getDescription() {
164         return description;
165     }
166 
167     public void setDescription(String description) {
168         this.description = description;
169     }
170 
171     public String getReturnType() {
172         return returnType;
173     }
174 
175     public void setReturnType(String returnType) {
176         this.returnType = returnType;
177     }
178 
179     public String getTypeId() {
180         return typeId;
181     }
182 
183     public void setTypeId(String typeId) {
184         this.typeId = typeId;
185     }
186 
187     public boolean getActive() {
188         return active;
189     }
190 
191     public boolean isActive() {
192         return active;
193     }
194 
195     public void setActive(boolean active) {
196         this.active = active;
197     }
198 
199     public List<FunctionParameterBo> getParameters() {
200         return parameters;
201     }
202 
203     public void setParameters(List<FunctionParameterBo> parameters) {
204         this.parameters = parameters;
205     }
206 
207     public List<CategoryBo> getCategories() {
208         return categories;
209     }
210 
211     public void setCategories(List<CategoryBo> categories) {
212         this.categories = categories;
213     }
214 
215     public Long getVersionNumber() {
216         return versionNumber;
217     }
218 
219     public void setVersionNumber(Long versionNumber) {
220         this.versionNumber = versionNumber;
221     }
222 }