Skip to content

Commit

Permalink
feat(engine+rest): add query filter for failed activity id
Browse files Browse the repository at this point in the history
related to CAM-11274
  • Loading branch information
tmetzke authored and koevskinikola committed Feb 5, 2020
1 parent f315a98 commit 23c0cb5
Show file tree
Hide file tree
Showing 12 changed files with 129 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public class HistoricIncidentQueryDto extends AbstractQueryDto<HistoricIncidentQ
protected String processInstanceId;
protected String executionId;
protected String activityId;
protected String failedActivityId;
protected String causeIncidentId;
protected String rootCauseIncidentId;
protected String configuration;
Expand Down Expand Up @@ -142,6 +143,11 @@ public void setActivityId(String activityId) {
this.activityId = activityId;
}

@CamundaQueryParam("failedActivityId")
public void setFailedActivityId(String activityId) {
this.failedActivityId = activityId;
}

@CamundaQueryParam("causeIncidentId")
public void setCauseIncidentId(String causeIncidentId) {
this.causeIncidentId = causeIncidentId;
Expand Down Expand Up @@ -228,6 +234,9 @@ protected void applyFilters(HistoricIncidentQuery query) {
if (activityId != null) {
query.activityId(activityId);
}
if (failedActivityId != null) {
query.failedActivityId(failedActivityId);
}
if (causeIncidentId != null) {
query.causeIncidentId(causeIncidentId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public class IncidentQueryDto extends AbstractQueryDto<IncidentQuery>{
protected String processInstanceId;
protected String executionId;
protected String activityId;
protected String failedActivityId;
protected String causeIncidentId;
protected String rootCauseIncidentId;
protected String configuration;
Expand Down Expand Up @@ -127,6 +128,11 @@ public void setActivityId(String activityId) {
this.activityId = activityId;
}

@CamundaQueryParam("failedActivityId")
public void setFailedActivityId(String activityId) {
this.failedActivityId = activityId;
}

@CamundaQueryParam("causeIncidentId")
public void setCauseIncidentId(String causeIncidentId) {
this.causeIncidentId = causeIncidentId;
Expand Down Expand Up @@ -189,6 +195,9 @@ protected void applyFilters(IncidentQuery query) {
if (activityId != null) {
query.activityId(activityId);
}
if (failedActivityId != null) {
query.failedActivityId(failedActivityId);
}
if (causeIncidentId != null) {
query.causeIncidentId(causeIncidentId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,11 +464,23 @@ public void testQueryByActivityId() {
String activityId = MockProvider.EXAMPLE_INCIDENT_ACTIVITY_ID;

given()
.queryParam("activityId", activityId)
.queryParam("activityId", activityId)
.then().expect().statusCode(Status.OK.getStatusCode())
.when().get(INCIDENT_QUERY_URL);

verify(mockedQuery).activityId(activityId);
}

@Test
public void testQueryByFailedActivityId() {
String activityId = MockProvider.EXAMPLE_INCIDENT_FAILED_ACTIVITY_ID;

given()
.queryParam("failedActivityId", activityId)
.then().expect().statusCode(Status.OK.getStatusCode())
.when().get(INCIDENT_QUERY_URL);

verify(mockedQuery).activityId(activityId);
verify(mockedQuery).failedActivityId(activityId);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,11 +497,23 @@ public void testQueryByActivityId() {
String activityId = MockProvider.EXAMPLE_HIST_INCIDENT_ACTIVITY_ID;

given()
.queryParam("activityId", activityId)
.queryParam("activityId", activityId)
.then().expect().statusCode(Status.OK.getStatusCode())
.when().get(HISTORY_INCIDENT_QUERY_URL);

verify(mockedQuery).activityId(activityId);
}

@Test
public void testQueryByFailedActivityId() {
String activityId = MockProvider.EXAMPLE_HIST_INCIDENT_FAILED_ACTIVITY_ID;

given()
.queryParam("failedActivityId", activityId)
.then().expect().statusCode(Status.OK.getStatusCode())
.when().get(HISTORY_INCIDENT_QUERY_URL);

verify(mockedQuery).activityId(activityId);
verify(mockedQuery).failedActivityId(activityId);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public interface HistoricIncidentQuery extends Query<HistoricIncidentQuery, Hist
/** Only select historic incidents which contain an activity with the given id. **/
HistoricIncidentQuery activityId(String activityId);

/** Only select historic incidents which were created due to a failure at an activity with the given id. **/
HistoricIncidentQuery failedActivityId(String activityId);

/** Only select historic incidents which contain the id of the cause incident. **/
HistoricIncidentQuery causeIncidentId(String causeIncidentId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.camunda.bpm.engine.history.IncidentState;
import org.camunda.bpm.engine.impl.interceptor.CommandContext;
import org.camunda.bpm.engine.impl.interceptor.CommandExecutor;
import org.camunda.bpm.engine.runtime.IncidentQuery;

/**
* @author Roman Smirnov
Expand All @@ -41,6 +40,7 @@ public class HistoricIncidentQueryImpl extends AbstractVariableQueryImpl<Histori
protected String incidentMessage;
protected String executionId;
protected String activityId;
protected String failedActivityId;
protected String processInstanceId;
protected String processDefinitionId;
protected String[] processDefinitionKeys;
Expand Down Expand Up @@ -90,6 +90,12 @@ public HistoricIncidentQuery activityId(String activityId) {
return this;
}

public HistoricIncidentQuery failedActivityId(String activityId) {
ensureNotNull("failedActivityId", activityId);
this.failedActivityId = activityId;
return this;
}

public HistoricIncidentQuery processInstanceId(String processInstanceId) {
ensureNotNull("processInstanceId", processInstanceId);
this.processInstanceId = processInstanceId;
Expand Down Expand Up @@ -294,6 +300,10 @@ public String getActivityId() {
return activityId;
}

public String getFailedActivityId() {
return failedActivityId;
}

public String getProcessInstanceId() {
return processInstanceId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.camunda.bpm.engine.impl.interceptor.CommandExecutor;
import org.camunda.bpm.engine.runtime.Incident;
import org.camunda.bpm.engine.runtime.IncidentQuery;
import org.camunda.bpm.engine.runtime.ProcessInstanceQuery;

/**
* @author roman.smirnov
Expand All @@ -39,6 +38,7 @@ public class IncidentQueryImpl extends AbstractQuery<IncidentQuery, Incident> im
protected String incidentMessage;
protected String executionId;
protected String activityId;
protected String failedActivityId;
protected String processInstanceId;
protected String processDefinitionId;
protected String[] processDefinitionKeys;
Expand Down Expand Up @@ -80,6 +80,11 @@ public IncidentQuery activityId(String activityId) {
return this;
}

public IncidentQuery failedActivityId(String activityId) {
this.failedActivityId = activityId;
return this;
}

public IncidentQuery processInstanceId(String processInstanceId) {
this.processInstanceId = processInstanceId;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ public interface IncidentQuery extends Query<IncidentQuery, Incident> {
/** Only select incidents which contain an activity with the given id. **/
IncidentQuery activityId(String activityId);

/** Only select incidents which were created due to a failure at an activity with the given id. **/
IncidentQuery failedActivityId(String activityId);

/** Only select incidents which contain the id of the cause incident. **/
IncidentQuery causeIncidentId(String causeIncidentId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,9 @@
<if test="activityId != null">
and RES.ACTIVITY_ID_ = #{activityId}
</if>
<if test="failedActivityId != null">
and RES.FAILED_ACTIVITY_ID_ = #{failedActivityId}
</if>
<if test="processInstanceId != null">
and RES.PROC_INST_ID_ = #{processInstanceId}
</if>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@
<if test="activityId != null">
and RES.ACTIVITY_ID_ = #{activityId}
</if>
<if test="failedActivityId != null">
and RES.FAILED_ACTIVITY_ID_ = #{failedActivityId}
</if>
<if test="processInstanceId != null">
and RES.PROC_INST_ID_ = #{processInstanceId}
</if>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,29 @@ public void testQueryByInvalidActivityId() {
assertNull(incident);
}

@Test
public void testQueryByFailedActivityId() {
IncidentQuery query = runtimeService.createIncidentQuery().failedActivityId("task");
assertEquals(4, query.count());

List<Incident> incidents = query.list();
assertFalse(incidents.isEmpty());
assertEquals(4, incidents.size());
}

@Test
public void testQueryByInvalidFailedActivityId() {
IncidentQuery query = runtimeService.createIncidentQuery().failedActivityId("invalid");

assertEquals(0, query.count());

List<Incident> incidents = query.list();
assertTrue(incidents.isEmpty());

Incident incident = query.singleResult();
assertNull(incident);
}

@Test
public void testQueryByConfiguration() {
String jobId = managementService.createJobQuery().processInstanceId(processInstanceIds.get(0)).singleResult().getId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,10 @@ public void testQueryByActivityId() {
}

@Test
@Deployment(resources={"org/camunda/bpm/engine/test/api/runtime/oneFailingServiceProcess.bpmn20.xml"})
public void testQueryByInvalidActivityId() {
startProcessInstance(PROCESS_DEFINITION_KEY);

HistoricIncidentQuery query = historyService.createHistoricIncidentQuery();

assertEquals(0, query.activityId("invalid").list().size());
Expand All @@ -327,6 +330,34 @@ public void testQueryByInvalidActivityId() {
} catch (ProcessEngineException e) { }
}

@Test
@Deployment(resources={"org/camunda/bpm/engine/test/api/runtime/oneFailingServiceProcess.bpmn20.xml"})
public void testQueryByFailedActivityId() {
startProcessInstance(PROCESS_DEFINITION_KEY);

HistoricIncidentQuery query = historyService.createHistoricIncidentQuery()
.failedActivityId("theServiceTask");

assertEquals(1, query.list().size());
assertEquals(1, query.count());
}

@Test
@Deployment(resources={"org/camunda/bpm/engine/test/api/runtime/oneFailingServiceProcess.bpmn20.xml"})
public void testQueryByFailedInvalidActivityId() {
startProcessInstance(PROCESS_DEFINITION_KEY);

HistoricIncidentQuery query = historyService.createHistoricIncidentQuery();

assertEquals(0, query.failedActivityId("invalid").list().size());
assertEquals(0, query.failedActivityId("invalid").count());

try {
query.failedActivityId(null);
fail("It was possible to set a null value as failedActivityId.");
} catch (ProcessEngineException e) { }
}

@Test
@Deployment(resources={"org/camunda/bpm/engine/test/history/HistoricIncidentQueryTest.testQueryByCauseIncidentId.bpmn20.xml",
"org/camunda/bpm/engine/test/api/runtime/oneFailingServiceProcess.bpmn20.xml"})
Expand Down

0 comments on commit 23c0cb5

Please sign in to comment.