diff --git a/blueprints/javaAppBlueprint/src/main/java/com/rws/lt/lc/blueprint/service/AppMetadataService.java b/blueprints/javaAppBlueprint/src/main/java/com/rws/lt/lc/blueprint/service/AppMetadataService.java index 1d7fea7..c85dc95 100644 --- a/blueprints/javaAppBlueprint/src/main/java/com/rws/lt/lc/blueprint/service/AppMetadataService.java +++ b/blueprints/javaAppBlueprint/src/main/java/com/rws/lt/lc/blueprint/service/AppMetadataService.java @@ -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; @@ -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 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); } diff --git a/blueprints/javaAppBlueprint/src/main/resources/application.yml b/blueprints/javaAppBlueprint/src/main/resources/application.yml index 5018165..a62ff3a 100644 --- a/blueprints/javaAppBlueprint/src/main/resources/application.yml +++ b/blueprints/javaAppBlueprint/src/main/resources/application.yml @@ -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