# ===================================================================
# Spring Boot configuration for the "dev" profile.
#
# This configuration overrides the application.yml file.
# ===================================================================

# ===================================================================
# Standard Spring Boot properties.
# Full reference is available at:
# http://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html
# ===================================================================

<%_ if (applicationType == 'microservice' || applicationType == 'gateway' || applicationType == 'uaa') { _%>
eureka:
    instance:
        prefer-ip-address: true
    client:
        enabled: true
        healthcheck:
            enabled: true
        registerWithEureka: true
        fetchRegistry: true
        serviceUrl:
            defaultZone: http://admin:admin@localhost:8761/eureka/
<%_ } _%>

spring:
    <%_ if (applicationType == 'gateway' && databaseType != 'cassandra') { _%>
    autoconfigure:
        exclude: org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration
    <%_ } _%>
    devtools:
        restart:
            enabled: true
        livereload:
            enabled: false # we use gulp + BrowserSync for livereload
    jackson:
        serialization.indent_output: true
    <%_ if (databaseType == 'sql') { _%>
    datasource:
        <%_ if (devDatabaseType == 'mysql') { _%>
        url: jdbc:mysql://localhost:3306/<%= baseName %>?useUnicode=true&characterEncoding=utf8&useSSL=false
        <%_ } else if (devDatabaseType == 'mariadb') { _%>
        url: jdbc:mariadb://localhost:3306/<%= baseName %>
        <%_ } else if (devDatabaseType == 'postgresql') { _%>
        url: jdbc:postgresql://localhost:5432/<%= baseName %>
        <%_ } else if (devDatabaseType == 'oracle') { _%>
        url: jdbc:oracle:thin:@localhost:1521:<%= baseName %>
        <%_ } else if (devDatabaseType == 'h2Disk') { _%>
        url: jdbc:h2:file:./target/h2db/db/<%= lowercaseBaseName %>;DB_CLOSE_DELAY=-1
        <%_ } else if (devDatabaseType == 'h2Memory') { _%>
        url: jdbc:h2:mem:<%= lowercaseBaseName %>;DB_CLOSE_DELAY=-1
        <%_ } _%>
        name:
        username: <% if (devDatabaseType == 'mysql' || devDatabaseType == 'mariadb') { %>root<% } else if (devDatabaseType == 'postgresql' || devDatabaseType == 'h2Disk' || devDatabaseType == 'h2Memory') { %><%= baseName %><% } %>
        password:
        <%_ if (devDatabaseType == 'mysql' || devDatabaseType == 'mariadb') { _%>
        hikari:
            data-source-properties:
                cachePrepStmts: true
                prepStmtCacheSize: 250
                prepStmtCacheSqlLimit: 2048
                useServerPrepStmts: true
        <%_ } _%>
    <%_ if (devDatabaseType == 'h2Disk' || devDatabaseType == 'h2Memory') { _%>
    h2:
        console:
            enabled: false
    <%_ } _%>
    jpa:
        <%_ if (devDatabaseType == 'mysql') { _%>
        database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
        <%_ } else if (devDatabaseType == 'mariadb') { _%>
        database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
        <%_ } else if (devDatabaseType == 'postgresql') { _%>
        database-platform: <%=packageName%>.domain.util.FixedPostgreSQL82Dialect
        <%_ } else if (devDatabaseType == 'oracle') { _%>
        database-platform: org.hibernate.dialect.Oracle10gDialect
        <%_ } else { _%>
        database-platform: <%=packageName%>.domain.util.FixedH2Dialect
        <%_ } _%>
        <%_ if (devDatabaseType == 'mysql' || devDatabaseType === 'mariadb') { _%>
        database: MYSQL
        <%_ } else if (devDatabaseType == 'postgresql') { _%>
        database: POSTGRESQL
        <%_ } else if (devDatabaseType == 'oracle') { _%>
        database: ORACLE
        <%_ } else { _%>
        database: H2
        <%_ } _%>
        show-sql: true
        properties:
            hibernate.cache.use_second_level_cache: <% if (hibernateCache == 'ehcache' || hibernateCache == 'hazelcast') { %>true<% } else { %>false<% } %>
            hibernate.cache.use_query_cache: false
            hibernate.generate_statistics: true
            <%_ if (hibernateCache == 'ehcache') { _%>
            hibernate.cache.region.factory_class: org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory
            <%_ } else if (hibernateCache == 'hazelcast') { _%>
            hibernate.cache.region.factory_class: <%=packageName%>.config.hazelcast.HazelcastCacheRegionFactory
            <%_ } _%>
            <%_ if (hibernateCache == 'hazelcast') { _%>
            hibernate.cache.use_minimal_puts: true
            hibernate.cache.hazelcast.use_lite_member: true
            <%_ } _%>
    <%_ } _%>
    <%_ if (databaseType == 'mongodb' || databaseType == 'cassandra' || applicationType == 'gateway' || searchEngine == 'elasticsearch') { _%>
    data:
    <%_ } _%>
    <%_ if (databaseType == 'mongodb') { _%>
        mongodb:
            uri: mongodb://localhost:27017
            database: <%= baseName %>
    <%_ } _%>
    <%_ if (databaseType == 'cassandra' || applicationType == 'gateway') { _%>
        cassandra:
            contactPoints: localhost
            protocolVersion: V4
            compression: LZ4
            keyspaceName: <%= baseName %>
    <%_ if (applicationType == 'gateway') { _%>
            repositories:
                enabled: false
    <%_ } } _%>
    <%_ if (searchEngine == 'elasticsearch') { _%>
        elasticsearch:
            cluster-name:
            cluster-nodes:
            properties:
                path:
                  logs: target/elasticsearch/log
                  data: target/elasticsearch/data
    <%_ } _%>
    mail:
        host: localhost
        port: 25
        username:
        password:
    messages:
        cache-seconds: 1
    thymeleaf:
        cache: false
    profiles:
        include: swagger # automatically set the 'swagger' profile

