From ec1f052fe0488955a824bfd0498d04236653147f Mon Sep 17 00:00:00 2001
From: OZGCloud <ozgcloud@mgm-tp.com>
Date: Wed, 19 Jun 2024 11:11:54 +0200
Subject: [PATCH] OZG-5400 use static final for constants

---
 .../keycloak/realm/KeycloakRealmMapper.java   | 31 ++++++++++++-------
 1 file changed, 19 insertions(+), 12 deletions(-)

diff --git a/ozgcloud-keycloak-operator/src/main/java/de/ozgcloud/operator/keycloak/realm/KeycloakRealmMapper.java b/ozgcloud-keycloak-operator/src/main/java/de/ozgcloud/operator/keycloak/realm/KeycloakRealmMapper.java
index 4d7ea13..76bdd86 100644
--- a/ozgcloud-keycloak-operator/src/main/java/de/ozgcloud/operator/keycloak/realm/KeycloakRealmMapper.java
+++ b/ozgcloud-keycloak-operator/src/main/java/de/ozgcloud/operator/keycloak/realm/KeycloakRealmMapper.java
@@ -38,26 +38,33 @@ import org.mapstruct.ReportingPolicy;
 @Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE, unmappedSourcePolicy = ReportingPolicy.IGNORE)
 interface KeycloakRealmMapper {
 
+	public static final String ACTION_TOKEN_GENERATED_BY_USER_LIFE_SPAN = "900";
+	public static final String PASSWORD_POLICY = "upperCase(1) and lowerCase(1) and length(8) and notUsername";
+	public static final String  DEFAULT_LOCAL = "de";
+	public static final String RESET_PASSWORD_ALLOWED = "true";
+	public static final String ENABLED = "true";
+	public static final String INTERNATIONALIZATION_ENABLED = "true";
+
 	@Mapping(target = "displayName", source = "displayName")
-	@Mapping(target = "enabled", constant = "true")
-	@Mapping(target = "resetPasswordAllowed", constant = "true")
+	@Mapping(target = "enabled", constant = ENABLED)
+	@Mapping(target = "resetPasswordAllowed", constant = RESET_PASSWORD_ALLOWED)
 	@Mapping(target = "supportedLocales", source = ".", qualifiedByName = "supportedLocales")
-	@Mapping(target = "defaultLocale", constant = "de")
-	@Mapping(target = "internationalizationEnabled", constant = "true")
-	@Mapping(target = "passwordPolicy", constant = "upperCase(1) and lowerCase(1) and length(8) and notUsername")
-	@Mapping(target = "actionTokenGeneratedByUserLifespan", constant = "900")
+	@Mapping(target = "defaultLocale", constant = DEFAULT_LOCAL)
+	@Mapping(target = "internationalizationEnabled", constant = INTERNATIONALIZATION_ENABLED)
+	@Mapping(target = "passwordPolicy", constant = PASSWORD_POLICY)
+	@Mapping(target = "actionTokenGeneratedByUserLifespan", constant = ACTION_TOKEN_GENERATED_BY_USER_LIFE_SPAN)
 	@Mapping(target = "smtpServer", source = "smtpServer", qualifiedByName = "smtpServer")
 	@Mapping(target = "roles.realm", source = "realmRoles")
 	public RealmRepresentation map(OzgCloudKeycloakRealmSpec realm);
 
 	@Mapping(target = "displayName", source = "displayName")
-	@Mapping(target = "enabled", constant = "true")
-	@Mapping(target = "resetPasswordAllowed", constant = "true")
+	@Mapping(target = "enabled", constant = ENABLED)
+	@Mapping(target = "resetPasswordAllowed", constant = RESET_PASSWORD_ALLOWED)
 	@Mapping(target = "supportedLocales", source = ".", qualifiedByName = "supportedLocales")
-	@Mapping(target = "defaultLocale", constant = "de")
-	@Mapping(target = "internationalizationEnabled", constant = "true")
-	@Mapping(target = "passwordPolicy", constant = "upperCase(1) and lowerCase(1) and length(8) and notUsername")
-	@Mapping(target = "actionTokenGeneratedByUserLifespan", constant = "900")
+	@Mapping(target = "defaultLocale", constant = DEFAULT_LOCAL)
+	@Mapping(target = "internationalizationEnabled", constant = INTERNATIONALIZATION_ENABLED)
+	@Mapping(target = "passwordPolicy", constant = PASSWORD_POLICY)
+	@Mapping(target = "actionTokenGeneratedByUserLifespan", constant = ACTION_TOKEN_GENERATED_BY_USER_LIFE_SPAN)
 	@Mapping(target = "smtpServer", source = "smtpServer", qualifiedByName = "smtpServer")
 	@Mapping(target = "roles.realm", source = "realmRoles")
 	RealmRepresentation update(@MappingTarget RealmRepresentation existingRealm, OzgCloudKeycloakRealmSpec spec);
-- 
GitLab