// Path: src/main/java/org/mockenize/exception/ScriptExecutionException.java
// public class ScriptExecutionException extends WebApplicationException {
// 
// 	private static final long serialVersionUID = -4348584639704062868L;
// 
// 	public ScriptExecutionException(Throwable cause) {
// 		super(cause, Response.Status.NOT_FOUND);
// 	}
// }
// 
// Path: src/main/java/org/mockenize/exception/ScriptNotFoundException.java
// public class ScriptNotFoundException extends WebApplicationException {
// 
// 	private static final long serialVersionUID = 3414602294218839377L;
// 
// 	public ScriptNotFoundException(String scriptName) {
// 		super("JS not found: " + scriptName, Response.Status.NOT_FOUND);
// 	}
// }
// 
// Path: src/main/java/org/mockenize/model/ScriptBean.java
// @Data
// public class ScriptBean implements Serializable, Cacheable {
// 
// 	private static final long serialVersionUID = 1L;
// 
// 	private String name;
// 
// 	private String value;
// 
// 	public ScriptBean(String name, String value) {
// 		this.name = name;
// 		this.value = value;
// 	}
// 
// 	@Override
// 	public String getKey() {
// 		return this.name;
// 	}
// }
// 
// Path: src/main/java/org/mockenize/repository/ScriptRespository.java
// @Repository
// public class ScriptRespository extends AbstractRepository<ScriptBean> {
// 
// 	private static final String CACHE_KEY = "scripts";
// 
// 	@Autowired
// 	public ScriptRespository(HazelcastInstance hazelcastInstance) {
// 		super(hazelcastInstance, CACHE_KEY);
// 	}
// 
// }


import java.io.IOException;
import java.util.Collection;
import javax.script.Invocable;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import org.mockenize.exception.ScriptExecutionException;
import org.mockenize.exception.ScriptNotFoundException;
import org.mockenize.model.ScriptBean;
import org.mockenize.repository.ScriptRespository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
		}

		return scriptBean;
	}

	public ScriptBean delete(ScriptBean scriptBean) {
		return scriptRespository.delete(scriptBean.getName());
	}

	public Collection<ScriptBean> deleteAll() {
		return scriptRespository.deleteAll();
	}

	public void save(ScriptBean scriptBean) {
		scriptRespository.save(scriptBean);
	}

	public Collection<ScriptBean> getAll() {
		return scriptRespository.findAll();
	}

	public JsonNode execute(ScriptBean scriptBean, String uri, JsonNode body) {
		try {
			ScriptEngine scriptEngine = new ScriptEngineManager().getEngineByName(ENGINE_NAME);
			scriptEngine.eval(PARSE_FUNCTION + scriptBean.getValue());
			Invocable invocable = (Invocable) scriptEngine;
			String stringBody = body != null ? body.toString() : EMPTY;
			String ret = String.valueOf(invocable.invokeFunction(DEFAUL_FUNCTION_NAME, uri, stringBody));
			return parse(ret);
		} catch (NoSuchMethodException | ScriptException | IOException e) {
// Path: src/main/java/org/mockenize/exception/ScriptExecutionException.java
// public class ScriptExecutionException extends WebApplicationException {
// 
// 	private static final long serialVersionUID = -4348584639704062868L;
// 
// 	public ScriptExecutionException(Throwable cause) {
// 		super(cause, Response.Status.NOT_FOUND);
// 	}
// }
// 
// Path: src/main/java/org/mockenize/exception/ScriptNotFoundException.java
// public class ScriptNotFoundException extends WebApplicationException {
// 
// 	private static final long serialVersionUID = 3414602294218839377L;
// 
// 	public ScriptNotFoundException(String scriptName) {
// 		super("JS not found: " + scriptName, Response.Status.NOT_FOUND);
// 	}
// }
// 
// Path: src/main/java/org/mockenize/model/ScriptBean.java
// @Data
// public class ScriptBean implements Serializable, Cacheable {
// 
// 	private static final long serialVersionUID = 1L;
// 
// 	private String name;
// 
// 	private String value;
// 
// 	public ScriptBean(String name, String value) {
// 		this.name = name;
// 		this.value = value;
// 	}
// 
// 	@Override
// 	public String getKey() {
// 		return this.name;
// 	}
// }
// 
// Path: src/main/java/org/mockenize/repository/ScriptRespository.java
// @Repository
// public class ScriptRespository extends AbstractRepository<ScriptBean> {
// 
// 	private static final String CACHE_KEY = "scripts";
// 
// 	@Autowired
// 	public ScriptRespository(HazelcastInstance hazelcastInstance) {
// 		super(hazelcastInstance, CACHE_KEY);
// 	}
// 
// }


// Path: src/main/java/org/mockenize/service/ScriptService.java
import java.io.IOException;
import java.util.Collection;
import javax.script.Invocable;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import org.mockenize.exception.ScriptExecutionException;
import org.mockenize.exception.ScriptNotFoundException;
import org.mockenize.model.ScriptBean;
import org.mockenize.repository.ScriptRespository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

		}

		return scriptBean;
	}

	public ScriptBean delete(ScriptBean scriptBean) {
		return scriptRespository.delete(scriptBean.getName());
	}

	public Collection<ScriptBean> deleteAll() {
		return scriptRespository.deleteAll();
	}

	public void save(ScriptBean scriptBean) {
		scriptRespository.save(scriptBean);
	}

	public Collection<ScriptBean> getAll() {
		return scriptRespository.findAll();
	}

	public JsonNode execute(ScriptBean scriptBean, String uri, JsonNode body) {
		try {
			ScriptEngine scriptEngine = new ScriptEngineManager().getEngineByName(ENGINE_NAME);
			scriptEngine.eval(PARSE_FUNCTION + scriptBean.getValue());
			Invocable invocable = (Invocable) scriptEngine;
			String stringBody = body != null ? body.toString() : EMPTY;
			String ret = String.valueOf(invocable.invokeFunction(DEFAUL_FUNCTION_NAME, uri, stringBody));
			return parse(ret);
		} catch (NoSuchMethodException | ScriptException | IOException e) {
			throw new ScriptExecutionException(e);