package com.x.processplatform.assemble.surface.jaxrs.script; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.container.AsyncResponse; import javax.ws.rs.container.Suspended; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import com.google.gson.JsonElement; import com.x.base.core.project.annotation.JaxrsDescribe; import com.x.base.core.project.annotation.JaxrsMethodDescribe; import com.x.base.core.project.annotation.JaxrsParameterDescribe; import com.x.base.core.project.http.ActionResult; import com.x.base.core.project.http.EffectivePerson; import com.x.base.core.project.http.HttpMediaType; import com.x.base.core.project.jaxrs.ResponseFactory; import com.x.base.core.project.jaxrs.StandardJaxrsAction; import com.x.base.core.project.logger.Logger; import com.x.base.core.project.logger.LoggerFactory; import io.swagger.v3.oas.annotations.tags.Tag; @Tag(name = "ScriptAction", description = "脚本接口.") @Path("script") @JaxrsDescribe("脚本接口.") public class ScriptAction extends StandardJaxrsAction { private static Logger logger = LoggerFactory.getLogger(ScriptAction.class); @JaxrsMethodDescribe(value = "获取Script以及依赖脚本内容。", action = ActionLoad.class) @POST @Path("{flag}/application/{applicationFlag}") @Produces(HttpMediaType.APPLICATION_JSON_UTF_8) @Consumes(MediaType.APPLICATION_JSON) public void load(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request, @JaxrsParameterDescribe("脚本标识") @PathParam("flag") String flag, @JaxrsParameterDescribe("应用标识") @PathParam("applicationFlag") String applicationFlag, JsonElement jsonElement) { ActionResult result = new ActionResult<>(); EffectivePerson effectivePerson = this.effectivePerson(request); try { result = new ActionLoad().execute(effectivePerson, flag, applicationFlag, jsonElement); } catch (Exception e) { logger.error(e, effectivePerson, request, jsonElement); result.error(e); } asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result)); } @JaxrsMethodDescribe(value = "GET方法获取Script以及依赖脚本内容,POST无法缓存,GET方法不过滤已经导入的脚本.", action = ActionGetImported.class) @GET @Path("{flag}/application/{applicationFlag}/imported") @Produces(HttpMediaType.APPLICATION_JSON_UTF_8) @Consumes(MediaType.APPLICATION_JSON) public void getImported(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request, @JaxrsParameterDescribe("脚本标识") @PathParam("flag") String flag, @JaxrsParameterDescribe("应用标识") @PathParam("applicationFlag") String applicationFlag) { ActionResult result = new ActionResult<>(); EffectivePerson effectivePerson = this.effectivePerson(request); try { result = new ActionGetImported().execute(effectivePerson, flag, applicationFlag); } catch (Exception e) { logger.error(e, effectivePerson, request, null); result.error(e); } asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result)); } }