#
# Explore config for CMEM 24.2
#

# maxFileSize and maxRequestSize are now set in environments: EXPLORE_MAX_FILE_SIZE, EXPLORE_MAX_REQUEST_SIZE
# Keycloak Path are now set in enviroments EXPLORE_AUTH_URL
server:
  compression:
    enabled: true
    min-response-size: 4096
    mime-types:
      - "text/html"
      - "text/xml"
      - "text/plain"
      - "text/css"
      - "text/javascript"
      - "application/javascript"
      - "application/json"
      - "text/turtle"
      - "application/n-triples"
      - "application/trig"
      - "application/n-quads"
      - "application/ld+json"

## The Concise Boundary Description is used for viewing and editing resoures.
## By default up to a max of 5 Blank nodes are traversed for calculation.
## Increasing the max fetch will support deeper constructs, but will also add to loading time.
maxCBDDepth: "10"

## Cross-Origin Resource Sharing (CORS) settings
http:
  cors:
    allowedOrigins:
      - "*"

proxy:
  cacheSelectiveInvalidation: "true"
  cacheInvalidationCron: "0 */30 * * * *"

logging:
  config: "/data/logback.xml"
  file: "/data/logs/application.log"
  level:
    com.eccenca.elds.backend: WARN
    com.eccenca.elds.backend.webapp.health: INFO
    com.eccenca.elds.backend.webapp.app.semspect.event: DEBUG
    org.springframework: WARN
    org.springframework.security: WARN
    # to supress the "No CORS headers added" spam
    com.eccenca.elds.backend.webapp.web.filter.SimpleCorsFilter: WARN
    # to enable better exception logging
    com.eccenca.elds.backend.webapp.web.GlobalControllerExceptionHandler: TRACE
    # if set to TRACE outputs queries into log
  pattern:
    console: "%d{yyyy-MM-dd'T'HH:mm:ss.SSSX,UTC} %-5level %logger{15} - %message%n%xException"
    file: "%d{yyyy-MM-dd'T'HH:mm:ss.SSSX,UTC} %-5level %logger{15} - %message%n%xException"


# can also be added as environmets like this:
# !! But be careful, this can easily causes DP 500 errors
  #SPRING_SECURITY_OAUTH2_RESOURCESERVER_ANONYMOUS: {{ .Values.explore.config.anonymousLogin | quote }}
  #SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_JWKSETURI: {{ print .Values.global.keycloakIssuerUrl "/protocol/openid-connect/certs" | quote }}
  #SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_KEYCLOAK_CLIENTID: {{ print .Values.global.oauthClientId | quote }}
  #SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_KEYCLOAK_REDIRECTURI: {{ .Values.global.protocol }}://{{ .Values.global.hostname }}{{ .Values.explore.config.contextPath }}/login/oauth2/code/{registrationId}
  #SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_KEYCLOAK_JWKSETURI: {{ print .Values.global.keycloakIssuerUrl "/protocol/openid-connect/certs" | quote }}
  #SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_KEYCLOAK_AUTHORIZATIONURI: {{ print .Values.global.keycloakIssuerUrl "/protocol/openid-connect/auth" | quote }}
  #SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_KEYCLOAK_TOKENURI: {{ print .Values.global.keycloakIssuerUrl "/protocol/openid-connect/token" | quote }}
  #SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_KEYCLOAK_USERINFO_URI: {{ print .Values.global.keycloakIssuerUrl "/protocol/openid-connect/userinfo" | quote }}


spring.security.oauth2:
  resourceserver:
    anonymous: "${EXPLORE_ANONYMOUS}"
    jwt:
      jwk-set-uri: "${OAUTH_JWK_SET_URL}"
  client:
    registration:
      keycloak:
        client-id: ${OAUTH_CLIENT_ID}
        authorization-grant-type: "authorization_code"
        client-authentication-method: "client_secret_basic"
        redirectUri: "${DEPLOY_BASE_URL}/dataplatform/login/oauth2/code/{registrationId}"
        provider: keycloak
        scope:  # openid is mandatory as spring somehow does not add it to the userinfo request
          - openid
          - profile
          - email
      explore-service:
        client-id: ${EXPLORE_CMEM_SERVICE_CLIENT}
        client-secret: ${EXPLORE_CMEM_SERVICE_CLIENT_SECRET}
        authorization-grant-type: client_credentials
        provider: keycloak
    provider:
      keycloak:
        jwk-set-uri: "${OAUTH_JWK_SET_URL}"
        authorization-uri: "${OAUTH_AUTHORIZATION_URL}"
        token-uri: "${OAUTH_TOKEN_URL}"
        user-info-uri: "${OAUTH_USERINFO_URL}"
        user-name-attribute: "preferred_username"

server.forward-headers-strategy: NATIVE

{{- if .Values.explore.store.graphdb.enabled }}
store:
  graphdb:
    importDirectory: "/data/import"
    useDirectTransfer: true
{{- end }}


spring.ai.chat.client.enabled: {{ .Values.explore.companion.enabled}}
spring.ai.chat.client.model.chat: {{ .Values.explore.companion.model | quote }}

{{- if .Values.explore.companion.enabled }}

spring.ai:
  {{ toYaml .Values.explore.companion.config | nindent 2}}

{{- end }}

spring.datasource:
  # JDBC driver class for HSQLDB
  driver-class-name: "org.hsqldb.jdbc.JDBCDriver"
  # JDBC URL for HSQLDB file-based database with proper shutdown behavior
  {{- if .Values.explore.companion.enabled }}
  url: "jdbc:hsqldb:file:/{{ .Values.explore.companion.persistence.mountPath }}/chat-memory;shutdown=true"
  {{- else }}
  url: "jdbc:hsqldb:mem:chat-memory"
  {{- end }}
  # Database username for HSQLDB
  username: "sa"
  # Database password for HSQLDB (empty for embedded mode)
  password: ""


{{- if .Values.graphinsights.enabled }}
semspect:
  enabled: true
  integration:
    url: {{ print "http://" .Values.graphinsights.service.name ":" .Values.graphinsights.service.port .Values.graphinsights.service.contextPath | quote }}
    externalUrl: '${DEPLOY_BASE_URL}{{ .Values.graphinsights.service.contextPath}}'
    automaticResyncCronExpression: "0 0/30 8-10 * * *"
    localDatasetStatePath: /graphinsights/infinispan # path inside explore container where to store graphinsights infinispan data
    ### Configure either fileShareIntegrationSettings or graph-store-integration-settings
    # fileShareIntegrationSettings:
    localGraphStoragePathExplore: /graphinsights
    # localGraphStoragePathSemspect: /explore-share/
    graph-store-integration-settings:
      semspect-dataplatform-url: http://{{ print .Values.explore.service.name ":" .Values.explore.service.port }}/dataplatform
{{- end }}
