From f9290fdf0ed55bca9af7d243134b1a5c036cb39f Mon Sep 17 00:00:00 2001 From: Francisco J Lopez-Pellicer Date: Mon, 22 Apr 2024 19:26:46 +0200 Subject: [PATCH] Feat: #179 publish globals --- .../java/org/sitmun/authorization/dto/ProfileDto.java | 2 ++ .../java/org/sitmun/authorization/dto/ProfileMapper.java | 6 ++++++ .../java/org/sitmun/authorization/service/Profile.java | 3 +++ .../org/sitmun/authorization/service/ProfileService.java | 9 +++++++-- .../org/sitmun/authorization/service/ProfileUtils.java | 5 ++++- .../resources/config/liquibase/changelog/06_params.yaml | 2 +- .../config/liquibase/changelog/06_params/STM_CONF.csv | 1 + .../ClientConfigurationProfileControllerTest.java | 7 +++++++ 8 files changed, 31 insertions(+), 4 deletions(-) diff --git a/common/src/main/java/org/sitmun/authorization/dto/ProfileDto.java b/common/src/main/java/org/sitmun/authorization/dto/ProfileDto.java index cc93649c..0c9773ac 100644 --- a/common/src/main/java/org/sitmun/authorization/dto/ProfileDto.java +++ b/common/src/main/java/org/sitmun/authorization/dto/ProfileDto.java @@ -5,6 +5,7 @@ import lombok.Setter; import java.util.List; +import java.util.Map; @Getter @Setter @@ -17,4 +18,5 @@ public class ProfileDto { private List services; private List tasks; private List trees; + private Map global; } diff --git a/common/src/main/java/org/sitmun/authorization/dto/ProfileMapper.java b/common/src/main/java/org/sitmun/authorization/dto/ProfileMapper.java index 9ed43337..70b16146 100644 --- a/common/src/main/java/org/sitmun/authorization/dto/ProfileMapper.java +++ b/common/src/main/java/org/sitmun/authorization/dto/ProfileMapper.java @@ -10,6 +10,7 @@ import org.sitmun.domain.background.Background; import org.sitmun.domain.cartography.Cartography; import org.sitmun.domain.cartography.permission.CartographyPermission; +import org.sitmun.domain.configuration.ConfigurationParameter; import org.sitmun.domain.service.Service; import org.sitmun.domain.task.Task; import org.sitmun.domain.tree.Tree; @@ -136,6 +137,10 @@ default TreeDto map(Tree tree) { .build(); } + default Map map(List global) { + return global.stream().collect(Collectors.toMap(ConfigurationParameter::getName, ConfigurationParameter::getValue)); + } + @AfterMapping default void completeProfile(Profile profile, @MappingTarget ProfileDto.ProfileDtoBuilder builder) { Comparator order = Comparator.nullsLast(Comparator.comparing(ApplicationBackground::getOrder)); @@ -181,6 +186,7 @@ private static void computeApplicationExtent(Profile profile, ProfileDto.Profile } + default String mapCartographyPermissionToString(CartographyPermission value) { if (value == null) { return null; diff --git a/common/src/main/java/org/sitmun/authorization/service/Profile.java b/common/src/main/java/org/sitmun/authorization/service/Profile.java index aa55fa58..3d034901 100644 --- a/common/src/main/java/org/sitmun/authorization/service/Profile.java +++ b/common/src/main/java/org/sitmun/authorization/service/Profile.java @@ -6,11 +6,13 @@ import org.sitmun.domain.application.Application; import org.sitmun.domain.cartography.Cartography; import org.sitmun.domain.cartography.permission.CartographyPermission; +import org.sitmun.domain.configuration.ConfigurationParameter; import org.sitmun.domain.service.Service; import org.sitmun.domain.task.Task; import org.sitmun.domain.territory.Territory; import java.util.List; +import java.util.Map; @Getter @Setter @@ -22,4 +24,5 @@ public class Profile { private List services; private List layers; private List tasks; + private List global; } diff --git a/common/src/main/java/org/sitmun/authorization/service/ProfileService.java b/common/src/main/java/org/sitmun/authorization/service/ProfileService.java index 6438006b..2169c70c 100644 --- a/common/src/main/java/org/sitmun/authorization/service/ProfileService.java +++ b/common/src/main/java/org/sitmun/authorization/service/ProfileService.java @@ -1,6 +1,8 @@ package org.sitmun.authorization.service; import org.sitmun.domain.application.Application; +import org.sitmun.domain.configuration.ConfigurationParameter; +import org.sitmun.domain.configuration.ConfigurationParameterRepository; import org.sitmun.domain.role.Role; import org.sitmun.domain.territory.Territory; import org.sitmun.domain.user.User; @@ -23,10 +25,12 @@ public class ProfileService { private final UserRepository userRepository; private final UserConfigurationRepository userConfigurationRepository; + private final ConfigurationParameterRepository configurationParameterRepository; - public ProfileService(UserRepository userRepository, UserConfigurationRepository userConfigurationRepository) { + public ProfileService(UserRepository userRepository, UserConfigurationRepository userConfigurationRepository, ConfigurationParameterRepository configurationParameterRepository) { this.userRepository = userRepository; this.userConfigurationRepository = userConfigurationRepository; + this.configurationParameterRepository = configurationParameterRepository; } @@ -176,9 +180,10 @@ private List getApplications(User user, Integer terrId) { * @return the profile */ public Optional buildProfile(String username, String appId, String terrId) { + Iterable global = configurationParameterRepository.findAll(); return userRepository.findByUsername(username) .filter(user -> !user.getBlocked()) - .flatMap(user -> ProfileUtils.buildProfile(user, appId, terrId)); + .flatMap(user -> ProfileUtils.buildProfile(user, appId, terrId, global)); } } diff --git a/common/src/main/java/org/sitmun/authorization/service/ProfileUtils.java b/common/src/main/java/org/sitmun/authorization/service/ProfileUtils.java index 5702e9ce..c6725469 100644 --- a/common/src/main/java/org/sitmun/authorization/service/ProfileUtils.java +++ b/common/src/main/java/org/sitmun/authorization/service/ProfileUtils.java @@ -1,8 +1,10 @@ package org.sitmun.authorization.service; +import com.google.common.collect.ImmutableList; import org.sitmun.domain.application.Application; import org.sitmun.domain.cartography.Cartography; import org.sitmun.domain.cartography.permission.CartographyPermission; +import org.sitmun.domain.configuration.ConfigurationParameter; import org.sitmun.domain.service.Service; import org.sitmun.domain.task.Task; import org.sitmun.domain.territory.Territory; @@ -22,7 +24,7 @@ private ProfileUtils() { // Utility class } - static Optional buildProfile(User user, String appId, String terrId) { + static Optional buildProfile(User user, String appId, String terrId, Iterable global) { return user.getPermissions() .stream() .filter(it -> Objects.equals(it.getTerritory().getId(), Integer.valueOf(terrId))) @@ -46,6 +48,7 @@ static Optional buildProfile(User user, String appId, String terrId) { .layers(layers) .services(services) .tasks(tasks) + .global(ImmutableList.copyOf(global)) .build(); }); } diff --git a/deploy/heroku-dev-lite/src/main/resources/config/liquibase/changelog/06_params.yaml b/deploy/heroku-dev-lite/src/main/resources/config/liquibase/changelog/06_params.yaml index 18758cd6..82e4706d 100644 --- a/deploy/heroku-dev-lite/src/main/resources/config/liquibase/changelog/06_params.yaml +++ b/deploy/heroku-dev-lite/src/main/resources/config/liquibase/changelog/06_params.yaml @@ -20,4 +20,4 @@ databaseChangeLog: name: CNF_VALUE type: STRING - sql: - sql: INSERT INTO STM_SEQUENCE(SEQ_NAME, SEQ_COUNT) VALUES ('CNF_ID', 4); \ No newline at end of file + sql: INSERT INTO STM_SEQUENCE(SEQ_NAME, SEQ_COUNT) VALUES ('CNF_ID', 6); \ No newline at end of file diff --git a/deploy/heroku-dev-lite/src/main/resources/config/liquibase/changelog/06_params/STM_CONF.csv b/deploy/heroku-dev-lite/src/main/resources/config/liquibase/changelog/06_params/STM_CONF.csv index 81ba3419..17a80265 100644 --- a/deploy/heroku-dev-lite/src/main/resources/config/liquibase/changelog/06_params/STM_CONF.csv +++ b/deploy/heroku-dev-lite/src/main/resources/config/liquibase/changelog/06_params/STM_CONF.csv @@ -4,3 +4,4 @@ CNF_ID,CNF_NAME,CNF_VALUE 3,srs.default.x,x 4,srs.default.y,y 5,srs.default.proj4,"+proj=utm +zone=31 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs" +6,proxy,https://middleware.com diff --git a/deploy/heroku-dev-lite/src/test/java/org/sitmun/authorization/controller/ClientConfigurationProfileControllerTest.java b/deploy/heroku-dev-lite/src/test/java/org/sitmun/authorization/controller/ClientConfigurationProfileControllerTest.java index 1d80a2d1..14b748e2 100644 --- a/deploy/heroku-dev-lite/src/test/java/org/sitmun/authorization/controller/ClientConfigurationProfileControllerTest.java +++ b/deploy/heroku-dev-lite/src/test/java/org/sitmun/authorization/controller/ClientConfigurationProfileControllerTest.java @@ -141,4 +141,11 @@ void tree() throws Exception { .andExpect(jsonPath("$.trees[?(@.id=='tree/1')].nodes['node/9'].resource", hasItem("layer/9"))); } + @Test + @DisplayName("Get proxy details") + void proxy() throws Exception { + mvc.perform(get(URIConstants.CONFIG_CLIENT_PROFILE_URI, 1, 1)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.global.proxy", is("https://middleware.com"))); + } }