<commit_before>package me.shortify.sparkserver;

import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Calendar;

import me.shortify.dao.DAO;
import me.shortify.sparkserver.exception.BadCustomURLException;
import me.shortify.sparkserver.exception.BadURLException;
import me.shortify.sparkserver.exception.ShortURLNotFoundException;
import me.shortify.sparkserver.exception.URLExistsException;
import me.shortify.utils.filter.DomainChecker;
import me.shortify.utils.filter.WordChecker;
import me.shortify.utils.geoLocation.CountryIPInformation;
import me.shortify.utils.shortenerUrl.Algorithm;

import org.json.JSONException;
import org.json.JSONObject;

import com.maxmind.geoip2.exception.AddressNotFoundException;
import com.maxmind.geoip2.exception.GeoIp2Exception;

public class ShortenerServices {
	
	private static final int MAX_COUNT = 10;
	
	private DAO dao;
	
	public ShortenerServices(DAO dao) {
		this.dao = dao;
	}
	
	public String conversioneURL(String jsonURL) {		
		JSONObject jsonObject = new JSONObject(jsonURL);
		
		//si ottiene il long url dalla richiesta
		String url = jsonObject.getString("longurl");
		
		DomainChecker dc = new DomainChecker();	
		if (!dc.isBadDomain(url)) {
			String customText;
    		String shortUrl = "";
    		
    		try {
    			
    			//se e' stato inserito un custom text
    			customText = jsonObject.getString("customText");
    		} catch(JSONException e) {
    			customText = "";
    		}
    		
    		//reset json di risposta
    		jsonObject = new JSONObject();
    		
    	
    		if(customText.equals("")) {		//se non e' stato inserito un custom text		
    			int numTentativi = 0;
    			
    			do {
		    		//creazione dell'url
		    		shortUrl = Algorithm.buildShortUrl(url);<commit_msg>controll se l'url inizia con https:// o http://<commit_after>package me.shortify.sparkserver;

import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Calendar;

import me.shortify.dao.DAO;
import me.shortify.sparkserver.exception.BadCustomURLException;
import me.shortify.sparkserver.exception.BadURLException;
import me.shortify.sparkserver.exception.ShortURLNotFoundException;
import me.shortify.sparkserver.exception.URLExistsException;
import me.shortify.utils.filter.DomainChecker;
import me.shortify.utils.filter.WordChecker;
import me.shortify.utils.geoLocation.CountryIPInformation;
import me.shortify.utils.shortenerUrl.Algorithm;

import org.json.JSONException;
import org.json.JSONObject;

import com.maxmind.geoip2.exception.AddressNotFoundException;
import com.maxmind.geoip2.exception.GeoIp2Exception;

public class ShortenerServices {
	
	private static final int MAX_COUNT = 10;
	
	private DAO dao;
	
	public ShortenerServices(DAO dao) {
		this.dao = dao;
	}
	
	public String conversioneURL(String jsonURL) {		
		JSONObject jsonObject = new JSONObject(jsonURL);
		
		//si ottiene il long url dalla richiesta
		String url = jsonObject.getString("longurl");
		
		//controllo se l'url inizia con http:// o https://
		if (!url.startsWith("https://") && !url.startsWith("http://")) {
            url = "http://"+url;
        } 		
		
		DomainChecker dc = new DomainChecker();	
		if (!dc.isBadDomain(url)) {
			String customText;
    		String shortUrl = "";
    		
    		try {
    			
    			//se e' stato inserito un custom text
    			customText = jsonObject.getString("customText");
    		} catch(JSONException e) {
    			customText = "";
    		}
    		
    		//reset json di risposta
    		jsonObject = new JSONObject();
    		
    	
    		if(customText.equals("")) {		//se non e' stato inserito un custom text		
    			int numTentativi = 0;
    			
    			do {
		    		//creazione dell'url
		    		shortUrl = Algorithm.buildShortUrl(url);
{'fraction_non_alphanumeric': 0.1012523314681588, 'fraction_numerical': 0.0031974420463629096, 'mean_word_length': 3.3906432748538013, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 3, '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': '5934692', 'n_tokens_mistral': 1294, 'n_tokens_neox': 1213, 'n_words': 251}