<commit_before>package com.github.missioncriticalcloud.cosmic.usage.core.repositories.jdbc;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.function.Function;
import java.util.stream.Collectors;

import com.github.missioncriticalcloud.cosmic.usage.core.exceptions.NoMetricsFoundException;
import com.github.missioncriticalcloud.cosmic.usage.core.model.Domain;
import com.github.missioncriticalcloud.cosmic.usage.core.repositories.DomainsRepository;
import com.github.missioncriticalcloud.cosmic.usage.core.repositories.jdbc.mappers.DomainMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Repository;

@Repository
public class DomainsJdbcRepository implements DomainsRepository {

    private final NamedParameterJdbcTemplate jdbcTemplate;
    private final Properties queries;
    private final DomainMapper domainMapper;

    @Autowired
    public DomainsJdbcRepository(
            final NamedParameterJdbcTemplate jdbcTemplate,
            @Qualifier("queries") final Properties queries,
            final DomainMapper domainMapper
    ) {
        this.jdbcTemplate = jdbcTemplate;
        this.queries = queries;
        this.domainMapper = domainMapper;
    }

    @Override
    public List<Domain> search(final String path) {
        return jdbcTemplate.query(
                queries.getProperty("domains-repository.search-domains"),
                new MapSqlParameterSource("path", path + "%"),
                domainMapper
        );
    }

    @Override
    public Domain getByPath(final String path) {
        return jdbcTemplate.queryForObject(
                queries.getProperty("domains-repository.get-domain"),
                new MapSqlParameterSource("path", path),
                domainMapper
        );
    }

    @Override
    public Domain get(final String uuid) {
        return jdbcTemplate.queryForObject(
                queries.getProperty("domains-repository.get-domain-by-uuid"),
                new MapSqlParameterSource("uuid", uuid),
                domainMapper
        );
    }

    @Override
    public Map<String, Domain> map(final String path, final boolean detailed) {
        final List<Domain> domains = detailed
                ? Collections.singletonList(getByPath(path))
                : search(path);

        if (domains.isEmpty()) {
            throw new NoMetricsFoundException();
        }

        final Map<String, Domain> domainsMap = new HashMap<>();
        domainsMap.putAll(domains.stream().collect(Collectors.toMap(Domain::getUuid, Function.identity())));

        return domainsMap;
    }
}<commit_msg>DomainsJdbcRepository handles EmptyResultDataAccessException<commit_after>package com.github.missioncriticalcloud.cosmic.usage.core.repositories.jdbc;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.function.Function;
import java.util.stream.Collectors;

import com.github.missioncriticalcloud.cosmic.usage.core.exceptions.NoMetricsFoundException;
import com.github.missioncriticalcloud.cosmic.usage.core.model.Domain;
import com.github.missioncriticalcloud.cosmic.usage.core.repositories.DomainsRepository;
import com.github.missioncriticalcloud.cosmic.usage.core.repositories.jdbc.mappers.DomainMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Repository;

@Repository
public class DomainsJdbcRepository implements DomainsRepository {

    private final NamedParameterJdbcTemplate jdbcTemplate;
    private final Properties queries;
    private final DomainMapper domainMapper;

    @Autowired
    public DomainsJdbcRepository(
            final NamedParameterJdbcTemplate jdbcTemplate,
            @Qualifier("queries") final Properties queries,
            final DomainMapper domainMapper
    ) {
        this.jdbcTemplate = jdbcTemplate;
        this.queries = queries;
        this.domainMapper = domainMapper;
    }

    @Override
    public List<Domain> search(final String path) {
        return jdbcTemplate.query(
                queries.getProperty("domains-repository.search-domains"),
                new MapSqlParameterSource("path", path + "%"),
                domainMapper
        );
    }

    @Override
    public Domain getByPath(final String path) {
        return jdbcTemplate.queryForObject(
                queries.getProperty("domains-repository.get-domain"),
                new MapSqlParameterSource("path", path),
                domainMapper
        );
    }

    @Override
    public Domain get(final String uuid) {
        return jdbcTemplate.queryForObject(
                queries.getProperty("domains-repository.get-domain-by-uuid"),
                new MapSqlParameterSource("uuid", uuid),
                domainMapper
        );
    }

    @Override
    public Map<String, Domain> map(final String path, final boolean detailed) {
        final List<Domain> domains;
        try {
             domains = detailed
                    ? Collections.singletonList(getByPath(path))
                    : search(path);
        } catch (EmptyResultDataAccessException e) {
            throw new NoMetricsFoundException();
        }
        if (domains.isEmpty()) {
            throw new NoMetricsFoundException();
        }

        final Map<String, Domain> domainsMap = new HashMap<>();
        domainsMap.putAll(domains.stream().collect(Collectors.toMap(Domain::getUuid, Function.identity())));

        return domainsMap;
    }
}
{'fraction_non_alphanumeric': 0.08846091072302921, 'fraction_numerical': 0.0, 'mean_word_length': 3.1405405405405404, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '426102', 'n_tokens_mistral': 1602, 'n_tokens_neox': 1537, 'n_words': 294}