Commit 14a2f74a authored by Brian Long's avatar Brian Long
Browse files

added ProcessInstanceApi and ExecutionApi

parent 24ad70c2
Loading
Loading
Loading
Loading
+225 −0
Original line number Diff line number Diff line
/*
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or (at your
 * option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <https://www.gnu.org/licenses/>.
 */
package com.inteligr8.activiti.api;

import java.util.List;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.inteligr8.activiti.model.Action;
import com.inteligr8.activiti.model.Action.ActionValue;
import com.inteligr8.activiti.model.Execution;
import com.inteligr8.activiti.model.ResultList;
import com.inteligr8.activiti.model.SignalEventAction;
import com.inteligr8.activiti.model.SortOrder;
import com.inteligr8.activiti.model.Variable;

@Path("/api/runtime/executions")
public interface ExecutionApi {
    
    public enum Sort {
        @JsonProperty("id")
        ProcessInstanceId,
        @JsonProperty("processDefinitionId")
        ProcessDefinitionId,
        @JsonProperty("tenantId")
        TenantId,
        @JsonProperty("processDefinitionKey")
        ProcessDefinitionKey;
    }
    
    public enum VariableScope {
        @JsonProperty("local")
        Local,
        @JsonProperty("global")
        Global,
    }

    @GET
    @Path("{executionId}")
    @Produces({ MediaType.APPLICATION_JSON })
    Execution get(
            @PathParam("executionId") String executionId);

    @GET
    @Path("{executionId}/activities")
    @Produces({ MediaType.APPLICATION_JSON })
    List<String> getActiveActivities(
            @PathParam("executionId") String executionId);

    default Execution signal(
            String processInstanceId,
            List<Variable> variables) {
        Action action = new Action(ActionValue.Signal);
        if (variables != null && !variables.isEmpty())
            action.setVariables(variables);
        return this.execute(processInstanceId, action);
    }

    default Execution signalReceived(
            String processInstanceId,
            String signal,
            List<Variable> variables) {
        Action action = new SignalEventAction(ActionValue.SignalReceived, signal);
        if (variables != null && !variables.isEmpty())
            action.setVariables(variables);
        return this.execute(processInstanceId, action);
    }

    default Execution messageReceived(
            String processInstanceId,
            String message,
            List<Variable> variables) {
        Action action = new SignalEventAction(ActionValue.MessageReceived, message);
        if (variables != null && !variables.isEmpty())
            action.setVariables(variables);
        return this.execute(processInstanceId, action);
    }

    @PUT
    @Path("{executionId}")
    @Consumes({ MediaType.APPLICATION_JSON })
    @Produces({ MediaType.APPLICATION_JSON })
    Execution execute(
            @PathParam("executionId") String executionId,
            Action action);

    default ResultList<Execution> getWithoutTenant(
            String executionId,
            String activityId,
            String processDefinitionKey,
            String processDefinitionId,
            String processInstanceId,
            String messageEventSubscriptionName,
            String signalEventSubscriptionName,
            String parentId,
            Sort sort,
            SortOrder sortOrder,
            Integer pageStart,
            Integer pageSize) {
        return this.getByAny(executionId, activityId, processDefinitionKey, processDefinitionId, processInstanceId,
                messageEventSubscriptionName, signalEventSubscriptionName, parentId, null, null, true,
                sort, sortOrder, pageStart, pageSize);
    }

    default ResultList<Execution> getByTenant(
            String executionId,
            String activityId,
            String processDefinitionKey,
            String processDefinitionId,
            String processInstanceId,
            String messageEventSubscriptionName,
            String signalEventSubscriptionName,
            String parentId,
            String tenantId,
            Sort sort,
            SortOrder sortOrder,
            Integer pageStart,
            Integer pageSize) {
        return this.getByAny(executionId, activityId, processDefinitionKey, processDefinitionId, processInstanceId,
                messageEventSubscriptionName, signalEventSubscriptionName, parentId, tenantId, null, false,
                sort, sortOrder, pageStart, pageSize);
    }

    default ResultList<Execution> getByTenants(
            String executionId,
            String activityId,
            String processDefinitionKey,
            String processDefinitionId,
            String processInstanceId,
            String messageEventSubscriptionName,
            String signalEventSubscriptionName,
            String parentId,
            String tenantIdLike,
            Sort sort,
            SortOrder sortOrder,
            Integer pageStart,
            Integer pageSize) {
        return this.getByAny(executionId, activityId, processDefinitionKey, processDefinitionId, processInstanceId,
                messageEventSubscriptionName, signalEventSubscriptionName, parentId, null, tenantIdLike, false,
                sort, sortOrder, pageStart, pageSize);
    }

