001/** 002 * Copyright 2005-2017 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.NotificationRecipient; 019import org.kuali.rice.ken.api.notification.NotificationRecipientContract; 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.*; 025 026/** 027 * This class houses information pertaining to each recipient for a Notification message. This 028 * recipient can be either a user or a group - which is specified by the recipient type. 029 * @author Kuali Rice Team (rice.collab@kuali.org) 030 */ 031@Entity 032@Table(name="KREN_RECIP_T") 033public class NotificationRecipientBo extends PersistableBusinessObjectBase implements NotificationRecipientContract { 034 @Id 035 @GeneratedValue(generator="KREN_RECIP_S") 036 @PortableSequenceGenerator(name="KREN_RECIP_S") 037 @Column(name="RECIP_ID") 038 private Long id; 039 @Column(name="RECIP_TYP_CD", nullable=false) 040 private String recipientType; 041 @Column(name="PRNCPL_ID", nullable=false) 042 private String recipientId; 043 044 // Added for JPA uni-directional one-to-many (not yet supported by JPA) 045 @ManyToOne(fetch=FetchType.EAGER, cascade={CascadeType.PERSIST, CascadeType.REMOVE}) 046 @JoinColumn(name="NTFCTN_ID", nullable = false) 047 private NotificationBo notification; 048 049 /** 050 * Constructs a NotificationRecipient instance. 051 */ 052 public NotificationRecipientBo() { 053 } 054 055 /** 056 * Gets the id attribute. 057 * @return Returns the id. 058 */ 059 public Long getId() { 060 return id; 061 } 062 063 /** 064 * Sets the id attribute value. 065 * @param id The id to set. 066 */ 067 public void setId(Long id) { 068 this.id = id; 069 } 070 071 /** 072 * Gets the notificationId attribute. 073 * @return Returns the notificationId. 074 */ 075 public Long getNotificationId() { 076 return (notification == null) ? null : notification.getId(); 077 } 078 079 /** 080 * Gets the recipientId attribute. 081 * @return Returns the recipientId. 082 */ 083 public String getRecipientId() { 084 return recipientId; 085 } 086 087 /** 088 * Sets the recipientId attribute value. 089 * @param recipientId The recipientId to set. 090 */ 091 public void setRecipientId(String recipientId) { 092 this.recipientId = recipientId; 093 } 094 095 /** 096 * Gets the recipientType attribute. 097 * @return Returns the recipientType. 098 */ 099 public String getRecipientType() { 100 return recipientType; 101 } 102 103 /** 104 * Sets the recipientType attribute value. 105 * @param recipientType The recipientType to set. 106 */ 107 public void setRecipientType(String recipientType) { 108 this.recipientType = recipientType; 109 } 110 111 public NotificationBo getNotification() { 112 return notification; 113 } 114 115 public void setNotification(NotificationBo notification) { 116 this.notification = notification; 117 } 118 119 /** 120 * Converts a mutable bo to its immutable counterpart 121 * @param bo the mutable business object 122 * @return the immutable object 123 */ 124 public static NotificationRecipient to(NotificationRecipientBo bo) { 125 if (bo == null) { 126 return null; 127 } 128 129 return NotificationRecipient.Builder.create(bo).build(); 130 } 131 132 /** 133 * Converts a immutable object to its mutable counterpart 134 * @param im immutable object 135 * @return the mutable bo 136 */ 137 public static NotificationRecipientBo from(NotificationRecipient im) { 138 if (im == null) { 139 return null; 140 } 141 142 NotificationRecipientBo bo = new NotificationRecipientBo(); 143 bo.setId(im.getId()); 144 bo.setVersionNumber(im.getVersionNumber()); 145 bo.setObjectId(im.getObjectId()); 146 147 bo.setRecipientType(im.getRecipientType()); 148 bo.setRecipientId(im.getRecipientId()); 149 if (im.getNotificationId() != null) { 150 NotificationBo notification = 151 KradDataServiceLocator.getDataObjectService().find(NotificationBo.class, im.getNotificationId()); 152 bo.setNotification(notification); 153 } 154 return bo; 155 } 156} 157