View Javadoc

1   /**
2    * Copyright 2005-2008 the original author or authors.
3    *
4    * Licensed under the Gnu General Pubic License, Version 2.0 (the
5    * "License"); you may not use this file except in compliance with
6    * the License. You may obtain a copy of the License at
7    *
8    *      http://www.opensource.org/licenses/gpl-license.php
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13   * See the Gnu General Public License for more details.
14   */
15  package org.figure8.join.businessobjects.reporting;
16  
17  import org.figure8.join.core.EntityObject;
18  
19  import java.util.List;
20  import java.util.ArrayList;
21  /**
22   * A mailing list is used for reporting when a defined event happened
23   * within process for a defined element of domain model. It allows to specify
24   * templates for message titles and contents, overriding those defined for the
25   * type of event this list is dedicated to. A list also offers access to
26   * user's subscriptions.
27   * @author  <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
28   * @version $Revision: 1.3 $
29   *
30   * @hibernate.class table="join_mailinglists"
31   *
32   * @hibernate.query name="join.mailinglist_findByName"
33   *    query="from MailingList ml where ml.name = :mlName"
34   * @hibernate.query name="join.mailinglist_findByEvent"
35   *    query="from MailingList ml where ml.event = :mlEvent"
36   */
37  public class MailingList extends EntityObject{
38     
39     // Attributes ---------------------------------------------------------------
40  
41     /** The name of this mailing list */
42     private String name;
43     /** A string representing template for generating messages title */
44     private String msgTitleTemplate;
45     /** A string representing template for generating messages content */
46     private String msgContentTemplate;
47     /** A list of <code>Subscription</code> objects for this mailing list */
48     private List subscriptions = new ArrayList();
49  
50     /** The event this mailing list is attached to. */
51     private Event event = null;
52     /** The identifier of resource associated with this mailing list event (if any) */
53     private String resourceId;
54  
55  
56     // Constructors -------------------------------------------------------------
57     
58     /** Creates a new instance of MailingList */
59     public MailingList(){
60     }
61  
62     /**
63      * Creates a new instance of MalingList with mandatory attributes
64      * @param name The name identifying this list
65      * @param msgTitleTemplate A template for generating messages title
66      * @param msgContentTemplate A template for generating messages content
67      * @param event The type of event this mailing list is dedicated to
68      */
69     public MailingList(String name, String msgTitleTemplate, String msgContentTemplate, Event event){
70        this.name = name;
71        this.msgTitleTemplate = msgTitleTemplate;
72        this.msgContentTemplate = msgContentTemplate;
73        this.event = event;
74     }
75  
76  
77     // Public -------------------------------------------------------------------
78  
79     /**
80      * @hibernate.property column="s_name"
81      *    not-null="true" unique="true" length="100"
82      * @return The name identifying this mailing list
83      */
84     public String getName(){
85        return name;
86     }
87     /** @param name The name identifying this mailing list */
88     public void setName(String name){
89        this.name = name;
90     }
91  
92     /**
93      * @hibernate.property column="s_msgtitle" length="255"
94      * @return A string representing template for generating messages title
95      */
96     public String getMsgTitleTemplate(){
97        return msgTitleTemplate;
98     }
99     /** @param msgTitleTemplate String representing template for title generation */
100    public void setMsgTitleTemplate(String msgTitleTemplate){
101       this.msgTitleTemplate = msgTitleTemplate;
102    }
103 
104    /**
105     * @hibernate.property column="s_msgcontent" type="text"
106     * @return A string representing template for generating messages content
107     */
108    public String getMsgContentTemplate(){
109       return msgContentTemplate;
110    }
111    /** @param msgContentTemplate String representing template for generating messages content */
112    public void setMsgContentTemplate(String msgContentTemplate){
113       this.msgContentTemplate = msgContentTemplate;
114    }
115 
116    /**
117     * @hibernate.bag lazy="true" cascade="all-delete-orphan" inverse="true"
118     * @hibernate.collection-key column="n_mailinglist_fk"
119     * @hibernate.collection-one-to-many class="org.figure8.join.businessobjects.reporting.Subscription"
120     * @return A set of {@code Subscription} objects for this mailing list
121     */
122    public List getSubscriptions(){
123       return subscriptions;
124    }
125    /** @param subscriptions A set of {@code Subscription} objects for this mailing list */ 
126    public void setSubscriptions(List subscriptions){
127       this.subscriptions = subscriptions;
128    }
129    /**
130     * Convenient method for adding a subscription to this list
131     * (will ensure that subscription list is correctly set)
132     * @param subscription The subscription to add
133     */
134    public void addSubscription(Subscription subscription){
135       subscriptions.add(subscriptions);
136       subscription.setMailingList(this);
137    }
138 
139    /**
140     * @hibernate.many-to-one column="n_event_fk"
141     * @return The type of event this message is dedicated to
142     */
143    public Event getEvent(){
144       return event;
145    }
146    /** @param event The type of event this mailing list is dedicated to */
147    public void setEvent(Event event){
148       this.event = event;
149    }
150 
151    /**
152     * @hibernate.property column="s_resourceid"
153     * @return The identifier of the resource to whom this mailing list applies
154     */
155    public String getResourceId(){
156       return resourceId;
157    }
158    /** @param resourceId The identifier of the resource to whom this mailing list applies */
159    public void setResourceId(String resourceId){
160       this.resourceId = resourceId;
161    }
162 
163    /** @return true if this MailingList doesn't apply to a specific resource */
164    public boolean isGlobalMailingList(){
165       return !isResourceMailingList();
166    }
167    /** @return true if this MailingList applies to a specific resource */
168    public boolean isResourceMailingList(){
169       return (getResourceId() != null);
170    }
171 }