001/** 002 * Copyright 2005-2014 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.NotificationListRecipient; 019import org.kuali.rice.ken.api.notification.NotificationListRecipientContract; 020import org.kuali.rice.krad.bo.PersistableBusinessObjectBase; 021import org.kuali.rice.krad.data.jpa.PortableSequenceGenerator; 022 023import javax.persistence.CascadeType; 024import javax.persistence.Column; 025import javax.persistence.Entity; 026import javax.persistence.FetchType; 027import javax.persistence.GeneratedValue; 028import javax.persistence.Id; 029import javax.persistence.JoinColumn; 030import javax.persistence.ManyToOne; 031import javax.persistence.Table; 032 033/** 034 * This class represents the data structure that will house a default recipient list for a notification channel. 035 * @author Kuali Rice Team (rice.collab@kuali.org) 036 */ 037@Entity 038@Table(name="KREN_RECIP_LIST_T") 039public class NotificationRecipientListBo extends PersistableBusinessObjectBase implements NotificationListRecipientContract { 040 @Id 041 @GeneratedValue(generator="KREN_RECIP_LIST_S") 042 @PortableSequenceGenerator(name="KREN_RECIP_LIST_S") 043 @Column(name="RECIP_LIST_ID") 044 private Long id; 045 @Column(name="RECIP_TYP_CD", nullable=false) 046 private String recipientType; 047 @Column(name="RECIP_ID", nullable=false) 048 private String recipientId; 049 050 @ManyToOne(fetch=FetchType.EAGER, cascade={CascadeType.REFRESH, CascadeType.MERGE}) 051 @JoinColumn(name="CHNL_ID", insertable=false, updatable=false) 052 private NotificationChannelBo channel; 053 054 /** 055 * Constructs a NotificationRecipientList.java instance. 056 */ 057 public NotificationRecipientListBo() { 058 } 059 060 /** 061 * Gets the channel attribute. 062 * @return Returns the channel. 063 */ 064 public NotificationChannelBo getChannel() { 065 return channel; 066 } 067 068 069 /** 070 * Sets the channel attribute value. 071 * @param channel The channel to set. 072 */ 073 public void setChannel(NotificationChannelBo channel) { 074 this.channel = channel; 075 } 076 077 /** 078 * Gets the id attribute. 079 * @return Returns the id. 080 */ 081 public Long getId() { 082 return id; 083 } 084 085 /** 086 * Sets the id attribute value. 087 * @param id The id to set. 088 */ 089 public void setId(Long id) { 090 this.id = id; 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 NotificationListRecipient to(NotificationRecipientListBo bo) { 131 if (bo == null) { 132 return null; 133 } 134 135 return NotificationListRecipient.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 NotificationRecipientListBo from(NotificationListRecipient im) { 144 if (im == null) { 145 return null; 146 } 147 148 NotificationRecipientListBo bo = new NotificationRecipientListBo(); 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 156 bo.setChannel(im.getChannel() == null ? null : NotificationChannelBo.from(im.getChannel())); 157 return bo; 158 } 159} 160