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.ken.bo;
017
018import org.hibernate.annotations.GenericGenerator;
019import org.hibernate.annotations.Parameter;
020import org.kuali.rice.ken.api.notification.NotificationListRecipient;
021import org.kuali.rice.ken.api.notification.NotificationListRecipientContract;
022import org.kuali.rice.ken.api.notification.NotificationProducer;
023import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
024
025import javax.persistence.*;
026
027/**
028 * This class represents the data structure that will house a default recipient list for a notification channel.
029 * @author Kuali Rice Team (rice.collab@kuali.org)
030 */
031@Entity
032@Table(name="KREN_RECIP_LIST_T")
033public class NotificationRecipientListBo extends PersistableBusinessObjectBase implements NotificationListRecipientContract {
034    @Id
035    @GeneratedValue(generator="KREN_RECIP_LIST_S")
036        @GenericGenerator(name="KREN_RECIP_LIST_S",strategy="org.hibernate.id.enhanced.SequenceStyleGenerator",parameters={
037                        @Parameter(name="sequence_name",value="KREN_RECIP_LIST_S"),
038                        @Parameter(name="value_column",value="id")
039        })
040        @Column(name="RECIP_LIST_ID")
041        private Long id;
042    @Column(name="RECIP_TYP_CD", nullable=false)
043        private String recipientType;
044    @Column(name="RECIP_ID", nullable=false)
045        private String recipientId;
046    
047    @ManyToOne(fetch=FetchType.EAGER, cascade={CascadeType.REFRESH, CascadeType.MERGE})
048        @JoinColumn(name="CHNL_ID", insertable=false, updatable=false)
049        private NotificationChannelBo channel;
050    
051    /**
052     * Constructs a NotificationRecipientList.java instance.
053     */
054    public NotificationRecipientListBo() {
055    }
056
057    /**
058     * Gets the channel attribute. 
059     * @return Returns the channel.
060     */
061    public NotificationChannelBo getChannel() {
062        return channel;
063    }
064
065
066    /**
067     * Sets the channel attribute value.
068     * @param channel The channel to set.
069     */
070    public void setChannel(NotificationChannelBo channel) {
071        this.channel = channel;
072    }
073
074    /**
075     * Gets the id attribute. 
076     * @return Returns the id.
077     */
078    public Long getId() {
079        return id;
080    }
081
082    /**
083     * Sets the id attribute value.
084     * @param id The id to set.
085     */
086    public void setId(Long id) {
087        this.id = id;
088    }
089
090    /**
091     * Gets the recipientId attribute. 
092     * @return Returns the recipientId.
093     */
094    public String getRecipientId() {
095        return recipientId;
096    }
097
098    /**
099     * Sets the recipientId attribute value.
100     * @param recipientId The recipientId to set.
101     */
102    public void setRecipientId(String recipientId) {
103        this.recipientId = recipientId;
104    }
105
106    /**
107     * Gets the recipientType attribute. 
108     * @return Returns the recipientType.
109     */
110    public String getRecipientType() {
111        return recipientType;
112    }
113
114    /**
115     * Sets the recipientType attribute value.
116     * @param recipientType The recipientType to set.
117     */
118    public void setRecipientType(String recipientType) {
119        this.recipientType = recipientType;
120    }
121
122    /**
123     * Converts a mutable bo to its immutable counterpart
124     * @param bo the mutable business object
125     * @return the immutable object
126     */
127    public static NotificationListRecipient to(NotificationRecipientListBo bo) {
128        if (bo == null) {
129            return null;
130        }
131
132        return NotificationListRecipient.Builder.create(bo).build();
133    }
134
135    /**
136     * Converts a immutable object to its mutable counterpart
137     * @param im immutable object
138     * @return the mutable bo
139     */
140    public static NotificationRecipientListBo from(NotificationListRecipient im) {
141        if (im == null) {
142            return null;
143        }
144
145        NotificationRecipientListBo bo = new NotificationRecipientListBo();
146        bo.setId(im.getId());
147        bo.setVersionNumber(im.getVersionNumber());
148        bo.setObjectId(im.getObjectId());
149
150        bo.setRecipientType(im.getRecipientType());
151        bo.setRecipientId(im.getRecipientId());
152
153        bo.setChannel(im.getChannel() == null ? null : NotificationChannelBo.from(im.getChannel()));
154        return bo;
155    }
156}
157