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.KewTypeAttributeContract;
021import org.kuali.rice.krad.data.jpa.PortableSequenceGenerator;
022import org.kuali.rice.krad.data.jpa.converters.BooleanYNConverter;
023
024import javax.persistence.Column;
025import javax.persistence.Convert;
026import javax.persistence.Entity;
027import javax.persistence.GeneratedValue;
028import javax.persistence.Id;
029import javax.persistence.JoinColumn;
030import javax.persistence.ManyToOne;
031import javax.persistence.Table;
032import javax.persistence.Version;
033
034/**
035 *  Kuali workflow type attribute business object.
036 *
037 * @author Kuali Rice Team (rice.collab@kuali.org)
038 */
039@Entity
040@Table(name = "KREW_TYP_ATTR_T")
041public class KewTypeAttributeBo implements KewTypeAttributeContract, MutableInactivatable {
042
043    @Id
044    @GeneratedValue(generator = "KREW_TYP_ATTR_S")
045    @PortableSequenceGenerator(name = "KREW_TYP_ATTR_S")
046    @Column(name = "TYP_ATTR_ID", nullable = false)
047    private String id;
048
049    @Column(name = "SEQ_NO", nullable = false)
050    private Integer sequenceNumber;
051
052    @Column(name = "ACTV", nullable = false)
053    @Convert(converter = BooleanYNConverter.class)
054    private boolean active;
055
056    @Version
057    @Column(name = "VER_NBR", nullable = false)
058    private Long versionNumber;
059
060    @ManyToOne
061    @JoinColumn(name = "TYP_ID", nullable = false)
062    private KewTypeBo type;
063
064    @ManyToOne
065    @JoinColumn(name = "ATTR_DEFN_ID", nullable = false)
066    private KewAttributeDefinitionBo attributeDefinition;
067
068    /**
069     * Converts a mutable bo to it's immutable counterpart
070     * @param bo the mutable business object
071     * @return the immutable object
072     */
073    public static KewTypeAttribute to(KewTypeAttributeBo bo) {
074        if (null == bo) {
075            return null;
076        } else {
077            return org.kuali.rice.kew.api.repository.type.KewTypeAttribute.Builder.create(bo).build();
078        }
079    }
080
081    /**
082     * Converts a immutable object to it's mutable bo counterpart
083     * @param im immutable object
084     * @return the mutable bo
085     */
086    public static KewTypeAttributeBo from(KewTypeAttribute im, KewTypeBo kewType) {
087        if (null == im) {
088            return null;
089        } else {
090            KewTypeAttributeBo bo = new KewTypeAttributeBo();
091            bo.setId(im.getId());
092            bo.setType(kewType);
093            bo.setSequenceNumber(im.getSequenceNumber());
094            bo.setActive(im.isActive());
095            bo.setAttributeDefinition(KewAttributeDefinitionBo.from(im.getAttributeDefinition()));
096            return bo;
097        }
098    }
099
100    /**
101     * Default constructor
102     */
103    public KewTypeAttributeBo() { }
104
105    /**
106     * Returns the type attribute id.
107     * @return the type attribute id
108     */
109    public String getId() {
110        return id;
111    }
112
113    /**
114     * @see #getId()
115     */
116    public void setId(String id) {
117        this.id = id;
118    }
119
120    /**
121     * Returns the sequence number.
122     * @return the sequence number
123     */
124    public Integer getSequenceNumber() {
125        return sequenceNumber;
126    }
127
128    /**
129     * @see #getSequenceNumber()
130     */
131    public void setSequenceNumber(Integer sequenceNumber) {
132        this.sequenceNumber = sequenceNumber;
133    }
134
135    /**
136     * Returns the status of the KEW type attribute.
137     * @return TRUE if the KEW type attribute is active, FALSE otherwise
138     */
139    public boolean isActive() {
140        return active;
141    }
142
143    /**
144     * @see #isActive()
145     */
146    public void setActive(boolean active) {
147        this.active = active;
148    }
149
150    /**
151     * Returns the version number.
152     * @return the version number
153     */
154    public Long getVersionNumber() {
155        return versionNumber;
156    }
157
158    /**
159     * @see #getVersionNumber()
160     */
161    public void setVersionNumber(Long versionNumber) {
162        this.versionNumber = versionNumber;
163    }
164
165    /**
166     * Returns the {@link KewAttributeDefinitionBo}.
167     * @return a {@link KewAttributeDefinitionBo}
168     */
169    public KewAttributeDefinitionBo getAttributeDefinition() {
170        return attributeDefinition;
171    }
172
173    /**
174     * @see #getAttributeDefinition()
175     */
176    public void setAttributeDefinition(KewAttributeDefinitionBo attributeDefinition) {
177        this.attributeDefinition = attributeDefinition;
178    }
179
180    /**
181     * Returns the attribute definition id from the internal attribute definition parameter.
182     * @return the attribute definition id, or null if the attribute definition is not set.
183     */
184    public String getAttributeDefinitionId() {
185
186        if (null != this.attributeDefinition) {
187            return this.attributeDefinition.getId();
188        } else {
189            return null;
190        }
191    }
192
193    public KewTypeBo getType() {
194        return type;
195    }
196
197    public void setType(KewTypeBo type) {
198        this.type = type;
199    }
200
201    public String getTypeId() {
202        if (getType() == null) {
203            return null;
204        }
205        return getType().getId();
206    }
207}