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.edl.impl.extract;
017
018import javax.persistence.CascadeType;
019import javax.persistence.Column;
020import javax.persistence.Entity;
021import javax.persistence.FetchType;
022import javax.persistence.GeneratedValue;
023import javax.persistence.Id;
024import javax.persistence.JoinColumn;
025import javax.persistence.ManyToOne;
026import javax.persistence.Table;
027import javax.persistence.Version;
028
029import org.kuali.rice.edl.framework.extract.FieldDTO;
030import org.kuali.rice.krad.data.jpa.PortableSequenceGenerator;
031
032import java.io.Serializable;
033
034/**
035 *
036 *
037 *
038 * @author Kuali Rice Team (rice.collab@kuali.org)
039 *
040 */
041@Entity
042@Table(name="KREW_EDL_FLD_DMP_T")
043public class Fields implements Serializable {
044
045    //  private static final long serialVersionUID = -6136544551121011531L;
046
047    @Id
048    @GeneratedValue(generator="KREW_EDL_FLD_DMP_S")
049    @PortableSequenceGenerator(name = "KREW_EDL_FLD_DMP_S")
050    @Column(name="EDL_FIELD_DMP_ID")
051    private Long fieldId;
052
053    @Column(name="DOC_HDR_ID")
054    private String docId;
055
056    @Column(name="FLD_NM")
057    private String fieldName;
058
059    @Column(name="FLD_VAL")
060    private String fieldValue;
061
062    @Version
063    @Column(name="VER_NBR")
064    private Integer lockVerNbr;
065
066    @ManyToOne(fetch=FetchType.EAGER, cascade={CascadeType.PERSIST})
067    @JoinColumn(name="DOC_HDR_ID", insertable=false, updatable=false)
068    private Dump dump;
069
070    /**
071     * Returns the field id.
072     * @return the field id
073     */
074    public Long getFieldId() {
075        return fieldId;
076    }
077
078    /**
079     *
080     * @see #getFieldId()
081     */
082    public void setFieldId(Long fieldId) {
083        this.fieldId = fieldId;
084    }
085
086    /**
087     * Returns the doc id.
088     * @return the doc id
089     */
090    public String getDocId() {
091        return docId;
092    }
093
094    /**
095     *
096     * @see #getDocId()
097     */
098    public void setDocId(final String docId) {
099        this.docId = docId;
100    }
101
102    /**
103     * Returns the field value.
104     * @return the field value
105     */
106    public String getFieldValue() {
107        return fieldValue;
108    }
109
110    /**
111     *
112     * @see #getFieldValue()
113     */
114    public void setFieldValue(final String fieldValue) {
115        this.fieldValue = fieldValue;
116    }
117
118    /**
119     * Returns the field name.
120     * @return the field name
121     */
122    public String getFieldName() {
123        return fieldName;
124    }
125
126    /**
127     *
128     * @see #getFieldName()
129     */
130    public void setFieldName(final String filedName) {
131        this.fieldName = filedName;
132    }
133
134    /**
135     * Returns the lock version number.
136     * @return the lock version number
137     */
138    public Integer getLockVerNbr() {
139        return lockVerNbr;
140    }
141
142    /**
143     *
144     * @see #getLockVerNbr()
145     */
146    public void setLockVerNbr(final Integer lockVerNbr) {
147        this.lockVerNbr = lockVerNbr;
148    }
149
150    /**
151     * Returns a {@link Dump}
152     * @return a {@link Dump}
153     */
154    public Dump getDump() {
155        return dump;
156    }
157
158    /**
159     *
160     * @see #getDump()
161     */
162    public void setDump(final Dump dump) {
163        this.dump = dump;
164    }
165
166    /**
167     * Converts a {@link Fields} to a {@link FieldDTO}.
168     * @param field the {@link Fields} to convert.
169     * @return a {@link Fields}
170     */
171    public static FieldDTO to(Fields field) {
172        if (field == null) {
173            return null;
174        }
175        FieldDTO fieldDTO = new FieldDTO();
176        fieldDTO.setDocId(field.getDocId());
177        fieldDTO.setFieldName(field.getFieldName());
178        fieldDTO.setFieldValue(field.getFieldValue());
179        fieldDTO.setLockVerNbr(field.getLockVerNbr());
180        return fieldDTO;
181    }
182
183    /**
184     * Converts a {@link FieldDTO} to a {@link Fields}
185     * @param fieldDTO the {@link FieldDTO} to convert.
186     * @param dump a {@link Dump}
187     * @return a {@link Fields}
188     */
189    public static Fields from(FieldDTO fieldDTO, Dump dump) {
190        if (fieldDTO == null) {
191            return null;
192        }
193        Fields fields = new Fields();
194        fields.setDump(dump);
195        fields.setDocId(fieldDTO.getDocId());
196        fields.setFieldName(fieldDTO.getFiledName());
197        fields.setFieldValue(fieldDTO.getFieldValue());
198        fields.setLockVerNbr(fieldDTO.getLockVerNbr());
199        return fields;
200    }
201}
202