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.kim.impl.identity;
017
018import javax.persistence.Column;
019import javax.persistence.Id;
020import javax.persistence.MappedSuperclass;
021
022import org.kuali.rice.kim.api.identity.CodedAttribute;
023import org.kuali.rice.kim.api.identity.CodedAttributeContract;
024import org.kuali.rice.krad.bo.DataObjectBase;
025import org.kuali.rice.krad.data.jpa.converters.BooleanYNConverter;
026
027@MappedSuperclass
028public abstract class CodedAttributeBo extends DataObjectBase implements CodedAttributeContract {
029    private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(CodedAttributeBo.class);
030    private static final long serialVersionUID = -5023039880648352464L;
031    @Id
032    @Column(name = "CD")
033    private String code;
034    @Column(name = "NM")
035    private String name;
036    @javax.persistence.Convert(converter=BooleanYNConverter.class)
037    @Column(name = "ACTV_IND")
038    private boolean active;
039    @Column(name = "DISPLAY_SORT_CD")
040    private String sortCode;
041
042    /**
043     * Converts a mutable extension CodedAttributeBo to an immutable CodedAttribute representation.
044     *
045     * @param bo
046     * @return an immutable EntityCitizenshipChangeType
047     */
048    public static <T extends CodedAttributeBo>CodedAttribute to(T bo) {
049        if (bo == null) {
050            return null;
051        }
052
053        return CodedAttribute.Builder.create(bo).build();
054    }
055
056    /**
057     * Creates a EntityCitizenshipChangeTypeBo business object from an immutable representation of a
058     * EntityCitizenshipChangeType.
059     *
060     * @param immutable an immutable CodedAttribute
061     * @return an object extending from CodedAttributeBo
062     */
063    public static <T extends CodedAttributeBo> T from(Class<T> type, CodedAttribute immutable) {
064        if (immutable == null) {
065            return null;
066        }
067        T bo = null;
068        try {
069            bo = type.newInstance();
070
071            bo.setCode(immutable.getCode());
072            bo.setName(immutable.getName());
073            bo.setSortCode(immutable.getSortCode());
074            bo.setActive(immutable.isActive());
075            bo.setVersionNumber(immutable.getVersionNumber());
076            bo.setObjectId(immutable.getObjectId());
077        } catch (InstantiationException e) {
078            LOG.error(e.getMessage(), e);
079        } catch (IllegalAccessException e) {
080            LOG.error(e.getMessage(), e);
081        }
082        return bo;
083    }
084
085    @Override
086    public String getCode() {
087        return code;
088    }
089
090    public void setCode(String code) {
091        this.code = code;
092    }
093
094    @Override
095    public String getName() {
096        return name;
097    }
098
099    public void setName(String name) {
100        this.name = name;
101    }
102
103    @Override
104    public boolean isActive() {
105        return active;
106    }
107
108    public void setActive(boolean active) {
109        this.active = active;
110    }
111
112    @Override
113    public String getSortCode() {
114        return sortCode;
115    }
116
117    public void setSortCode(String sortCode) {
118        this.sortCode = sortCode;
119    }
120
121    public void refresh() {
122    }
123
124}