提交 f7fbf874 编写于 作者: O o2null

增加已完成工作的snap功能

上级 0d2bafb9
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.WorkCompleted;
class ActionTypeSnapWorkCompleted extends BaseAction {
private static Logger logger = LoggerFactory.getLogger(ActionTypeSnapWorkCompleted.class);
ActionResult<Wo> execute(EffectivePerson effectivePerson, String workCompletedId) throws Exception {
String job = null;
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
WorkCompleted workCompleted = emc.find(workCompletedId, WorkCompleted.class);
if (null == workCompleted) {
throw new ExceptionEntityNotExist(workCompletedId, WorkCompleted.class);
}
if (BooleanUtils.isFalse(business.canManageApplicationOrProcess(effectivePerson,
workCompleted.getApplication(), workCompleted.getProcess()))) {
throw new ExceptionAccessDenied(effectivePerson, workCompleted);
}
job = workCompleted.getJob();
}
Wo wo = ThisApplication.context().applications()
.getQuery(effectivePerson.getDebugger(), x_processplatform_service_processing.class, Applications
.joinQueryUri("snap", "workcompleted", workCompletedId, "type", "snapworkcompleted"), 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;
}
}
......@@ -37,7 +37,7 @@ public class SnapAction extends StandardJaxrsAction {
private static Logger logger = LoggerFactory.getLogger(SnapAction.class);
@JaxrsMethodDescribe(value = "对工作进行快照", action = ActionTypeSnap.class)
@JaxrsMethodDescribe(value = "对工作进行快照.", action = ActionTypeSnap.class)
@GET
@Path("work/{workId}/type/snap")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
......@@ -55,7 +55,7 @@ public class SnapAction extends StandardJaxrsAction {
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "对工作进行快照,并标记为废弃", action = ActionTypeAbandoned.class)
@JaxrsMethodDescribe(value = "对工作进行快照,并标记为废弃.", action = ActionTypeAbandoned.class)
@GET
@Path("work/{workId}/type/abandoned")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
......@@ -73,18 +73,35 @@ public class SnapAction extends StandardJaxrsAction {
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "对已完成工作进行快照,并标记为废弃", action = ActionTypeAbandonedWorkCompleted.class)
@JaxrsMethodDescribe(value = "挂起工作", action = ActionTypeSuspend.class)
@GET
@Path("workcompleted/{workCompletedId}/type/abandonedworkcompleted")
@Path("work/{workId}/type/suspend")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void typeAbandonedWorkCompleted(@Suspended final AsyncResponse asyncResponse,
@Context HttpServletRequest request,
public void typeSuspend(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
@JaxrsParameterDescribe("工作标识") @PathParam("workId") String workId) {
ActionResult<ActionTypeSuspend.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionTypeSuspend().execute(effectivePerson, workId);
} catch (Exception e) {
logger.error(e, effectivePerson, request, null);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "对已完成工作进行快照.", action = ActionTypeSnapWorkCompleted.class)
@GET
@Path("workcompleted/{workCompletedId}/type/snapworkcompleted")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void typeSnapWorkCompleted(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
@JaxrsParameterDescribe("工作标识") @PathParam("workCompletedId") String workCompletedId) {
ActionResult<ActionTypeAbandonedWorkCompleted.Wo> result = new ActionResult<>();
ActionResult<ActionTypeSnapWorkCompleted.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionTypeAbandonedWorkCompleted().execute(effectivePerson, workCompletedId);
result = new ActionTypeSnapWorkCompleted().execute(effectivePerson, workCompletedId);
} catch (Exception e) {
logger.error(e, effectivePerson, request, null);
result.error(e);
......@@ -92,17 +109,18 @@ public class SnapAction extends StandardJaxrsAction {
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "挂起工作", action = ActionTypeSuspend.class)
@JaxrsMethodDescribe(value = "对已完成工作进行快照,并标记为废弃.", action = ActionTypeAbandonedWorkCompleted.class)
@GET
@Path("work/{workId}/type/suspend")
@Path("workcompleted/{workCompletedId}/type/abandonedworkcompleted")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void typeSuspend(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
@JaxrsParameterDescribe("工作标识") @PathParam("workId") String workId) {
ActionResult<ActionTypeSuspend.Wo> result = new ActionResult<>();
public void typeAbandonedWorkCompleted(@Suspended final AsyncResponse asyncResponse,
@Context HttpServletRequest request,
@JaxrsParameterDescribe("工作标识") @PathParam("workCompletedId") String workCompletedId) {
ActionResult<ActionTypeAbandonedWorkCompleted.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionTypeSuspend().execute(effectivePerson, workId);
result = new ActionTypeAbandonedWorkCompleted().execute(effectivePerson, workCompletedId);
} catch (Exception e) {
logger.error(e, effectivePerson, request, null);
result.error(e);
......
......@@ -48,6 +48,8 @@ public class Snap extends SliceJpaObject {
public static final String TYPE_ABANDONEDWORKCOMPLETED = "abandonedWorkCompleted";
public static final String TYPE_SNAPWORKCOMPLETED = "snapWorkCompleted";
public String getId() {
return id;
}
......
......@@ -72,7 +72,8 @@ class ActionRestore extends BaseAction {
if (null == snap) {
throw new ExceptionEntityNotExist(id, Snap.class);
}
if (Objects.equals(Snap.TYPE_ABANDONEDWORKCOMPLETED, snap.getType())) {
if (Objects.equals(Snap.TYPE_ABANDONEDWORKCOMPLETED, snap.getType())
|| Objects.equals(Snap.TYPE_SNAPWORKCOMPLETED, snap.getType())) {
CompletableFuture.allOf(deleteItem(business, snap.getJob()),
deleteWorkCompleted(business, snap.getJob()), deleteTask(business, snap.getJob()),
deleteTaskCompleted(business, snap.getJob()), deleteRead(business, snap.getJob()),
......@@ -89,7 +90,8 @@ class ActionRestore extends BaseAction {
deleteDocumentVersion(business, snap.getJob())).get();
}
emc.commit();
if (Objects.equals(Snap.TYPE_ABANDONEDWORKCOMPLETED, snap.getType())) {
if (Objects.equals(Snap.TYPE_ABANDONEDWORKCOMPLETED, snap.getType())
|| Objects.equals(Snap.TYPE_SNAPWORKCOMPLETED, snap.getType())) {
restoreWorkCompleted(business, snap);
} else {
restore(business, snap);
......
package com.x.processplatform.service.processing.jaxrs.snap;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
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.exception.ExceptionEntityNotExist;
import com.x.base.core.project.executor.ProcessPlatformExecutorFactory;
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.core.entity.content.Attachment;
import com.x.processplatform.core.entity.content.Read;
import com.x.processplatform.core.entity.content.ReadCompleted;
import com.x.processplatform.core.entity.content.Record;
import com.x.processplatform.core.entity.content.Review;
import com.x.processplatform.core.entity.content.Snap;
import com.x.processplatform.core.entity.content.TaskCompleted;
import com.x.processplatform.core.entity.content.WorkCompleted;
import com.x.processplatform.core.entity.content.WorkLog;
import com.x.processplatform.service.processing.Business;
import com.x.query.core.entity.Item;
class ActionTypeSnapWorkCompleted extends BaseAction {
private static Logger logger = LoggerFactory.getLogger(ActionTypeSnapWorkCompleted.class);
ActionResult<Wo> execute(EffectivePerson effectivePerson, String workCompletedId) throws Exception {
String job = null;
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
WorkCompleted workCompleted = emc.find(workCompletedId, WorkCompleted.class);
if (null == workCompleted) {
throw new ExceptionEntityNotExist(workCompletedId, WorkCompleted.class);
}
job = workCompleted.getJob();
}
return ProcessPlatformExecutorFactory.get(job).submit(new CallableImpl(workCompletedId)).get(300,
TimeUnit.SECONDS);
}
public class CallableImpl implements Callable<ActionResult<Wo>> {
private String id;
public CallableImpl(String id) {
this.id = id;
}
public ActionResult<Wo> call() throws Exception {
ActionResult<Wo> result = new ActionResult<>();
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
WorkCompleted workCompleted = emc.find(id, WorkCompleted.class);
if (null == workCompleted) {
throw new ExceptionEntityNotExist(id, WorkCompleted.class);
}
Snap snap = new Snap(workCompleted);
List<Item> items = new ArrayList<>();
List<TaskCompleted> taskCompleteds = new ArrayList<>();
List<Read> reads = new ArrayList<>();
List<ReadCompleted> readCompleteds = new ArrayList<>();
List<Review> reviews = new ArrayList<>();
List<WorkLog> workLogs = new ArrayList<>();
List<Record> records = new ArrayList<>();
List<Attachment> attachments = new ArrayList<>();
snap.setProperties(snap(business, workCompleted.getJob(), items, workCompleted, taskCompleteds, reads,
readCompleteds, reviews, workLogs, records, attachments));
snap.setType(Snap.TYPE_SNAPWORKCOMPLETED);
emc.beginTransaction(Snap.class);
emc.persist(snap, CheckPersistType.all);
emc.commit();
// clean(business, items, workCompleted, taskCompleteds, reads, readCompleteds, reviews, workLogs, records,
// attachments);
// emc.commit();
Wo wo = new Wo();
wo.setId(snap.getId());
result.setData(wo);
return result;
}
}
}
public static class Wo extends WoId {
private static final long serialVersionUID = -2577413577740827608L;
}
}
......@@ -104,6 +104,24 @@ public class SnapAction extends StandardJaxrsAction {
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "对已完成工作进行快照", action = ActionTypeSnapWorkCompleted.class)
@GET
@Path("workcompleted/{workCompletedId}/type/snapworkcompleted")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void typeSnapWorkCompleted(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
@JaxrsParameterDescribe("已完成工作标识") @PathParam("workCompletedId") String workCompletedId) {
ActionResult<ActionTypeSnapWorkCompleted.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionTypeSnapWorkCompleted().execute(effectivePerson, workCompletedId);
} catch (Exception e) {
logger.error(e, effectivePerson, request, null);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "删除快照", action = ActionDelete.class)
@DELETE
@Path("{id}")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册