package com.x.common.core.application.jaxrs.cache;

import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import com.x.base.core.http.ActionResult;
import com.x.base.core.http.HttpMediaType;
import com.x.base.core.http.ResponseFactory;
import com.x.base.core.http.WrapOutString;
import com.x.base.core.http.annotation.HttpMethodDescribe;
import com.x.common.core.application.cache.ApplicationCache;
import com.x.common.core.application.cache.ClearCacheRequest;
import com.x.common.core.application.jaxrs.AbstractJaxrsAction;

@Path("cache")
public class CacheAction extends AbstractJaxrsAction {

	@PUT
	@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
	@Consumes(MediaType.APPLICATION_JSON)
	@HttpMethodDescribe(value = "处理Cache刷新信息.", request = ClearCacheRequest.class, response = WrapOutString.class)
	public Response remove(@Context HttpServletRequest request, ClearCacheRequest clearCacheRequest) {
		ActionResult<WrapOutString> result = new ActionResult<>();
		WrapOutString wrap = new WrapOutString();
		try {
			ApplicationCache.receive(clearCacheRequest);
			wrap.setValue(clearCacheRequest.getClassName());
			result.setData(wrap);
		} catch (Throwable th) {
			th.printStackTrace();
			result.error(th);
		}
		return ResponseFactory.getDefaultActionResultResponse(result);
	}
}