Skip to content

Commit

Permalink
Feat: #179 publish globals
Browse files Browse the repository at this point in the history
  • Loading branch information
fjlopez committed Apr 22, 2024
1 parent 18bf8d6 commit f9290fd
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import lombok.Setter;

import java.util.List;
import java.util.Map;

@Getter
@Setter
Expand All @@ -17,4 +18,5 @@ public class ProfileDto {
private List<ServiceDto> services;
private List<TaskDto> tasks;
private List<TreeDto> trees;
private Map<String,String> global;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -136,6 +137,10 @@ default TreeDto map(Tree tree) {
.build();
}

default Map<String,String> map(List<ConfigurationParameter> global) {
return global.stream().collect(Collectors.toMap(ConfigurationParameter::getName, ConfigurationParameter::getValue));
}

@AfterMapping
default void completeProfile(Profile profile, @MappingTarget ProfileDto.ProfileDtoBuilder builder) {
Comparator<ApplicationBackground> order = Comparator.nullsLast(Comparator.comparing(ApplicationBackground::getOrder));
Expand Down Expand Up @@ -181,6 +186,7 @@ private static void computeApplicationExtent(Profile profile, ProfileDto.Profile
}



default String mapCartographyPermissionToString(CartographyPermission value) {
if (value == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -22,4 +24,5 @@ public class Profile {
private List<Service> services;
private List<Cartography> layers;
private List<Task> tasks;
private List<ConfigurationParameter> global;
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
}


Expand Down Expand Up @@ -176,9 +180,10 @@ private List<Application> getApplications(User user, Integer terrId) {
* @return the profile
*/
public Optional<Profile> buildProfile(String username, String appId, String terrId) {
Iterable<ConfigurationParameter> 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));
}

}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -22,7 +24,7 @@ private ProfileUtils() {
// Utility class
}

static Optional<Profile> buildProfile(User user, String appId, String terrId) {
static Optional<Profile> buildProfile(User user, String appId, String terrId, Iterable<ConfigurationParameter> global) {
return user.getPermissions()
.stream()
.filter(it -> Objects.equals(it.getTerritory().getId(), Integer.valueOf(terrId)))
Expand All @@ -46,6 +48,7 @@ static Optional<Profile> buildProfile(User user, String appId, String terrId) {
.layers(layers)
.services(services)
.tasks(tasks)
.global(ImmutableList.copyOf(global))
.build();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ databaseChangeLog:
name: CNF_VALUE
type: STRING
- sql:
sql: INSERT INTO STM_SEQUENCE(SEQ_NAME, SEQ_COUNT) VALUES ('CNF_ID', 4);
sql: INSERT INTO STM_SEQUENCE(SEQ_NAME, SEQ_COUNT) VALUES ('CNF_ID', 6);
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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")));
}
}

0 comments on commit f9290fd

Please sign in to comment.