View Javadoc
1   /*
2    * Copyright 2016 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.boot.hl7v2;
18  
19  import ca.uhn.hl7v2.util.Home;
20  import lombok.Getter;
21  import lombok.Setter;
22  import org.springframework.boot.context.properties.ConfigurationProperties;
23  import org.springframework.boot.context.properties.NestedConfigurationProperty;
24  
25  import java.nio.charset.Charset;
26  
27  /**
28   *
29   */
30  @ConfigurationProperties(prefix = "ipf.hl7v2")
31  public class IpfHl7v2ConfigurationProperties {
32  
33      /**
34       * Charset used for decoding and encoding HL7 messages
35       */
36      @Getter
37      private String charset = "UTF-8";
38  
39      /**
40       * Whether to convert line feeds to proper segment separators before parsing starts
41       */
42      @Getter @Setter
43      private boolean convertLinefeed = false;
44  
45      public void setCharset(String charset) {
46          // Ensure that charset exists
47          Charset.forName(charset);
48          this.charset = charset;
49      }
50  
51      /**
52       * Whether to instantiate a continuation cache
53       */
54      @Getter @Setter
55      private boolean caching = false;
56  
57      /**
58       * Whether ID generator to use. One of "file" (default), "uuid", "nano". Alternatively, you can
59       * provide your own bean of type {@link ca.uhn.hl7v2.util.idgenerator.IDGenerator}.
60       */
61      @Getter @Setter
62      private String generator = "file";
63  
64      @Getter
65      @NestedConfigurationProperty
66      private final FileIdGeneratorProperties idGenerator = new FileIdGeneratorProperties();
67  
68      public static class FileIdGeneratorProperties  {
69  
70          /**
71           * How many IDs to be generated internally before incrementing the file value
72           */
73          @Getter @Setter private int lo = 100;
74  
75          /**
76           * Directory of the ID file
77           */
78          @Getter @Setter private String directory = Home.getHomeDirectory().getAbsolutePath();
79  
80          /**
81           * Name of the ID file
82           */
83          @Getter @Setter private String fileMame = "id_file";
84  
85          /**
86           * If set to <code>false</code> (default is <code>true</code>),
87           * retrieving a new ID may fail if the ID file in the home
88           * directory can not be written/read. If set to true, failures
89           * will be ignored, which means that IDs may be repeated after
90           * a JVM restart.
91           */
92          @Getter @Setter private boolean neverFail = true;
93  
94          /**
95           * If set to <code>true</code> (default is <code>false</code>) the generator
96           * minimizes the number of disk reads by caching the last read value. This means
97           * one less disk read per X number of IDs generated, but also means that multiple
98           * instances of this generator may clobber each other's values.
99           */
100         @Getter @Setter private boolean minimizeReads = false;
101     }
102 
103 }