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.active.MutableInactivatable; 019import org.kuali.rice.krad.data.jpa.converters.BooleanYNConverter; 020import org.kuali.rice.krad.data.jpa.PortableSequenceGenerator; 021import org.kuali.rice.krms.api.repository.type.KrmsTypeAttribute; 022import org.kuali.rice.krms.api.repository.type.KrmsTypeAttributeContract; 023 024import javax.persistence.Column; 025import javax.persistence.Convert; 026import javax.persistence.Entity; 027import javax.persistence.FetchType; 028import javax.persistence.GeneratedValue; 029import javax.persistence.Id; 030import javax.persistence.JoinColumn; 031import javax.persistence.ManyToOne; 032import javax.persistence.Table; 033import javax.persistence.Version; 034import java.io.Serializable; 035 036@Entity 037@Table(name = "KRMS_TYP_ATTR_T") 038public class KrmsTypeAttributeBo implements MutableInactivatable, KrmsTypeAttributeContract, Serializable { 039 040 private static final long serialVersionUID = 1l; 041 042 @PortableSequenceGenerator(name = "KRMS_TYP_ATTR_S") 043 @GeneratedValue(generator = "KRMS_TYP_ATTR_S") 044 @Id 045 @Column(name = "TYP_ATTR_ID") 046 private String id; 047 048 @ManyToOne(fetch= FetchType.LAZY) 049 @JoinColumn(name = "TYP_ID", referencedColumnName = "TYP_ID") 050 private KrmsTypeBo type; 051 052 @Column(name = "SEQ_NO") 053 private Integer sequenceNumber; 054 055 @Column(name = "ACTV") 056 @Convert(converter = BooleanYNConverter.class) 057 private boolean active = true; 058 059 @Version 060 @Column(name="VER_NBR", length=8) 061 protected Long versionNumber; 062 063 @Column(name = "ATTR_DEFN_ID") 064 private String attributeDefinitionId; 065 066 /** 067 * Converts a mutable bo to it's immutable counterpart 068 * 069 * @param bo the mutable business object 070 * @return the immutable object 071 */ 072 public static KrmsTypeAttribute to(KrmsTypeAttributeBo bo) { 073 if (bo == null) { 074 return null; 075 } 076 077 return KrmsTypeAttribute.Builder.create(bo).build(); 078 } 079 080 /** 081 * Converts a immutable object to it's mutable bo counterpart 082 * 083 * @param im immutable object 084 * @return the mutable bo 085 */ 086 public static KrmsTypeAttributeBo from(KrmsTypeAttribute im) { 087 if (im == null) { 088 return null; 089 } 090 091 KrmsTypeAttributeBo bo = new KrmsTypeAttributeBo(); 092 bo.id = im.getId(); 093 094 // not setting type, it will be set within KrmsTypeBo.from 095 096 bo.attributeDefinitionId = im.getAttributeDefinitionId(); 097 bo.sequenceNumber = im.getSequenceNumber(); 098 bo.active = im.isActive(); 099 bo.setVersionNumber(im.getVersionNumber()); 100 101 return bo; 102 } 103 104 public String getId() { 105 return id; 106 } 107 108 public void setId(String id) { 109 this.id = id; 110 } 111 112 public String getTypeId() { 113 if (type != null) { 114 return type.getId(); 115 } 116 117 return null; 118 } 119 120 public KrmsTypeBo getType() { 121 return type; 122 } 123 124 public void setType(KrmsTypeBo type) { 125 this.type = type; 126 } 127 128 public String getAttributeDefinitionId() { 129 return attributeDefinitionId; 130 } 131 132 public void setAttributeDefinitionId(String attributeDefinitionId) { 133 this.attributeDefinitionId = attributeDefinitionId; 134 } 135 136 public Integer getSequenceNumber() { 137 return sequenceNumber; 138 } 139 140 public void setSequenceNumber(Integer sequenceNumber) { 141 this.sequenceNumber = sequenceNumber; 142 } 143 144 public boolean getActive() { 145 return active; 146 } 147 148 public boolean isActive() { 149 return active; 150 } 151 152 public void setActive(boolean active) { 153 this.active = active; 154 } 155 156 public Long getVersionNumber() { 157 return versionNumber; 158 } 159 160 public void setVersionNumber(Long versionNumber) { 161 this.versionNumber = versionNumber; 162 } 163}