提交 204d9cce 编写于 作者: O o2null

Merge branch 'feature/增加流程附件拷贝到已完成文档的接口' into 'develop'

【流程平台】增加流程附件拷贝到已完成工作接口

See merge request o2oa/o2oa!1578
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.Applications;
import com.x.base.core.project.annotation.ActionLogger;
import com.x.base.core.project.annotation.FieldDescribe;
import com.x.base.core.project.exception.ExceptionAccessDenied;
import com.x.base.core.project.exception.ExceptionEntityNotExist;
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.WoId;
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.base.core.project.x_processplatform_service_processing;
import com.x.processplatform.assemble.surface.Business;
import com.x.processplatform.assemble.surface.ThisApplication;
import com.x.processplatform.assemble.surface.WorkControl;
import com.x.processplatform.core.entity.content.Attachment;
import com.x.processplatform.core.entity.content.WorkCompleted;
import java.util.ArrayList;
import java.util.List;
class ActionCopyToWorkCompleted extends BaseAction {
@ActionLogger
private static Logger logger = LoggerFactory.getLogger(ActionCopyToWorkCompleted.class);
ActionResult<List<Wo>> execute(EffectivePerson effectivePerson, String workCompletedId, JsonElement jsonElement)
throws Exception {
ActionResult<List<Wo>> result = new ActionResult<>();
List<Wo> wos = new ArrayList<>();
Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
WorkCompleted workCompleted = null;
Req req = new Req();
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
workCompleted = emc.flag(workCompletedId, WorkCompleted.class);
if((null == workCompleted)){
throw new ExceptionEntityNotExist(workCompletedId, WorkCompleted.class);
}
if (!business.canManageApplicationOrProcess(effectivePerson, workCompleted.getApplication(),
workCompleted.getProcess())) {
throw new ExceptionAccessDenied(effectivePerson);
}
if (ListTools.isNotEmpty(wi.getAttachmentList())) {
for (WiAttachment w : wi.getAttachmentList()) {
Attachment o = emc.find(w.getId(), Attachment.class);
if (null == o) {
throw new ExceptionEntityNotExist(w.getId(), Attachment.class);
}
if (!business.readableWithJob(effectivePerson, o.getJob())) {
throw new ExceptionAccessDenied(effectivePerson, o.getJob());
}
ReqAttachment q = new ReqAttachment();
q.setId(o.getId());
q.setName(w.getName());
q.setSite(w.getSite());
req.getAttachmentList().add(q);
}
}
}
if (ListTools.isNotEmpty(req.getAttachmentList())) {
wos = ThisApplication.context().applications()
.postQuery(effectivePerson.getDebugger(), x_processplatform_service_processing.class,
Applications.joinQueryUri("attachment", "copy", "workcompleted", workCompleted.getId()), req, workCompleted.getJob())
.getDataAsList(Wo.class);
}
result.setData(wos);
return result;
}
public static class Wi extends GsonPropertyObject {
@FieldDescribe("附件对象")
private List<WiAttachment> attachmentList = new ArrayList<>();
public List<WiAttachment> getAttachmentList() {
return attachmentList;
}
public void setAttachmentList(List<WiAttachment> attachmentList) {
this.attachmentList = attachmentList;
}
}
public static class ReqAttachment extends GsonPropertyObject {
private String id;
private String name;
private String site;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSite() {
return site;
}
public void setSite(String site) {
this.site = site;
}
}
public static class Req extends GsonPropertyObject {
List<ReqAttachment> attachmentList = new ArrayList<>();
public List<ReqAttachment> getAttachmentList() {
return attachmentList;
}
public void setAttachmentList(List<ReqAttachment> attachmentList) {
this.attachmentList = attachmentList;
}
}
public static class WiAttachment extends GsonPropertyObject {
private String id;
private String name;
private String site;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSite() {
return site;
}
public void setSite(String site) {
this.site = site;
}
}
public static class Wo extends WoId {
}
public static class WoWorkControl extends WorkControl {
}
}
\ No newline at end of file
......@@ -598,6 +598,24 @@ public class AttachmentAction extends StandardJaxrsAction {
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "由指定的工作拷贝附件.", action = ActionCopyToWorkCompleted.class)
@POST
@Path("copy/workcompleted/{workCompletedId}")
@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) {
ActionResult<List<ActionCopyToWorkCompleted.Wo>> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionCopyToWorkCompleted().execute(effectivePerson, workCompletedId, jsonElement);
} catch (Exception e) {
logger.error(e, effectivePerson, request, null);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "更新附件.", action = ActionChangeSite.class)
@GET
@Path("{id}/work/{workId}/change/site/{site}")
......
......@@ -92,6 +92,23 @@ public class Attachment extends StorageObject {
this.setActivityType(work.getActivityType());
}
public Attachment(WorkCompleted work, String person, String site) {
this.setCompleted(true);
this.setWork(work.getWork());
this.setWorkCompleted(work.getId());
this.setPerson(person);
this.setLastUpdatePerson(person);
this.setSite(site);
/** 用于判断目录的值 */
this.setWorkCreateTime(work.getStartTime() != null ? work.getStartTime() : new Date());
this.setApplication(work.getApplication());
this.setProcess(work.getProcess());
this.setJob(work.getJob());
this.setActivity(work.getActivity());
this.setActivityName(work.getActivityName());
}
/** 更新运行方法 */
@Override
......
package com.x.processplatform.service.processing.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.entity.annotation.CheckPersistType;
import com.x.base.core.project.annotation.ActionLogger;
import com.x.base.core.project.annotation.FieldDescribe;
import com.x.base.core.project.config.StorageMapping;
import com.x.base.core.project.exception.ExceptionEntityNotExist;
import com.x.base.core.project.executor.ProcessPlatformExecutorFactory;
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.WoId;
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.core.entity.content.Attachment;
import com.x.processplatform.core.entity.content.WorkCompleted;
import com.x.processplatform.service.processing.ThisApplication;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
/**
*
* @author zhour 复制指定的附件到work,仅拷贝内容,并清除其他附带的信息
*/
class ActionCopyToWorkCompleted extends BaseAction {
@ActionLogger
private static Logger logger = LoggerFactory.getLogger(ActionCopyToWorkCompleted.class);
ActionResult<List<Wo>> execute(EffectivePerson effectivePerson, String workCompletedId, JsonElement jsonElement)
throws Exception {
Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
String executorSeed = null;
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
WorkCompleted work = emc.fetch(workCompletedId, WorkCompleted.class, ListTools.toList(WorkCompleted.job_FIELDNAME));
if (null == work) {
throw new ExceptionEntityNotExist(workCompletedId, WorkCompleted.class);
}
executorSeed = work.getJob();
}
Callable<ActionResult<List<Wo>>> callable = new Callable<ActionResult<List<Wo>>>() {
public ActionResult<List<Wo>> call() throws Exception {
List<Wo> wos = new ArrayList<>();
ActionResult<List<Wo>> result = new ActionResult<>();
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
WorkCompleted work = emc.find(workCompletedId, WorkCompleted.class);
if (null == work) {
throw new ExceptionEntityNotExist(workCompletedId, WorkCompleted.class);
}
List<Attachment> adds = new ArrayList<>();
for (WiAttachment w : ListTools.trim(wi.getAttachmentList(), true, true)) {
Attachment o = emc.find(w.getId(), Attachment.class);
if (null == o) {
throw new ExceptionEntityNotExist(w.getId(), Attachment.class);
}
StorageMapping fromStorageMapping = ThisApplication.context().storageMappings()
.get(Attachment.class, o.getStorage());
StorageMapping mapping = ThisApplication.context().storageMappings().random(Attachment.class);
byte[] bs = o.readContent(fromStorageMapping);
Attachment attachment = new Attachment(work, effectivePerson.getDistinguishedName(),
w.getSite());
attachment.saveContent(mapping, bs, w.getName());
adds.add(attachment);
}
if (!adds.isEmpty()) {
emc.beginTransaction(Attachment.class);
for (Attachment o : adds) {
emc.persist(o, CheckPersistType.all);
Wo wo = new Wo();
wo.setId(o.getId());
wos.add(wo);
}
emc.commit();
}
}
result.setData(wos);
return result;
}
};
return ProcessPlatformExecutorFactory.get(executorSeed).submit(callable).get();
}
public static class Wi extends GsonPropertyObject {
@FieldDescribe("附件对象")
private List<WiAttachment> attachmentList = new ArrayList<>();
public List<WiAttachment> getAttachmentList() {
return attachmentList;
}
public void setAttachmentList(List<WiAttachment> attachmentList) {
this.attachmentList = attachmentList;
}
}
public static class WiAttachment extends Attachment {
private static final long serialVersionUID = 5623475924507252797L;
}
public static class Wo extends WoId {
}
}
\ No newline at end of file
......@@ -143,4 +143,22 @@ public class AttachmentAction extends StandardJaxrsAction {
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "由指定的工作拷贝附件.", action = ActionCopyToWorkCompleted.class)
@POST
@Path("copy/workcompleted/{workCompletedId}")
@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) {
ActionResult<List<ActionCopyToWorkCompleted.Wo>> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionCopyToWorkCompleted().execute(effectivePerson, workCompletedId, jsonElement);
} catch (Exception e) {
logger.error(e, effectivePerson, request, jsonElement);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册