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.peopleflow;
017
018import org.kuali.rice.core.api.mo.common.Versioned;
019import org.kuali.rice.kew.api.repository.type.KewAttributeDefinition;
020import org.kuali.rice.kew.impl.type.KewAttributeDefinitionBo;
021import org.kuali.rice.krad.data.jpa.PortableSequenceGenerator;
022
023import javax.persistence.Column;
024import javax.persistence.Entity;
025import javax.persistence.GeneratedValue;
026import javax.persistence.Id;
027import javax.persistence.JoinColumn;
028import javax.persistence.ManyToOne;
029import javax.persistence.Table;
030import javax.persistence.Version;
031import java.io.Serializable;
032
033@Entity
034@Table(name = "KREW_PPL_FLW_ATTR_T")
035public class PeopleFlowAttributeBo implements Serializable, Versioned {
036
037    @Id
038    @GeneratedValue(generator = "KREW_PPL_FLW_ATTR_S")
039    @PortableSequenceGenerator(name = "KREW_PPL_FLW_ATTR_S")
040    @Column(name="PPL_FLW_ATTR_ID", nullable = false)
041    private String id;
042
043    @Column(name="ATTR_VAL")
044    private String value;
045
046    @Version
047    @Column(name="VER_NBR", nullable = false)
048    private Long versionNumber;
049
050    @ManyToOne
051    @JoinColumn(name = "PPL_FLW_ID", nullable = false)
052    private PeopleFlowBo peopleFlow;
053
054    @ManyToOne
055    @JoinColumn(name="ATTR_DEFN_ID", nullable = false)
056    private KewAttributeDefinitionBo attributeDefinition;
057
058    public static PeopleFlowAttributeBo from(KewAttributeDefinition attributeDefinition, String id, PeopleFlowBo peopleFlow,
059            String value) {
060
061        if (null == attributeDefinition) {
062            return null;
063        }
064
065        PeopleFlowAttributeBo peopleFlowAttributeBo = new PeopleFlowAttributeBo();
066        peopleFlowAttributeBo.setId(id);
067        peopleFlowAttributeBo.setPeopleFlow(peopleFlow);
068        peopleFlowAttributeBo.setValue(value);
069        peopleFlowAttributeBo.setAttributeDefinition(KewAttributeDefinitionBo.from(attributeDefinition));
070
071        return peopleFlowAttributeBo;
072    }
073
074    /**
075     * Default constructor.
076     */
077    public PeopleFlowAttributeBo() { }
078
079    /**
080     * Returns the people flow attribute id.
081     * @return the people flow attribute id
082     */
083    public String getId() {
084        return id;
085    }
086
087    /**
088     * @see #getId()
089     */
090    public void setId(String id) {
091        this.id = id;
092    }
093
094    public PeopleFlowBo getPeopleFlow() {
095        return peopleFlow;
096    }
097
098    public void setPeopleFlow(PeopleFlowBo peopleFlow) {
099        this.peopleFlow = peopleFlow;
100    }
101
102    /**
103     * Returns the attribute value.
104     * @return the attribute value
105     */
106    public String getValue() {
107        return value;
108    }
109
110    /**
111     * @see #getValue()
112     */
113    public void setValue(String value) {
114        this.value = value;
115    }
116
117    /**
118     * Returns the version number.
119     * @return the version number
120     */
121    public Long getVersionNumber() {
122        return versionNumber;
123    }
124
125    /**
126     * @see #getVersionNumber()
127     */
128    public void setVersionNumber(Long versionNumber) {
129        this.versionNumber = versionNumber;
130    }
131
132    /**
133     * Returns a {@link KewAttributeDefinitionBo}
134     * @return {@link KewAttributeDefinitionBo}
135     */
136    public KewAttributeDefinitionBo getAttributeDefinition() {
137        return attributeDefinition;
138    }
139
140    /**
141     * @see #getAttributeDefinitionId()
142     */
143    public void setAttributeDefinition(KewAttributeDefinitionBo attributeDefinition) {
144        this.attributeDefinition = attributeDefinition;
145    }
146
147    /**
148     * Returns the @{link KewAttributeDefinitionBo} id
149     * @return the @{link KewAttributeDefinitonBo} id
150     */
151    public String getAttributeDefinitionId() {
152        if (null != this.attributeDefinition) {
153            return this.attributeDefinition.getId();
154        } else {
155            return null;
156        }
157    }
158}