提交 f54eb811 编写于 作者: O o2null

Merge branch 'feature/index' into 'develop'

add projection by job

See merge request o2oa/o2oa!827
......@@ -95,9 +95,6 @@ class ActionInfo extends BaseAction {
if (optional.isPresent()) {
return (CompiledScript) optional.get();
} else {
System.out.println("!!!!!###");
System.out.println(ScriptingFactory.functionalization(text));
System.out.println("!!!!!###");
CompiledScript compiledScript = ScriptingFactory.functionalizationCompile(text);
CacheManager.put(cache, cacheKey, compiledScript);
return compiledScript;
......
......@@ -79,4 +79,22 @@ public class JobAction extends StandardJaxrsAction {
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "根据给定的任务标识立即执行字段映射.", action = V2Projection.class)
@GET
@Path("v2/{job}/projection")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void v2Projection(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
@JaxrsParameterDescribe("标识") @PathParam("job") String job) {
ActionResult<V2Projection.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new V2Projection().execute(effectivePerson, job);
} catch (Exception e) {
LOGGER.error(e, effectivePerson, request, null);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
}
\ No newline at end of file
package com.x.processplatform.assemble.surface.jaxrs.job;
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.WrapBoolean;
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.assemble.surface.WorkCompletedControl;
import com.x.processplatform.assemble.surface.WorkControl;
import com.x.processplatform.core.entity.content.Work;
import com.x.processplatform.core.entity.content.WorkCompleted;
import com.x.processplatform.core.entity.element.Process;
import io.swagger.v3.oas.annotations.media.Schema;
class V2Projection extends BaseAction {
private static final Logger LOGGER = LoggerFactory.getLogger(V2Projection.class);
ActionResult<Wo> execute(EffectivePerson effectivePerson, String job) throws Exception {
LOGGER.debug("execute:{}.", effectivePerson::getDistinguishedName);
Process process = null;
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
Work work = emc.firstEqual(Work.class, Work.job_FIELDNAME, job);
if (null != work) {
job = work.getJob();
ControlOfWork controlOfWork = business.getControl(effectivePerson, work, ControlOfWork.class);
if (BooleanUtils.isNotTrue(controlOfWork.getAllowVisit())) {
throw new ExceptionAccessDenied(effectivePerson);
}
process = emc.find(work.getProcess(), Process.class);
if (null == process) {
throw new ExceptionEntityNotExist(job);
}
} else {
WorkCompleted workCompleted = emc.firstEqual(WorkCompleted.class, WorkCompleted.job_FIELDNAME, job);
if (null != workCompleted) {
job = workCompleted.getJob();
ControlOfWorkCompleted controlOfWorkCompleted = business.getControl(effectivePerson, workCompleted,
ControlOfWorkCompleted.class);
if (BooleanUtils.isNotTrue(controlOfWorkCompleted.getAllowVisit())) {
throw new ExceptionAccessDenied(effectivePerson);
}
process = emc.find(workCompleted.getProcess(), Process.class);
if (null == process) {
throw new ExceptionEntityNotExist(job);
}
}
}
}
Wo wo = ThisApplication.context().applications().getQuery(x_processplatform_service_processing.class,
Applications.joinQueryUri("job", "v2", job, "projection"), job).getData(Wo.class);
ActionResult<Wo> result = new ActionResult<>();
result.setData(wo);
return result;
}
@Schema(name = "com.x.processplatform.assemble.surface.jaxrs.job.V2Projection$ControlOfWork")
public static class ControlOfWork extends WorkControl {
private static final long serialVersionUID = -7502336484666914474L;
}
@Schema(name = "com.x.processplatform.assemble.surface.jaxrs.job.V2Projection$ControlOfWorkCompleted")
public static class ControlOfWorkCompleted extends WorkCompletedControl {
private static final long serialVersionUID = -1496905228538215987L;
}
@Schema(name = "com.x.processplatform.assemble.surface.jaxrs.job.V2Projection$Wo")
public static class Wo extends WrapBoolean {
private static final long serialVersionUID = -3206075665001702872L;
}
}
\ No newline at end of file
......@@ -14,6 +14,8 @@ import javax.ws.rs.container.Suspended;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import org.eclipse.jetty.client.ProxyProtocolClientConnectionFactory.V2;
import com.x.base.core.project.annotation.JaxrsDescribe;
import com.x.base.core.project.annotation.JaxrsMethodDescribe;
import com.x.base.core.project.annotation.JaxrsParameterDescribe;
......@@ -66,4 +68,22 @@ public class JobAction extends StandardJaxrsAction {
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "根据给定的任务标识立即执行字段映射.", action = V2Projection.class)
@GET
@Path("v2/{job}/projection")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void v2Projection(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
@JaxrsParameterDescribe("标识") @PathParam("job") String job) {
ActionResult<V2Projection.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new V2Projection().execute(effectivePerson, job);
} catch (Exception e) {
logger.error(e, effectivePerson, request, null);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
}
\ No newline at end of file
package com.x.processplatform.service.processing.jaxrs.job;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import org.apache.commons.lang3.BooleanUtils;
import com.google.gson.reflect.TypeToken;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.project.exception.ExceptionEntityNotExist;
import com.x.base.core.project.executor.ProcessPlatformExecutorFactory;
import com.x.base.core.project.gson.XGsonBuilder;
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.core.entity.content.Data;
import com.x.processplatform.core.entity.content.Read;
import com.x.processplatform.core.entity.content.ReadCompleted;
import com.x.processplatform.core.entity.content.Review;
import com.x.processplatform.core.entity.content.Task;
import com.x.processplatform.core.entity.content.TaskCompleted;
import com.x.processplatform.core.entity.content.Work;
import com.x.processplatform.core.entity.content.WorkCompleted;
import com.x.processplatform.core.entity.element.Process;
import com.x.processplatform.core.entity.element.Projection;
import com.x.processplatform.core.entity.element.util.ProjectionFactory;
import com.x.processplatform.service.processing.Business;
import com.x.processplatform.service.processing.WorkDataHelper;
class V2Projection extends BaseAction {
private static final Logger LOGGER = LoggerFactory.getLogger(V2Projection.class);
ActionResult<Wo> execute(EffectivePerson effectivePerson, String job) throws Exception {
LOGGER.debug("execute:{}.", effectivePerson::getDistinguishedName);
Data data = null;
Process process = null;
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Work work = emc.firstEqual(Work.class, Work.job_FIELDNAME, job);
if (null != work) {
job = work.getJob();
data = new WorkDataHelper(emc, work).get();
process = emc.find(work.getProcess(), Process.class);
} else {
WorkCompleted workCompleted = emc.firstEqual(WorkCompleted.class, WorkCompleted.job_FIELDNAME, job);
if (null != workCompleted) {
job = workCompleted.getJob();
data = BooleanUtils.isTrue(workCompleted.getMerged()) ? workCompleted.getProperties().getData()
: new WorkDataHelper(emc, workCompleted).get();
process = emc.find(workCompleted.getProcess(), Process.class);
}
}
}
if (null == process) {
throw new ExceptionEntityNotExist(job);
}
CallableImpl callable = new CallableImpl(job, data, process);
return ProcessPlatformExecutorFactory.get(job).submit(callable).get(300, TimeUnit.SECONDS);
}
private class CallableImpl implements Callable<ActionResult<Wo>> {
private Process process;
private Data data;
private String job;
private CallableImpl(String job, Data data, Process process) {
this.job = job;
this.data = data;
this.process = process;
}
@Override
public ActionResult<Wo> call() throws Exception {
ActionResult<Wo> result = new ActionResult<>();
Wo wo = new Wo();
wo.setValue(false);
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
List<Projection> projections = listProjections(process);
if (ListTools.isNotEmpty(projections)) {
projection(new Business(emc), job, data, projections);
wo.setValue(true);
}
}
result.setData(wo);
return result;
}
private void projection(Business business, String job, Data data, List<Projection> projections)
throws Exception {
EntityManagerContainer emc = business.entityManagerContainer();
emc.beginTransaction(Work.class);
emc.beginTransaction(WorkCompleted.class);
emc.beginTransaction(Task.class);
emc.beginTransaction(TaskCompleted.class);
emc.beginTransaction(Read.class);
emc.beginTransaction(ReadCompleted.class);
emc.beginTransaction(Review.class);
for (Work o : emc.listEqual(Work.class, Work.job_FIELDNAME, job)) {
ProjectionFactory.projectionWork(projections, data, o);
}
for (WorkCompleted o : emc.listEqual(WorkCompleted.class, WorkCompleted.job_FIELDNAME, job)) {
ProjectionFactory.projectionWorkCompleted(projections, data, o);
}
for (Task o : emc.listEqual(Task.class, Task.job_FIELDNAME, job)) {
ProjectionFactory.projectionTask(projections, data, o);
}
for (TaskCompleted o : emc.listEqual(TaskCompleted.class, TaskCompleted.job_FIELDNAME, job)) {
ProjectionFactory.projectionTaskCompleted(projections, data, o);
}
for (Read o : emc.listEqual(Read.class, Read.job_FIELDNAME, job)) {
ProjectionFactory.projectionRead(projections, data, o);
}
for (ReadCompleted o : emc.listEqual(ReadCompleted.class, ReadCompleted.job_FIELDNAME, job)) {
ProjectionFactory.projectionReadCompleted(projections, data, o);
}
for (Review o : emc.listEqual(Review.class, Review.job_FIELDNAME, job)) {
ProjectionFactory.projectionReview(projections, data, o);
}
emc.commit();
}
private List<Projection> listProjections(Process process) {
List<Projection> list = new ArrayList<>();
String text = process.getProjection();
if (XGsonBuilder.isJsonArray(text)) {
list = XGsonBuilder.instance().fromJson(text, new TypeToken<List<Projection>>() {
}.getType());
}
return list;
}
}
public static class Wo extends WrapBoolean {
private static final long serialVersionUID = -3206075665001702872L;
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册