From ecd61a17b7085a5b87cdbbb03553324a9865dd76 Mon Sep 17 00:00:00 2001 From: zhourui Date: Wed, 14 Oct 2020 15:47:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=AE=A1=E7=90=86=E5=91=98?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E9=99=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- o2server/configSample/node_127.0.0.1.json | 2 +- .../attachment/ActionManageDownload.java | 67 +++++++++++++++++++ .../ActionManageDownloadStream.java | 60 +++++++++++++++++ .../jaxrs/attachment/AttachmentAction.java | 60 +++++++++++++---- .../jaxrs/snap/ActionTypeAbandoned.java | 59 ++++++++++++++++ .../center/jaxrs/invoke/BaseAction.java | 52 +++++++------- 6 files changed, 261 insertions(+), 39 deletions(-) create mode 100644 o2server/x_processplatform_assemble_surface/src/main/java/com/x/processplatform/assemble/surface/jaxrs/attachment/ActionManageDownload.java create mode 100644 o2server/x_processplatform_assemble_surface/src/main/java/com/x/processplatform/assemble/surface/jaxrs/attachment/ActionManageDownloadStream.java create mode 100644 o2server/x_processplatform_assemble_surface/src/main/java/com/x/processplatform/assemble/surface/jaxrs/snap/ActionTypeAbandoned.java diff --git a/o2server/configSample/node_127.0.0.1.json b/o2server/configSample/node_127.0.0.1.json index dcf66929b2..a50eeae2e0 100644 --- a/o2server/configSample/node_127.0.0.1.json +++ b/o2server/configSample/node_127.0.0.1.json @@ -108,7 +108,7 @@ "###excludes": "在此节点上不存储的类,和includes一起设置实际存储的类,可以使用通配符*###", "###jmxEnable": "是否启动jmx,如果启用,可以通过本地的jmx客户端进行访问,不支持远程jmx客户端.###", "###cacheSize": "H2数据库缓存大小,设置H2用于作为缓存的内存大小,以M作为单位,这里默认为512M.###", - "###logLevel": "默认日志级别###", + "###logLevel": "默认日志级别,FATAL, ERROR, WARN, INFO, TRACE. 完成的配置为DefaultLevel\u003dWARN, Tool\u003dTRACE, Enhance\u003dTRACE, METADATA\u003dTRACE, Runtime\u003dTRACE, Query\u003dTRACE, DataCache\u003dTRACE, JDBC\u003dTRACE, SQL\u003dTRACE###", "###maxTotal": "最大使用连接数###", "###maxIdle": "最大空闲连接数###", "###statEnable": "启用统计,默认启用###", diff --git a/o2server/x_processplatform_assemble_surface/src/main/java/com/x/processplatform/assemble/surface/jaxrs/attachment/ActionManageDownload.java b/o2server/x_processplatform_assemble_surface/src/main/java/com/x/processplatform/assemble/surface/jaxrs/attachment/ActionManageDownload.java new file mode 100644 index 0000000000..6b2b6a0033 --- /dev/null +++ b/o2server/x_processplatform_assemble_surface/src/main/java/com/x/processplatform/assemble/surface/jaxrs/attachment/ActionManageDownload.java @@ -0,0 +1,67 @@ +package com.x.processplatform.assemble.surface.jaxrs.attachment; + +import java.util.Optional; + +import org.apache.commons.io.FilenameUtils; +import org.apache.commons.lang3.BooleanUtils; +import org.apache.commons.lang3.StringUtils; + +import com.x.base.core.container.EntityManagerContainer; +import com.x.base.core.container.factory.EntityManagerContainerFactory; +import com.x.base.core.project.config.Config; +import com.x.base.core.project.config.ProcessPlatform.WorkCompletedExtensionEvent; +import com.x.base.core.project.config.StorageMapping; +import com.x.base.core.project.connection.CipherConnectionAction; +import com.x.base.core.project.exception.ExceptionAccessDenied; +import com.x.base.core.project.exception.ExceptionEntityNotExist; +import com.x.base.core.project.http.ActionResult; +import com.x.base.core.project.http.EffectivePerson; +import com.x.base.core.project.jaxrs.WoFile; +import com.x.processplatform.assemble.surface.Business; +import com.x.processplatform.assemble.surface.ThisApplication; +import com.x.processplatform.assemble.surface.WorkCompletedControl; +import com.x.processplatform.core.entity.content.Attachment; +import com.x.processplatform.core.entity.content.WorkCompleted; + +/** + * 管理员下载 + * + * @author zhour + * + */ +class ActionManageDownload extends BaseAction { + ActionResult execute(EffectivePerson effectivePerson, String id) throws Exception { + + ActionResult result = new ActionResult<>(); + Attachment attachment = null; + + try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) { + Business business = new Business(emc); + attachment = emc.find(id, Attachment.class); + if (null == attachment) { + throw new ExceptionEntityNotExist(id, Attachment.class); + } + if (BooleanUtils.isNotTrue(business.canManageApplicationOrProcess(effectivePerson, + attachment.getApplication(), attachment.getProcess()))) { + throw new ExceptionAccessDenied(effectivePerson, attachment); + } + } + StorageMapping mapping = ThisApplication.context().storageMappings().get(Attachment.class, + attachment.getStorage()); + String fileName = attachment.getName() + + (StringUtils.isNotEmpty(attachment.getExtension()) ? "." + attachment.getExtension() : ""); + byte[] bytes = attachment.readContent(mapping); + Wo wo = new Wo(bytes, this.contentType(false, fileName), this.contentDisposition(false, fileName)); + result.setData(wo); + return result; + } + + public static class Wo extends WoFile { + + public Wo(byte[] bytes, String contentType, String contentDisposition) { + super(bytes, contentType, contentDisposition); + } + + } + +} \ No newline at end of file diff --git a/o2server/x_processplatform_assemble_surface/src/main/java/com/x/processplatform/assemble/surface/jaxrs/attachment/ActionManageDownloadStream.java b/o2server/x_processplatform_assemble_surface/src/main/java/com/x/processplatform/assemble/surface/jaxrs/attachment/ActionManageDownloadStream.java new file mode 100644 index 0000000000..b9fbe3a380 --- /dev/null +++ b/o2server/x_processplatform_assemble_surface/src/main/java/com/x/processplatform/assemble/surface/jaxrs/attachment/ActionManageDownloadStream.java @@ -0,0 +1,60 @@ +package com.x.processplatform.assemble.surface.jaxrs.attachment; + +import org.apache.commons.io.FilenameUtils; +import org.apache.commons.lang3.BooleanUtils; +import org.apache.commons.lang3.StringUtils; + +import com.x.base.core.container.EntityManagerContainer; +import com.x.base.core.container.factory.EntityManagerContainerFactory; +import com.x.base.core.project.config.StorageMapping; +import com.x.base.core.project.exception.ExceptionAccessDenied; +import com.x.base.core.project.exception.ExceptionEntityNotExist; +import com.x.base.core.project.http.ActionResult; +import com.x.base.core.project.http.EffectivePerson; +import com.x.base.core.project.jaxrs.WoFile; +import com.x.processplatform.assemble.surface.Business; +import com.x.processplatform.assemble.surface.ThisApplication; +import com.x.processplatform.core.entity.content.Attachment; + +/** + * 管理员下载 + * + * @author zhour + * + */ +class ActionManageDownloadStream extends BaseAction { + ActionResult execute(EffectivePerson effectivePerson, String id) throws Exception { + + ActionResult result = new ActionResult<>(); + Attachment attachment = null; + + try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) { + Business business = new Business(emc); + attachment = emc.find(id, Attachment.class); + if (null == attachment) { + throw new ExceptionEntityNotExist(id, Attachment.class); + } + if (BooleanUtils.isNotTrue(business.canManageApplicationOrProcess(effectivePerson, + attachment.getApplication(), attachment.getProcess()))) { + throw new ExceptionAccessDenied(effectivePerson, attachment); + } + } + StorageMapping mapping = ThisApplication.context().storageMappings().get(Attachment.class, + attachment.getStorage()); + String fileName = attachment.getName() + + (StringUtils.isNotEmpty(attachment.getExtension()) ? "." + attachment.getExtension() : ""); + byte[] bytes = attachment.readContent(mapping); + Wo wo = new Wo(bytes, this.contentType(true, fileName), this.contentDisposition(true, fileName)); + result.setData(wo); + return result; + } + + public static class Wo extends WoFile { + + public Wo(byte[] bytes, String contentType, String contentDisposition) { + super(bytes, contentType, contentDisposition); + } + + } + +} \ No newline at end of file diff --git a/o2server/x_processplatform_assemble_surface/src/main/java/com/x/processplatform/assemble/surface/jaxrs/attachment/AttachmentAction.java b/o2server/x_processplatform_assemble_surface/src/main/java/com/x/processplatform/assemble/surface/jaxrs/attachment/AttachmentAction.java index c519732b83..886ab6cc40 100644 --- a/o2server/x_processplatform_assemble_surface/src/main/java/com/x/processplatform/assemble/surface/jaxrs/attachment/AttachmentAction.java +++ b/o2server/x_processplatform_assemble_surface/src/main/java/com/x/processplatform/assemble/surface/jaxrs/attachment/AttachmentAction.java @@ -18,6 +18,12 @@ import javax.ws.rs.container.Suspended; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; +import org.apache.commons.lang3.StringUtils; +import org.glassfish.jersey.media.multipart.FormDataBodyPart; +import org.glassfish.jersey.media.multipart.FormDataContentDisposition; +import org.glassfish.jersey.media.multipart.FormDataMultiPart; +import org.glassfish.jersey.media.multipart.FormDataParam; + import com.google.gson.JsonElement; import com.x.base.core.project.annotation.JaxrsDescribe; import com.x.base.core.project.annotation.JaxrsMethodDescribe; @@ -30,12 +36,6 @@ 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 org.apache.commons.lang3.StringUtils; -import org.glassfish.jersey.media.multipart.FormDataBodyPart; -import org.glassfish.jersey.media.multipart.FormDataContentDisposition; -import org.glassfish.jersey.media.multipart.FormDataMultiPart; -import org.glassfish.jersey.media.multipart.FormDataParam; - @Path("attachment") @JaxrsDescribe("附件操作") public class AttachmentAction extends StandardJaxrsAction { @@ -85,8 +85,8 @@ public class AttachmentAction extends StandardJaxrsAction { @Produces(HttpMediaType.APPLICATION_JSON_UTF_8) @Consumes(MediaType.APPLICATION_JSON) public void getWithWorkCompleted(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request, - @JaxrsParameterDescribe("已完成工作标识") @PathParam("workCompletedId") String workCompletedId, - @JaxrsParameterDescribe("附件标识") @PathParam("id") String id) { + @JaxrsParameterDescribe("已完成工作标识") @PathParam("workCompletedId") String workCompletedId, + @JaxrsParameterDescribe("附件标识") @PathParam("id") String id) { ActionResult result = new ActionResult<>(); EffectivePerson effectivePerson = this.effectivePerson(request); try { @@ -103,9 +103,10 @@ public class AttachmentAction extends StandardJaxrsAction { @Path("{id}/workorworkcompleted/{workOrWorkCompleted}") @Produces(HttpMediaType.APPLICATION_JSON_UTF_8) @Consumes(MediaType.APPLICATION_JSON) - public void getWithWorkOrWorkCompleted(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request, - @JaxrsParameterDescribe("工作或已完成工作标识") @PathParam("workOrWorkCompleted") String workOrWorkCompleted, - @JaxrsParameterDescribe("附件标识") @PathParam("id") String id) { + public void getWithWorkOrWorkCompleted(@Suspended final AsyncResponse asyncResponse, + @Context HttpServletRequest request, + @JaxrsParameterDescribe("工作或已完成工作标识") @PathParam("workOrWorkCompleted") String workOrWorkCompleted, + @JaxrsParameterDescribe("附件标识") @PathParam("id") String id) { ActionResult result = new ActionResult<>(); EffectivePerson effectivePerson = this.effectivePerson(request); try { @@ -604,7 +605,8 @@ public class AttachmentAction extends StandardJaxrsAction { @Produces(HttpMediaType.APPLICATION_JSON_UTF_8) @Consumes(MediaType.APPLICATION_JSON) public void copyToWorkCompleted(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request, - @JaxrsParameterDescribe("已完成工作标识") @PathParam("workCompletedId") String workCompletedId, JsonElement jsonElement) { + @JaxrsParameterDescribe("已完成工作标识") @PathParam("workCompletedId") String workCompletedId, + JsonElement jsonElement) { ActionResult> result = new ActionResult<>(); EffectivePerson effectivePerson = this.effectivePerson(request); try { @@ -932,6 +934,40 @@ public class AttachmentAction extends StandardJaxrsAction { asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result)); } + @JaxrsMethodDescribe(value = "管理员角色下载附件", action = ActionManageDownload.class) + @GET + @Path("download/{id}/manage") + @Consumes(MediaType.APPLICATION_JSON) + public void manageDownload(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request, + @JaxrsParameterDescribe("附件标识") @PathParam("id") String id) { + ActionResult result = new ActionResult<>(); + EffectivePerson effectivePerson = this.effectivePerson(request); + try { + result = new ActionManageDownload().execute(effectivePerson, id); + } catch (Exception e) { + logger.error(e, effectivePerson, request, null); + result.error(e); + } + asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result)); + } + + @JaxrsMethodDescribe(value = "管理员角色下载附件,stream", action = ActionManageDownloadStream.class) + @GET + @Path("download/{id}/manage/stream") + @Consumes(MediaType.APPLICATION_JSON) + public void manageDownloadStream(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request, + @JaxrsParameterDescribe("附件标识") @PathParam("id") String id) { + ActionResult result = new ActionResult<>(); + EffectivePerson effectivePerson = this.effectivePerson(request); + try { + result = new ActionManageDownloadStream().execute(effectivePerson, id); + } catch (Exception e) { + logger.error(e, effectivePerson, request, null); + result.error(e); + } + asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result)); + } + @JaxrsMethodDescribe(value = "html转pdf工具类,转换后通过downloadTransfer接口下载", action = ActionHtmlToPdf.class) @POST @Path("html/to/pdf") diff --git a/o2server/x_processplatform_assemble_surface/src/main/java/com/x/processplatform/assemble/surface/jaxrs/snap/ActionTypeAbandoned.java b/o2server/x_processplatform_assemble_surface/src/main/java/com/x/processplatform/assemble/surface/jaxrs/snap/ActionTypeAbandoned.java new file mode 100644 index 0000000000..e70296710a --- /dev/null +++ b/o2server/x_processplatform_assemble_surface/src/main/java/com/x/processplatform/assemble/surface/jaxrs/snap/ActionTypeAbandoned.java @@ -0,0 +1,59 @@ +package com.x.processplatform.assemble.surface.jaxrs.snap; + +import org.apache.commons.lang3.BooleanUtils; + +import com.x.base.core.container.EntityManagerContainer; +import com.x.base.core.container.factory.EntityManagerContainerFactory; +import com.x.base.core.project.Applications; +import com.x.base.core.project.x_processplatform_service_processing; +import com.x.base.core.project.exception.ExceptionAccessDenied; +import com.x.base.core.project.exception.ExceptionEntityNotExist; +import com.x.base.core.project.http.ActionResult; +import com.x.base.core.project.http.EffectivePerson; +import com.x.base.core.project.jaxrs.WoId; +import com.x.base.core.project.logger.Logger; +import com.x.base.core.project.logger.LoggerFactory; +import com.x.processplatform.assemble.surface.Business; +import com.x.processplatform.assemble.surface.ThisApplication; +import com.x.processplatform.core.entity.content.Work; +import com.x.processplatform.core.entity.element.Activity; + +class ActionTypeAbandoned extends BaseAction { + + private static Logger logger = LoggerFactory.getLogger(ActionTypeAbandoned.class); + + ActionResult execute(EffectivePerson effectivePerson, String workId) throws Exception { + String job = null; + try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) { + Business business = new Business(emc); + Work work = emc.find(workId, Work.class); + if (null == work) { + throw new ExceptionEntityNotExist(workId, Work.class); + } + job = work.getJob(); + Activity activity = business.getActivity(work.getActivity(), work.getActivityType()); + if (BooleanUtils.isNotTrue( + business.canManageApplicationOrProcess(effectivePerson, work.getApplication(), work.getProcess())) + && ((!business.editable(effectivePerson, work)) + || (BooleanUtils.isNotTrue(activity.getAllowSuspend())))) { + throw new ExceptionAccessDenied(effectivePerson, work); + } + } + + Wo wo = ThisApplication.context().applications() + .getQuery(effectivePerson.getDebugger(), x_processplatform_service_processing.class, + Applications.joinQueryUri("snap", "work", workId, "type", "abandoned"), job) + .getData(Wo.class); + ActionResult result = new ActionResult<>(); + result.setData(wo); + return result; + + } + + public static class Wo extends WoId { + + private static final long serialVersionUID = -2577413577740827608L; + + } + +} diff --git a/o2server/x_program_center/src/main/java/com/x/program/center/jaxrs/invoke/BaseAction.java b/o2server/x_program_center/src/main/java/com/x/program/center/jaxrs/invoke/BaseAction.java index 9592e80893..974c0788fa 100644 --- a/o2server/x_program_center/src/main/java/com/x/program/center/jaxrs/invoke/BaseAction.java +++ b/o2server/x_program_center/src/main/java/com/x/program/center/jaxrs/invoke/BaseAction.java @@ -10,31 +10,31 @@ import com.x.program.center.core.entity.Invoke; abstract class BaseAction extends StandardJaxrsAction { - private static String COMMENT = ""; - - private static final Pattern COMMENT_REGEX = Pattern.compile("^\\/\\*(\\s|.)*?\\*\\/"); - - static { - COMMENT = "/*" + StringUtils.LF; - COMMENT += "* resources.getEntityManagerContainer() // 实体管理容器." + StringUtils.LF; - COMMENT += "* resources.getContext() //上下文根." + StringUtils.LF; - COMMENT += "* resources.getOrganization() //组织访问接口." + StringUtils.LF; - COMMENT += "* requestText //请求内容." + StringUtils.LF; - COMMENT += "* request //请求对象." + StringUtils.LF; - COMMENT += "*/" + StringUtils.LF; - } - - protected void addComment(Invoke invoke) { - if (StringUtils.isEmpty(invoke.getText())) { - invoke.setText(COMMENT); - } else { - Matcher m = COMMENT_REGEX.matcher(invoke.getText()); - if (m.find()) { - invoke.setText(COMMENT + m.replaceFirst("")); - } else { - invoke.setText(COMMENT + invoke.getText()); - } - } - } +// private static String COMMENT = ""; +// +// private static final Pattern COMMENT_REGEX = Pattern.compile("^\\/\\*(\\s|.)*?\\*\\/"); +// +// static { +// COMMENT = "/*" + StringUtils.LF; +// COMMENT += "* resources.getEntityManagerContainer() // 实体管理容器." + StringUtils.LF; +// COMMENT += "* resources.getContext() //上下文根." + StringUtils.LF; +// COMMENT += "* resources.getOrganization() //组织访问接口." + StringUtils.LF; +// COMMENT += "* requestText //请求内容." + StringUtils.LF; +// COMMENT += "* request //请求对象." + StringUtils.LF; +// COMMENT += "*/" + StringUtils.LF; +// } +// +// protected void addComment(Invoke invoke) { +// if (StringUtils.isEmpty(invoke.getText())) { +// invoke.setText(COMMENT); +// } else { +// Matcher m = COMMENT_REGEX.matcher(invoke.getText()); +// if (m.find()) { +// invoke.setText(COMMENT + m.replaceFirst("")); +// } else { +// invoke.setText(COMMENT + invoke.getText()); +// } +// } +// } } -- GitLab