Skip to content

Commit

Permalink
fix(engine): fix task filter properties with nested structures
Browse files Browse the repository at this point in the history
related to CAM-9881
  • Loading branch information
tasso94 committed Mar 21, 2019
1 parent 2bd788a commit ce5a5e6
Show file tree
Hide file tree
Showing 14 changed files with 408 additions and 50 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2013-2018 camunda services GmbH and various authors (info@camunda.com)
* Copyright © 2013-2019 camunda services GmbH and various authors (info@camunda.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -60,6 +60,6 @@ public RestartProcessInstancesBatchConfiguration toObject(JsonObject json) {
}

protected List<String> readProcessInstanceIds(JsonObject jsonObject) {
return JsonUtil.asList(JsonUtil.getArray(jsonObject, PROCESS_INSTANCE_IDS));
return JsonUtil.asStringList(JsonUtil.getArray(jsonObject, PROCESS_INSTANCE_IDS));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2013-2018 camunda services GmbH and various authors (info@camunda.com)
* Copyright © 2013-2019 camunda services GmbH and various authors (info@camunda.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -44,6 +44,6 @@ public BatchConfiguration toObject(JsonObject json) {
}

protected List<String> readProcessInstanceIds(JsonObject jsonObject) {
return JsonUtil.asList(JsonUtil.getArray(jsonObject, HISTORIC_PROCESS_INSTANCE_IDS));
return JsonUtil.asStringList(JsonUtil.getArray(jsonObject, HISTORIC_PROCESS_INSTANCE_IDS));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2013-2018 camunda services GmbH and various authors (info@camunda.com)
* Copyright © 2013-2019 camunda services GmbH and various authors (info@camunda.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -57,6 +57,6 @@ public DeleteProcessInstanceBatchConfiguration toObject(JsonObject json) {
}

protected List<String> readProcessInstanceIds(JsonObject jsonObject) {
return JsonUtil.asList(JsonUtil.getArray(jsonObject, PROCESS_INSTANCE_IDS));
return JsonUtil.asStringList(JsonUtil.getArray(jsonObject, PROCESS_INSTANCE_IDS));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2013-2018 camunda services GmbH and various authors (info@camunda.com)
* Copyright © 2013-2019 camunda services GmbH and various authors (info@camunda.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -45,7 +45,7 @@ public SetRetriesBatchConfiguration toObject(JsonObject json) {
}

protected List<String> readExternalTaskIds(JsonObject json) {
return JsonUtil.asList(JsonUtil.getArray(json, EXTERNAL_TASK_IDS));
return JsonUtil.asStringList(JsonUtil.getArray(json, EXTERNAL_TASK_IDS));
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2013-2018 camunda services GmbH and various authors (info@camunda.com)
* Copyright © 2013-2019 camunda services GmbH and various authors (info@camunda.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -49,6 +49,6 @@ public SetRetriesBatchConfiguration toObject(JsonObject json) {
}

protected List<String> readJobIds(JsonObject jsonObject) {
return JsonUtil.asList(JsonUtil.getArray(jsonObject, JOB_IDS));
return JsonUtil.asStringList(JsonUtil.getArray(jsonObject, JOB_IDS));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2013-2018 camunda services GmbH and various authors (info@camunda.com)
* Copyright © 2013-2019 camunda services GmbH and various authors (info@camunda.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -43,6 +43,6 @@ public UpdateProcessInstancesSuspendStateBatchConfiguration toObject(JsonObject
}

protected List<String> readProcessInstanceIds(JsonObject jsonObject) {
return JsonUtil.asList(JsonUtil.getArray(jsonObject, PROCESS_INSTANCE_IDS));
return JsonUtil.asStringList(JsonUtil.getArray(jsonObject, PROCESS_INSTANCE_IDS));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2013-2018 camunda services GmbH and various authors (info@camunda.com)
* Copyright © 2013-2019 camunda services GmbH and various authors (info@camunda.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -40,7 +40,7 @@ public BatchConfiguration toObject(JsonObject json) {
}

protected List<String> readDecisionInstanceIds(JsonObject jsonNode) {
return JsonUtil.asList(JsonUtil.getArray(jsonNode, HISTORIC_DECISION_INSTANCE_IDS));
return JsonUtil.asStringList(JsonUtil.getArray(jsonNode, HISTORIC_DECISION_INSTANCE_IDS));
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2013-2018 camunda services GmbH and various authors (info@camunda.com)
* Copyright © 2013-2019 camunda services GmbH and various authors (info@camunda.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -52,7 +52,7 @@ public MigrationBatchConfiguration toObject(JsonObject json) {
}

protected List<String> readProcessInstanceIds(JsonObject jsonObject) {
return JsonUtil.asList(JsonUtil.getArray(jsonObject, PROCESS_INSTANCE_IDS));
return JsonUtil.asStringList(JsonUtil.getArray(jsonObject, PROCESS_INSTANCE_IDS));
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2013-2018 camunda services GmbH and various authors (info@camunda.com)
* Copyright © 2013-2019 camunda services GmbH and various authors (info@camunda.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -63,7 +63,7 @@ public ModificationBatchConfiguration toObject(JsonObject json) {
}

protected List<String> readProcessInstanceIds(JsonObject jsonObject) {
return JsonUtil.asList(JsonUtil.getArray(jsonObject, PROCESS_INSTANCE_IDS));
return JsonUtil.asStringList(JsonUtil.getArray(jsonObject, PROCESS_INSTANCE_IDS));
}

}
115 changes: 84 additions & 31 deletions engine/src/main/java/org/camunda/bpm/engine/impl/util/JsonUtil.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2013-2018 camunda services GmbH and various authors (info@camunda.com)
* Copyright © 2013-2019 camunda services GmbH and various authors (info@camunda.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -38,7 +38,6 @@
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSyntaxException;
import com.google.gson.internal.LazilyParsedNumber;
import com.google.gson.reflect.TypeToken;
import org.camunda.bpm.engine.impl.ProcessEngineLogger;

/**
Expand All @@ -48,8 +47,6 @@ public final class JsonUtil {

private static final EngineUtilLogger LOG = ProcessEngineLogger.UTIL_LOGGER;

protected static final Type MAP_TYPE_TOKEN = new TypeToken<Map<String, Object>>() {}.getType();

protected static Gson gsonMapper = createGsonMapper();

public static void addFieldRawValue(JsonObject jsonObject, String memberName, Object rawValue) {
Expand Down Expand Up @@ -277,7 +274,7 @@ public static JsonObject asObject(Map<String, Object> properties) {
}
}

public static List<String> asList(JsonElement jsonObject) {
public static List<String> asStringList(JsonElement jsonObject) {
JsonArray jsonArray = null;

if (jsonObject != null) {
Expand Down Expand Up @@ -341,40 +338,94 @@ public static <T> List<T> asList(JsonArray jsonArray, JsonObjectConverter<T> con
return list;
}

public static Map<String, Object> asMap(JsonObject jsonObject) {
if (jsonObject != null) {
Map<String, Object> map = null;
public static List<Object> asList(JsonElement jsonElement) {
if (jsonElement == null) {
return Collections.emptyList();
}

try {
map = getGsonMapper().fromJson(jsonObject, MAP_TYPE_TOKEN);
JsonArray jsonArray = null;

} catch (JsonParseException | ClassCastException e) {
LOG.logJsonException(e);
}
try {
jsonArray = jsonElement.getAsJsonArray();

if (map != null) {
} catch (IllegalStateException | ClassCastException e) {
LOG.logJsonException(e);
}

for (Map.Entry<String, Object> entry : map.entrySet()) {
Object value = entry.getValue();
if (jsonArray == null) {
return Collections.emptyList();
}

if (value != null && value instanceof JsonPrimitive) {
List<Object> list = new ArrayList<>();
for (JsonElement entry : jsonArray) {

Object rawObject = asPrimitiveObject((JsonPrimitive) value);
if (rawObject != null) {
map.put(entry.getKey(), rawObject);
}
}
if (entry.isJsonPrimitive()) {

Object rawObject = asPrimitiveObject((JsonPrimitive) entry);
if (rawObject != null) {
list.add(rawObject);
}

return map;
} else if (entry.isJsonNull()) {
list.add(null);

} else {
return Collections.emptyMap();
} else if (entry.isJsonObject()) {
list.add(asMap(entry));

} else if (entry.isJsonArray()) {
list.add(asList(entry));

}
} else {
}

return list;
}

public static Map<String, Object> asMap(JsonElement jsonElement) {
if (jsonElement == null) {
return Collections.emptyMap();
}

JsonObject jsonObject = null;

try {
jsonObject = jsonElement.getAsJsonObject();

} catch (IllegalStateException | ClassCastException e) {
LOG.logJsonException(e);
}

if (jsonObject == null) {
return Collections.emptyMap();

}

Map<String, Object> map = new HashMap<>();
for (Map.Entry<String, JsonElement> jsonEntry : jsonObject.entrySet()) {

String key = jsonEntry.getKey();
JsonElement value = jsonEntry.getValue();

if (value.isJsonPrimitive()) {

Object rawObject = asPrimitiveObject((JsonPrimitive) value);
if (rawObject != null) {
map.put(key, rawObject);
}

} else if (value.isJsonNull()) {
map.put(key, null);

} else if (value.isJsonObject()) {
map.put(key, asMap(value));

} else if (value.isJsonArray()) {
map.put(key, asList(value));

}
}

return map;
}

public static String asString(Map<String, Object> properties) {
Expand Down Expand Up @@ -466,22 +517,24 @@ public static Object asPrimitiveObject(JsonPrimitive jsonValue) {
Object rawObject = null;

if (jsonValue.isNumber()) {
LazilyParsedNumber numberValue = null;
Object numberValue = null;

try {
numberValue = (LazilyParsedNumber) jsonValue.getAsNumber();
numberValue = jsonValue.getAsNumber();

} catch (ClassCastException | NumberFormatException e) {
} catch (NumberFormatException e) {
LOG.logJsonException(e);
}

if (numberValue != null) {

if (numberValue != null && numberValue instanceof LazilyParsedNumber) {
String numberString = numberValue.toString();
if (numberString != null) {
rawObject = parseNumber(numberString);
}

} else {
rawObject = numberValue;

}
} else { // string, boolean
try {
Expand Down
Loading

0 comments on commit ce5a5e6

Please sign in to comment.