001/**
002 * Copyright 2005-2014 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.PortableSequenceGenerator;
020import org.kuali.rice.krms.api.repository.function.FunctionParameterDefinition;
021import org.kuali.rice.krms.api.repository.function.FunctionParameterDefinitionContract;
022
023import javax.persistence.Column;
024import javax.persistence.Entity;
025import javax.persistence.FetchType;
026import javax.persistence.GeneratedValue;
027import javax.persistence.Id;
028import javax.persistence.JoinColumn;
029import javax.persistence.ManyToOne;
030import javax.persistence.Table;
031import javax.persistence.Transient;
032import java.io.Serializable;
033import java.util.ArrayList;
034import java.util.Collections;
035import java.util.List;
036
037@Entity
038@Table(name = "KRMS_FUNC_PARM_T")
039public class FunctionParameterBo implements FunctionParameterDefinitionContract, Serializable {
040
041    private static final long serialVersionUID = 1l;
042
043    @PortableSequenceGenerator(name = "KRMS_FUNC_S")
044    @GeneratedValue(generator = "KRMS_FUNC_S")
045    @Id
046    @Column(name = "FUNC_PARM_ID")
047    private String id;
048
049    @Column(name = "NM")
050    private String name;
051
052    @Column(name = "DESC_TXT")
053    private String description;
054
055    @ManyToOne(fetch = FetchType.LAZY)
056    @JoinColumn(name="FUNC_ID")
057    private FunctionBo function;
058
059    @Column(name = "TYP")
060    private String parameterType;
061
062    @Column(name = "SEQ_NO")
063    private Integer sequenceNumber;
064
065    @Transient
066    protected Long versionNumber;
067
068    /**
069     * Converts a mutable bo to it's immutable counterpart
070     *
071     * @param bo the mutable business object
072     * @return the immutable object
073     */
074    public static FunctionParameterDefinition to(FunctionParameterBo bo) {
075        if (bo == null) {
076            return null;
077        }
078
079        return FunctionParameterDefinition.Builder.create(bo).build();
080    }
081
082    /**
083     * Converts a list of mutable bos to it's immutable counterpart
084     *
085     * @param bos the list of mutable business objects
086     * @return and immutable list containing the immutable objects
087     */
088    public static List<FunctionParameterDefinition> to(List<FunctionParameterBo> bos) {
089        if (bos == null) {
090            return null;
091        }
092
093        List<FunctionParameterDefinition> parms = new ArrayList<FunctionParameterDefinition>();
094
095        for (FunctionParameterBo p : bos) {
096            parms.add(FunctionParameterDefinition.Builder.create(p).build());
097        }
098
099        return Collections.unmodifiableList(parms);
100    }
101
102    /**
103     * Converts a immutable object to it's mutable bo counterpart
104     *
105     * @param im immutable object
106     * @return the mutable bo
107     */
108    public static FunctionParameterBo from(FunctionParameterDefinition im) {
109        if (im == null) {
110            return null;
111        }
112        FunctionParameterBo bo = new FunctionParameterBo();
113        bo.id = im.getId();
114        bo.name = im.getName();
115        bo.description = im.getDescription();
116
117        // not setting function here, it will be set in FunctionBo.from
118
119        bo.parameterType = im.getParameterType();
120        bo.sequenceNumber = im.getSequenceNumber();
121        bo.setVersionNumber(im.getVersionNumber());
122        return bo;
123    }
124
125    public static List<FunctionParameterBo> from(List<FunctionParameterDefinition> ims) {
126        if (ims == null) {
127            return null;
128        }
129
130        List<FunctionParameterBo> bos = new ArrayList<FunctionParameterBo>();
131        for (FunctionParameterDefinition im : ims) {
132            FunctionParameterBo bo = FunctionParameterBo.from(im);
133            ((ArrayList<FunctionParameterBo>) bos).add(bo);
134        }
135
136        return Collections.unmodifiableList(bos);
137    }
138
139    public String getId() {
140        return id;
141    }
142
143    public void setId(String id) {
144        this.id = id;
145    }
146
147    public String getName() {
148        return name;
149    }
150
151    public void setName(String name) {
152        this.name = name;
153    }
154
155    public String getDescription() {
156        return description;
157    }
158
159    public void setDescription(String description) {
160        this.description = description;
161    }
162
163    public String getFunctionId() {
164        if (function != null){
165            return function.getId();
166        }
167
168        return null;
169    }
170
171    public FunctionBo getFunction() {
172        return function;
173    }
174
175    public void setFunction(FunctionBo function) {
176        this.function = function;
177    }
178
179    public String getParameterType() {
180        return parameterType;
181    }
182
183    public void setParameterType(String parameterType) {
184        this.parameterType = parameterType;
185    }
186
187    public Integer getSequenceNumber() {
188        return sequenceNumber;
189    }
190
191    public void setSequenceNumber(Integer sequenceNumber) {
192        this.sequenceNumber = sequenceNumber;
193    }
194
195    public Long getVersionNumber() {
196        return versionNumber;
197    }
198
199    public void setVersionNumber(Long versionNumber) {
200        this.versionNumber = versionNumber;
201    }
202}