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.krad.data.jpa.converters.BooleanYNConverter;
020import org.kuali.rice.krad.data.jpa.PortableSequenceGenerator;
021import org.kuali.rice.krms.api.repository.typerelation.RelationshipType;
022import org.kuali.rice.krms.api.repository.typerelation.TypeTypeRelation;
023import org.kuali.rice.krms.api.repository.typerelation.TypeTypeRelationContract;
024import org.kuali.rice.krms.impl.repository.jpa.RelationshipTypeConverter;
025
026import javax.persistence.CascadeType;
027import javax.persistence.Column;
028import javax.persistence.Convert;
029import javax.persistence.Entity;
030import javax.persistence.EnumType;
031import javax.persistence.Enumerated;
032import javax.persistence.GeneratedValue;
033import javax.persistence.Id;
034import javax.persistence.JoinColumn;
035import javax.persistence.ManyToOne;
036import javax.persistence.Table;
037import javax.persistence.Version;
038import java.io.Serializable;
039
040/**
041 * The mutable implementation of the @{link TypeTypeRelationContract} interface, the counterpart to the immutable implementation {@link TypeTypeRelation}.
042 * @author Kuali Rice Team (rice.collab@kuali.org)
043 * 
044 */
045@Entity
046@Table(name = "KRMS_TYP_RELN_T")
047public class TypeTypeRelationBo implements TypeTypeRelationContract, Versioned, Serializable {
048
049    private static final long serialVersionUID = 1l;
050
051    @Column(name = "FROM_TYP_ID")
052    private String fromTypeId;
053
054    @Column(name = "TO_TYP_ID")
055    private String toTypeId;
056
057    @Column(name = "RELN_TYP")
058    @Convert(converter = RelationshipTypeConverter.class)
059
060    @Enumerated(value = EnumType.ORDINAL)
061    private RelationshipType relationshipType;
062
063    @Column(name = "SEQ_NO")
064    private Integer sequenceNumber;
065
066    @PortableSequenceGenerator(name = "KRMS_TYP_RELN_S")
067    @GeneratedValue(generator = "KRMS_TYP_RELN_S")
068    @Id
069    @Column(name = "TYP_RELN_ID")
070    private String id;
071
072    @Column(name = "ACTV")
073    @Convert(converter = BooleanYNConverter.class)
074    private boolean active;
075
076    @Column(name = "VER_NBR")
077    @Version
078    private Long versionNumber;
079
080    @ManyToOne(targetEntity = KrmsTypeBo.class, cascade = { CascadeType.REFRESH })
081    @JoinColumn(name = "FROM_TYP_ID", referencedColumnName = "TYP_ID", insertable = false, updatable = false)
082    private KrmsTypeBo fromType;
083
084    @ManyToOne(targetEntity = KrmsTypeBo.class, cascade = { CascadeType.REFRESH })
085    @JoinColumn(name = "TO_TYP_ID", referencedColumnName = "TYP_ID", insertable = false, updatable = false)
086    private KrmsTypeBo toType;
087
088    /**
089     * Default Constructor
090     * 
091     */
092    public TypeTypeRelationBo() {
093    }
094
095    @Override
096    public String getFromTypeId() {
097        return this.fromTypeId;
098    }
099
100    @Override
101    public String getToTypeId() {
102        return this.toTypeId;
103    }
104
105    @Override
106    public RelationshipType getRelationshipType() {
107        return this.relationshipType;
108    }
109
110    @Override
111    public Integer getSequenceNumber() {
112        return this.sequenceNumber;
113    }
114
115    @Override
116    public String getId() {
117        return this.id;
118    }
119
120    @Override
121    public boolean isActive() {
122        return this.active;
123    }
124
125    @Override
126    public Long getVersionNumber() {
127        return this.versionNumber;
128    }
129
130    /**
131     * Sets the value of fromTypeId on this builder to the given value.
132     * 
133     * @param fromTypeId the fromTypeId value to set.
134     * 
135     */
136    public void setFromTypeId(String fromTypeId) {
137        this.fromTypeId = fromTypeId;
138    }
139
140    /**
141     * Sets the value of toTypeId on this builder to the given value.
142     * 
143     * @param toTypeId the toTypeId value to set.
144     * 
145     */
146    public void setToTypeId(String toTypeId) {
147        this.toTypeId = toTypeId;
148    }
149
150    /**
151     * Sets the value of relationshipType on this builder to the given value.
152     * 
153     * @param relationshipType the relationshipType value to set.
154     * 
155     */
156    public void setRelationshipType(RelationshipType relationshipType) {
157        this.relationshipType = relationshipType;
158    }
159
160    /**
161     * Sets the value of sequenceNumber on this builder to the given value.
162     * 
163     * @param sequenceNumber the sequenceNumber value to set.
164     * 
165     */
166    public void setSequenceNumber(Integer sequenceNumber) {
167        this.sequenceNumber = sequenceNumber;
168    }
169
170    /**
171     * Sets the value of id on this builder to the given value.
172     * 
173     * @param id the id value to set.
174     * 
175     */
176    public void setId(String id) {
177        this.id = id;
178    }
179
180    /**
181     * Sets the value of active on this builder to the given value.
182     * 
183     * @param active the active value to set.
184     * 
185     */
186    public void setActive(boolean active) {
187        this.active = active;
188    }
189
190    /**
191     * Sets the value of versionNumber on this builder to the given value.
192     * 
193     * @param versionNumber the versionNumber value to set.
194     * 
195     */
196    public void setVersionNumber(Long versionNumber) {
197        this.versionNumber = versionNumber;
198    }
199
200    /**
201     * Converts a mutable {@link TypeTypeRelationBo} to its immutable counterpart, {@link TypeTypeRelation}.
202     * @param typeTypeRelationBo the mutable business object.
203     * @return a {@link TypeTypeRelation} the immutable object.
204     * 
205     */
206    public static TypeTypeRelation to(TypeTypeRelationBo typeTypeRelationBo) {
207        if (typeTypeRelationBo == null) {
208            return null;
209        }
210
211        return TypeTypeRelation.Builder.create(typeTypeRelationBo).build();
212    }
213
214    /**
215     * Converts a immutable {@link TypeTypeRelation} to its mutable {@link TypeTypeRelationBo} counterpart.
216     * @param typeTypeRelation the immutable object.
217     * @return a {@link TypeTypeRelationBo} the mutable TypeTypeRelationBo.
218     * 
219     */
220    public static org.kuali.rice.krms.impl.repository.TypeTypeRelationBo from(TypeTypeRelation typeTypeRelation) {
221        if (typeTypeRelation == null) {
222            return null;
223        }
224
225        TypeTypeRelationBo typeTypeRelationBo = new TypeTypeRelationBo();
226        typeTypeRelationBo.setFromTypeId(typeTypeRelation.getFromTypeId());
227        typeTypeRelationBo.setToTypeId(typeTypeRelation.getToTypeId());
228        typeTypeRelationBo.setRelationshipType(typeTypeRelation.getRelationshipType());
229        typeTypeRelationBo.setSequenceNumber(typeTypeRelation.getSequenceNumber());
230        typeTypeRelationBo.setId(typeTypeRelation.getId());
231        typeTypeRelationBo.setActive(typeTypeRelation.isActive());
232        typeTypeRelationBo.setVersionNumber(typeTypeRelation.getVersionNumber());
233
234        return typeTypeRelationBo;
235    }
236
237    public KrmsTypeBo getFromType() {
238        return fromType;
239    }
240
241    public void setFromType(KrmsTypeBo fromType) {
242        this.fromType = fromType;
243    }
244
245    public KrmsTypeBo getToType() {
246        return toType;
247    }
248
249    public void setToType(KrmsTypeBo toType) {
250        this.toType = toType;
251    }
252}