View Javadoc
1   /*
2    * Copyright 2018 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  
17  package org.openehealth.ipf.commons.audit.event;
18  
19  import org.openehealth.ipf.commons.audit.model.AuditMessage;
20  import org.openehealth.ipf.commons.audit.model.TypeValuePairType;
21  import org.openehealth.ipf.commons.audit.model.Validateable;
22  
23  import static java.util.Objects.requireNonNull;
24  
25  /**
26   * Base interface for building DICOM audit messages
27   *
28   * @author Christian Ohr
29   * @since 3.5
30   */
31  public interface AuditMessageBuilder<T extends AuditMessageBuilder<T>> extends Validateable {
32  
33      /**
34       * @return the audit message being built
35       */
36      AuditMessage getMessage();
37  
38      /**
39       * @return the audit message being built as only element in an array
40       */
41      default AuditMessage[] getMessages() {
42          return new AuditMessage[]{getMessage()};
43      }
44  
45  
46      /**
47       * Create and set a Type Value Pair instance for a given type and value
48       *
49       * @param type  The type to set
50       * @param value The value to set
51       * @return The Type Value Pair instance
52       */
53      default TypeValuePairType getTypeValuePair(String type, Object value) {
54          return new TypeValuePairType(
55                  requireNonNull(type, "Type of TypeValuePair must not be null"),
56                  requireNonNull(value, "Value of TypeValuePair must not be null").toString());
57      }
58  
59      /**
60       * @return this builder
61       */
62      @SuppressWarnings("unchecked")
63      default T self() {
64          return (T) this;
65      }
66  }