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.NotificationRecipient;
021import org.kuali.rice.ken.api.notification.NotificationSender;
022import org.kuali.rice.ken.api.notification.NotificationSenderContract;
023import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
024
025import javax.persistence.*;
026
027/**
028 * This class represents the data structure that will house information about the non-system 
029 * sender that a notification message is sent on behalf of.
030 * @author Kuali Rice Team (rice.collab@kuali.org)
031 */
032@Entity
033@Table(name="KREN_SNDR_T")
034public class NotificationSenderBo extends PersistableBusinessObjectBase implements NotificationSenderContract {
035    @Id
036    @GeneratedValue(generator="KREN_SNDR_S")
037        @GenericGenerator(name="KREN_SNDR_S",strategy="org.hibernate.id.enhanced.SequenceStyleGenerator",parameters={
038                        @Parameter(name="sequence_name",value="KREN_SNDR_S"),
039                        @Parameter(name="value_column",value="id")
040        })
041        @Column(name="SNDR_ID")
042        private Long id;
043    @Column(name="NTFCTN_ID", nullable=false)
044        private Long notificationId;
045    @Column(name="NM", nullable=false)
046        private String senderName;
047
048    // Added for JPA uni-directional one-to-many (not yet supported by JPA)
049    @ManyToOne(fetch=FetchType.EAGER, cascade={CascadeType.PERSIST, CascadeType.REMOVE})
050    @JoinColumn(name="NTFCTN_ID", insertable=false, updatable=false)
051    private NotificationBo notification;
052
053    /**
054     * Constructs a NotificationSender.java instance.
055     */
056    public NotificationSenderBo() {
057    }
058
059    /**
060     * Gets the id attribute. 
061     * @return Returns the id.
062     */
063    public Long getId() {
064        return id;
065    }
066
067    /**
068     * Sets the id attribute value.
069     * @param id The id to set.
070     */
071    public void setId(Long id) {
072        this.id = id;
073    }
074
075    /**
076     * Gets the notificationId attribute. 
077     * @return Returns the notificationId.
078     */
079    public Long getNotificationId() {
080        return notificationId;
081    }
082
083    /**
084     * Sets the notificationId attribute value.
085     * @param notificationId The notificationId to set.
086     */
087    public void setNotificationId(Long notificationId) {
088        this.notificationId = notificationId;
089    }
090
091    /**
092     * Gets the senderName attribute. 
093     * @return Returns the senderName.
094     */
095    public String getSenderName() {
096        return senderName;
097    }
098
099    /**
100     * Sets the senderName attribute value.
101     * @param userId The senderName to set.
102     */
103    public void setSenderName(String userId) {
104        this.senderName = userId;
105    }
106
107    /**
108     * Converts a mutable bo to its immutable counterpart
109     * @param bo the mutable business object
110     * @return the immutable object
111     */
112    public static NotificationSender to(NotificationSenderBo bo) {
113        if (bo == null) {
114            return null;
115        }
116
117        return NotificationSender.Builder.create(bo).build();
118    }
119
120    /**
121     * Converts a immutable object to its mutable counterpart
122     * @param im immutable object
123     * @return the mutable bo
124     */
125    public static NotificationSenderBo from(NotificationSender im) {
126        if (im == null) {
127            return null;
128        }
129
130        NotificationSenderBo bo = new NotificationSenderBo();
131        bo.setId(im.getId());
132        bo.setVersionNumber(im.getVersionNumber());
133        bo.setObjectId(im.getObjectId());
134        bo.setSenderName(im.getSenderName());
135        bo.setNotificationId(im.getNotificationId());
136        return bo;
137    }
138}