<commit_before>package org.oasis_eu.portal.services;

import org.oasis_eu.portal.config.environnements.EnvProperties;
import org.oasis_eu.portal.config.environnements.helpers.EnvConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@Service
public class EnvPropertiesService {

    @Autowired
    private EnvProperties envProperties;

    @Autowired
    private HttpServletRequest request;

    public EnvConfig getConfig() {
        String website = extractEnvKey();
        EnvConfig envConfig = envProperties.getConfs().get(website);
        if (envConfig != null) {
            return envConfig;
        } else {
            return envProperties.getConfs().get("ozwillo");
        }
    }

    public String extractEnvKey(){
        String URL = extractURL(request.getRequestURL().toString());
        Map<String, EnvConfig> envConfigMap = envProperties.getConfs();

        for(Map.Entry<String,EnvConfig> entry : envConfigMap.entrySet()){
            String key = entry.getKey();
            EnvConfig envConfig = entry.getValue();

            if(envConfig.getBaseUrl().equals(URL)){
                return key;
            }
        }

        return "ozwillo";
    }


    public EnvConfig getCurrentConfig(){
        try {
            return getConfig();
        }catch(Exception e){
            return null;
        }
    }

    private String extractURL(String URL){
        Pattern p = Pattern.compile("((https|http)?:\\/\\/)(.*?)(?=\\/)");
        Matcher m = p.matcher(URL);
        m.find();
        return m.group(0);
    }


}<commit_msg>Make detection-by-URL mechanism more resilient<commit_after>package org.oasis_eu.portal.services;

import org.oasis_eu.portal.config.environnements.EnvProperties;
import org.oasis_eu.portal.config.environnements.helpers.EnvConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@Service
public class EnvPropertiesService {

    @Autowired
    private EnvProperties envProperties;

    @Autowired
    private HttpServletRequest request;

    public EnvConfig getConfig() {
        String website = extractEnvKey();
        EnvConfig envConfig = envProperties.getConfs().get(website);
        if (envConfig != null) {
            return envConfig;
        } else {
            return envProperties.getConfs().get("ozwillo");
        }
    }

    public String extractEnvKey(){
        String URL = extractURL(request.getRequestURL().toString());
        Map<String, EnvConfig> envConfigMap = envProperties.getConfs();

        for(Map.Entry<String,EnvConfig> entry : envConfigMap.entrySet()){
            String key = entry.getKey();
            EnvConfig envConfig = entry.getValue();

            if(envConfig.getBaseUrl().contains(URL)){
                return key;
            }
        }

        return "ozwillo";
    }


    public EnvConfig getCurrentConfig(){
        try {
            return getConfig();
        }catch(Exception e){
            return null;
        }
    }

    private String extractURL(String URL){
        Pattern p = Pattern.compile("((https|http)?:\\/\\/)(.*?)(?=\\/)");
        Matcher m = p.matcher(URL);
        m.find();
        return m.group(0);
    }


}
{'fraction_non_alphanumeric': 0.11741462037821056, 'fraction_numerical': 0.0005644933672029354, 'mean_word_length': 2.597969543147208, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '1219598', 'n_tokens_mistral': 991, 'n_tokens_neox': 987, 'n_words': 192}