<commit_before>package net.anotheria.moskito.webui.threshold.resource;

import net.anotheria.anoplass.api.APIException;
import net.anotheria.anoplass.api.APIFinder;
import net.anotheria.moskito.webui.shared.resource.ReplyObject;
import net.anotheria.moskito.webui.threshold.api.ThresholdAPI;
import net.anotheria.moskito.webui.threshold.api.ThresholdPO;

import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.WebApplicationException;

/**
 * This handles thresholds in the moskito-inspect rest interface.
 *
 * @author lrosenberg
 * @since 11.02.13 18:24
 */
@Path("/thresholds")
public class ThresholdResource {

	/**
	 * Threshold API.
	 */
	private ThresholdAPI thresholdAPI = APIFinder.findAPI(ThresholdAPI.class);

	@GET
	@Path("list")
	public ReplyObject getThresholds(){
		try{
			ReplyObject ret = ReplyObject.success();
			ret.addResult("statuses", thresholdAPI.getThresholdStatuses());
			ret.addResult("definitions", thresholdAPI.getThresholdDefinitions());
			return ret;
		}catch(APIException e){
			throw new WebApplicationException(e);
		}
	}

	@GET
	@Path("definitions")
	public ReplyObject getThresholdDefinitions(){
		try{
			ReplyObject ret = ReplyObject.success();
			ret.addResult("definitions", thresholdAPI.getThresholdDefinitions());
			return ret;
		}catch(APIException e){
			throw new WebApplicationException(e);
		}
	}

	@GET
	@Path("statuses")
	public ReplyObject getThresholdStatuses(){
		try{
			ReplyObject ret = ReplyObject.success();
			ret.addResult("statuses", thresholdAPI.getThresholdStatuses());
			return ret;
		}catch(APIException e){
			throw new WebApplicationException(e);
		}
	}

	@POST
	@Path("create")
	public ReplyObject createThreshold(ThresholdPO po){
		try{
			thresholdAPI.createThreshold(po);
			return ReplyObject.success();
		}catch(APIException e){
			throw new WebApplicationException(e);
		}
	}

	@GET
	@Path("remove/{id}")
	public ReplyObject deleteThreshold(@PathParam("id") String id){
		try{
			thresholdAPI.removeThreshold(id);
			return ReplyObject.success();
		}catch(APIException e){
			throw new WebApplicationException(e);
		}
	}

	@GET
	@Path("alerts")
	public ReplyObject getAlerts(){
		try{
			return ReplyObject.success("status", thresholdAPI.getAlerts());
		}catch(APIException e){
			throw new WebApplicationException(e);
		}
	}

	@GET @Path("worstStatus")
	public ReplyObject getWorstStatus(){
		try{
			return ReplyObject.success("status", thresholdAPI.getWorstStatus());
		}catch(APIException e){
			throw new WebApplicationException(e);
		}
	}

	@POST @Path("worstStatusForSelectedThresholds")
	public ReplyObject getWorstStatus(StatusForm statusForm){
		try{
			return ReplyObject.success("status", thresholdAPI.getWorstStatus(statusForm.getThresholdNames()));
		}catch(APIException e){
			throw new WebApplicationException(e);
		}
	}
}<commit_msg>obtain api through abstract resource<commit_after>package net.anotheria.moskito.webui.threshold.resource;

import net.anotheria.anoplass.api.APIException;
import net.anotheria.moskito.webui.shared.resource.AbstractResource;
import net.anotheria.moskito.webui.shared.resource.ReplyObject;
import net.anotheria.moskito.webui.threshold.api.ThresholdPO;

import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.WebApplicationException;

/**
 * This handles thresholds in the moskito-inspect rest interface.
 *
 * @author lrosenberg
 * @since 11.02.13 18:24
 */
@Path("/thresholds")
public class ThresholdResource extends AbstractResource{

	@GET
	@Path("list")
	public ReplyObject getThresholds(){
		try{
			ReplyObject ret = ReplyObject.success();
			ret.addResult("statuses", getThresholdAPI().getThresholdStatuses());
			ret.addResult("definitions", getThresholdAPI().getThresholdDefinitions());
			return ret;
		}catch(APIException e){
			throw new WebApplicationException(e);
		}
	}

	@GET
	@Path("definitions")
	public ReplyObject getThresholdDefinitions(){
		try{
			ReplyObject ret = ReplyObject.success();
			ret.addResult("definitions", getThresholdAPI().getThresholdDefinitions());
			return ret;
		}catch(APIException e){
			throw new WebApplicationException(e);
		}
	}

	@GET
	@Path("statuses")
	public ReplyObject getThresholdStatuses(){
		try{
			ReplyObject ret = ReplyObject.success();
			ret.addResult("statuses", getThresholdAPI().getThresholdStatuses());
			return ret;
		}catch(APIException e){
			throw new WebApplicationException(e);
		}
	}

	@POST
	@Path("create")
	public ReplyObject createThreshold(ThresholdPO po){
		try{
			getThresholdAPI().createThreshold(po);
			return ReplyObject.success();
		}catch(APIException e){
			throw new WebApplicationException(e);
		}
	}

	@GET
	@Path("remove/{id}")
	public ReplyObject deleteThreshold(@PathParam("id") String id){
		try{
			getThresholdAPI().removeThreshold(id);
			return ReplyObject.success();
		}catch(APIException e){
			throw new WebApplicationException(e);
		}
	}

	@GET
	@Path("alerts")
	public ReplyObject getAlerts(){
		try{
			return ReplyObject.success("status", getThresholdAPI().getAlerts());
		}catch(APIException e){
			throw new WebApplicationException(e);
		}
	}

	@GET @Path("worstStatus")
	public ReplyObject getWorstStatus(){
		try{
			return ReplyObject.success("status", getThresholdAPI().getWorstStatus());
		}catch(APIException e){
			throw new WebApplicationException(e);
		}
	}

	@POST @Path("worstStatusForSelectedThresholds")
	public ReplyObject getWorstStatus(StatusForm statusForm){
		try{
			return ReplyObject.success("status", getThresholdAPI().getWorstStatus(statusForm.getThresholdNames()));
		}catch(APIException e){
			throw new WebApplicationException(e);
		}
	}
}
{'fraction_non_alphanumeric': 0.12685136783411743, 'fraction_numerical': 0.003484927687750479, 'mean_word_length': 5.363636363636363, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2775333', 'n_tokens_mistral': 2016, 'n_tokens_neox': 1786, 'n_words': 348}