1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.openehealth.ipf.commons.audit.model;
17
18 import lombok.EqualsAndHashCode;
19 import lombok.Getter;
20 import lombok.Setter;
21 import org.openehealth.ipf.commons.audit.AuditException;
22 import org.openehealth.ipf.commons.audit.event.BaseAuditMessageBuilder;
23 import org.openehealth.ipf.commons.audit.marshal.dicom.Current;
24
25 import java.io.Serializable;
26 import java.util.ArrayList;
27 import java.util.List;
28 import java.util.function.Predicate;
29 import java.util.stream.Collectors;
30
31
32
33
34
35
36
37
38
39
40 @EqualsAndHashCode
41 public class AuditMessage implements Serializable, Validateable {
42
43 @Getter @Setter
44 private EventIdentificationType eventIdentification;
45
46 private List<ActiveParticipantType> activeParticipants;
47
48 @Getter @Setter
49 private AuditSourceIdentificationType auditSourceIdentification;
50 private List<ParticipantObjectIdentificationType> participantObjectIdentifications;
51
52 public List<ActiveParticipantType> getActiveParticipants() {
53 if (activeParticipants == null) {
54 activeParticipants = new ArrayList<>();
55 }
56 return this.activeParticipants;
57 }
58
59 public List<ActiveParticipantType> findActiveParticipants(Predicate<ActiveParticipantType> selector) {
60 return getActiveParticipants().stream()
61 .filter(selector)
62 .collect(Collectors.toList());
63 }
64
65 public List<ParticipantObjectIdentificationType> getParticipantObjectIdentifications() {
66 if (participantObjectIdentifications == null) {
67 participantObjectIdentifications = new ArrayList<>();
68 }
69 return this.participantObjectIdentifications;
70 }
71
72 public List<ParticipantObjectIdentificationType> findParticipantObjectIdentifications(Predicate<ParticipantObjectIdentificationType> selector) {
73 return getParticipantObjectIdentifications().stream()
74 .filter(selector)
75 .collect(Collectors.toList());
76 }
77
78
79
80
81
82
83
84 @Override
85 public void validate() {
86 if (eventIdentification == null) {
87 throw new AuditException("The event must be identified");
88 }
89 if (auditSourceIdentification == null) {
90 throw new AuditException("The event must be have an audit source");
91 }
92 if (getActiveParticipants().isEmpty()) {
93 throw new AuditException("The event must have one or more active participants");
94 }
95
96 eventIdentification.validate();
97 auditSourceIdentification.validate();
98 activeParticipants.forEach(ActiveParticipantType::validate);
99 participantObjectIdentifications.forEach(ParticipantObjectIdentificationType::validate);
100 }
101
102
103
104
105 public String toString() {
106 return Current.toString(this, true);
107 }
108 }