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.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.KrmsAttributeDefinition;
022import org.kuali.rice.krms.api.repository.type.KrmsAttributeDefinitionContract;
023
024import javax.persistence.Column;
025import javax.persistence.Convert;
026import javax.persistence.Entity;
027import javax.persistence.GeneratedValue;
028import javax.persistence.Id;
029import javax.persistence.Table;
030import javax.persistence.Version;
031import java.io.Serializable;
032
033@Entity
034@Table(name = "KRMS_ATTR_DEFN_T")
035public class KrmsAttributeDefinitionBo implements KrmsAttributeDefinitionContract, MutableInactivatable, Serializable {
036
037    private static final long serialVersionUID = 1l;
038
039    @PortableSequenceGenerator(name = "KRMS_ATTR_DEFN_S")
040    @GeneratedValue(generator = "KRMS_ATTR_DEFN_S")
041    @Id
042    @Column(name = "ATTR_DEFN_ID")
043    private String id;
044
045    @Column(name = "NM")
046    private String name;
047
048    @Column(name = "NMSPC_CD")
049    private String namespace;
050
051    @Column(name = "LBL")
052    private String label;
053
054    @Column(name = "DESC_TXT")
055    private String description;
056
057    @Column(name = "ACTV")
058    @Convert(converter = BooleanYNConverter.class)
059    private boolean active = true;
060
061    @Column(name = "CMPNT_NM")
062    private String componentName;
063
064    @Version
065    @Column(name="VER_NBR", length=8)
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 KrmsAttributeDefinition to(KrmsAttributeDefinitionBo bo) {
075        if (bo == null) {
076            return null;
077        }
078
079        return KrmsAttributeDefinition.Builder.create(bo).build();
080    }
081
082    /**
083     * Converts a immutable object to it's mutable bo counterpart
084     *
085     * @param im immutable object
086     * @return the mutable bo
087     */
088    public static KrmsAttributeDefinitionBo from(KrmsAttributeDefinition im) {
089        if (im == null) {
090            return null;
091        }
092
093        KrmsAttributeDefinitionBo bo = new KrmsAttributeDefinitionBo();
094        bo.id = im.getId();
095        bo.name = im.getName();
096        bo.namespace = im.getNamespace();
097        bo.label = im.getLabel();
098        bo.description = im.getDescription();
099        bo.active = im.isActive();
100        bo.componentName = im.getComponentName();
101        bo.setVersionNumber(im.getVersionNumber());
102
103        return bo;
104    }
105
106    public String getId() {
107        return id;
108    }
109
110    public void setId(String id) {
111        this.id = id;
112    }
113
114    public String getName() {
115        return name;
116    }
117
118    public void setName(String name) {
119        this.name = name;
120    }
121
122    public String getNamespace() {
123        return namespace;
124    }
125
126    public void setNamespace(String namespace) {
127        this.namespace = namespace;
128    }
129
130    public String getLabel() {
131        return label;
132    }
133
134    public void setLabel(String label) {
135        this.label = label;
136    }
137
138    public String getDescription() {
139        return description;
140    }
141
142    public void setDescription(String description) {
143        this.description = description;
144    }
145
146    public boolean getActive() {
147        return active;
148    }
149
150    public boolean isActive() {
151        return active;
152    }
153
154    public void setActive(boolean active) {
155        this.active = active;
156    }
157
158    public String getComponentName() {
159        return componentName;
160    }
161
162    public void setComponentName(String componentName) {
163        this.componentName = componentName;
164    }
165
166    public Long getVersionNumber() {
167        return versionNumber;
168    }
169
170    public void setVersionNumber(Long versionNumber) {
171        this.versionNumber = versionNumber;
172    }
173}