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