1 | package gov.hhs.fha.nhinc.subscription.repository.data;
|
---|
2 |
|
---|
3 | import gov.hhs.fha.nhinc.subscription.repository.SubscriptionRepositoryException;
|
---|
4 | import java.io.Serializable;
|
---|
5 | import java.util.ArrayList;
|
---|
6 | import java.util.Iterator;
|
---|
7 | import java.util.List;
|
---|
8 |
|
---|
9 | /**
|
---|
10 | * Data class for subscription criteria
|
---|
11 | *
|
---|
12 | * @author Neil Webb
|
---|
13 | */
|
---|
14 | public class SubscriptionCriteria implements Serializable
|
---|
15 | {
|
---|
16 | private static final long serialVersionUID = 2035932112955401949L;
|
---|
17 | private Patient subscriberPatient;
|
---|
18 | private Patient subscribeePatient;
|
---|
19 | private List<Criterion> criteria;
|
---|
20 | private TopicExpression topicExpression;
|
---|
21 | private SubscriptionPolicy subscriptionPolicy;
|
---|
22 |
|
---|
23 | public TopicExpression getTopicExpression()
|
---|
24 | {
|
---|
25 | return topicExpression;
|
---|
26 | }
|
---|
27 |
|
---|
28 | public void setTopicExpression(TopicExpression topicExpression)
|
---|
29 | {
|
---|
30 | this.topicExpression = topicExpression;
|
---|
31 | }
|
---|
32 |
|
---|
33 | public Patient getSubscriberPatient()
|
---|
34 | {
|
---|
35 | return subscriberPatient;
|
---|
36 | }
|
---|
37 |
|
---|
38 | public void setSubscriberPatient(Patient patient)
|
---|
39 | {
|
---|
40 | this.subscriberPatient = patient;
|
---|
41 | }
|
---|
42 |
|
---|
43 | public Patient getSubscribeePatient()
|
---|
44 | {
|
---|
45 | return subscribeePatient;
|
---|
46 | }
|
---|
47 |
|
---|
48 | public void setSubscribeePatient(Patient patient)
|
---|
49 | {
|
---|
50 | this.subscribeePatient = patient;
|
---|
51 | }
|
---|
52 |
|
---|
53 | public List<Criterion> getCriteria()
|
---|
54 | {
|
---|
55 | if (criteria == null)
|
---|
56 | {
|
---|
57 | criteria = new ArrayList<Criterion>();
|
---|
58 | }
|
---|
59 | return criteria;
|
---|
60 | }
|
---|
61 |
|
---|
62 | public void setCriteria(List<Criterion> criteria)
|
---|
63 | {
|
---|
64 | this.criteria = criteria;
|
---|
65 | }
|
---|
66 |
|
---|
67 | public SubscriptionPolicy getSubscriptionPolicy()
|
---|
68 | {
|
---|
69 | return subscriptionPolicy;
|
---|
70 | }
|
---|
71 |
|
---|
72 | public void setSubscriptionPolicy(SubscriptionPolicy subscriptionPolicy)
|
---|
73 | {
|
---|
74 | this.subscriptionPolicy = subscriptionPolicy;
|
---|
75 | }
|
---|
76 |
|
---|
77 | public void addCriterion(Criterion criterion) throws SubscriptionRepositoryException
|
---|
78 | {
|
---|
79 | // Validate criterion object
|
---|
80 | if (criterion == null)
|
---|
81 | {
|
---|
82 | throw new SubscriptionRepositoryException("Attempted to add null criterion to subscription criteria list");
|
---|
83 | }
|
---|
84 |
|
---|
85 | // Validate key
|
---|
86 | if ((criterion.getKey() == null) || "".equals(criterion.getKey().trim()))
|
---|
87 | {
|
---|
88 | throw new SubscriptionRepositoryException("Attempted to add criterion with an invalid key to subscription criteria list - key: " + criterion.getKey());
|
---|
89 | }
|
---|
90 | else
|
---|
91 | {
|
---|
92 | // Trim key prior to storage
|
---|
93 | criterion.setKey(criterion.getKey().trim());
|
---|
94 | }
|
---|
95 |
|
---|
96 | // Valiedate value
|
---|
97 | if ((criterion.getValue() == null) || "".equals(criterion.getValue().trim()))
|
---|
98 | {
|
---|
99 | throw new SubscriptionRepositoryException("Attempted to add criterion to the subscription criteria list with an invalid value for key: " + criterion.getKey());
|
---|
100 | }
|
---|
101 | getCriteria().add(criterion);
|
---|
102 | }
|
---|
103 |
|
---|
104 | public void removeCriterion(Criterion criterion)
|
---|
105 | {
|
---|
106 | if (criterion != null)
|
---|
107 | {
|
---|
108 | Iterator<Criterion> iter = getCriteria().iterator();
|
---|
109 | while (iter.hasNext())
|
---|
110 | {
|
---|
111 | Criterion c = iter.next();
|
---|
112 | if (c.equals(criterion))
|
---|
113 | {
|
---|
114 | iter.remove();
|
---|
115 | break;
|
---|
116 | }
|
---|
117 | }
|
---|
118 | }
|
---|
119 | }
|
---|
120 |
|
---|
121 | @Override
|
---|
122 | public boolean equals(Object obj)
|
---|
123 | {
|
---|
124 | if (obj == null)
|
---|
125 | {
|
---|
126 | return false;
|
---|
127 | }
|
---|
128 | if (getClass() != obj.getClass())
|
---|
129 | {
|
---|
130 | return false;
|
---|
131 | }
|
---|
132 | final SubscriptionCriteria other = (SubscriptionCriteria) obj;
|
---|
133 | if (this.subscriberPatient != other.subscriberPatient && (this.subscriberPatient == null || !this.subscriberPatient.equals(other.subscriberPatient)))
|
---|
134 | {
|
---|
135 | return false;
|
---|
136 | }
|
---|
137 | if (this.subscribeePatient != other.subscribeePatient && (this.subscribeePatient == null || !this.subscribeePatient.equals(other.subscribeePatient)))
|
---|
138 | {
|
---|
139 | return false;
|
---|
140 | }
|
---|
141 | if (this.criteria != other.criteria && (this.criteria == null || !this.criteria.equals(other.criteria)))
|
---|
142 | {
|
---|
143 | return false;
|
---|
144 | }
|
---|
145 | if (this.topicExpression != other.topicExpression && (this.topicExpression == null || !this.topicExpression.equals(other.topicExpression)))
|
---|
146 | {
|
---|
147 | return false;
|
---|
148 | }
|
---|
149 | if (this.subscriptionPolicy != other.subscriptionPolicy && (this.subscriptionPolicy == null || !this.subscriptionPolicy.equals(other.subscriptionPolicy)))
|
---|
150 | {
|
---|
151 | return false;
|
---|
152 | }
|
---|
153 | return true;
|
---|
154 | }
|
---|
155 |
|
---|
156 | @Override
|
---|
157 | public int hashCode()
|
---|
158 | {
|
---|
159 | int hash = 3;
|
---|
160 | hash = 97 * hash + (this.subscriberPatient != null ? this.subscriberPatient.hashCode() : 0);
|
---|
161 | hash = 97 * hash + (this.subscribeePatient != null ? this.subscribeePatient.hashCode() : 0);
|
---|
162 | hash = 97 * hash + (this.criteria != null ? this.criteria.hashCode() : 0);
|
---|
163 | return hash;
|
---|
164 | }
|
---|
165 | }
|
---|