Skip to content

Commit

Permalink
[26790] Such-Funktion Sortierfunktion Designe angepasst und Einstellu…
Browse files Browse the repository at this point in the history
…ng (#406)
  • Loading branch information
Daksic28 authored Dec 10, 2024
1 parent 69a7863 commit 84ba1e1
Show file tree
Hide file tree
Showing 43 changed files with 1,187 additions and 561 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,6 @@ public interface IMednetAuthService {
*/
public Optional<String> getToken(Map<String, Object> parameters);

/**
* Get the bearer token for the provided parameters. Existing tokens are
* returned without user interaction. If there is no existing token a
* {@link IMednetAuthUi} implementation is needed for user interaction.
*
* @param parameters
* @return
*/
public Optional<String> delToken(Map<String, Object> parameters);

/**
* Call this method to inform the {@link IMednetAuthService} about a exception
* occurred accessing a web service using a token from the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
import java.util.stream.Collectors;

import org.apache.commons.lang3.StringUtils;
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.ServiceReference;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
Expand All @@ -48,12 +45,9 @@ public class MednetAuthService implements IMednetAuthService {
@Reference(cardinality = ReferenceCardinality.OPTIONAL, policyOption = ReferencePolicyOption.GREEDY)
private IMednetAuthUi authUi;

private boolean useQueryParam = true;

private String currentState;
private String currentCodeVerifier;


@Override
public Optional<String> getToken(Map<String, Object> parameters) {
if (configService == null) {
Expand All @@ -74,37 +68,6 @@ public Optional<String> getToken(Map<String, Object> parameters) {
return Optional.empty();
}

@Override
public Optional<String> delToken(Map<String, Object> parameters) {

String tokenGroup = "mednet";
BundleContext context = FrameworkUtil.getBundle(getClass()).getBundleContext();
ServiceReference<IMednetAuthService> serviceReference = context.getServiceReference(IMednetAuthService.class);

if (serviceReference != null) {
IMednetAuthService authService = context.getService(serviceReference);
try {

if (configService == null) {

}

configService.setActiveMandator(PreferenceConstants.PREF_TOKEN + tokenGroup, null);
configService.setActiveMandator(PreferenceConstants.PREF_TOKEN_EXPIRES + tokenGroup, null);
configService.setActiveMandator(PreferenceConstants.PREF_REFRESHTOKEN + tokenGroup, null);

} catch (Exception ex) {

LoggerFactory.getLogger(getClass()).error("Error when removing token", ex);
} finally {
context.ungetService(serviceReference);
}
} else {

}
return Optional.empty();
}

private Optional<String> getToken(String tokenGroup, IMednetAuthUi iMednetAuthUi) {
Optional<String> authCode = getAuthCode(tokenGroup, iMednetAuthUi);
if (authCode.isPresent()) {
Expand All @@ -116,9 +79,8 @@ private Optional<String> getToken(String tokenGroup, IMednetAuthUi iMednetAuthUi
return Optional.empty();
}


private String getOauthRestUrl() {
return configService.get(PreferenceConstants.PREF_RESTBASEURL, ApiConstants.BASE_URI);
return configService.get(PreferenceConstants.PREF_RESTBASEURL, ApiConstants.getBaseUri());
}

private Optional<String> getAccessTokenWithRefresh(String tokenGroup, String refreshToken, String oauthRestUrl) {
Expand All @@ -127,7 +89,6 @@ private Optional<String> getAccessTokenWithRefresh(String tokenGroup, String ref
parameters.put("refresh_token", refreshToken);
parameters.put("client_id", getClientId());
parameters.put("client_secret", getClientSecret());

String form = parameters.entrySet().stream()
.map(e -> e.getKey() + "=" + URLEncoder.encode(e.getValue(), StandardCharsets.UTF_8))
.collect(Collectors.joining("&"));
Expand Down Expand Up @@ -165,9 +126,8 @@ private Optional<String> getAccessTokenWithRefresh(String tokenGroup, String ref

return Optional.of(token);
} catch (JsonSyntaxException ex) {
LoggerFactory.getLogger(getClass()).error(
"The answer is not a valid JSON: " + response.statusCode(),
ex);
LoggerFactory.getLogger(getClass())
.error("The answer is not a valid JSON: " + response.statusCode(), ex);
}
} else {
LoggerFactory.getLogger(getClass()).error("Getting refreshed access token failed ["
Expand All @@ -179,7 +139,6 @@ private Optional<String> getAccessTokenWithRefresh(String tokenGroup, String ref
return Optional.empty();
}


public Optional<String> getAuthCode(String tokenGroup, IMednetAuthUi iMedNetAuthUi) {
String codeVerifier = generateCodeVerifier();
String codeChallenge = generateCodeChallenge(codeVerifier);
Expand All @@ -195,7 +154,6 @@ public Optional<String> getAuthCode(String tokenGroup, IMednetAuthUi iMedNetAuth
new GetAuthCodeWithStateSupplier(stateValue));

if (value instanceof String) {
LoggerFactory.getLogger(getClass()).info("Authorization Code received: {}", value);
return Optional.of((String) value);
}
LoggerFactory.getLogger(getClass()).warn("No authorization code received.");
Expand Down Expand Up @@ -235,7 +193,7 @@ private String getLoginHint() {
LoggerFactory.getLogger(getClass()).warn("Kein Login-Hinweis in den Einstellungen gefunden.");
} else {
LoggerFactory.getLogger(getClass()).info("Login-Hinweis abgerufen: {}", userName);
}
}
return userName;
}

Expand Down Expand Up @@ -288,7 +246,6 @@ private String generateCodeVerifier() {
return Base64.getUrlEncoder().withoutPadding().encodeToString(code).substring(0, 43);
}


private String generateCodeChallenge(String codeVerifier) {
try {
MessageDigest digest = MessageDigest.getInstance("SHA-256");
Expand All @@ -311,11 +268,16 @@ private String getCurrentState(boolean refresh) {
}

private String getClientId() {
String mode = configService.getActiveUserContact(PreferenceConstants.MEDNET_MODE, "DEMO");
try (InputStream properties = getClass().getResourceAsStream("/rsc/id.properties")) {
if (properties != null) {
Properties idProps = new Properties();
idProps.load(properties);
return idProps.getProperty("client_id");
if ("PRODUKTIV".equals(mode)) {
return idProps.getProperty("client_id_prod");
} else {
return idProps.getProperty("client_id_demo");
}
}
} catch (Exception e) {
LoggerFactory.getLogger(getClass()).error("Error loading id properties", e);
Expand All @@ -324,11 +286,16 @@ private String getClientId() {
}

private String getClientSecret() {
String mode = configService.getActiveUserContact(PreferenceConstants.MEDNET_MODE, "DEMO");
try (InputStream properties = getClass().getResourceAsStream("/rsc/id.properties")) {
if (properties != null) {
Properties idProps = new Properties();
idProps.load(properties);
return idProps.getProperty("client_secret");
if ("PRODUKTIV".equals(mode)) {
return idProps.getProperty("client_secret_prod");
} else {
return idProps.getProperty("client_secret_demo");
}
}
} catch (Exception e) {
LoggerFactory.getLogger(getClass()).error("Error loading id properties", e);
Expand All @@ -350,8 +317,8 @@ private Optional<String> validateToken(String existingToken, String tokenGroup)
getOauthRestUrl());
if (refreshedToken.isPresent()) {
return refreshedToken;
} else {
configService.setActiveMandator(PreferenceConstants.PREF_REFRESHTOKEN + tokenGroup, null);
} else {
configService.setActiveMandator(PreferenceConstants.PREF_REFRESHTOKEN + tokenGroup, null);
}
}
configService.setActiveMandator(PreferenceConstants.PREF_TOKEN + tokenGroup, null);
Expand All @@ -376,6 +343,3 @@ public Optional<String> handleException(Exception ex, Map<String, Object> parame
return Optional.empty();
}
}



Original file line number Diff line number Diff line change
@@ -1,20 +1,52 @@
package ch.elexis.mednet.webapi.core.constants;

import java.util.Optional;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ch.elexis.core.services.IConfigService;
import ch.elexis.core.utils.OsgiServiceUtil;

public class ApiConstants {

// API Base URL
public static final String BASE_API_URL = "https://demo.mednet.swiss/web/api/v1/external";
public static final String BASE_URI = "https://demo.mednetpatient.swiss/idsrv";
public static final String BASE_REDERICT_URI = "https://tools.medelexis.ch/mednet/ac";
public static final String BASE_REDERICT_URI_OBTAIN = "https://tools.medelexis.ch/mednet/ac-obtain/";
private static final Logger logger = LoggerFactory.getLogger(ApiConstants.class);

// Specific API Endpoints
public static final String CUSTOMERS_URL = BASE_API_URL + "/customers?includeDetails=true";
public static final String PROVIDERS_URL = BASE_API_URL + "/providers?customerId=%d&includeDetails=true";
public static final String FORMS_URL = BASE_API_URL + "/forms?customerId=%d&providerId=%d";
public static final String SUBMITTED_FORMS_URL = BASE_API_URL + "/submitted-forms?customerId=%d";
public static final String PATIENTS_URL = BASE_API_URL + "/patients";
public static String getBaseApiUrl() {
Optional<IConfigService> configService = OsgiServiceUtil.getServiceWait(IConfigService.class, 5000);
if (configService.isPresent()) {
String mode = configService.get().getActiveUserContact(PreferenceConstants.MEDNET_MODE, "DEMO");

if ("PRODUKTIV".equals(mode)) {
return "https://www.mednet.swiss/web/api/v1/external";
} else {
return "https://demo.mednet.swiss/web/api/v1/external";
}
} else {
logger.error("Error when retrieving the base API URL from the preferences: {}");
}
return "https://demo.mednet.swiss/web/api/v1/external";
}

}
public static String getBaseUri() {

Optional<IConfigService> configService = OsgiServiceUtil.getServiceWait(IConfigService.class, 5000);
if (configService.isPresent()) {
String mode = configService.get().getActiveUserContact(PreferenceConstants.MEDNET_MODE, "DEMO");
if ("PRODUKTIV".equals(mode)) {
return "https://www.mednet.swiss/idsrv";
} else {
return "https://demo.mednetpatient.swiss/idsrv";
}
}
return "https://demo.mednetpatient.swiss/idsrv";
}

public static final String BASE_REDERICT_URI = "https://tools.medelexis.ch/mednet/ac";
public static final String BASE_REDERICT_URI_OBTAIN = "https://tools.medelexis.ch/mednet/ac-obtain/";
public static final String CUSTOMERS_URL = "/customers?includeDetails=true";
public static final String PROVIDERS_URL = "/providers?customerId=%d&includeDetails=true";
public static final String FORMS_URL = "/forms?customerId=%d&providerId=%d";
public static final String SUBMITTED_FORMS_URL = "/submitted-forms?customerId=%d";
public static final String PATIENTS_URL = "/patients";
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ public class IconConstants {
public static final String ICON_SETTINGS_WHITE = "icons/settings_white.png";
public static final String ICON_CONECT_BLUE = "icons/conect_blue.png";
public static final String ICON_CONECT_WHITE = "icons/conect_white.png";
public static final String ICON_TOGGEL_RED = "icons/toggel_red.png";
public static final String ICON_TOGGEL_GREEN = "icons/toggel_green.png";
public static final String ICON_WARNUNG_GELB = "icons/warnung_gelb.png";
public static final String ICON_WARNUNG_GRUEN = "icons/warnung_gruen.png";
public static final String ICON_TOGGEL_RED = "icons/on-off-button-rot.png";
public static final String ICON_TOGGEL_GREEN = "icons/on-off-button-gruen.png";
public static final String ICON_LEFT_ARROW = "icons/left-arrow.png";
public static final String ICON_LEFT_ARROW_WHITE = "icons/left-arrow_white.png";

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ public class PreferenceConstants {

public static final String TOKEN_GROUP = "token_group";
public static final String TOKEN_GROUP_KEY = "mednet";
public static final String MEDNET_MODE = "mednet_mode";

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package ch.elexis.mednet.webapi.core.constants;

public class StateConstants {
public static final String CUSTOMER = "CUSTOMER";
public static final String PROVIDER = "PROVIDER";
public static final String FORM = "FORM";
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,35 @@
package ch.elexis.mednet.webapi.core.constants;

import java.util.Optional;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ch.elexis.core.services.IConfigService;
import ch.elexis.core.utils.OsgiServiceUtil;

public class URLConstants {
private static final Logger logger = LoggerFactory.getLogger(URLConstants.class);

public static String getBaseApiUrl() {
Optional<IConfigService> configService = OsgiServiceUtil.getServiceWait(IConfigService.class, 5000);
if (configService.isPresent()) {
String mode = configService.get().getActiveUserContact(PreferenceConstants.MEDNET_MODE, "DEMO");

if ("PRODUKTIV".equals(mode)) {
return "https://www.mednet.swiss";
} else {
return "https://demo.mednet.swiss";
}
} else {
logger.error("Error when retrieving the base API URL from the preferences: {}");
}
return "https://demo.mednet.swiss";
}

public static final String URL_PATIENTS = "https://demo.mednet.swiss/DoctorUser/patients";
public static final String URL_TASKS = "https://demo.mednet.swiss/DoctorUser/tasks";
public static final String URL_DOCUMENTS = "https://demo.mednet.swiss/DoctorUser/documents";
public static final String URL_THERAPY = "https://demo.mednet.swiss/DoctorUser/chronic-diseases/chronic-diseases-list";
public static final String URL_PATIENTS = "/DoctorUser/patients";
public static final String URL_TASKS = "/DoctorUser/tasks";
public static final String URL_DOCUMENTS = "/DoctorUser/documents";
public static final String URL_THERAPY = "/DoctorUser/chronic-diseases/chronic-diseases-list";

}
Loading

0 comments on commit 84ba1e1

Please sign in to comment.