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.bo.ui;
017
018import java.util.List;
019
020import javax.persistence.CascadeType;
021import javax.persistence.Column;
022import javax.persistence.Entity;
023import javax.persistence.GeneratedValue;
024import javax.persistence.Id;
025import javax.persistence.JoinColumn;
026import javax.persistence.JoinColumns;
027import javax.persistence.OneToMany;
028import javax.persistence.Table;
029import javax.persistence.Transient;
030
031import org.eclipse.persistence.annotations.JoinFetch;
032import org.eclipse.persistence.annotations.JoinFetchType;
033import org.kuali.rice.kim.api.responsibility.Responsibility;
034import org.kuali.rice.kim.api.services.KimApiServiceLocator;
035import org.kuali.rice.kim.impl.responsibility.ResponsibilityBo;
036import org.kuali.rice.krad.data.jpa.PortableSequenceGenerator;
037import org.springframework.util.AutoPopulatingList;
038
039/**
040 * @author Kuali Rice Team (rice.collab@kuali.org)
041 */
042@Entity
043@Table(name = "KRIM_PND_ROLE_RSP_T")
044public class KimDocumentRoleResponsibility extends KimDocumentBoActivatableBase {
045
046    private static final long serialVersionUID = -4465768714850961538L;
047
048    @PortableSequenceGenerator(name = "KRIM_ROLE_RSP_ID_S")
049    @GeneratedValue(generator = "KRIM_ROLE_RSP_ID_S")
050    @Id
051    @Column(name = "ROLE_RSP_ID")
052    protected String roleResponsibilityId;
053
054    @Column(name = "ROLE_ID")
055    protected String roleId;
056
057    @Column(name = "RSP_ID")
058    protected String responsibilityId;
059
060    // temporary default value in lieu of optimistic locking                       
061//    @Column(name = "VER_NBR")
062//    protected Long versionNumber = 0L;
063
064    @Transient
065    protected ResponsibilityBo kimResponsibility;
066
067    @JoinFetch(value= JoinFetchType.OUTER)
068    @OneToMany(targetEntity = KimDocumentRoleResponsibilityAction.class, orphanRemoval = true, cascade = { CascadeType.REFRESH, CascadeType.REMOVE, CascadeType.PERSIST })
069    @JoinColumns({ 
070            @JoinColumn(name = "FDOC_NBR", referencedColumnName = "FDOC_NBR", insertable = false, updatable = false) 
071            ,@JoinColumn(name = "ROLE_RSP_ID", referencedColumnName = "ROLE_RSP_ID", insertable = false, updatable = false) 
072    })
073    protected List<KimDocumentRoleResponsibilityAction> roleRspActions = new AutoPopulatingList<KimDocumentRoleResponsibilityAction>(KimDocumentRoleResponsibilityAction.class);
074
075    @Transient
076    protected String name;
077
078    @Transient
079    protected String namespaceCode;
080
081    public String getRoleId() {
082        return roleId;
083    }
084
085    public void setRoleId(String roleId) {
086        this.roleId = roleId;
087    }
088
089    public void setRoleResponsibilityId(String roleResponsibilityId) {
090        this.roleResponsibilityId = roleResponsibilityId;
091    }
092
093    /**
094         * @return the roleResponsibilityId
095         */
096    public String getRoleResponsibilityId() {
097        return this.roleResponsibilityId;
098    }
099
100    /**
101         * @return the kimResponsibility
102         */
103    public ResponsibilityBo getKimResponsibility() {
104        if (kimResponsibility == null && responsibilityId != null) {
105            //TODO: this needs to be changed to use the KimResponsibilityInfo object                       
106            // but the changes are involved in the UiDocumentService based on the copyProperties method used                       
107            // to move the data to/from the document/real objects                       
108            Responsibility info = KimApiServiceLocator.getResponsibilityService().getResponsibility(getResponsibilityId());
109            kimResponsibility = ResponsibilityBo.from(info);
110        }
111        return this.kimResponsibility;
112    }
113
114    /**
115         * @param responsibilityId the responsibilityId to set
116         */
117    public void setResponsibilityId(String responsibilityId) {
118        this.responsibilityId = responsibilityId;
119    }
120
121    /**
122         * @param kimResponsibility the kimResponsibility to set
123         */
124    public void setKimResponsibility(ResponsibilityBo kimResponsibility) {
125        this.kimResponsibility = kimResponsibility;
126    }
127
128    /**
129         * @return the responsibilityId
130         */
131    public String getResponsibilityId() {
132        return this.responsibilityId;
133    }
134
135    /**
136         * @return the roleRspActions
137         */
138    public KimDocumentRoleResponsibilityAction getRoleRspAction() {
139        if (this.roleRspActions != null && this.roleRspActions.size() > 0)
140            return this.roleRspActions.get(0);
141        return null;
142    }
143
144    /**
145         * @return the roleRspActions
146         */
147    public List<KimDocumentRoleResponsibilityAction> getRoleRspActions() {
148        return this.roleRspActions;
149    }
150
151    /**
152         * @param roleRspActions the roleRspActions to set
153         */
154    public void setRoleRspActions(List<KimDocumentRoleResponsibilityAction> roleRspActions) {
155        this.roleRspActions = roleRspActions;
156    }
157
158    public String getName() {
159        if (null == kimResponsibility) {
160            getKimResponsibility();
161        }
162        if (null == kimResponsibility) {
163            return "";
164        }
165        return kimResponsibility.getName();
166    }
167
168    public String getNamespaceCode() {
169        if (null == kimResponsibility) {
170            getKimResponsibility();
171        }
172        if (null == kimResponsibility) {
173            return "";
174        }
175        return kimResponsibility.getNamespaceCode();
176    }
177}