1
|
package eu.dnetlib.enabling.is.hib.objects;
|
2
|
|
3
|
import java.util.Set;
|
4
|
|
5
|
import javax.persistence.CascadeType;
|
6
|
import javax.persistence.Entity;
|
7
|
import javax.persistence.FetchType;
|
8
|
import javax.persistence.JoinColumn;
|
9
|
import javax.persistence.ManyToOne;
|
10
|
import javax.persistence.OneToMany;
|
11
|
import javax.persistence.PrimaryKeyJoinColumn;
|
12
|
import javax.persistence.Table;
|
13
|
import javax.persistence.Transient;
|
14
|
|
15
|
import com.google.common.collect.Sets;
|
16
|
|
17
|
import eu.dnetlib.enabling.is.rmi.objects.DnetService;
|
18
|
|
19
|
@Entity(name = "services")
|
20
|
@Table(name = "services")
|
21
|
@PrimaryKeyJoinColumn(name = "id")
|
22
|
public class HibService extends HibDnetResource {
|
23
|
|
24
|
@Transient
|
25
|
private static final long serialVersionUID = -9176477709836024551L;
|
26
|
|
27
|
@ManyToOne
|
28
|
@JoinColumn(name = "type", nullable = false)
|
29
|
private HibResourceType type;
|
30
|
|
31
|
@OneToMany(mappedBy = "id.service", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
32
|
private Set<HibServiceProtocol> protocols = Sets.newLinkedHashSet();
|
33
|
|
34
|
@OneToMany(mappedBy = "service", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
35
|
private Set<HibBlackboardMessage> blackboard = Sets.newLinkedHashSet();
|
36
|
|
37
|
@OneToMany(mappedBy = "subscriber", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
38
|
private Set<HibSubscription> subscriptions = Sets.newLinkedHashSet();
|
39
|
|
40
|
public HibService() {
|
41
|
super();
|
42
|
}
|
43
|
|
44
|
public HibService(final String id, final HibResourceType type, final boolean valid) {
|
45
|
super(id, valid);
|
46
|
this.type = type;
|
47
|
}
|
48
|
|
49
|
public HibResourceType getType() {
|
50
|
return type;
|
51
|
}
|
52
|
|
53
|
public void setType(final HibResourceType type) {
|
54
|
this.type = type;
|
55
|
}
|
56
|
|
57
|
public Set<HibServiceProtocol> getProtocols() {
|
58
|
return protocols;
|
59
|
}
|
60
|
|
61
|
public void setProtocols(final Set<HibServiceProtocol> protocols) {
|
62
|
this.protocols = protocols;
|
63
|
}
|
64
|
|
65
|
public Set<HibBlackboardMessage> getBlackboard() {
|
66
|
return blackboard;
|
67
|
}
|
68
|
|
69
|
public void setBlackboard(final Set<HibBlackboardMessage> blackboard) {
|
70
|
this.blackboard = blackboard;
|
71
|
}
|
72
|
|
73
|
public Set<HibSubscription> getSubscriptions() {
|
74
|
return subscriptions;
|
75
|
}
|
76
|
|
77
|
public void setSubscriptions(final Set<HibSubscription> subscriptions) {
|
78
|
this.subscriptions = subscriptions;
|
79
|
}
|
80
|
|
81
|
public DnetService asDnetService() {
|
82
|
final DnetService service = new DnetService();
|
83
|
service.setId(getId());
|
84
|
service.setName(getType().getId());
|
85
|
service.setDate(getDate());
|
86
|
service.setValid(isValid());
|
87
|
|
88
|
for (HibServiceProtocol p : getProtocols()) {
|
89
|
service.getProtocols().put(p.getId().getName(), p.getAddress());
|
90
|
}
|
91
|
for (HibDnetResourceProperty p : getProperties()) {
|
92
|
service.getProperties().put(p.getId().getName(), p.getValue());
|
93
|
}
|
94
|
for (HibBlackboardMessage m : getBlackboard()) {
|
95
|
service.getBlackboard().add(m.asDnetBlackboardMessage());
|
96
|
}
|
97
|
|
98
|
for (HibSubscription s : getSubscriptions()) {
|
99
|
service.getSubscriptions().add(s.asDnetSubscription());
|
100
|
}
|
101
|
|
102
|
return service;
|
103
|
}
|
104
|
|
105
|
@Override
|
106
|
public int hashCode() {
|
107
|
return super.hashCode();
|
108
|
}
|
109
|
}
|