    @GET
    @Produces({ MediaType.APPLICATION_JSON })
    public ResultList<Execution> getByAny(
            @QueryParam("id") String executionId,
            @QueryParam("activityId") String activityId,
            @QueryParam("processDefinitionKey") String processDefinitionKey,
            @QueryParam("processDefinitionId") String processDefinitionId,
            @QueryParam("processInstanceId") String processInstanceId,
            @QueryParam("messageEventSubscriptionName") String messageEventSubscriptionName,
            @QueryParam("signalEventSubscriptionName") String signalEventSubscriptionName,
            @QueryParam("parentId") String parentId,
            @QueryParam("tenantId") String tenantId,
            @QueryParam("tenantIdLike") String tenantIdLike,
            @QueryParam("withoutTenantId") Boolean withoutTenantId,
            @QueryParam("sort") Sort sort,
            @QueryParam("order") SortOrder sortOrder,
            @QueryParam("start") Integer pageStart,
            @QueryParam("size") Integer pageSize);

    @GET
    @Path("{executionId}/variables")
    @Produces({ MediaType.APPLICATION_JSON })
    List<Variable> getVariables(
            @PathParam("executionId") String executionId,
            @QueryParam("scope") VariableScope scope);

    @GET
    @Path("{executionId}/variables/{variableName}")
    @Produces({ MediaType.APPLICATION_JSON })
    Variable getVariable(
            @PathParam("executionId") String executionId,
            @PathParam("variableName") String variableName);

    @POST
    @Path("{executionId}/variables")
    @Consumes({ MediaType.APPLICATION_JSON })
    void createVariables(
            @PathParam("executionId") String executionId,
            List<Variable> variables);

    @PUT
    @Path("{executionId}/variables")
    @Consumes({ MediaType.APPLICATION_JSON })
    void updateVariables(
            @PathParam("executionId") String executionId,
            List<Variable> variables);

    default void updateVariable(
            String executionId,
            Variable variable) {
        this.updateVariable(executionId, variable.getName(), variable);
    }
    
    @PUT
    @Path("{executionId}/variables/{variableName}")
    @Consumes({ MediaType.APPLICATION_JSON })
    void updateVariable(
            @PathParam("executionId") String executionId,
            @PathParam("variableName") String variableName,
            Variable variable); 

}
+139 −121
Original line number Diff line number Diff line
@@ -25,89 +25,111 @@ import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.inteligr8.activiti.model.Action;
import com.inteligr8.activiti.model.Action.ActionValue;
import com.inteligr8.activiti.model.Engine;
import com.inteligr8.activiti.model.EngineProperties;
import com.inteligr8.activiti.model.ExecuteAction;
import com.inteligr8.activiti.model.ExecuteAction.Action;
import com.inteligr8.activiti.model.Job;
import com.inteligr8.activiti.model.ResultList;

@Path("/api/management")
public interface ManagementApi {

    public enum JobType {
        @JsonProperty("jobs")
        Job,
        @JsonProperty("deadletter-jobs")
        DeadletterJob
    }

    @GET
    @Path("engine")
    @Produces({ "application/json" })
    @Produces({ MediaType.APPLICATION_JSON })
    public Engine getEngine();

    @GET
    @Path("properties")
    @Produces({ "application/json" })
    @Produces({ MediaType.APPLICATION_JSON })
    public EngineProperties getEngineProperties();
    
    
    
    @Path("jobs")
    public interface JobsApiImpl extends JobsApi {}
    
    @Path("timer-jobs")
    public interface TimerJobsApiImpl extends JobsApi {}
    
    @Path("deadletter-jobs")
    public interface DeadletterJobsApiImpl extends JobsApi {}
    
    public interface JobsApi {
        
        @GET
    @Path("{jobType}/{jobId}")
    @Produces({ "application/json" })
        @Path("{jobId}")
        @Produces({ MediaType.APPLICATION_JSON })
        public Job getJob(
            @PathParam("jobType") JobType jobType,
                @PathParam("jobId") String jobId);
        
        @DELETE
    @Path("{jobType}/{jobId}")
        @Path("{jobId}")
        public void deleteJob(
            @PathParam("jobType") JobType jobType,
                @PathParam("jobId") String jobId);
        
