class RdsConfigValidator {

    public void validateRdsConfigs(ClusterV4Request request, User user, Workspace workspace) {
        if (request.getDatabases() != null) {
            Set<String> multipleTypes = request.getDatabases().stream()
                    .map(rdsConfigName -> rdsConfigService.getByNameForWorkspace(rdsConfigName, workspace))
                    .collect(groupingBy(RDSConfig::getType, counting()))
                    .entrySet().stream()
                    .filter(e -> e.getValue() > 1L)
                    .map(Map.Entry::getKey)
                    .collect(toCollection(TreeSet::new));
            if (!multipleTypes.isEmpty()) {
                throw new BadRequestException("Multiple databases are defined for the following types: "
                        + String.join(",", multipleTypes));
            }
        }
    }

}