All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
class-templates.RestResourceUserTaskTemplate Maven / Gradle / Ivy
package com.myspace.demo;
import java.util.List;
import org.drools.core.WorkItemNotFoundException;
import org.jbpm.util.JsonSchemaUtil;
import org.kie.kogito.process.ProcessInstance;
import org.kie.kogito.process.WorkItem;
import org.kie.kogito.process.impl.Sig;
public class $Type$Resource {
@POST
@Path("/{id}/$taskName$")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public javax.ws.rs.core.Response signal(@PathParam("id") final String id) {
return org.kie.kogito.services.uow.UnitOfWorkExecutor.executeInUnitOfWork(application.unitOfWorkManager(), () -> {
ProcessInstance<$Type$> pi = process.instances().findById(id).orElse(null);
if (pi == null) {
return null;
}
pi.send(Sig.of("$taskNodeName$", java.util.Collections.emptyMap()));
java.util.Optional task = pi.workItems().stream().filter(wi -> wi.getName().equals("$taskName$")).findFirst();
if(task.isPresent()) {
return javax.ws.rs.core.Response.ok(getModel(pi))
.header("Link", "" + id + "/$taskName$/" + task.get().getId() + ">; rel='instance'")
.build();
}
return javax.ws.rs.core.Response.status(javax.ws.rs.core.Response.Status.NOT_FOUND).build();
});
}
@POST()
@Path("/{id}/$taskName$/{workItemId}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public $Type$Output completeTask(@PathParam("id") final String id, @PathParam("workItemId") final String workItemId, @QueryParam("phase") @DefaultValue("complete") final String phase, @QueryParam("user") final String user, @QueryParam("group") final List groups, final $TaskOutput$ model) {
try {
return org.kie.kogito.services.uow.UnitOfWorkExecutor.executeInUnitOfWork(application.unitOfWorkManager(), () -> {
ProcessInstance<$Type$> pi = process.instances().findById(id).orElse(null);
if (pi == null) {
return null;
}
org.kie.kogito.auth.IdentityProvider identity = null;
if (user != null) {
identity = new org.kie.kogito.services.identity.StaticIdentityProvider(user, groups);
}
org.jbpm.process.instance.impl.humantask.HumanTaskTransition transition = new org.jbpm.process.instance.impl.humantask.HumanTaskTransition(phase, model.toMap(), identity);
pi.transitionWorkItem(workItemId, transition);
return getModel(pi);
});
} catch (WorkItemNotFoundException e) {
return null;
}
}
@GET()
@Path("/{id}/$taskName$/{workItemId}")
@Produces(MediaType.APPLICATION_JSON)
public $TaskInput$ getTask(@PathParam("id") String id, @PathParam("workItemId") String workItemId, @QueryParam("user") final String user, @QueryParam("group") final List groups) {
try {
ProcessInstance<$Type$> pi = process.instances().findById(id).orElse(null);
if (pi == null) {
return null;
}
WorkItem workItem = pi.workItem(workItemId, policies(user, groups));
if (workItem == null) {
return null;
}
return $TaskInput$.fromMap(workItem.getId(), workItem.getName(), workItem.getParameters());
} catch (WorkItemNotFoundException e) {
return null;
}
}
@GET()
@Path("$taskName$/schema")
@Produces(MediaType.APPLICATION_JSON)
public Map getSchema() {
return JsonSchemaUtil.load(this.getClass().getClassLoader(), process.id(), "$taskName$");
}
@GET()
@Path("/{id}/$taskName$/{workItemId}/schema")
@Produces(MediaType.APPLICATION_JSON)
public Map getSchemaAndPhases(@PathParam("id") final String id,
@PathParam("workItemId") final String workItemId,
@QueryParam("user") final String user,
@QueryParam("group") final List groups) {
return JsonSchemaUtil.addPhases(process, application, id, workItemId, policies(user, groups), JsonSchemaUtil.load(this.getClass().getClassLoader(), process.id(), "$taskName$"));
}
@DELETE()
@Path("/{id}/$taskName$/{workItemId}")
@Produces(MediaType.APPLICATION_JSON)
public $Type$Output abortTask(@PathParam("id") final String id, @PathParam("workItemId") final String workItemId, @QueryParam("phase") @DefaultValue("abort") final String phase, @QueryParam("user") final String user, @QueryParam("group") final List groups) {
try {
return org.kie.kogito.services.uow.UnitOfWorkExecutor.executeInUnitOfWork(application.unitOfWorkManager(), () -> {
ProcessInstance<$Type$> pi = process.instances().findById(id).orElse(null);
if (pi == null) {
return null;
}
org.kie.kogito.auth.IdentityProvider identity = null;
if (user != null) {
identity = new org.kie.kogito.services.identity.StaticIdentityProvider(user, groups);
}
org.jbpm.process.instance.impl.humantask.HumanTaskTransition transition = new org.jbpm.process.instance.impl.humantask.HumanTaskTransition(phase, null, identity);
pi.transitionWorkItem(workItemId, transition);
return getModel(pi);
});
} catch (WorkItemNotFoundException e) {
return null;
}
}
}