Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ph 1828 subset #4866

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@
"desc": "Filter by process instance ids. ${listTypeDescription}."
},

"processInstanceIdNotIn": {
"type": "array",
"itemType": "string",
"desc": "Exclude instances by process instance ids. ${listTypeDescription}."
},

"processDefinitionId": {
"type": "string",
"desc": "Filter by the process definition the instances run on."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public class HistoricProcessInstanceQueryDto extends AbstractQueryDto<HistoricPr

private String processInstanceId;
private Set<String> processInstanceIds;
private Set<String> processInstanceIdNotIn;
private String processDefinitionId;
private String processDefinitionKey;
private List<String> processDefinitionKeys;
Expand Down Expand Up @@ -145,6 +146,11 @@ public void setProcessInstanceIds(Set<String> processInstanceIds) {
this.processInstanceIds = processInstanceIds;
}

@CamundaQueryParam(value = "processInstanceIdNotIn", converter = StringSetConverter.class)
public void setProcessInstanceIdNotIn(Set<String> processDefinitionKeys) {
this.processInstanceIdNotIn = processDefinitionKeys;
}

public String getProcessDefinitionId() {
return processDefinitionId;
}
Expand Down Expand Up @@ -413,6 +419,9 @@ protected void applyFilters(HistoricProcessInstanceQuery query) {
if (processInstanceIds != null) {
query.processInstanceIds(processInstanceIds);
}
if (processInstanceIdNotIn != null) {
query.processInstanceIdNotIn(processInstanceIdNotIn);
}
if (processDefinitionId != null) {
query.processDefinitionId(processDefinitionId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1078,6 +1078,47 @@ private void verifyProcessInstanceIdSetInvocation() {
verify(mockedQuery).list();
}

@Test
public void testQueryByProcessInstanceIdNotIn() {
given()
.queryParam("processInstanceIdNotIn", "firstProcessInstanceId,secondProcessInstanceId")
.then()
.expect()
.statusCode(Status.OK.getStatusCode())
.when()
.get(HISTORIC_PROCESS_INSTANCE_RESOURCE_URL);

Set<String> processInstanceIds = new HashSet<String>();
processInstanceIds.add("firstProcessInstanceId");
processInstanceIds.add("secondProcessInstanceId");

verify(mockedQuery).processInstanceIdNotIn(processInstanceIds);
verify(mockedQuery).list();
}

@Test
public void testQueryByProcessInstanceIdNotInAsPost() {
Map<String, Set<String>> parameters = new HashMap<String, Set<String>>();

Set<String> processInstanceIds = new HashSet<String>();
processInstanceIds.add("firstProcessInstanceId");
processInstanceIds.add("secondProcessInstanceId");

parameters.put("processInstanceIdNotIn", processInstanceIds);

given()
.contentType(POST_JSON_CONTENT_TYPE)
.body(parameters)
.then()
.expect()
.statusCode(Status.OK.getStatusCode())
.when()
.post(HISTORIC_PROCESS_INSTANCE_RESOURCE_URL);

verify(mockedQuery).processInstanceIdNotIn(processInstanceIds);
verify(mockedQuery).list();
}

@Test
public void testQueryByProcessDefinitionKeyNotIn() {
given()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ public interface HistoricProcessInstanceQuery extends Query<HistoricProcessInsta
*/
HistoricProcessInstanceQuery processInstanceIds(Set<String> processInstanceIds);

/**
* Only select historic process instances whose id is not in the given set of ids.
* {@link ProcessInstance) ids and {@link HistoricProcessInstance} ids match.
*/
HistoricProcessInstanceQuery processInstanceIdNotIn(Set<String> processInstanceIdNotIn);

/**
* Only select historic process instances for the given process definition
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public class HistoricProcessInstanceQueryImpl extends AbstractVariableQueryImpl<
protected String processDefinitionKey;
protected String[] processDefinitionKeys;
protected Set<String> processInstanceIds;
protected Set<String> processInstanceIdNotIn;
protected String[] tenantIds;
protected boolean isTenantIdSet;
protected String[] executedActivityIds;
Expand Down Expand Up @@ -120,6 +121,12 @@ public HistoricProcessInstanceQuery processInstanceIds(Set<String> processInstan
return this;
}

public HistoricProcessInstanceQuery processInstanceIdNotIn(Set<String> processDefinitionIdNotIn){
ensureNotEmpty("Set of process instance ids", processDefinitionIdNotIn);
this.processInstanceIdNotIn = processDefinitionIdNotIn;
return this;
}

public HistoricProcessInstanceQueryImpl processDefinitionId(String processDefinitionId) {
this.processDefinitionId = processDefinitionId;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,13 @@
<bind name="fieldName" value="'SELF.PROC_INST_ID_'" />
<include refid="org.camunda.bpm.engine.impl.persistence.entity.Commons.applyInForPaginatedCollection" />
</if>
<if test="query.processInstanceIdNotIn != null and !query.processInstanceIdNotIn.isEmpty()">
${queryType} SELF.PROC_INST_ID_ NOT IN
<foreach item="processInstanceId" index="index" collection="query.processInstanceIdNotIn"
open="(" separator="," close=")">
#{processInstanceId}
</foreach>
</if>
<if test="query.caseInstanceId != null">
${queryType} SELF.CASE_INST_ID_ = #{query.caseInstanceId}
</if>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;

import java.util.Set;
import java.util.stream.Collectors;
import org.apache.commons.lang3.time.DateUtils;
import org.camunda.bpm.engine.BadUserRequestException;
Expand Down Expand Up @@ -549,14 +551,34 @@ public void testHistoricProcessInstanceQuery() {
assertEquals(1, historyService.createHistoricProcessInstanceQuery().processDefinitionNameLike("%One Task\\_Process").count());
assertEquals(1, historyService.createHistoricProcessInstanceQuery().processDefinitionNameLike("%One Task%").count());

List<String> exludeIds = new ArrayList<String>();
exludeIds.add("unexistingProcessDefinition");

assertEquals(1, historyService.createHistoricProcessInstanceQuery().processDefinitionKeyNotIn(exludeIds).count());
Set<String> excludeIdsSet = new HashSet<>();
excludeIdsSet.add("unexistingProcessDefinition");
assertEquals(1, historyService.createHistoricProcessInstanceQuery().processInstanceIdNotIn(excludeIdsSet).count());

exludeIds.add("oneTaskProcess");
assertEquals(0, historyService.createHistoricProcessInstanceQuery().processDefinitionKey("oneTaskProcess").processDefinitionKeyNotIn(exludeIds).count());
assertEquals(0, historyService.createHistoricProcessInstanceQuery().processDefinitionKeyNotIn(exludeIds).count());
String processInstanceId = processInstance.getId();
excludeIdsSet.add(processInstanceId);
assertEquals(0,
historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId). processInstanceIdNotIn(excludeIdsSet).count());
assertEquals(0, historyService.createHistoricProcessInstanceQuery().processInstanceIdNotIn(excludeIdsSet).count());

// TODO this would fail when using array but not with set. The check in the processInstanceIdNotIn differ
// try {
// historyService.createHistoricProcessInstanceQuery().processInstanceIdNotIn(Set.of(""));
// fail("Exception expected");
// }
// catch (NotValidException e) {
// // expected
// }

List<String> exludeIdsList = new ArrayList<String>();
exludeIdsList.add("unexistingProcessDefinition");

assertEquals(1, historyService.createHistoricProcessInstanceQuery().processDefinitionKeyNotIn(exludeIdsList).count());

exludeIdsList.add("oneTaskProcess");
assertEquals(0, historyService.createHistoricProcessInstanceQuery().processDefinitionKey("oneTaskProcess").processDefinitionKeyNotIn(exludeIdsList).count());
assertEquals(0, historyService.createHistoricProcessInstanceQuery().processDefinitionKeyNotIn(exludeIdsList).count());

try {
// oracle handles empty string like null which seems to lead to undefined behavior of the LIKE comparison
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
<span ng-show="varType !== 'option'"
class="cam-widget-inline-field btn-group">
<button type="button"
ng-if="inOperator && !(varType === 'datetime' || varType === 'date' || varType === 'time')"
ng-if="(inOperator || notInOperator) && !(varType === 'datetime' || varType === 'date' || varType === 'time')"
class="btn btn-xs btn-default"
ng-click="expandValue()">
<span class="glyphicon glyphicon-resize-full"></span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ module.exports = [
varValue: '=value',
varType: '@type',
inOperator: '=?',
notInOperator: '=?',
validator: '&validate',
change: '&',
onStart: '&onStartEditing',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
ng-keydown="onKeydown($event, 'value')"
type="{{ valueType }}"
in-operator="operator.value.key === 'In'"
not-in-operator="operator.value.key === 'NotIn'"
change="changeSearch('value', varValue, $event)"
on-start-editing="clearEditTrigger('value')"
ng-if="!basic"
Expand Down
Loading