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.kim.impl.type; 017 018import javax.persistence.CascadeType; 019import javax.persistence.Column; 020import javax.persistence.Convert; 021import javax.persistence.Entity; 022import javax.persistence.GeneratedValue; 023import javax.persistence.Id; 024import javax.persistence.JoinColumn; 025import javax.persistence.ManyToOne; 026import javax.persistence.Table; 027 028import org.eclipse.persistence.annotations.JoinFetch; 029import org.eclipse.persistence.annotations.JoinFetchType; 030import org.kuali.rice.kim.api.common.attribute.KimAttribute; 031import org.kuali.rice.kim.api.type.KimTypeAttribute; 032import org.kuali.rice.kim.api.type.KimTypeAttributeContract; 033import org.kuali.rice.kim.impl.common.attribute.KimAttributeBo; 034import org.kuali.rice.krad.bo.DataObjectBase; 035import org.kuali.rice.krad.data.jpa.PortableSequenceGenerator; 036import org.kuali.rice.krad.data.jpa.converters.BooleanYNConverter; 037 038@Entity 039@Table(name = "KRIM_TYP_ATTR_T") 040public class KimTypeAttributeBo extends DataObjectBase implements KimTypeAttributeContract { 041 private static final long serialVersionUID = 1L; 042 043 @PortableSequenceGenerator(name = "KRIM_TYP_ATTR_ID_S") 044 @GeneratedValue(generator = "KRIM_TYP_ATTR_ID_S") 045 @Id 046 @Column(name = "KIM_TYP_ATTR_ID") 047 private String id; 048 049 @Column(name = "SORT_CD") 050 private String sortCode; 051 052 @Column(name = "KIM_ATTR_DEFN_ID") 053 private String kimAttributeId; 054 055 @JoinFetch(value= JoinFetchType.OUTER) 056 @ManyToOne(targetEntity = KimAttributeBo.class, cascade = { CascadeType.REFRESH }) 057 @JoinColumn(name = "KIM_ATTR_DEFN_ID", referencedColumnName = "KIM_ATTR_DEFN_ID", insertable = false, updatable = false) 058 private KimAttributeBo kimAttribute; 059 060 @Column(name = "KIM_TYP_ID") 061 private String kimTypeId; 062 063 @Column(name = "ACTV_IND") 064 @Convert(converter = BooleanYNConverter.class) 065 private boolean active; 066 067 /** 068 * Converts a mutable bo to its immutable counterpart 069 * 070 * @param bo the mutable business object 071 * @return the immutable object 072 */ 073 public static KimTypeAttribute to(KimTypeAttributeBo bo) { 074 if (bo == null) { 075 return null; 076 } 077 return KimTypeAttribute.Builder.create(bo).build(); 078 } 079 080 /** 081 * Converts a immutable object to its mutable counterpart 082 * 083 * @param im immutable object 084 * @return the mutable bo 085 */ 086 public static KimTypeAttributeBo from(KimTypeAttribute im) { 087 if (im == null) { 088 return null; 089 } 090 KimTypeAttributeBo bo = new KimTypeAttributeBo(); 091 bo.setId(im.getId()); 092 bo.sortCode = im.getSortCode(); 093 final KimAttribute attribute = im.getKimAttribute(); 094 bo.kimAttributeId = (attribute == null ? null : attribute.getId()); 095 bo.kimAttribute = KimAttributeBo.from(im.getKimAttribute()); 096 bo.kimTypeId = im.getKimTypeId(); 097 bo.active = im.isActive(); 098 bo.setVersionNumber(im.getVersionNumber()); 099 bo.setObjectId(im.getObjectId()); 100 return bo; 101 } 102 103 @Override 104 public KimAttributeBo getKimAttribute() { 105 return kimAttribute; 106 } 107 108 @Override 109 public String getId() { 110 return id; 111 } 112 113 public void setId(String id) { 114 this.id = id; 115 } 116 117 @Override 118 public String getSortCode() { 119 return sortCode; 120 } 121 122 public void setSortCode(String sortCode) { 123 this.sortCode = sortCode; 124 } 125 126 public String getKimAttributeId() { 127 return kimAttributeId; 128 } 129 130 public void setKimAttributeId(String kimAttributeId) { 131 this.kimAttributeId = kimAttributeId; 132 } 133 134 public void setKimAttribute(KimAttributeBo kimAttribute) { 135 this.kimAttribute = kimAttribute; 136 } 137 138 @Override 139 public String getKimTypeId() { 140 return kimTypeId; 141 } 142 143 public void setKimTypeId(String kimTypeId) { 144 this.kimTypeId = kimTypeId; 145 } 146 147 public boolean getActive() { 148 return active; 149 } 150 151 @Override 152 public boolean isActive() { 153 return active; 154 } 155 156 public void setActive(boolean active) { 157 this.active = active; 158 } 159}