Skip to content

Commit

Permalink
Filter jobs by handlerType over REST (#3713)
Browse files Browse the repository at this point in the history
  • Loading branch information
amporsim committed Aug 29, 2023
1 parent 0a57281 commit 67ae239
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,7 @@ public JobResponse createJobResponse(Job job, RestUrlBuilder urlBuilder, String[
response.setTenantId(job.getTenantId());
response.setElementId(job.getElementId());
response.setElementName(job.getElementName());
response.setHandlerType(job.getJobHandlerType());

response.setUrl(urlBuilder.buildUrl(urlJobSegments, job.getId()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class JobResponse {
protected String planItemInstanceId;
protected String elementId;
protected String elementName;
protected String handlerType;
protected Integer retries;
protected String exceptionMessage;
@JsonSerialize(using = DateToStringSerializer.class, as = Date.class)
Expand Down Expand Up @@ -127,6 +128,15 @@ public void setElementName(String elementName) {
this.elementName = elementName;
}

public void setHandlerType(String handlerType) {
this.handlerType = handlerType;
}

@ApiModelProperty(example = "cmmn-trigger-timer")
public String getHandlerType() {
return handlerType;
}

@ApiModelProperty(example = "3")
public Integer getRetries() {
return retries;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public void testGetTimerJob() throws Exception {
+ "caseInstanceId: '" + timerJob.getScopeId() + "',"
+ "elementId: 'timerListener',"
+ "elementName: 'Timer listener',"
+ "handlerType: 'cmmn-trigger-timer',"
+ "retries: " + timerJob.getRetries() + ","
+ "dueDate: " + new TextNode(getISODateStringWithTZ(timerJob.getDuedate())) + ","
+ "tenantId: ''"
Expand Down Expand Up @@ -109,6 +110,7 @@ public void testGetDeadLetterJob() throws Exception {
+ "caseInstanceId: '" + deadLetterJob.getScopeId() + "',"
+ "elementId: 'timerListener',"
+ "elementName: 'Timer listener',"
+ "handlerType: 'cmmn-trigger-timer',"
+ "retries: " + deadLetterJob.getRetries() + ","
+ "dueDate: " + new TextNode(getISODateStringWithTZ(deadLetterJob.getDuedate())) + ","
+ "tenantId: ''"
Expand Down Expand Up @@ -167,6 +169,7 @@ public Void execute(CommandContext commandContext) {
+ "caseInstanceId: '" + lockedJob.getScopeId() + "',"
+ "elementId: 'timerListener',"
+ "elementName: 'Timer listener',"
+ "handlerType: 'cmmn-trigger-timer',"
+ "retries: " + lockedJob.getRetries() + ","
+ "dueDate: " + new TextNode(getISODateStringWithTZ(lockedJob.getDuedate())) + ","
+ "lockOwner: 'test',"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,7 @@ protected JobResponse createJobResponse(Job job, RestUrlBuilder urlBuilder, Stri
response.setElementName(job.getElementName());
response.setRetries(job.getRetries());
response.setCreateTime(job.getCreateTime());
response.setHandlerType(job.getJobHandlerType());
if (job instanceof JobInfoEntity) {
JobInfoEntity jobInfoEntity = (JobInfoEntity) job;
response.setLockOwner(jobInfoEntity.getLockOwner());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import static org.flowable.common.rest.api.PaginateListUtil.paginateList;

import java.util.Arrays;
import java.util.Map;

import org.flowable.common.engine.api.FlowableIllegalArgumentException;
Expand Down Expand Up @@ -63,6 +64,8 @@ public class DeadLetterJobCollectionResource {
@ApiImplicitParam(name = "processDefinitionId", dataType = "string", value = "Only return jobs with the given process definition id", paramType = "query"),
@ApiImplicitParam(name = "elementId", dataType = "string", value = "Only return jobs with the given element id", paramType = "query"),
@ApiImplicitParam(name = "elementName", dataType = "string", value = "Only return jobs with the given element name", paramType = "query"),
@ApiImplicitParam(name = "handlerType", dataType = "string", value = "Only return jobs with the given handler type", paramType = "query"),
@ApiImplicitParam(name = "handlerTypes", dataType = "string", value = "Only return jobs which have one of the given job handler type", paramType = "query"),
@ApiImplicitParam(name = "executable", dataType = "boolean", value = "If true, only return jobs which are executable. If false, this parameter is ignored.", paramType = "query"),
@ApiImplicitParam(name = "timersOnly", dataType = "boolean", value = "If true, only return jobs which are timers. If false, this parameter is ignored. Cannot be used together with 'messagesOnly'.", paramType = "query"),
@ApiImplicitParam(name = "messagesOnly", dataType = "boolean", value = "If true, only return jobs which are messages. If false, this parameter is ignored. Cannot be used together with 'timersOnly'", paramType = "query"),
Expand Down Expand Up @@ -108,6 +111,12 @@ public DataResponse<JobResponse> getJobs(@ApiParam(hidden = true) @RequestParam
if (allRequestParams.containsKey("elementName")) {
query.elementName(allRequestParams.get("elementName"));
}
if (allRequestParams.containsKey("handlerType")) {
query.handlerType(allRequestParams.get("handlerType"));
}
if (allRequestParams.containsKey("handlerTypes")) {
query.handlerTypes(Arrays.asList(allRequestParams.get("handlerTypes").split(",")));
}
if (allRequestParams.containsKey("executable")) {
query.executable();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import static org.flowable.common.rest.api.PaginateListUtil.paginateList;

import java.util.Arrays;
import java.util.Map;

import org.flowable.common.rest.api.DataResponse;
Expand Down Expand Up @@ -58,6 +59,8 @@ public class HistoryJobCollectionResource {
@ApiImplicitParam(name = "withException", dataType = "boolean", value = "If true, only return jobs for which an exception occurred while executing it. If false, this parameter is ignored.", paramType = "query"),
@ApiImplicitParam(name = "exceptionMessage", dataType = "string", value = "Only return jobs with the given exception message", paramType = "query"),
@ApiImplicitParam(name = "scopeType", dataType = "string", value = "Only return jobs with the given scope type", paramType = "query"),
@ApiImplicitParam(name = "handlerType", dataType = "string", value = "Only return jobs with the given handler type", paramType = "query"),
@ApiImplicitParam(name = "handlerTypes", dataType = "string", value = "Only return jobs which have one of the given job handler type", paramType = "query"),
@ApiImplicitParam(name = "tenantId", dataType = "string", value = "Only return jobs with the given tenantId.", paramType = "query"),
@ApiImplicitParam(name = "tenantIdLike", dataType = "string", value = "Only return jobs with a tenantId like the given value.", paramType = "query"),
@ApiImplicitParam(name = "withoutTenantId", dataType = "boolean", value = "If true, only returns jobs without a tenantId set. If false, the withoutTenantId parameter is ignored.", paramType = "query"),
Expand All @@ -80,6 +83,12 @@ public DataResponse<HistoryJobResponse> getHistoryJobs(@ApiParam(hidden = true)
if (allRequestParams.containsKey("scopeType")) {
query.jobId(allRequestParams.get("scopeType"));
}
if (allRequestParams.containsKey("handlerType")) {
query.handlerType(allRequestParams.get("handlerType"));
}
if (allRequestParams.containsKey("handlerTypes")) {
query.handlerTypes(Arrays.asList(allRequestParams.get("handlerTypes").split(",")));
}
if (allRequestParams.containsKey("withException")) {
if (Boolean.parseBoolean(allRequestParams.get("withException"))) {
query.withException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import static org.flowable.common.rest.api.PaginateListUtil.paginateList;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -81,6 +82,8 @@ public class JobCollectionResource {
@ApiImplicitParam(name = "processDefinitionId", dataType = "string", value = "Only return jobs with the given process definition id", paramType = "query"),
@ApiImplicitParam(name = "elementId", dataType = "string", value = "Only return jobs with the given element id", paramType = "query"),
@ApiImplicitParam(name = "elementName", dataType = "string", value = "Only return jobs with the given element name", paramType = "query"),
@ApiImplicitParam(name = "handlerType", dataType = "string", value = "Only return jobs with the given handler type", paramType = "query"),
@ApiImplicitParam(name = "handlerTypes", dataType = "string", value = "Only return jobs which have one of the given job handler type", paramType = "query"),
@ApiImplicitParam(name = "timersOnly", dataType = "boolean", value = "If true, only return jobs which are timers. If false, this parameter is ignored. Cannot be used together with 'messagesOnly'.", paramType = "query"),
@ApiImplicitParam(name = "messagesOnly", dataType = "boolean", value = "If true, only return jobs which are messages. If false, this parameter is ignored. Cannot be used together with 'timersOnly'", paramType = "query"),
@ApiImplicitParam(name = "withException", dataType = "boolean", value = "If true, only return jobs for which an exception occurred while executing it. If false, this parameter is ignored.", paramType = "query"),
Expand Down Expand Up @@ -125,6 +128,12 @@ public DataResponse<JobResponse> getJobs(@ApiParam(hidden = true) @RequestParam
if (allRequestParams.containsKey("elementName")) {
query.elementName(allRequestParams.get("elementName"));
}
if (allRequestParams.containsKey("handlerType")) {
query.handlerType(allRequestParams.get("handlerType"));
}
if (allRequestParams.containsKey("handlerTypes")) {
query.handlerTypes(Arrays.asList(allRequestParams.get("handlerTypes").split(",")));
}
if (allRequestParams.containsKey("timersOnly")) {
if (allRequestParams.containsKey("messagesOnly")) {
throw new FlowableIllegalArgumentException("Only one of 'timersOnly' or 'messagesOnly' can be provided.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class JobResponse {
protected String executionUrl;
protected String elementId;
protected String elementName;
protected String handlerType;
protected Integer retries;
protected String exceptionMessage;
@JsonSerialize(using = DateToStringSerializer.class, as = Date.class)
Expand Down Expand Up @@ -147,6 +148,15 @@ public void setElementName(String elementName) {
this.elementName = elementName;
}

@ApiModelProperty(example = "trigger-timer")
public String getHandlerType() {
return handlerType;
}

public void setHandlerType(String handlerType) {
this.handlerType = handlerType;
}

@ApiModelProperty(example = "3")
public Integer getRetries() {
return retries;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import static org.flowable.common.rest.api.PaginateListUtil.paginateList;

import java.util.Arrays;
import java.util.Map;

import org.flowable.common.engine.api.FlowableIllegalArgumentException;
Expand Down Expand Up @@ -64,6 +65,8 @@ public class SuspendedJobCollectionResource {
@ApiImplicitParam(name = "processDefinitionId", dataType = "string", value = "Only return jobs with the given process definition id", paramType = "query"),
@ApiImplicitParam(name = "elementId", dataType = "string", value = "Only return jobs with the given element id", paramType = "query"),
@ApiImplicitParam(name = "elementName", dataType = "string", value = "Only return jobs with the given element name", paramType = "query"),
@ApiImplicitParam(name = "handlerType", dataType = "string", value = "Only return jobs with the given handler type", paramType = "query"),
@ApiImplicitParam(name = "handlerTypes", dataType = "string", value = "Only return jobs which have one of the given job handler type", paramType = "query"),
@ApiImplicitParam(name = "executable", dataType = "boolean", value = "If true, only return jobs which are executable. If false, this parameter is ignored.", paramType = "query"),
@ApiImplicitParam(name = "timersOnly", dataType = "boolean", value = "If true, only return jobs which are timers. If false, this parameter is ignored. Cannot be used together with 'messagesOnly'.", paramType = "query"),
@ApiImplicitParam(name = "messagesOnly", dataType = "boolean", value = "If true, only return jobs which are messages. If false, this parameter is ignored. Cannot be used together with 'timersOnly'", paramType = "query"),
Expand Down Expand Up @@ -109,6 +112,12 @@ public DataResponse<JobResponse> getJobs(@ApiParam(hidden = true) @RequestParam
if (allRequestParams.containsKey("elementName")) {
query.elementName(allRequestParams.get("elementName"));
}
if (allRequestParams.containsKey("handlerType")) {
query.handlerType(allRequestParams.get("handlerType"));
}
if (allRequestParams.containsKey("handlerTypes")) {
query.handlerTypes(Arrays.asList(allRequestParams.get("handlerTypes").split(",")));
}
if (allRequestParams.containsKey("executable")) {
query.executable();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import static org.flowable.common.rest.api.PaginateListUtil.paginateList;

import java.util.Arrays;
import java.util.Map;

import org.flowable.common.engine.api.FlowableIllegalArgumentException;
Expand Down Expand Up @@ -64,6 +65,8 @@ public class TimerJobCollectionResource {
@ApiImplicitParam(name = "processDefinitionId", dataType = "string", value = "Only return jobs with the given process definition id", paramType = "query"),
@ApiImplicitParam(name = "elementId", dataType = "string", value = "Only return jobs with the given element id", paramType = "query"),
@ApiImplicitParam(name = "elementName", dataType = "string", value = "Only return jobs with the given element name", paramType = "query"),
@ApiImplicitParam(name = "handlerType", dataType = "string", value = "Only return jobs with the given handler type", paramType = "query"),
@ApiImplicitParam(name = "handlerTypes", dataType = "string", value = "Only return jobs which have one of the given job handler type", paramType = "query"),
@ApiImplicitParam(name = "executable", dataType = "boolean", value = "If true, only return jobs which are executable. If false, this parameter is ignored.", paramType = "query"),
@ApiImplicitParam(name = "timersOnly", dataType = "boolean", value = "If true, only return jobs which are timers. If false, this parameter is ignored. Cannot be used together with 'messagesOnly'.", paramType = "query"),
@ApiImplicitParam(name = "messagesOnly", dataType = "boolean", value = "If true, only return jobs which are messages. If false, this parameter is ignored. Cannot be used together with 'timersOnly'", paramType = "query"),
Expand Down Expand Up @@ -106,6 +109,12 @@ public DataResponse<JobResponse> getJobs(@ApiParam(hidden = true) @RequestParam
if (allRequestParams.containsKey("elementId")) {
query.elementId(allRequestParams.get("elementId"));
}
if (allRequestParams.containsKey("handlerType")) {
query.handlerType(allRequestParams.get("handlerType"));
}
if (allRequestParams.containsKey("handlerTypes")) {
query.handlerTypes(Arrays.asList(allRequestParams.get("handlerTypes").split(",")));
}
if (allRequestParams.containsKey("elementName")) {
query.elementName(allRequestParams.get("elementName"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,18 @@ public void testGetJobs() throws Exception {
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TIMER_JOB_COLLECTION) + "?withoutScopeId=true";
assertResultsPresentInDataResponse(url, timerJob.getId());

url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TIMER_JOB_COLLECTION) + "?handlerType=trigger-timer";
assertResultsPresentInDataResponse(url, timerJob.getId());

url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TIMER_JOB_COLLECTION) + "?handlerType=unknown-type";
assertResultsPresentInDataResponse(url);

url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TIMER_JOB_COLLECTION) + "?handlerTypes=unknown-type,trigger-timer";
assertResultsPresentInDataResponse(url, timerJob.getId());

url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TIMER_JOB_COLLECTION) + "?handlerTypes=unknown-type";
assertResultsPresentInDataResponse(url);

Job timerJob2 = managementService.createTimerJobQuery().processInstanceId(processInstance.getId()).timers().singleResult();
for (int i = 0; i < timerJob2.getRetries(); i++) {
// Force execution of job until retries are exhausted
Expand Down Expand Up @@ -301,6 +313,32 @@ public void testGetJobs() throws Exception {
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB_COLLECTION) + "?tenantIdLike=anotherTenant";
assertResultsPresentInDataResponse(url);

// Handler type(s)
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB_COLLECTION) + "?handlerType=async-continuation";
assertResultsPresentInDataResponse(url, asyncJob.getId());

url = RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB_COLLECTION) + "?handlerType=unknown-type";
assertResultsPresentInDataResponse(url);

url = RestUrls.createRelativeResourceUrl(RestUrls.URL_DEADLETTER_JOB_COLLECTION) + "?handlerType=trigger-timer";
assertResultsPresentInDataResponse(url, timerJob.getId());

url = RestUrls.createRelativeResourceUrl(RestUrls.URL_DEADLETTER_JOB_COLLECTION) + "?handlerType=unknown-type";
assertResultsPresentInDataResponse(url);

url = RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB_COLLECTION) + "?handlerTypes=unknown-type,async-continuation";
assertResultsPresentInDataResponse(url, asyncJob.getId());

url = RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB_COLLECTION) + "?handlerTypes=unknown-type";
assertResultsPresentInDataResponse(url);

url = RestUrls.createRelativeResourceUrl(RestUrls.URL_DEADLETTER_JOB_COLLECTION) + "?handlerTypes=unknown-type,trigger-timer";
assertResultsPresentInDataResponse(url, timerJob.getId());

url = RestUrls.createRelativeResourceUrl(RestUrls.URL_DEADLETTER_JOB_COLLECTION) + "?handlerTypes=unknown-type";
assertResultsPresentInDataResponse(url);


}
@Test
public void getUnexistingDeadLetterJob() throws Exception {
Expand Down
Loading

0 comments on commit 67ae239

Please sign in to comment.