        @POST
    @Path("{jobType}/{jobId}")
    @Consumes({ "application/json" })
        @Path("{jobId}")
        @Consumes({ MediaType.APPLICATION_JSON })
        public void executeJob(
            @PathParam("jobType") JobType jobType,
                @PathParam("jobId") String jobId,
            ExecuteAction execute);
                Action execute);
        
        default void executeJob(
            JobType jobType,
                String jobId,
            Action action) {
        this.executeJob(jobType, jobId, new ExecuteAction(action));
                ActionValue action) {
            this.executeJob(jobId, new Action(action));
        }
        
        default void executeJob(
            JobType jobType,
                String jobId) {
        this.executeJob(jobType, jobId, new ExecuteAction(Action.Execute));
            this.executeJob(jobId, new Action(ActionValue.Execute));
        }
        
        @GET
    @Path("{jobType}/{jobId}/execution-stacktrace")
    @Produces({ "application/octet-stream" })
        @Path("{jobId}/execution-stacktrace")
        @Produces({ MediaType.APPLICATION_OCTET_STREAM })
        public File getJobStacktrace(
            @PathParam("jobType") JobType jobType,
                @PathParam("jobId") String jobId);
        
        @GET
    @Path("{jobType}")
    @Produces({ "application/json" })
        @Produces({ MediaType.APPLICATION_JSON })
        public ResultList<Job> queryJobs(
                @QueryParam("processInstanceId") String processInstanceId,
                @QueryParam("executionId") String executionId,
                @QueryParam("processDefinitionId") String processDefinitionId,
                @QueryParam("withRetriesLeft") Boolean withRetriesLeft,
                @QueryParam("executable") Boolean executable,
                @QueryParam("dueBefore") LocalDate dueBefore,
                @QueryParam("dueAfter") LocalDate dueAfter,
                @QueryParam("withoutTenantId") Boolean withoutTenatId,
                @QueryParam("sort") String sort);
        
        @GET
        @Produces({ MediaType.APPLICATION_JSON })
        public ResultList<Job> queryJobs(
                @QueryParam("processInstanceId") String processInstanceId,
                @QueryParam("executionId") String executionId,
                @QueryParam("processDefinitionId") String processDefinitionId,
                @QueryParam("withRetriesLeft") Boolean withRetriesLeft,
                @QueryParam("executable") Boolean executable,
                @QueryParam("dueBefore") LocalDate dueBefore,
                @QueryParam("dueAfter") LocalDate dueAfter,
                @QueryParam("tenantId") String tenantId,
                @QueryParam("tenantIdLike") String tenantIdLike,
                @QueryParam("sort") String sort);
        
