001/** 002 * Copyright 2005-2016 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.kew.impl.type; 017 018import org.kuali.rice.core.api.mo.common.active.MutableInactivatable; 019import org.kuali.rice.kew.api.repository.type.KewTypeAttribute; 020import org.kuali.rice.kew.api.repository.type.KewTypeDefinition; 021import org.kuali.rice.kew.api.repository.type.KewTypeDefinitionContract; 022import org.kuali.rice.krad.data.jpa.converters.BooleanYNConverter; 023import org.kuali.rice.krad.data.jpa.PortableSequenceGenerator; 024 025import javax.persistence.CascadeType; 026import javax.persistence.Column; 027import javax.persistence.Convert; 028import javax.persistence.Entity; 029import javax.persistence.GeneratedValue; 030import javax.persistence.Id; 031import javax.persistence.OneToMany; 032import javax.persistence.Table; 033import javax.persistence.Version; 034import java.util.ArrayList; 035import java.util.List; 036 037/** 038 * Kuali workflow type business object. 039 * 040 * @author Kuali Rice Team (rice.collab@kuali.org) 041 */ 042@Entity 043@Table(name = "KREW_TYP_T") 044public class KewTypeBo implements KewTypeDefinitionContract, MutableInactivatable { 045 046 @Id 047 @GeneratedValue(generator = "KREW_TYP_S") 048 @PortableSequenceGenerator(name = "KREW_TYP_S") 049 @Column(name = "TYP_ID", nullable = false) 050 private String id; 051 052 @Column(name = "NM", nullable = false) 053 private String name; 054 055 @Column(name = "NMSPC_CD", nullable = false) 056 private String namespace; 057 058 @Column(name = "SRVC_NM") 059 private String serviceName; 060 061 @Column(name = "ACTV", nullable = false) 062 @Convert(converter = BooleanYNConverter.class) 063 private boolean active; 064 065 @Version 066 @Column(name = "VER_NBR", nullable = false) 067 private Long versionNumber; 068 069 @OneToMany(cascade = CascadeType.ALL, mappedBy = "type", orphanRemoval = true) 070 private List<KewTypeAttributeBo> attributes; 071 072 /** 073 * Converts a mutable bo to it's immutable counterpart 074 * @param bo the mutable business object 075 * @return the immutable object 076 */ 077 public static KewTypeDefinition to(KewTypeBo bo) { 078 if (null == bo) { 079 return null; 080 } else { 081 return KewTypeDefinition.Builder.create(bo).build(); 082 } 083 } 084 085 /** 086 * Converts a immutable object to it's mutable bo counterpart 087 * @param im immutable object 088 * @return the mutable bo 089 */ 090 public static KewTypeBo from(org.kuali.rice.kew.api.repository.type.KewTypeDefinition im) { 091 if (null == im) { 092 return null; 093 } else { 094 KewTypeBo bo = new KewTypeBo(); 095 bo.setId(im.getId()); 096 bo.setName(im.getName()); 097 bo.setNamespace(im.getNamespace()); 098 bo.setServiceName(im.getServiceName()); 099 bo.setActive(im.isActive()); 100 bo.setAttributes(new ArrayList<KewTypeAttributeBo>()); 101 if (null != im.getAttributes() && !im.getAttributes().isEmpty()) { 102 for(KewTypeAttribute attr : im.getAttributes()) { 103 bo.getAttributes().add(KewTypeAttributeBo.from(attr, bo)); 104 } 105 } 106 107 return bo; 108 } 109 } 110 111 /** 112 * Default constructor. 113 */ 114 public KewTypeBo() { } 115 116 /** 117 * Returns the type id. 118 * @return the type id 119 */ 120 public String getId() { 121 return id; 122 } 123 124 /** 125 * @see #getId() 126 */ 127 public void setId(String id) { 128 this.id = id; 129 } 130 131 /** 132 * Returns the KEW type name. 133 * @return the KEW type name 134 */ 135 public String getName() { 136 return name; 137 } 138 139 /** 140 * @see #getName() 141 */ 142 public void setName(String name) { 143 this.name = name; 144 } 145 146 /** 147 * Returns the name space. 148 * @return the name space. 149 */ 150 public String getNamespace() { 151 return namespace; 152 } 153 154 /** 155 * @see #getNamespace() 156 */ 157 public void setNamespace(String namespace) { 158 this.namespace = namespace; 159 } 160 161 /** 162 * Returns the service name. 163 * @return the service name 164 */ 165 public String getServiceName() { 166 return serviceName; 167 } 168 169 /** 170 * @see #getServiceName() 171 */ 172 public void setServiceName(String serviceName) { 173 this.serviceName = serviceName; 174 } 175 176 /** 177 * Returns the status of this KEW type 178 * @return TRUE if the type is active, FALSE otherwise. 179 */ 180 public boolean isActive() { 181 return active; 182 } 183 184 /** 185 * @see #isActive() 186 */ 187 public void setActive(boolean active) { 188 this.active = active; 189 } 190 191 /** 192 * Returns the version number. 193 * @return the version number. 194 */ 195 public Long getVersionNumber() { 196 return versionNumber; 197 } 198 199 /** 200 * @see #getVersionNumber() 201 */ 202 public void setVersionNumber(Long versionNumber) { 203 this.versionNumber = versionNumber; 204 } 205 206 /** 207 * Returns a {@link List} of {@link KewTypeAttributeBo}. 208 * @return a {@link List} of {@link KewTypeAttributeBo} 209 */ 210 public List<KewTypeAttributeBo> getAttributes() { 211 if (attributes == null) { 212 attributes = new ArrayList<KewTypeAttributeBo>(); 213 } 214 return attributes; 215 } 216 217 /** 218 * @see #getAttributes() 219 */ 220 public void setAttributes(List<KewTypeAttributeBo> attributes) { 221 this.attributes = attributes; 222 } 223}