1
|
package eu.dnetlib.enabling.is.hib.objects;
|
2
|
|
3
|
import java.util.Map;
|
4
|
|
5
|
import javax.persistence.Column;
|
6
|
import javax.persistence.Entity;
|
7
|
import javax.persistence.EnumType;
|
8
|
import javax.persistence.Enumerated;
|
9
|
import javax.persistence.Id;
|
10
|
import javax.persistence.JoinColumn;
|
11
|
import javax.persistence.ManyToOne;
|
12
|
import javax.persistence.Table;
|
13
|
|
14
|
import org.hibernate.Session;
|
15
|
|
16
|
import com.google.gson.Gson;
|
17
|
import com.google.gson.reflect.TypeToken;
|
18
|
|
19
|
import eu.dnetlib.enabling.is.rmi.objects.Operation;
|
20
|
import eu.dnetlib.enabling.is.rmi.objects.Subcription;
|
21
|
|
22
|
@Entity(name = "subscriptions")
|
23
|
@Table(name = "subscriptions")
|
24
|
public class HibSubscription extends HibDnetObject {
|
25
|
|
26
|
@Id
|
27
|
@Column(name = "id")
|
28
|
private String id;
|
29
|
|
30
|
@Enumerated(EnumType.STRING)
|
31
|
@Column(name = "operation", nullable = false)
|
32
|
private Operation operation;
|
33
|
|
34
|
@Column(name = "tbl", nullable = false)
|
35
|
private String table;
|
36
|
|
37
|
@Column(name = "condition")
|
38
|
private String condition;
|
39
|
|
40
|
@ManyToOne
|
41
|
@JoinColumn(name = "subscriber", nullable = false)
|
42
|
private HibService subscriber;
|
43
|
|
44
|
public HibSubscription() {}
|
45
|
|
46
|
public HibSubscription(final String id, final Operation operation, final String table, final String condition,
|
47
|
final HibService subscriber) {
|
48
|
this.id = id;
|
49
|
this.operation = operation;
|
50
|
this.table = table;
|
51
|
this.condition = condition;
|
52
|
this.subscriber = subscriber;
|
53
|
}
|
54
|
|
55
|
public String getId() {
|
56
|
return id;
|
57
|
}
|
58
|
|
59
|
public void setId(final String id) {
|
60
|
this.id = id;
|
61
|
}
|
62
|
|
63
|
public Operation getOperation() {
|
64
|
return operation;
|
65
|
}
|
66
|
|
67
|
public void setOperation(final Operation operation) {
|
68
|
this.operation = operation;
|
69
|
}
|
70
|
|
71
|
public String getTable() {
|
72
|
return table;
|
73
|
}
|
74
|
|
75
|
public void setTable(final String table) {
|
76
|
this.table = table;
|
77
|
}
|
78
|
|
79
|
public String getCondition() {
|
80
|
return condition;
|
81
|
}
|
82
|
|
83
|
public void setCondition(final String condition) {
|
84
|
this.condition = condition;
|
85
|
}
|
86
|
|
87
|
public HibService getSubscriber() {
|
88
|
return subscriber;
|
89
|
}
|
90
|
|
91
|
public void setSubscriber(final HibService subscriber) {
|
92
|
this.subscriber = subscriber;
|
93
|
}
|
94
|
|
95
|
public Subcription asDnetSubscription() {
|
96
|
final Gson gson = new Gson();
|
97
|
final Map<String, Object> map = gson.fromJson(condition, new TypeToken<Map<String, Object>>() {}.getType());
|
98
|
return new Subcription(id, subscriber.getId(), operation, table, map);
|
99
|
}
|
100
|
|
101
|
@Override
|
102
|
public void delete(final Session session) {
|
103
|
subscriber.getSubscriptions().remove(this);
|
104
|
subscriber.save(session);
|
105
|
super.delete(session);
|
106
|
}
|
107
|
|
108
|
@Override
|
109
|
public int hashCode() {
|
110
|
return id.hashCode();
|
111
|
}
|
112
|
}
|