提交 6e7ffee6 编写于 作者: O o2null

Merge branch 'feature/流程附件增加批量删除接口' into 'develop_java8'

[流程平台]流程附件增加批量删除接口

See merge request o2oa/o2oa!3270
package com.x.processplatform.assemble.surface.jaxrs.attachment;
import com.google.gson.JsonElement;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.project.annotation.FieldDescribe;
import com.x.base.core.project.config.StorageMapping;
import com.x.base.core.project.exception.ExceptionAccessDenied;
import com.x.base.core.project.gson.GsonPropertyObject;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.jaxrs.WrapBoolean;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.base.core.project.tools.ListTools;
import com.x.processplatform.assemble.surface.Business;
import com.x.processplatform.assemble.surface.ThisApplication;
import com.x.processplatform.core.entity.content.Attachment;
import java.util.List;
class ActionManageBatchDelete extends BaseAction {
private static Logger logger = LoggerFactory.getLogger(ActionManageBatchDelete.class);
ActionResult<Wo> execute(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
logger.print("manageBatchDelete receive id:{}, effectivePerson:{}.", wi.getIdList(), effectivePerson.getDistinguishedName());
ActionResult<Wo> result = new ActionResult<>();
Business business = new Business(emc);
if(!business.canManageApplication(effectivePerson, null)){
throw new ExceptionAccessDenied(effectivePerson);
}
if(ListTools.isNotEmpty(wi.getIdList())){
for (String id : wi.getIdList()){
Attachment attachment = emc.find(id.trim(), Attachment.class);
if(attachment!=null){
logger.print("manageBatchDelete attachment:{}——{}", attachment.getId(), attachment.getName());
StorageMapping mapping = ThisApplication.context().storageMappings().get(Attachment.class,
attachment.getStorage());
attachment.deleteContent(mapping);
emc.beginTransaction(Attachment.class);
emc.remove(attachment);
emc.commit();
}
}
}
Wo wo = new Wo();
wo.setValue(true);
result.setData(wo);
return result;
}
}
public static class Wo extends WrapBoolean {
}
public static class Wi extends GsonPropertyObject{
@FieldDescribe("待删除附件ID列表")
private List<String> idList;
public List<String> getIdList() {
return idList;
}
public void setIdList(List<String> idList) {
this.idList = idList;
}
}
}
...@@ -1273,6 +1273,24 @@ public class AttachmentAction extends StandardJaxrsAction { ...@@ -1273,6 +1273,24 @@ public class AttachmentAction extends StandardJaxrsAction {
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result)); asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
} }
@JaxrsMethodDescribe(value = "批量删除附件.", action = ActionManageBatchDelete.class)
@POST
@Path("batch/delete/manage")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void manageBatchDelete(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
JsonElement jsonElement) {
ActionResult<ActionManageBatchDelete.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionManageBatchDelete().execute(effectivePerson, jsonElement);
} catch (Exception e) {
logger.error(e, effectivePerson, request, null);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "上传附件", action = ActionUploadWithUrl.class) @JaxrsMethodDescribe(value = "上传附件", action = ActionUploadWithUrl.class)
@POST @POST
@Path("upload/with/url") @Path("upload/with/url")
...@@ -1308,4 +1326,5 @@ public class AttachmentAction extends StandardJaxrsAction { ...@@ -1308,4 +1326,5 @@ public class AttachmentAction extends StandardJaxrsAction {
} }
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result)); asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册