1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  package org.kuali.rice.ken.bo;
17  
18  import org.kuali.rice.ken.api.notification.NotificationRecipient;
19  import org.kuali.rice.ken.api.notification.NotificationRecipientContract;
20  import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
21  import org.kuali.rice.krad.data.KradDataServiceLocator;
22  import org.kuali.rice.krad.data.jpa.PortableSequenceGenerator;
23  
24  import javax.persistence.*;
25  
26  
27  
28  
29  
30  
31  @Entity
32  @Table(name="KREN_RECIP_T")
33  public class NotificationRecipientBo extends PersistableBusinessObjectBase implements NotificationRecipientContract {
34      @Id
35      @GeneratedValue(generator="KREN_RECIP_S")
36      @PortableSequenceGenerator(name="KREN_RECIP_S")
37  	@Column(name="RECIP_ID")
38  	private Long id;
39      @Column(name="RECIP_TYP_CD", nullable=false)
40  	private String recipientType;
41      @Column(name="PRNCPL_ID", nullable=false)
42  	private String recipientId;
43  
44      
45      @ManyToOne(fetch=FetchType.EAGER, cascade={CascadeType.PERSIST, CascadeType.REMOVE})
46      @JoinColumn(name="NTFCTN_ID", nullable = false)
47      private NotificationBo notification;
48  
49      
50  
51  
52      public NotificationRecipientBo() {
53      }
54  
55      
56  
57  
58  
59      public Long getId() {
60  	    return id;
61      }
62  
63      
64  
65  
66  
67      public void setId(Long id) {
68  	    this.id = id;
69      }
70  
71      
72  
73  
74  
75      public Long getNotificationId() {
76  	    return (notification == null) ? null : notification.getId();
77      }
78  
79      
80  
81  
82  
83      public String getRecipientId() {
84  	    return recipientId;
85      }
86  
87      
88  
89  
90  
91      public void setRecipientId(String recipientId) {
92  	    this.recipientId = recipientId;
93      }
94  
95      
96  
97  
98  
99      public String getRecipientType() {
100 	    return recipientType;
101     }
102 
103     
104 
105 
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 
121 
122 
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 
134 
135 
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