        @GET
        @Produces({ MediaType.APPLICATION_JSON })
        public ResultList<Job> queryJobs(
            @PathParam("jobType") JobType jobType,
            @QueryParam("id") String jobId,
                @QueryParam("processInstanceId") String processInstanceId,
                @QueryParam("executionId") String executionId,
                @QueryParam("processDefinitionId") String processDefinitionId,
                @QueryParam("withRetriesLeft") Boolean withRetriesLeft,
                @QueryParam("executable") Boolean executable,
            @QueryParam("timersOnly") Boolean timersOnly,
            @QueryParam("messagesOnly") Boolean messagesOnly,
                @QueryParam("withException") Boolean withException,
                @QueryParam("dueBefore") LocalDate dueBefore,
                @QueryParam("dueAfter") LocalDate dueAfter,
@@ -116,18 +138,13 @@ public interface ManagementApi {
                @QueryParam("sort") String sort);
        
        @GET
    @Path("{jobType}")
    @Produces({ "application/json" })
        @Produces({ MediaType.APPLICATION_JSON })
        public ResultList<Job> queryJobs(
            @PathParam("jobType") JobType jobType,
            @QueryParam("id") String jobId,
                @QueryParam("processInstanceId") String processInstanceId,
                @QueryParam("executionId") String executionId,
                @QueryParam("processDefinitionId") String processDefinitionId,
                @QueryParam("withRetriesLeft") Boolean withRetriesLeft,
                @QueryParam("executable") Boolean executable,
            @QueryParam("timersOnly") Boolean timersOnly,
            @QueryParam("messagesOnly") Boolean messagesOnly,
                @QueryParam("withException") Boolean withException,
                @QueryParam("dueBefore") LocalDate dueBefore,
                @QueryParam("dueAfter") LocalDate dueAfter,
@@ -136,8 +153,9 @@ public interface ManagementApi {
                @QueryParam("tenantIdLike") String tenantIdLike,
                @QueryParam("sort") String sort);
        
    default ResultList<Job> queryTimerJobs(
            JobType jobType,
        @GET
        @Produces({ MediaType.APPLICATION_JSON })
        public ResultList<Job> queryJobs(
                @QueryParam("id") String jobId,
                @QueryParam("processInstanceId") String processInstanceId,
                @QueryParam("executionId") String executionId,
@@ -148,13 +166,12 @@ public interface ManagementApi {
                @QueryParam("dueBefore") LocalDate dueBefore,
                @QueryParam("dueAfter") LocalDate dueAfter,
                @QueryParam("exceptionMessage") String exceptionMessage,
            @QueryParam("withoutTenantId") Boolean withoutTenantId,
            @QueryParam("sort") String sort) {
        return this.queryJobs(jobType, jobId, processInstanceId, executionId, processDefinitionId, withRetriesLeft, executable, true, false, withException, dueBefore, dueAfter, exceptionMessage, withoutTenantId, sort);
    }
                @QueryParam("withoutTenantId") Boolean withoutTenatId,
                @QueryParam("sort") String sort);
        
    default ResultList<Job> queryMessagesJobs(
            JobType jobType,
        @GET
        @Produces({ MediaType.APPLICATION_JSON })
        public ResultList<Job> queryJobs(
                @QueryParam("id") String jobId,
                @QueryParam("processInstanceId") String processInstanceId,
                @QueryParam("executionId") String executionId,
@@ -165,9 +182,10 @@ public interface ManagementApi {
                @QueryParam("dueBefore") LocalDate dueBefore,
                @QueryParam("dueAfter") LocalDate dueAfter,
                @QueryParam("exceptionMessage") String exceptionMessage,
            @QueryParam("withoutTenantId") Boolean withoutTenantId,
            @QueryParam("sort") String sort) {
        return this.queryJobs(jobType, jobId, processInstanceId, executionId, processDefinitionId, withRetriesLeft, executable, false, true, withException, dueBefore, dueAfter, exceptionMessage, withoutTenantId, sort);
                @QueryParam("tenantId") String tenantId,
                @QueryParam("tenantIdLike") String tenantIdLike,
                @QueryParam("sort") String sort);
        
    }

}
+214 −0

File added.

Preview size limit exceeded, changes collapsed.

+38 −0
Original line number Diff line number Diff line
/*
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or (at your
 * option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <https://www.gnu.org/licenses/>.
 */
package com.inteligr8.activiti.api;

import java.util.List;

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.MediaType;

import com.inteligr8.activiti.model.Variable;

@Path("/api/runtime")
public interface RuntimeApi {

    @POST
    @Path("signals")
    @Consumes({ MediaType.APPLICATION_JSON })
    void signalReceived(
            String signal,
            String tenantId,
            Boolean async,
            List<Variable> variables);

}
+67 −0
Original line number Diff line number Diff line
package com.inteligr8.activiti.model;

import java.util.List;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;

@JsonInclude(JsonInclude.Include.NON_NULL)
public class Action {

    public enum ActionValue {
        @JsonProperty("execute")
        Execute,
        @JsonProperty("suspend")
        Suspend,
        @JsonProperty("activate")
        Activate,
        @JsonProperty("signal")
        Signal,
        @JsonProperty("signalEventReceived")
        SignalReceived,
        @JsonProperty("messageEventReceived")
        MessageReceived
    }
    
    @JsonProperty("action")
    private ActionValue action;
    @JsonProperty("variables")
    private List<Variable> variables;

    /**
     * No args constructor for use in serialization
     */
    public Action() {
    }
    
    public Action(ActionValue action) {
        this.action = action;
    }

    public ActionValue getAction() {
        return action;
    }

    public void setAction(ActionValue action) {
        this.action = action;
    }

	public Action withAction(ActionValue action) {
        this.action = action;
        return this;
    }
	
	public List<Variable> getVariables() {
        return variables;
    }
	
	public void setVariables(List<Variable> variables) {
        this.variables = variables;
    }
    
    public Action withVariables(List<Variable> variables) {
        this.variables = variables;
        return this;
    }

}
Loading