KEYCLOAK-16244 RealmRealmLocalizationResourceTest fails on auth-server-quarkus
This commit is contained in:
parent
030a077e99
commit
9b2f2015f7
3 changed files with 32 additions and 9 deletions
|
@ -873,8 +873,9 @@ public class JpaRealmProvider implements RealmProvider, ClientProvider, GroupPro
|
|||
public boolean updateLocalizationText(RealmModel realm, String locale, String key, String text) {
|
||||
RealmLocalizationTextsEntity entity = getRealmLocalizationTextsEntity(locale, realm.getId());
|
||||
if (entity != null && entity.getTexts() != null && entity.getTexts().containsKey(key)) {
|
||||
entity.getTexts().put(key, text);
|
||||
|
||||
Map<String, String> keys = new HashMap<>(entity.getTexts());
|
||||
keys.put(key, text);
|
||||
entity.setTexts(keys);
|
||||
em.persist(entity);
|
||||
return true;
|
||||
} else {
|
||||
|
@ -891,7 +892,9 @@ public class JpaRealmProvider implements RealmProvider, ClientProvider, GroupPro
|
|||
entity.setLocale(locale);
|
||||
entity.setTexts(new HashMap<>());
|
||||
}
|
||||
entity.getTexts().put(key, text);
|
||||
Map<String, String> keys = new HashMap<>(entity.getTexts());
|
||||
keys.put(key, text);
|
||||
entity.setTexts(keys);
|
||||
em.persist(entity);
|
||||
}
|
||||
|
||||
|
@ -931,8 +934,9 @@ public class JpaRealmProvider implements RealmProvider, ClientProvider, GroupPro
|
|||
public boolean deleteLocalizationText(RealmModel realm, String locale, String key) {
|
||||
RealmLocalizationTextsEntity entity = getRealmLocalizationTextsEntity(locale, realm.getId());
|
||||
if (entity != null && entity.getTexts() != null && entity.getTexts().containsKey(key)) {
|
||||
entity.getTexts().remove(key);
|
||||
|
||||
Map<String, String> keys = new HashMap<>(entity.getTexts());
|
||||
keys.remove(key);
|
||||
entity.setTexts(keys);
|
||||
em.persist(entity);
|
||||
return true;
|
||||
} else {
|
||||
|
|
|
@ -2230,6 +2230,9 @@ public class RealmAdapter implements RealmModel, JpaModel<RealmEntity> {
|
|||
Map<String, RealmLocalizationTextsEntity> currentLocalizationTexts = realm.getRealmLocalizationTexts();
|
||||
if(currentLocalizationTexts.containsKey(locale)) {
|
||||
RealmLocalizationTextsEntity localizationTextsEntity = currentLocalizationTexts.get(locale);
|
||||
Map<String, String> keys = new HashMap<>(localizationTextsEntity.getTexts());
|
||||
keys.putAll(localizationTexts);
|
||||
localizationTextsEntity.setTexts(keys);
|
||||
localizationTextsEntity.getTexts().putAll(localizationTexts);
|
||||
|
||||
em.persist(localizationTextsEntity);
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
package org.keycloak.models.jpa.entities;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import javax.persistence.Column;
|
||||
|
@ -32,6 +33,11 @@ import org.keycloak.models.jpa.converter.MapStringConverter;
|
|||
@IdClass(RealmLocalizationTextsEntity.RealmLocalizationTextEntityKey.class)
|
||||
@Table(name = "REALM_LOCALIZATIONS")
|
||||
public class RealmLocalizationTextsEntity {
|
||||
|
||||
// TODO: Remove this constant once the quarkus issue is fixed and use the @Convert annotation in the proper JPA way. Ideally see the github history and revert whole commit,
|
||||
// which adds this "TODO" once the quarkus issue is fixed
|
||||
private static final MapStringConverter MAP_STRING_CONVERTER = new MapStringConverter();
|
||||
|
||||
static public class RealmLocalizationTextEntityKey implements Serializable {
|
||||
private String realmId;
|
||||
private String locale;
|
||||
|
@ -76,15 +82,25 @@ public class RealmLocalizationTextsEntity {
|
|||
private String locale;
|
||||
|
||||
@Column(name = "TEXTS")
|
||||
@Convert(converter = MapStringConverter.class)
|
||||
private Map<String,String> texts;
|
||||
private String texts;
|
||||
// TODO: The @Convert does not work as expected on quarkus. It doesn't update the "texts" in case that updated map has same keys (but different values) as old map had
|
||||
// @Convert(converter = MapStringConverter.class)
|
||||
// private Map<String,String> texts;
|
||||
|
||||
public Map<String,String> getTexts() {
|
||||
return texts;
|
||||
if (texts == null) {
|
||||
return Collections.emptyMap();
|
||||
} else {
|
||||
return Collections.unmodifiableMap(MAP_STRING_CONVERTER.convertToEntityAttribute(texts));
|
||||
}
|
||||
}
|
||||
|
||||
public void setTexts(Map<String,String> texts) {
|
||||
this.texts = texts;
|
||||
if (texts == null) {
|
||||
this.texts = null;
|
||||
} else {
|
||||
this.texts = MAP_STRING_CONVERTER.convertToDatabaseColumn(texts);
|
||||
}
|
||||
}
|
||||
|
||||
public String getLocale() {
|
||||
|
|
Loading…
Reference in a new issue