Skip to content

Commit

Permalink
add regional base URLs for Java blueprint
Browse files Browse the repository at this point in the history
  • Loading branch information
mdipsan committed Jul 24, 2024
1 parent ffd3728 commit 3bee01b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.rws.lt.lc.blueprint.service;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

import java.io.IOException;
Expand All @@ -18,19 +21,43 @@ public class AppMetadataService implements InitializingBean {
@Value("${baseUrl}")
private String baseUrl;

@Value("${multiRegion.enabled:false}")
private boolean isMultiRegionEnabled;

@Getter
private final ObjectNode descriptor;

private List<String> secretConfigs;

private final ObjectMapper objectMapper;

private final Environment env;

@Override
public void afterPropertiesSet() {
descriptor.put("baseUrl", baseUrl);

if (isMultiRegionEnabled) {
ObjectNode regionalBaseUrls = objectMapper.createObjectNode();
String euBaseUrl = env.getProperty("multiRegion.regionalBaseUrls.eu");
String caBaseUrl = env.getProperty("multiRegion.regionalBaseUrls.ca");

if(StringUtils.isNotEmpty(euBaseUrl)) {
regionalBaseUrls.put("eu", euBaseUrl);
}
if(StringUtils.isNotEmpty(caBaseUrl)) {
regionalBaseUrls.put("ca", caBaseUrl);
}

descriptor.put("regionalBaseUrls", regionalBaseUrls);
}
}

@Autowired
public AppMetadataService() throws IOException {
ObjectMapper objectMapper = new ObjectMapper();
public AppMetadataService(Environment environment) throws IOException {
env = environment;
objectMapper = new ObjectMapper();
objectMapper.enable(JsonParser.Feature.ALLOW_COMMENTS);
descriptor = objectMapper.readValue(getClass().getResourceAsStream("/descriptor.json"), ObjectNode.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ application:

# TODO: replace with a real URL
baseUrl: "replace-me"
multiRegion:
enabled: false
regionalBaseUrls:
eu: "replace-me-eu"
ca: "replace-me-ca"

server:
port: 5000
Expand Down

0 comments on commit 3bee01b

Please sign in to comment.