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.NotificationRecipient; 022import org.kuali.rice.ken.api.notification.NotificationRecipientContract; 023import org.kuali.rice.krad.bo.PersistableBusinessObjectBase; 024 025import javax.persistence.*; 026 027/** 028 * This class houses information pertaining to each recipient for a Notification message. This 029 * recipient can be either a user or a group - which is specified by the recipient type. 030 * @author Kuali Rice Team (rice.collab@kuali.org) 031 */ 032@Entity 033@Table(name="KREN_RECIP_T") 034public class NotificationRecipientBo extends PersistableBusinessObjectBase implements NotificationRecipientContract { 035 @Id 036 @GeneratedValue(generator="KREN_RECIP_S") 037 @GenericGenerator(name="KREN_RECIP_S",strategy="org.hibernate.id.enhanced.SequenceStyleGenerator",parameters={ 038 @Parameter(name="sequence_name",value="KREN_RECIP_S"), 039 @Parameter(name="value_column",value="id") 040 }) 041 @Column(name="RECIP_ID") 042 private Long id; 043 @Column(name="NTFCTN_ID", nullable=false) 044 private Long notificationId; 045 @Column(name="RECIP_TYP_CD", nullable=false) 046 private String recipientType; 047 @Column(name="PRNCPL_ID", nullable=false) 048 private String recipientId; 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", insertable=false, updatable=false) 053 private NotificationBo notification; 054 055 /** 056 * Constructs a NotificationRecipient instance. 057 */ 058 public NotificationRecipientBo() { 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 notificationId; 083 } 084 085 /** 086 * Sets the notificationId attribute value. 087 * @param notificationId The notificationId to set. 088 */ 089 public void setNotificationId(Long notificationId) { 090 this.notificationId = notificationId; 091 } 092 093 /** 094 * Gets the recipientId attribute. 095 * @return Returns the recipientId. 096 */ 097 public String getRecipientId() { 098 return recipientId; 099 } 100 101 /** 102 * Sets the recipientId attribute value. 103 * @param recipientId The recipientId to set. 104 */ 105 public void setRecipientId(String recipientId) { 106 this.recipientId = recipientId; 107 } 108 109 /** 110 * Gets the recipientType attribute. 111 * @return Returns the recipientType. 112 */ 113 public String getRecipientType() { 114 return recipientType; 115 } 116 117 /** 118 * Sets the recipientType attribute value. 119 * @param recipientType The recipientType to set. 120 */ 121 public void setRecipientType(String recipientType) { 122 this.recipientType = recipientType; 123 } 124 125 /** 126 * Converts a mutable bo to its immutable counterpart 127 * @param bo the mutable business object 128 * @return the immutable object 129 */ 130 public static NotificationRecipient to(NotificationRecipientBo bo) { 131 if (bo == null) { 132 return null; 133 } 134 135 return NotificationRecipient.Builder.create(bo).build(); 136 } 137 138 /** 139 * Converts a immutable object to its mutable counterpart 140 * @param im immutable object 141 * @return the mutable bo 142 */ 143 public static NotificationRecipientBo from(NotificationRecipient im) { 144 if (im == null) { 145 return null; 146 } 147 148 NotificationRecipientBo bo = new NotificationRecipientBo(); 149 bo.setId(im.getId()); 150 bo.setVersionNumber(im.getVersionNumber()); 151 bo.setObjectId(im.getObjectId()); 152 153 bo.setRecipientType(im.getRecipientType()); 154 bo.setRecipientId(im.getRecipientId()); 155 bo.setNotificationId(im.getNotificationId()); 156 return bo; 157 } 158} 159