View Javadoc
1   /*
2    * Copyright 2017 the original author or authors.
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *         http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
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.*;
21  import org.openehealth.ipf.commons.audit.types.PurposeOfUse;
22  
23  import java.util.Collections;
24  
25  /**
26   * Builds an Audit Event representing a Network Entry event as specified in
27   * http://dicom.nema.org/medical/dicom/current/output/html/part15.html#sect_A.5.3.9
28   * <p>
29   * This message describes the event of a system, such as a mobile device, intentionally entering or leaving the network.
30   * </p>
31   *
32   * @author Christian Ohr
33   * @since 3.5
34   */
35  public class NetworkEntryBuilder extends BaseAuditMessageBuilder<NetworkEntryBuilder> {
36  
37      public NetworkEntryBuilder(EventOutcomeIndicator outcome,
38                                 String eventOutcomeDescription,
39                                 EventTypeCode eventTypeCode) {
40          super();
41          setEventIdentification(outcome,
42                  eventOutcomeDescription,
43                  EventActionCode.Read,
44                  EventIdCode.NetworkEntry,
45                  eventTypeCode,
46                  (PurposeOfUse[]) null
47          );
48      }
49  
50      /**
51       * Sets the Active Participant of the Node or System entering or leaving the network
52       *
53       * @param userId    The person or process accessing the audit trail. If both are known,
54       *                  then two active participants shall be included (both the person and the process).
55       * @param altUserId Alternate UserID
56       * @param userName  UserName
57       * @param networkId Network Access Point ID
58       */
59      public NetworkEntryBuilder setSystemParticipant(String userId,
60                                                      String altUserId,
61                                                      String userName,
62                                                      ActiveParticipantRoleIdCode roleId,
63                                                      String networkId) {
64          return addActiveParticipant(
65                  userId,
66                  altUserId,
67                  userName,
68                  false,
69                  Collections.singletonList(roleId),
70                  networkId);
71      }
72  
73      public static class EnteringNetwork extends NetworkEntryBuilder {
74  
75          public EnteringNetwork(EventOutcomeIndicator outcome) {
76              this(outcome, null);
77          }
78  
79          public EnteringNetwork(EventOutcomeIndicator outcome, String eventOutcomeDescription) {
80              super(outcome, eventOutcomeDescription, EventTypeCode.Attach);
81          }
82      }
83  
84      public static class LeavingNetwork extends NetworkEntryBuilder {
85  
86          public LeavingNetwork(EventOutcomeIndicator outcome) {
87              this(outcome, null);
88          }
89  
90          public LeavingNetwork(EventOutcomeIndicator outcome, String eventOutcomeDescription) {
91              super(outcome, eventOutcomeDescription, EventTypeCode.Detach);
92          }
93      }
94  
95      @Override
96      public void validate() {
97          super.validate();
98          if (getMessage().getActiveParticipants().size() != 1) {
99              throw new AuditException("Must have one ActiveParticipant");
100         }
101     }
102 }