All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.anotheria.moskito.webui.threshold.action.GetThresholdDefinitionAction Maven / Gradle / Ivy

There is a newer version: 4.0.3
Show newest version
package net.anotheria.moskito.webui.threshold.action;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import net.anotheria.maf.action.Action;
import net.anotheria.maf.action.ActionCommand;
import net.anotheria.maf.action.ActionMapping;
import net.anotheria.maf.bean.FormBean;
import net.anotheria.moskito.webui.threshold.api.ThresholdDefinitionAO;
import net.anotheria.moskito.webui.util.APILookupUtility;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * This action returns the threshold definition for a threshold as json object.
 *
 * @author lrosenberg
 * @since 21.05.14 17:35
 */
public class GetThresholdDefinitionAction implements Action {

	@Override
	public void preProcess(ActionMapping mapping, HttpServletRequest req, HttpServletResponse res) throws Exception {

	}

	@Override
	public void postProcess(ActionMapping mapping, HttpServletRequest req, HttpServletResponse res) throws Exception {

	}

	@Override
	public ActionCommand execute(ActionMapping mapping, FormBean formBean, HttpServletRequest req, HttpServletResponse res) throws Exception {
		String id = req.getParameter("pId");
		ThresholdDefinitionAO definition = APILookupUtility.getThresholdAPI().getThresholdDefinition(id);

		Gson gson = new GsonBuilder().setPrettyPrinting().create();
		String jsonOutput = gson.toJson(definition);
		res.getOutputStream().write(jsonOutput.getBytes());
		res.getOutputStream().flush();

		return null;

	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy