1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.openehealth.ipf.commons.audit.event;
17
18
19 import org.openehealth.ipf.commons.audit.AuditException;
20 import org.openehealth.ipf.commons.audit.codes.ActiveParticipantRoleIdCode;
21 import org.openehealth.ipf.commons.audit.codes.EventActionCode;
22 import org.openehealth.ipf.commons.audit.codes.EventIdCode;
23 import org.openehealth.ipf.commons.audit.codes.EventOutcomeIndicator;
24 import org.openehealth.ipf.commons.audit.types.ActiveParticipantRoleId;
25 import org.openehealth.ipf.commons.audit.types.EventType;
26 import org.openehealth.ipf.commons.audit.types.PurposeOfUse;
27
28 import java.util.Collections;
29
30
31
32
33
34
35
36
37
38
39
40
41
42 public class QueryBuilder extends BaseAuditMessageBuilder<QueryBuilder> {
43
44 public QueryBuilder(EventOutcomeIndicator outcome,
45 EventType eventType,
46 PurposeOfUse... purposesOfUse) {
47 this(outcome, null, eventType, purposesOfUse);
48 }
49
50 public QueryBuilder(EventOutcomeIndicator outcome,
51 String eventOutcomeDescription,
52 EventType eventType,
53 PurposeOfUse... purposesOfUse) {
54 super();
55 setEventIdentification(outcome,
56 eventOutcomeDescription,
57 EventActionCode.Execute,
58 EventIdCode.Query,
59 eventType,
60 purposesOfUse
61 );
62 }
63
64
65
66
67
68
69
70
71
72
73
74
75 public QueryBuilder setQueryingParticipant(String userId,
76 String altUserId,
77 String userName,
78 String networkAccessPointId,
79 boolean userIsRequestor) {
80 return addSourceActiveParticipant(userId, altUserId, userName, networkAccessPointId, userIsRequestor);
81 }
82
83
84
85
86
87
88
89
90
91
92
93
94 public QueryBuilder setRespondingParticipant(String userId,
95 String altUserId,
96 String userName,
97 String networkAccessPointId,
98 boolean userIsRequestor) {
99 return addDestinationActiveParticipant(userId, altUserId, userName, networkAccessPointId, userIsRequestor);
100 }
101
102
103
104
105
106
107
108
109
110
111 public QueryBuilder addOtherActiveParticipant(String userId,
112 String altUserId,
113 String userName,
114 ActiveParticipantRoleId roleId,
115 String networkId,
116 boolean userIsRequestor) {
117 return addActiveParticipant(userId, altUserId, userName, userIsRequestor, Collections.singletonList(roleId), networkId);
118 }
119
120 @Override
121 public void validate() {
122 super.validate();
123 if (getMessage().findActiveParticipants(ap -> ap.getRoleIDCodes().contains(ActiveParticipantRoleIdCode.Source)).size() != 1) {
124 throw new AuditException("Must have one ActiveParticipant with RoleIDCode Source");
125 }
126 if (getMessage().findActiveParticipants(ap -> ap.getRoleIDCodes().contains(ActiveParticipantRoleIdCode.Destination)).size() != 1) {
127 throw new AuditException("Must have one ActiveParticipant with RoleIDCode Destination");
128 }
129
130
131
132 }
133 }