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.role;
017
018import javax.persistence.CascadeType;
019import javax.persistence.Column;
020import javax.persistence.Convert;
021import javax.persistence.Entity;
022import javax.persistence.GeneratedValue;
023import javax.persistence.Id;
024import javax.persistence.JoinColumn;
025import javax.persistence.ManyToOne;
026import javax.persistence.Table;
027
028import org.kuali.rice.kim.api.role.RolePermission;
029import org.kuali.rice.kim.api.role.RolePermissionContract;
030import org.kuali.rice.kim.impl.permission.PermissionBo;
031import org.kuali.rice.krad.bo.DataObjectBase;
032import org.kuali.rice.krad.data.jpa.PortableSequenceGenerator;
033import org.kuali.rice.krad.data.jpa.converters.BooleanYNConverter;
034
035@Entity
036@Table(name = "KRIM_ROLE_PERM_T")
037public class RolePermissionBo extends DataObjectBase implements RolePermissionContract {
038
039    private static final long serialVersionUID = 1L;
040
041    @PortableSequenceGenerator(name = "KRIM_ROLE_PERM_ID_S")
042    @GeneratedValue(generator = "KRIM_ROLE_PERM_ID_S")
043    @Id
044    @Column(name = "ROLE_PERM_ID")
045    private String id;
046
047    @Column(name = "ROLE_ID")
048    private String roleId;
049
050    @Column(name = "PERM_ID")
051    private String permissionId;
052
053    @Column(name = "ACTV_IND")
054    @Convert(converter = BooleanYNConverter.class)
055    private boolean active;
056
057    @ManyToOne(targetEntity = PermissionBo.class, cascade = { CascadeType.REFRESH })
058    @JoinColumn(name = "PERM_ID", referencedColumnName = "PERM_ID", insertable = false, updatable = false)
059    private PermissionBo permission;
060
061    /**
062     * Converts a mutable bo to its immutable counterpart
063     *
064     * @param bo the mutable business object
065     * @return the immutable object
066     */
067    public static RolePermission to(RolePermissionBo bo) {
068        if (bo == null) {
069            return null;
070        }
071        return RolePermission.Builder.create(bo).build();
072    }
073
074    /**
075     * Converts a immutable object to its mutable counterpart
076     *
077     * @param im immutable object
078     * @return the mutable bo
079     */
080    public static RolePermissionBo from(RolePermission im) {
081        if (im == null) {
082            return null;
083        }
084        RolePermissionBo bo = new RolePermissionBo();
085        bo.id = im.getId();
086        bo.roleId = im.getRoleId();
087        bo.permissionId = im.getPermissionId();
088        bo.active = im.isActive();
089        bo.setVersionNumber(im.getVersionNumber());
090        bo.setObjectId(im.getObjectId());
091        return bo;
092    }
093
094    @Override
095    public String getId() {
096        return id;
097    }
098
099    public void setId(String id) {
100        this.id = id;
101    }
102
103    @Override
104    public String getRoleId() {
105        return roleId;
106    }
107
108    public void setRoleId(String roleId) {
109        this.roleId = roleId;
110    }
111
112    @Override
113    public String getPermissionId() {
114        return permissionId;
115    }
116
117    public void setPermissionId(String permissionId) {
118        this.permissionId = permissionId;
119    }
120
121    public boolean getActive() {
122        return active;
123    }
124
125    @Override
126    public boolean isActive() {
127        return active;
128    }
129
130    public void setActive(boolean active) {
131        this.active = active;
132    }
133
134    public PermissionBo getPermission() {
135        return permission;
136    }
137
138    public void setPermission(PermissionBo permission) {
139        this.permission = permission;
140    }
141}