<%_ if (databaseType === 'sql') { _%>
liquibase:
    contexts: dev

<%_ } _%>
server:
<%_ if (applicationType == 'microservice' || applicationType == 'gateway' || applicationType == 'uaa') { _%>
    port: <%= serverPort %>
<%_ } else { _%>
    port: 8080
<%_ } _%>

# ===================================================================
# JHGenesis specific properties
# ===================================================================

jh-genesis:
    <%_ if (applicationType == 'gateway') { _%>
    gateway:
        rate-limiting: # Read the documentation in the GatewayConfiguration class before enabling.
            enabled: false
        authorized-microservices-endpoints: # Access Control Policy, if left empty for a route, all endpoints will be accessible
            app1: /api,/v2/api-docs # recommended dev configuration
    <%_ } _%>
    <%_ if (clusteredHttpSession == 'hazelcast' || hibernateCache == 'hazelcast' || hibernateCache == 'ehcache') { _%>
    cache: # Hibernate 2nd level cache, used by CacheConfiguration
        timeToLiveSeconds: 3600
        <%_ if (clusteredHttpSession == 'hazelcast' || hibernateCache == 'hazelcast') { _%>
        hazelcast:
            backupCount: 1
        <%_ } _%>
        <%_ if (hibernateCache == 'ehcache') { _%>
        ehcache:
            maxBytesLocalHeap: 16M
        <%_ } _%>
    <%_ } _%>
<%_ if (authenticationType == 'oauth2' || authenticationType == 'jwt') { _%>
    security:
        authentication:
    <%_ if (authenticationType == 'jwt') { _%>
            jwt:
                secret: my-secret-token-to-change-in-production
                # Token is valid 24 hours
                tokenValidityInSeconds: 86400
    <%_ } _%>
    <%_ if (authenticationType == 'oauth2') { _%>
            oauth:
                clientid: <%= baseName %>app
                secret: my-secret-token-to-change-in-production
                # Token is valid 30 minutes
                tokenValidityInSeconds: 1800
    <%_ } _%>
<%_ } _%>
<%_ if (authenticationType == 'session') { _%>
    security:
        rememberMe:
            # security key (this key should be unique for your application, and kept secret)
            key: <%= rememberMeKey %>
<%_ } _%>
    mail: # specific JHGenesis mail property, for standard properties see MailProperties
        from: <%= baseName %>@localhost
    metrics: # DropWizard Metrics configuration, used by MetricsConfiguration
        jmx.enabled: true
        spark:
            enabled: false
            host: localhost
            port: 9999
        graphite:
            enabled: false
            host: localhost
            port: 2003
            prefix: <%= baseName %>
        logs: # Reports Dropwizard metrics in the logs
            enabled: false
            reportFrequency: 60 # in seconds
    logging:
        logstash: # Forward logs to logstash over a socket, used by LoggingConfiguration
            enabled: false
            host: localhost
            port: 5000
            queueSize: 512
    <%_ if (applicationType == 'microservice' || applicationType == 'gateway') { _%>
        spectator-metrics: # Reports Spectator Circuit Breaker metrics in the logs
            enabled: false
            # edit spring.metrics.export.delay-millis to set report frequency
    <%_ } _%>
