From d8dec82565bc6496afb0bc06cd6808ccb8e19d9d Mon Sep 17 00:00:00 2001 From: Trisha Anand Date: Thu, 30 Sep 2021 20:28:32 +0530 Subject: [PATCH] Handling the empty object set for where clause in new actions (#8017) --- .../com/appsmith/external/models/Condition.java | 9 +++++++++ .../java/com/external/config/MethodConfig.java | 17 +++++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/models/Condition.java b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/models/Condition.java index 7821c4a8b0..2c1478737e 100644 --- a/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/models/Condition.java +++ b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/models/Condition.java @@ -2,6 +2,8 @@ package com.appsmith.external.models; import com.appsmith.external.constants.ConditionalOperator; import com.appsmith.external.constants.DataType; +import com.appsmith.external.exceptions.pluginExceptions.AppsmithPluginError; +import com.appsmith.external.exceptions.pluginExceptions.AppsmithPluginException; import com.fasterxml.jackson.annotation.JsonIgnore; import lombok.AllArgsConstructor; import lombok.Getter; @@ -12,6 +14,7 @@ import org.apache.commons.lang3.StringUtils; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.stream.Collectors; import static com.appsmith.external.helpers.DataTypeStringUtils.stringToKnownDataTypeConverter; @@ -66,6 +69,12 @@ public class Condition { for(Object config : configurationList) { Map condition = (Map) config; + if (condition.entrySet().isEmpty()) { + // Its an empty object set by the client for UX. Ignore the same + continue; + } else if (!condition.keySet().containsAll(Set.of("path", "operator", "value"))) { + throw new AppsmithPluginException(AppsmithPluginError.PLUGIN_EXECUTE_ARGUMENT_ERROR, "Filtering Condition not configured properly"); + } conditionList.add(new Condition( condition.get("path"), condition.get("operator"), diff --git a/app/server/appsmith-plugins/googleSheetsPlugin/src/main/java/com/external/config/MethodConfig.java b/app/server/appsmith-plugins/googleSheetsPlugin/src/main/java/com/external/config/MethodConfig.java index b307ad0e21..a5d088c4ba 100644 --- a/app/server/appsmith-plugins/googleSheetsPlugin/src/main/java/com/external/config/MethodConfig.java +++ b/app/server/appsmith-plugins/googleSheetsPlugin/src/main/java/com/external/config/MethodConfig.java @@ -12,6 +12,7 @@ import lombok.ToString; import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -41,8 +42,9 @@ public class MethodConfig { public MethodConfig(List propertyList) { propertyList.stream().parallel().forEach(property -> { - if (property.getValue() != null) { - String propertyValue = String.valueOf(property.getValue()); + Object value = property.getValue(); + if (value != null) { + String propertyValue = String.valueOf(value); switch (property.getKey()) { case "sheetUrl": this.spreadsheetUrl = propertyValue; @@ -89,8 +91,15 @@ public class MethodConfig { this.rowObjects = propertyValue; break; case "where": - if (property.getValue() != null && !((List) property.getValue()).isEmpty()) { - this.whereConditions = Condition.generateFromConfiguration((List) property.getValue()); + if (value != null && value instanceof List) { + // Check if all values in the where condition are null. + boolean allValuesNull = ((List) value).stream() + .allMatch(valueMap -> valueMap == null || + ((Map) valueMap).entrySet().stream().allMatch(e -> ((Map.Entry) e).getValue() == null)); + + if (!allValuesNull) { + this.whereConditions = Condition.generateFromConfiguration((List) value); + } } break; }