Skip to content
Snippets Groups Projects

Ozg 3936 refactor user profile url provider

Merged Felix Reichenbach requested to merge OZG-3936-refactor-UserProfileUrlProvider into main
9 files
+ 15
165
Compare changes
  • Side-by-side
  • Inline
Files
9
/*
* Copyright (C) 2023 Das Land Schleswig-Holstein vertreten durch den
* Ministerpräsidenten des Landes Schleswig-Holstein
* Staatskanzlei
* Abteilung Digitalisierung und zentrales IT-Management der Landesregierung
*
* Lizenziert unter der EUPL, Version 1.2 oder - sobald
* diese von der Europäischen Kommission genehmigt wurden -
* Folgeversionen der EUPL ("Lizenz");
* Sie dürfen dieses Werk ausschließlich gemäß
* dieser Lizenz nutzen.
* Eine Kopie der Lizenz finden Sie hier:
*
* https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
*
* Sofern nicht durch anwendbare Rechtsvorschriften
* gefordert oder in schriftlicher Form vereinbart, wird
* die unter der Lizenz verbreitete Software "so wie sie
* ist", OHNE JEGLICHE GEWÄHRLEISTUNG ODER BEDINGUNGEN -
* ausdrücklich oder stillschweigend - verbreitet.
* Die sprachspezifischen Genehmigungen und Beschränkungen
* unter der Lizenz sind dem Lizenztext zu entnehmen.
*/
package de.ozgcloud.alfa.common;
import java.util.Objects;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
import com.google.common.base.Preconditions;
@Component
public class UserProfileUrlProvider implements ApplicationContextAware {
// TODO auf javax.validation umstellen
private static final String ERROR_MESSAGE = "Key %s missing, please add it to the application.yml";
// TODO applicationContext darf nicht static abgelegt werden - es sollte möglich
// sein, dass eine andere Konfiguration in der jvm läuft.
private static ApplicationContext applicationContext;
static final String URL_ROOT_KEY = "ozgcloud.user-manager.url";
static final String USER_PROFILES_TEMPLATE_KEY = "ozgcloud.user-manager.profile-template";
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
UserProfileUrlProvider.setSpringContext(applicationContext);
}
private static void setSpringContext(ApplicationContext context) {
applicationContext = context;
}
public static boolean isConfigured() {
return Objects.nonNull(applicationContext.getEnvironment().getProperty(URL_ROOT_KEY))
&& Objects.nonNull(applicationContext.getEnvironment().getProperty(USER_PROFILES_TEMPLATE_KEY));
}
public static String getUrl(Object val) {
// TODO Abhängingkeit zu com.google.common ausbauen
Preconditions.checkNotNull(applicationContext, "ApplicationContext not initialized");
// TODO parameter lieber injezieren und validation verwenden
var rootUrl = applicationContext.getEnvironment().getProperty(URL_ROOT_KEY);
Preconditions.checkNotNull(rootUrl, ERROR_MESSAGE, URL_ROOT_KEY);
var template = applicationContext.getEnvironment().getProperty(USER_PROFILES_TEMPLATE_KEY);
Preconditions.checkNotNull(template, ERROR_MESSAGE, USER_PROFILES_TEMPLATE_KEY);
// TODO UriComponent Builder verwenden
var profilesUrl = rootUrl + template;
return String.format(profilesUrl, val);
}
}
Loading