From bc889ef8a4b36e9808e5a8292ecc20dea5decc62 Mon Sep 17 00:00:00 2001 From: Qi Shen Date: Fri, 24 Feb 2023 09:48:25 +0800 Subject: [PATCH] enable set appName for external navigation API --- .../LaunchpadNavigationServiceImpl.java | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/main/java/io/boomerang/service/profile/LaunchpadNavigationServiceImpl.java b/src/main/java/io/boomerang/service/profile/LaunchpadNavigationServiceImpl.java index a135e359..199cf33f 100644 --- a/src/main/java/io/boomerang/service/profile/LaunchpadNavigationServiceImpl.java +++ b/src/main/java/io/boomerang/service/profile/LaunchpadNavigationServiceImpl.java @@ -20,6 +20,7 @@ import io.boomerang.model.profile.Navigation; import io.boomerang.model.profile.NavigationResponse; import io.boomerang.model.profile.Platform; +import io.boomerang.mongo.model.Config; import io.boomerang.mongo.service.FlowSettingsService; import io.boomerang.security.model.UserToken; import io.boomerang.security.service.ApiTokenService; @@ -127,16 +128,29 @@ private NavigationResponse getExternalNavigationResponse(String email) { NavigationResponse result = response.getBody(); if (result != null && result.getPlatform() != null) { if(Strings.isBlank(result.getPlatform().getAppName())) { - // set default appName if the external Navigation API does NOT return appName. - String defaultAppName = settingsService.getConfiguration("customizations", "appName").getValue(); - result.getPlatform().setAppName(defaultAppName); + // set default appName from settings if the external Navigation API does NOT return appName. + result.getPlatform().setAppName(this.getAppNameInSettings()); } - if(!Strings.isBlank(result.getPlatform().getPlatformName())) { - // add | to the end of the platformName + if(!Strings.isBlank(result.getPlatform().getPlatformName()) + && !Strings.isBlank(result.getPlatform().getAppName())) { + /* + * add | to the end of the platformName when both platformName and appName exist. + * The UI header will display like "platformName | appName" + */ result.getPlatform().setPlatformName(result.getPlatform().getPlatformName() + " |"); } } - return response.getBody(); + return result; + } + + private String getAppNameInSettings() { + try { + Config config = settingsService.getConfiguration("customizations", "appName"); + return config == null ? null : config.getValue(); + } catch (Exception e) { + } + // return null instead of throwing exception when appName is not configured in settings. + return null; } private HttpHeaders buildHeaders(String email) { @@ -146,4 +160,4 @@ private HttpHeaders buildHeaders(String email) { headers.setContentType(MediaType.APPLICATION_JSON); return headers; } -} +} \ No newline at end of file