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.EventType;
22  import org.openehealth.ipf.commons.audit.types.PurposeOfUse;
23  
24  import java.util.Collections;
25  
26  
27  /**
28   * Builds an Audit Event representing a Application Activity event as specified in
29   * http://dicom.nema.org/medical/dicom/current/output/html/part15.html#sect_A.5.3.1
30   * <p>
31   * This audit message describes the event of an Application Entity starting or stopping.
32   * This is closely related to the more general case of any kind of application startup or shutdown,
33   * and may be suitable for those purposes also.
34   * </p>
35   *
36   * @author Christian Ohr
37   * @since 3.5
38   */
39  public class ApplicationActivityBuilder<T extends ApplicationActivityBuilder<T>> extends BaseAuditMessageBuilder<T> {
40  
41      public ApplicationActivityBuilder(EventOutcomeIndicator outcome,
42                                        EventType type) {
43          this(outcome, null, type);
44      }
45  
46      public ApplicationActivityBuilder(EventOutcomeIndicator outcome,
47                                        String eventOutcomeDescription,
48                                        EventType type) {
49          super();
50          setEventIdentification(outcome,
51                  eventOutcomeDescription,
52                  EventActionCode.Execute,
53                  EventIdCode.ApplicationActivity,
54                  type,
55                  (PurposeOfUse[]) null
56          );
57      }
58  
59      /**
60       * Add an Application Starter Active Participant to this message. This participant describes persons or processes
61       * that started or stopped the application.
62       *
63       * @param userId The person or process starting or stopping the Application
64       * @return this
65       */
66      public T addApplicationStarterParticipant(String userId) {
67          return addApplicationStarterParticipant(userId, null, null, null);
68      }
69  
70      /**
71       * Add an Application Starter Active Participant to this message. This participant describes persons or processes
72       * that started or stopped the application.
73       *
74       * @param userId    The person or process starting or stopping the Application
75       * @param altUserId The Active Participant's Alternate UserID
76       * @param userName  The Active Participant's UserName
77       * @param networkId The Active Participant's Network Access Point ID
78       * @return this
79       */
80      public T addApplicationStarterParticipant(String userId, String altUserId, String userName, String networkId) {
81          return addActiveParticipant(
82                          userId,
83                          altUserId,
84                          userName,
85                          true,
86                          Collections.singletonList(ActiveParticipantRoleIdCode.ApplicationLauncher),
87                          networkId);
88      }
89  
90      /**
91       * Add an Application Participant to this message. This participant describes the application that is started or stopped
92       * and must be added only once.
93       *
94       * @param userId    The identity of the process started or stopped formatted as specified in A.5.2.1.
95       * @param altUserId If the process supports DICOM, then the AE Titles as specified in A.5.2.2.
96       * @param userName  The Active Participant's UserName
97       * @param networkId The Active Participant's Network Access Point ID
98       * @return this
99       */
100     public T setApplicationParticipant(String userId, String altUserId, String userName, String networkId) {
101         return addActiveParticipant(
102                 userId,
103                 altUserId,
104                 userName,
105                 false,
106                 Collections.singletonList(ActiveParticipantRoleIdCode.Application),
107                 networkId);
108     }
109 
110     @Override
111     public void validate() {
112         super.validate();
113         if (getMessage().findActiveParticipants(ap -> ActiveParticipantRoleIdCode.Application.equals(ap)).size() != 1) {
114             throw new AuditException("Must have exactly one Application Active Participant");
115         }
116     }
117 
118     public static class ApplicationStart extends ApplicationActivityBuilder<ApplicationStart> {
119 
120         public ApplicationStart(EventOutcomeIndicator outcome) {
121             this(outcome, null);
122         }
123 
124         public ApplicationStart(EventOutcomeIndicator outcome, String eventOutcomeDescription) {
125             super(outcome, eventOutcomeDescription, EventTypeCode.ApplicationStart);
126         }
127     }
128 
129     public static class ApplicationStop extends ApplicationActivityBuilder<ApplicationStop> {
130 
131         public ApplicationStop(EventOutcomeIndicator outcome) {
132             this(outcome, null);
133         }
134 
135         public ApplicationStop(EventOutcomeIndicator outcome, String eventOutcomeDescription) {
136             super(outcome, eventOutcomeDescription, EventTypeCode.ApplicationStop);
137         }
138     }
139 
140 
141 }