001/** 002 * Copyright 2005-2017 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.krms.impl.repository; 017 018import org.kuali.rice.core.api.mo.common.Versioned; 019import org.kuali.rice.core.api.mo.common.active.MutableInactivatable; 020import org.kuali.rice.krad.data.jpa.converters.BooleanYNConverter; 021import org.kuali.rice.krad.data.jpa.PortableSequenceGenerator; 022import org.kuali.rice.krms.api.repository.category.CategoryDefinition; 023import org.kuali.rice.krms.api.repository.function.FunctionDefinition; 024import org.kuali.rice.krms.api.repository.function.FunctionDefinitionContract; 025import org.kuali.rice.krms.api.repository.function.FunctionParameterDefinition; 026 027import javax.persistence.CascadeType; 028import javax.persistence.Column; 029import javax.persistence.Convert; 030import javax.persistence.Entity; 031import javax.persistence.GeneratedValue; 032import javax.persistence.Id; 033import javax.persistence.JoinColumn; 034import javax.persistence.JoinTable; 035import javax.persistence.ManyToMany; 036import javax.persistence.OneToMany; 037import javax.persistence.Table; 038import javax.persistence.Version; 039import java.io.Serializable; 040import java.util.ArrayList; 041import java.util.List; 042 043@Entity 044@Table(name = "KRMS_FUNC_T") 045public class FunctionBo implements MutableInactivatable, FunctionDefinitionContract, Versioned, Serializable { 046 047 private static final long serialVersionUID = 1l; 048 049 @PortableSequenceGenerator(name = "KRMS_FUNC_S") 050 @GeneratedValue(generator = "KRMS_FUNC_S") 051 @Id 052 @Column(name = "FUNC_ID") 053 private String id; 054 055 @Column(name = "NMSPC_CD") 056 private String namespace; 057 058 @Column(name = "NM") 059 private String name; 060 061 @Column(name = "DESC_TXT") 062 private String description; 063 064 @Column(name = "RTRN_TYP") 065 private String returnType; 066 067 @Column(name = "TYP_ID") 068 private String typeId; 069 070 @Column(name = "ACTV") 071 @Convert(converter = BooleanYNConverter.class) 072 private boolean active = true; 073 074 @Version 075 @Column(name="VER_NBR", length=8) 076 protected Long versionNumber; 077 078 @OneToMany(cascade = CascadeType.ALL, mappedBy = "function") 079 private List<FunctionParameterBo> parameters; 080 081 @ManyToMany(targetEntity = CategoryBo.class, cascade = { CascadeType.REFRESH }) 082 @JoinTable(name = "KRMS_FUNC_CTGRY_T", 083 joinColumns = { @JoinColumn(name = "FUNC_ID", referencedColumnName = "FUNC_ID") }, 084 inverseJoinColumns = { @JoinColumn(name = "CTGRY_ID", referencedColumnName = "CTGRY_ID") }) 085 private List<CategoryBo> categories; 086 087 /** 088 * Converts a mutable bo to it's immutable counterpart 089 * 090 * @param bo the mutable business object 091 * @return the immutable object 092 */ 093 public static FunctionDefinition to(FunctionBo bo) { 094 if (bo == null) { 095 return null; 096 } 097 098 return FunctionDefinition.Builder.create(bo).build(); 099 } 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}