View Javadoc
1   /*
2    *  Copyright 2022 Búraló Technologies
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 com.buralotech.oss.identifier.spring;
18  
19  import com.buralotech.oss.identifier.api.IdentifierService;
20  import com.buralotech.oss.identifier.uuid.*;
21  import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
22  import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
23  import org.springframework.context.annotation.Bean;
24  import org.springframework.context.annotation.Configuration;
25  
26  /**
27   * Spring auto-configuration for identifier generation.
28   */
29  @Configuration
30  public class IdentifierConfig {
31  
32      /**
33       * Create the identifier service bean.
34       *
35       * @return The identifier service bean.
36       */
37      @Bean
38      IdentifierService identifierService(final UUIDVersionDelegate delegate) {
39          return new UUIDIdentifierService(delegate);
40      }
41  
42      /**
43       * Create the identifier converter bean.
44       *
45       * @return The identifier converter bean.
46       */
47      @Bean
48      IdentifierConverter identifierConverter(final IdentifierService service) {
49          return new IdentifierConverter(service);
50      }
51  
52      @Bean
53      @ConditionalOnProperty(name = "buralotech.identifier.generator", matchIfMissing = true, havingValue = "v7")
54      UUIDVersionDelegate version7Delegate() {
55          return new UUIDVersion7Delegate();
56      }
57  
58      @Bean
59      @ConditionalOnProperty(name = "buralotech.identifier.generator", havingValue = "v6")
60      UUIDVersionDelegate version6Delegate() {
61          return new UUIDVersion6Delegate();
62      }
63  
64      @Bean
65      @ConditionalOnProperty(name = "buralotech.identifier.generator", havingValue = "v1")
66      UUIDVersionDelegate version1Delegate() {
67          return new UUIDVersion1Delegate();
68      }
69  }