提交 ecd61a17 编写于 作者: Z zhourui

增加管理员下载附件

上级 77f05c17
...@@ -108,7 +108,7 @@ ...@@ -108,7 +108,7 @@
"###excludes": "在此节点上不存储的类,和includes一起设置实际存储的类,可以使用通配符*###", "###excludes": "在此节点上不存储的类,和includes一起设置实际存储的类,可以使用通配符*###",
"###jmxEnable": "是否启动jmx,如果启用,可以通过本地的jmx客户端进行访问,不支持远程jmx客户端.###", "###jmxEnable": "是否启动jmx,如果启用,可以通过本地的jmx客户端进行访问,不支持远程jmx客户端.###",
"###cacheSize": "H2数据库缓存大小,设置H2用于作为缓存的内存大小,以M作为单位,这里默认为512M.###", "###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": "最大使用连接数###", "###maxTotal": "最大使用连接数###",
"###maxIdle": "最大空闲连接数###", "###maxIdle": "最大空闲连接数###",
"###statEnable": "启用统计,默认启用###", "###statEnable": "启用统计,默认启用###",
......
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<Wo> execute(EffectivePerson effectivePerson, String id) throws Exception {
ActionResult<Wo> 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
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<Wo> execute(EffectivePerson effectivePerson, String id) throws Exception {
ActionResult<Wo> 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
...@@ -18,6 +18,12 @@ import javax.ws.rs.container.Suspended; ...@@ -18,6 +18,12 @@ import javax.ws.rs.container.Suspended;
import javax.ws.rs.core.Context; import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType; 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.google.gson.JsonElement;
import com.x.base.core.project.annotation.JaxrsDescribe; import com.x.base.core.project.annotation.JaxrsDescribe;
import com.x.base.core.project.annotation.JaxrsMethodDescribe; import com.x.base.core.project.annotation.JaxrsMethodDescribe;
...@@ -30,12 +36,6 @@ import com.x.base.core.project.jaxrs.StandardJaxrsAction; ...@@ -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.Logger;
import com.x.base.core.project.logger.LoggerFactory; 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") @Path("attachment")
@JaxrsDescribe("附件操作") @JaxrsDescribe("附件操作")
public class AttachmentAction extends StandardJaxrsAction { public class AttachmentAction extends StandardJaxrsAction {
...@@ -85,8 +85,8 @@ public class AttachmentAction extends StandardJaxrsAction { ...@@ -85,8 +85,8 @@ public class AttachmentAction extends StandardJaxrsAction {
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8) @Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
public void getWithWorkCompleted(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request, public void getWithWorkCompleted(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
@JaxrsParameterDescribe("已完成工作标识") @PathParam("workCompletedId") String workCompletedId, @JaxrsParameterDescribe("已完成工作标识") @PathParam("workCompletedId") String workCompletedId,
@JaxrsParameterDescribe("附件标识") @PathParam("id") String id) { @JaxrsParameterDescribe("附件标识") @PathParam("id") String id) {
ActionResult<ActionGetWithWorkCompleted.Wo> result = new ActionResult<>(); ActionResult<ActionGetWithWorkCompleted.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request); EffectivePerson effectivePerson = this.effectivePerson(request);
try { try {
...@@ -103,9 +103,10 @@ public class AttachmentAction extends StandardJaxrsAction { ...@@ -103,9 +103,10 @@ public class AttachmentAction extends StandardJaxrsAction {
@Path("{id}/workorworkcompleted/{workOrWorkCompleted}") @Path("{id}/workorworkcompleted/{workOrWorkCompleted}")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8) @Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
public void getWithWorkOrWorkCompleted(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request, public void getWithWorkOrWorkCompleted(@Suspended final AsyncResponse asyncResponse,
@JaxrsParameterDescribe("工作或已完成工作标识") @PathParam("workOrWorkCompleted") String workOrWorkCompleted, @Context HttpServletRequest request,
@JaxrsParameterDescribe("附件标识") @PathParam("id") String id) { @JaxrsParameterDescribe("工作或已完成工作标识") @PathParam("workOrWorkCompleted") String workOrWorkCompleted,
@JaxrsParameterDescribe("附件标识") @PathParam("id") String id) {
ActionResult<ActionGetWithWorkOrWorkCompleted.Wo> result = new ActionResult<>(); ActionResult<ActionGetWithWorkOrWorkCompleted.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request); EffectivePerson effectivePerson = this.effectivePerson(request);
try { try {
...@@ -604,7 +605,8 @@ public class AttachmentAction extends StandardJaxrsAction { ...@@ -604,7 +605,8 @@ public class AttachmentAction extends StandardJaxrsAction {
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8) @Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
public void copyToWorkCompleted(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request, 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<List<ActionCopyToWorkCompleted.Wo>> result = new ActionResult<>(); ActionResult<List<ActionCopyToWorkCompleted.Wo>> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request); EffectivePerson effectivePerson = this.effectivePerson(request);
try { try {
...@@ -932,6 +934,40 @@ public class AttachmentAction extends StandardJaxrsAction { ...@@ -932,6 +934,40 @@ public class AttachmentAction extends StandardJaxrsAction {
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result)); 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<ActionManageDownload.Wo> 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<ActionManageDownloadStream.Wo> 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) @JaxrsMethodDescribe(value = "html转pdf工具类,转换后通过downloadTransfer接口下载", action = ActionHtmlToPdf.class)
@POST @POST
@Path("html/to/pdf") @Path("html/to/pdf")
......
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<Wo> 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<Wo> result = new ActionResult<>();
result.setData(wo);
return result;
}
public static class Wo extends WoId {
private static final long serialVersionUID = -2577413577740827608L;
}
}
...@@ -10,31 +10,31 @@ import com.x.program.center.core.entity.Invoke; ...@@ -10,31 +10,31 @@ import com.x.program.center.core.entity.Invoke;
abstract class BaseAction extends StandardJaxrsAction { abstract class BaseAction extends StandardJaxrsAction {
private static String COMMENT = ""; // private static String COMMENT = "";
//
private static final Pattern COMMENT_REGEX = Pattern.compile("^\\/\\*(\\s|.)*?\\*\\/"); // private static final Pattern COMMENT_REGEX = Pattern.compile("^\\/\\*(\\s|.)*?\\*\\/");
//
static { // static {
COMMENT = "/*" + StringUtils.LF; // COMMENT = "/*" + StringUtils.LF;
COMMENT += "* resources.getEntityManagerContainer() // 实体管理容器." + StringUtils.LF; // COMMENT += "* resources.getEntityManagerContainer() // 实体管理容器." + StringUtils.LF;
COMMENT += "* resources.getContext() //上下文根." + StringUtils.LF; // COMMENT += "* resources.getContext() //上下文根." + StringUtils.LF;
COMMENT += "* resources.getOrganization() //组织访问接口." + StringUtils.LF; // COMMENT += "* resources.getOrganization() //组织访问接口." + StringUtils.LF;
COMMENT += "* requestText //请求内容." + StringUtils.LF; // COMMENT += "* requestText //请求内容." + StringUtils.LF;
COMMENT += "* request //请求对象." + StringUtils.LF; // COMMENT += "* request //请求对象." + StringUtils.LF;
COMMENT += "*/" + StringUtils.LF; // COMMENT += "*/" + StringUtils.LF;
} // }
//
protected void addComment(Invoke invoke) { // protected void addComment(Invoke invoke) {
if (StringUtils.isEmpty(invoke.getText())) { // if (StringUtils.isEmpty(invoke.getText())) {
invoke.setText(COMMENT); // invoke.setText(COMMENT);
} else { // } else {
Matcher m = COMMENT_REGEX.matcher(invoke.getText()); // Matcher m = COMMENT_REGEX.matcher(invoke.getText());
if (m.find()) { // if (m.find()) {
invoke.setText(COMMENT + m.replaceFirst("")); // invoke.setText(COMMENT + m.replaceFirst(""));
} else { // } else {
invoke.setText(COMMENT + invoke.getText()); // invoke.setText(COMMENT + invoke.getText());
} // }
} // }
} // }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册