1
|
package eu.dnetlib.enabling.is.sn.resourcestate;
|
2
|
|
3
|
import java.io.StringReader;
|
4
|
|
5
|
import javax.persistence.Column;
|
6
|
import javax.persistence.Entity;
|
7
|
import javax.persistence.Id;
|
8
|
import javax.persistence.Table;
|
9
|
import javax.xml.transform.stream.StreamSource;
|
10
|
import javax.xml.ws.EndpointReference;
|
11
|
import javax.xml.ws.wsaddressing.W3CEndpointReference;
|
12
|
|
13
|
import org.apache.commons.lang.builder.EqualsBuilder;
|
14
|
import org.apache.commons.lang.builder.HashCodeBuilder;
|
15
|
|
16
|
import eu.dnetlib.enabling.is.sn.SubscriptionRequest;
|
17
|
|
18
|
/**
|
19
|
* This class describes a ResourceState subscription, i.e. a subscription that is registered on a topic that depends on
|
20
|
* some xpath on some resource, and which is triggered when the value of this xpath changes.
|
21
|
*
|
22
|
* Topics of this type could not be there.
|
23
|
*
|
24
|
* @author marko
|
25
|
*
|
26
|
*/
|
27
|
@Entity(name = "subscriptions")
|
28
|
@Table(name = "subscriptions")
|
29
|
public class ResourceStateSubscription {
|
30
|
|
31
|
/**
|
32
|
* hash seed.
|
33
|
*/
|
34
|
private static final int HASH_SEED_2 = 59;
|
35
|
|
36
|
/**
|
37
|
* hash seed.
|
38
|
*/
|
39
|
private static final int HASH_SEED = 47;
|
40
|
|
41
|
/**
|
42
|
* create topic prefix.
|
43
|
*/
|
44
|
public static final String PREFIX_CREATE = "CREATE";
|
45
|
|
46
|
/**
|
47
|
* delete topic prefix.
|
48
|
*/
|
49
|
public static final String PREFIX_DELETE = "DELETE";
|
50
|
|
51
|
/**
|
52
|
* update topic prefix.
|
53
|
*/
|
54
|
public static final String PREFIX_UPDATE = "UPDATE";
|
55
|
|
56
|
/**
|
57
|
* pending create topic prefix.
|
58
|
*/
|
59
|
public static final String PREFIX_PENDING_CREATE = "PENDING_CREATE";
|
60
|
|
61
|
/**
|
62
|
* pending delete topic prefix.
|
63
|
*/
|
64
|
public static final String PREFIX_PENDING_DELETE = "PENDING_DELETE";
|
65
|
|
66
|
/**
|
67
|
* pending update topic prefix.
|
68
|
*/
|
69
|
public static final String PREFIX_PENDING_UPDATE = "PENDING_UPDATE";
|
70
|
|
71
|
|
72
|
/**
|
73
|
* subscription identifier.
|
74
|
*/
|
75
|
@Id
|
76
|
@Column(name = "subscriptionid")
|
77
|
private String subscriptionId;
|
78
|
|
79
|
/**
|
80
|
* prefix: crude.
|
81
|
*/
|
82
|
@Column(name = "prefix")
|
83
|
private String prefix;
|
84
|
|
85
|
/**
|
86
|
* resource type.
|
87
|
*/
|
88
|
@Column(name = "type")
|
89
|
private String type;
|
90
|
|
91
|
/**
|
92
|
* resource id.
|
93
|
*/
|
94
|
@Column(name = "resourceid")
|
95
|
private String resourceId;
|
96
|
|
97
|
/**
|
98
|
* xpath.
|
99
|
*/
|
100
|
@Column(name = "xpath")
|
101
|
private String xpath;
|
102
|
|
103
|
/**
|
104
|
* consumer (subscriber) reference.
|
105
|
*/
|
106
|
@Column(name = "subscriber", length = 4096)
|
107
|
private String subscriber;
|
108
|
|
109
|
/**
|
110
|
* default constructor. for unit testing.
|
111
|
*/
|
112
|
public ResourceStateSubscription() {
|
113
|
this.type = "*";
|
114
|
this.resourceId = "*";
|
115
|
}
|
116
|
|
117
|
/**
|
118
|
* create a new instance.
|
119
|
*
|
120
|
* @param request
|
121
|
* original request.
|
122
|
* @param prefix
|
123
|
* prefix
|
124
|
* @param type
|
125
|
* resource type
|
126
|
* @param resourceId
|
127
|
* resource identifier
|
128
|
* @param xpath
|
129
|
* xpath
|
130
|
*/
|
131
|
public ResourceStateSubscription(final SubscriptionRequest request, final String prefix, final String type, final String resourceId,
|
132
|
final String xpath) {
|
133
|
super();
|
134
|
setSubscriptionId(request.getSubscriptionId());
|
135
|
setSubscriber(request.getSubscriber());
|
136
|
setPrefix(prefix);
|
137
|
setType(type);
|
138
|
setResourceId(resourceId);
|
139
|
setXpath(xpath);
|
140
|
}
|
141
|
|
142
|
/**
|
143
|
* {@inheritDoc}
|
144
|
*
|
145
|
* @see java.lang.Object#hashCode()
|
146
|
*/
|
147
|
@Override
|
148
|
public int hashCode() {
|
149
|
return new HashCodeBuilder(HASH_SEED, HASH_SEED_2).append(subscriptionId).append(subscriber.toString()).append(prefix).append(type).append(xpath)
|
150
|
.toHashCode();
|
151
|
}
|
152
|
|
153
|
/**
|
154
|
* {@inheritDoc}
|
155
|
*
|
156
|
* @see java.lang.Object#equals(java.lang.Object)
|
157
|
*/
|
158
|
@Override
|
159
|
public boolean equals(final Object obj) {
|
160
|
if (!(obj instanceof ResourceStateSubscription))
|
161
|
return false;
|
162
|
|
163
|
if (this == obj)
|
164
|
return true;
|
165
|
|
166
|
final ResourceStateSubscription rhs = (ResourceStateSubscription) obj;
|
167
|
return new EqualsBuilder().append(subscriptionId, rhs.getSubscriptionId()).append(prefix, rhs.getPrefix()).append(
|
168
|
resourceId, rhs.getResourceId()).append(xpath, rhs.getXpath()).isEquals();
|
169
|
}
|
170
|
|
171
|
public String getSubscriptionId() {
|
172
|
return subscriptionId;
|
173
|
}
|
174
|
|
175
|
public void setSubscriptionId(final String subscriptionId) {
|
176
|
this.subscriptionId = subscriptionId;
|
177
|
}
|
178
|
|
179
|
public String getPrefix() {
|
180
|
return prefix;
|
181
|
}
|
182
|
|
183
|
public void setPrefix(final String prefix) {
|
184
|
this.prefix = prefix;
|
185
|
}
|
186
|
|
187
|
public String getType() {
|
188
|
return type;
|
189
|
}
|
190
|
|
191
|
public void setType(final String type) {
|
192
|
this.type = type == null || type.isEmpty() ? "*" : type;
|
193
|
}
|
194
|
|
195
|
public String getXpath() {
|
196
|
return xpath;
|
197
|
}
|
198
|
|
199
|
public void setXpath(final String xpath) {
|
200
|
this.xpath = xpath;
|
201
|
}
|
202
|
|
203
|
public String getSubscriber() {
|
204
|
return subscriber;
|
205
|
}
|
206
|
|
207
|
public W3CEndpointReference getSubscriberAsEpr() {
|
208
|
return (W3CEndpointReference) EndpointReference.readFrom(new StreamSource(new StringReader(getSubscriber())));
|
209
|
}
|
210
|
|
211
|
public void setSubscriber(final W3CEndpointReference epr) {
|
212
|
this.subscriber = (epr != null) ? epr.toString() : null;;
|
213
|
}
|
214
|
|
215
|
public void setSubscriber(final String subscriber) {
|
216
|
this.subscriber = subscriber;
|
217
|
}
|
218
|
|
219
|
public void setResourceId(final String resourceId) {
|
220
|
this.resourceId = resourceId == null || resourceId.isEmpty() ? "*" : resourceId;
|
221
|
}
|
222
|
|
223
|
public String getResourceId() {
|
224
|
return resourceId;
|
225
|
}
|
226
|
|
227
|
}
|