<commit_before>package au.com.noojee.acceloapi.dao;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.google.gson.annotations.SerializedName;

import au.com.noojee.acceloapi.AcceloApi;
import au.com.noojee.acceloapi.AcceloApi.HTTPMethod;
import au.com.noojee.acceloapi.AcceloException;
import au.com.noojee.acceloapi.AcceloFieldList;
import au.com.noojee.acceloapi.AcceloResponse;
import au.com.noojee.acceloapi.AcceloResponseList;
import au.com.noojee.acceloapi.EndPoint;
import au.com.noojee.acceloapi.HTTPResponse;
import au.com.noojee.acceloapi.Meta;
import au.com.noojee.acceloapi.entities.AcceloEntity;
import au.com.noojee.acceloapi.entities.Progression;
import au.com.noojee.acceloapi.entities.Ticket;

public class ProgressionDao extends AcceloDao<Progression>
{
	static private Logger logger = LogManager.getLogger(ProgressionDao.class);

	@Override
	protected AcceloFieldList getFieldList()
	{
		AcceloFieldList fields = new AcceloFieldList();
		fields.add("_ALL");
		fields.add("status._ALL");
		return fields;
	}

	@Override
	protected EndPoint getEndPoint()
	{
		return EndPoint.progressions;
	}
	
	
	public <E extends AcceloEntity<E>> List<Progression> getByEndPoint(EndPoint endPoint, E entity)
	{
		List<Progression> progressions = null;
		
		URL url;
		try
		{
			url = EndPoint.progressions.getURL(endPoint,  (entity == null ? 0 : entity.getId())); //  URL(endPoint.getURL() + "/" + entity.getId() + "/progressions");
			HTTPResponse result = AcceloApi.getInstance()._request(HTTPMethod.GET, url, null);
			
			if (result.getResponseCode() == 200)
			{
				ProgressionResponseList response = result.parseBody(ProgressionResponseList.class);
				progressions = response.progressions;
			}

		}
		catch (Throwable e)
		{
			logger.error(e,e);
			throw new AcceloException(e);
		}
		
		return progressions;
	}
	
	
	
	public <E extends AcceloEntity<E>> void triggerProgression(int progressionId, E entity)
	{
		URL url;
		try
		{
			url = new URL(EndPoint.tickets.getURL() + "/" + entity.getId() + "/progressions/" + progressionId + "/auto");
			HTTPResponse result = AcceloApi.getInstance()._request(HTTPMethod.POST, url, null);
			
			if (result.getResponseCode() == 200)
			{
				@SuppressWarnings("unused")
				ProgressionRunResponse response = result.parseBody(ProgressionRunResponse.class);
			}
		}
		catch (Throwable e)
		{
			logger.error(e,e);
			throw new AcceloException(e);
		}
		
	}
	
	class ProgressionRunResponse
	{
		Meta meta;
		
		@SerializedName("response")
		Ticket ticket;
	}
	
	class ProgressionResponseList
	{
		Meta meta;
		@SerializedName("response")
		List<Progression> progressions;
	}


	@Override
	protected Class<Progression> getEntityClass()
	{<commit_msg>progressions now return the ticket with its state updated after the progression is applied.<commit_after>package au.com.noojee.acceloapi.dao;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.google.gson.annotations.SerializedName;

import au.com.noojee.acceloapi.AcceloApi;
import au.com.noojee.acceloapi.AcceloApi.HTTPMethod;
import au.com.noojee.acceloapi.AcceloException;
import au.com.noojee.acceloapi.AcceloFieldList;
import au.com.noojee.acceloapi.AcceloResponse;
import au.com.noojee.acceloapi.AcceloResponseList;
import au.com.noojee.acceloapi.EndPoint;
import au.com.noojee.acceloapi.HTTPResponse;
import au.com.noojee.acceloapi.Meta;
import au.com.noojee.acceloapi.entities.AcceloEntity;
import au.com.noojee.acceloapi.entities.Progression;
import au.com.noojee.acceloapi.entities.Ticket;

public class ProgressionDao extends AcceloDao<Progression>
{
	static private Logger logger = LogManager.getLogger(ProgressionDao.class);

	@Override
	protected AcceloFieldList getFieldList()
	{
		AcceloFieldList fields = new AcceloFieldList();
		fields.add("_ALL");
		fields.add("status._ALL");
		return fields;
	}

	@Override
	protected EndPoint getEndPoint()
	{
		return EndPoint.progressions;
	}

	public <E extends AcceloEntity<E>> List<Progression> getByEndPoint(EndPoint endPoint, E entity)
	{
		List<Progression> progressions = null;

		URL url;
		try
		{
			url = EndPoint.progressions.getURL(endPoint, (entity == null ? 0 : entity.getId())); // URL(endPoint.getURL()
																									// + "/" +
																									// entity.getId() +
																									// "/progressions");
			HTTPResponse result = AcceloApi.getInstance()._request(HTTPMethod.GET, url, null);

			if (result.getResponseCode() == 200)
			{
				ProgressionResponseList response = result.parseBody(ProgressionResponseList.class);
				progressions = response.progressions;
			}

		}
		catch (Throwable e)
		{
			logger.error(e, e);
			throw new AcceloException(e);
		}

		return progressions;
	}

	public <E extends AcceloEntity<E>> Ticket triggerProgression(int progressionId, E entity)
	{
		ProgressionRunResponse response = null;
		try
		{
			URL url = new URL(
					EndPoint.tickets.getURL() + "/" + entity.getId() + "/progressions/" + progressionId + "/auto");
			HTTPResponse result = AcceloApi.getInstance()._request(HTTPMethod.POST, url, null);

			if (result.getResponseCode() == 200)
			{
				response = result.parseBody(ProgressionRunResponse.class);
			}
			else
				throw new AcceloException("Failed Progression: code: " + result.getResponseCode() + " Message: " + result.getResponseMessage());
		}
		catch (Throwable e)
		{
			logger.error(e, e);
			throw new AcceloException(e);
		}
		
		return response.ticket;

	}

	class ProgressionRunResponse
	{
		Meta meta;

		@SerializedName("response")
		Ticket ticket;
	}

	class ProgressionResponseList
	{
		Meta meta;
		@SerializedName("response")
		List<Progression> progressions;
	}

	@Override
	protected Class<Progression> getEntityClass()
	{
{'fraction_non_alphanumeric': 0.11739057521381854, 'fraction_numerical': 0.003018614791212477, 'mean_word_length': 4.263901147396293, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, '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': '5998983', 'n_tokens_mistral': 2216, 'n_tokens_neox': 1975, 'n_words': 363}