This is an automated email from the ASF dual-hosted git repository.
zehnder pushed a commit to branch
2886-bug-when-deleting-nested-properties-in-adapter
in repository https://gitbox.apache.org/repos/asf/streampipes.git
The following commit(s) were added to
refs/heads/2886-bug-when-deleting-nested-properties-in-adapter by this push:
new 896b648763 fix(#2886): Fix the deletion of nested properties in connect
896b648763 is described below
commit 896b6487639efb19d34261a4b3af0af9956a27e4
Author: Philipp Zehnder <[email protected]>
AuthorDate: Tue May 21 17:18:28 2024 +0200
fix(#2886): Fix the deletion of nested properties in connect
---
.../SupportsNestedTransformationRule.java | 5 +++-
.../transform/schema/DeleteTransformationRule.java | 2 ++
.../schema/DeleteTransformationRuleTest.java | 35 +++++++++++++++++++---
.../adapter/rules/deleteTransformationRule.spec.ts | 12 ++++++++
4 files changed, 49 insertions(+), 5 deletions(-)
diff --git
a/streampipes-connect-shared/src/main/java/org/apache/streampipes/connect/shared/preprocessing/SupportsNestedTransformationRule.java
b/streampipes-connect-shared/src/main/java/org/apache/streampipes/connect/shared/preprocessing/SupportsNestedTransformationRule.java
index d332a79e42..86a36b7d6c 100644
---
a/streampipes-connect-shared/src/main/java/org/apache/streampipes/connect/shared/preprocessing/SupportsNestedTransformationRule.java
+++
b/streampipes-connect-shared/src/main/java/org/apache/streampipes/connect/shared/preprocessing/SupportsNestedTransformationRule.java
@@ -42,7 +42,10 @@ public abstract class SupportsNestedTransformationRule
implements Transformation
applyNested((Map<String, Object>) event.get(eventKey.get(0)),
newKeysTmpList);
event.remove(key);
- event.put(key, newSubEvent);
+
+ if (newSubEvent != null) {
+ event.put(key, newSubEvent);
+ }
}
return event;
}
diff --git
a/streampipes-connect-shared/src/main/java/org/apache/streampipes/connect/shared/preprocessing/transform/schema/DeleteTransformationRule.java
b/streampipes-connect-shared/src/main/java/org/apache/streampipes/connect/shared/preprocessing/transform/schema/DeleteTransformationRule.java
index ae2d1c70d9..7fe7805baa 100644
---
a/streampipes-connect-shared/src/main/java/org/apache/streampipes/connect/shared/preprocessing/transform/schema/DeleteTransformationRule.java
+++
b/streampipes-connect-shared/src/main/java/org/apache/streampipes/connect/shared/preprocessing/transform/schema/DeleteTransformationRule.java
@@ -38,6 +38,8 @@ public class DeleteTransformationRule extends
SupportsNestedTransformationRule {
@Override
protected void applyTransformation(Map<String, Object> event, List<String>
eventKeys) {
+ if (event != null) {
event.remove(eventKeys.get(0));
+ }
}
}
diff --git
a/streampipes-connect-shared/src/test/java/org/apache/streampipes/connect/shared/preprocessing/transform/schema/DeleteTransformationRuleTest.java
b/streampipes-connect-shared/src/test/java/org/apache/streampipes/connect/shared/preprocessing/transform/schema/DeleteTransformationRuleTest.java
index 7253b33bd5..2edacf66e5 100644
---
a/streampipes-connect-shared/src/test/java/org/apache/streampipes/connect/shared/preprocessing/transform/schema/DeleteTransformationRuleTest.java
+++
b/streampipes-connect-shared/src/test/java/org/apache/streampipes/connect/shared/preprocessing/transform/schema/DeleteTransformationRuleTest.java
@@ -23,6 +23,7 @@ import org.junit.jupiter.api.Test;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -42,15 +43,41 @@ public class DeleteTransformationRuleTest {
@Test
public void transformNested() {
- var child = new HashMap<String, Object>();
- child.put("child", "value");
- var event = new HashMap<String, Object>();
- event.put("parent", child);
+ var event = getNestedTestEvent();
+
+ var deleteRule = new DeleteTransformationRule(List.of("parent", "child"));
+
+ var result = deleteRule.apply(event);
+
+ assertEquals(2, result.keySet().size());
+ }
+
+ @Test
+ // verifying that mathod applyTransformation method works when passed a null
event.
+ public void applyTransformationWithNullParameter() {
+ new DeleteTransformationRule(List.of())
+ .applyTransformation(null, List.of());
+ }
+
+ @Test
+ public void deleteNestedChildWithParentProperty() {
+
+ var event = getNestedTestEvent();
var deleteRule = new DeleteTransformationRule(Arrays.asList("parent",
"child"));
var result = deleteRule.apply(event);
assertEquals(1, result.keySet().size());
+ assertEquals("test", result.get("keepProperty"));
+ }
+
+ private Map<String, Object> getNestedTestEvent() {
+ var child = new HashMap<String, Object>();
+ child.put("child", "value");
+ var event = new HashMap<String, Object>();
+ event.put("parent", child);
+ event.put("keepProperty", "test");
+ return event;
}
}
diff --git a/ui/cypress/tests/adapter/rules/deleteTransformationRule.spec.ts
b/ui/cypress/tests/adapter/rules/deleteTransformationRule.spec.ts
index debbc5473f..13e14d2309 100644
--- a/ui/cypress/tests/adapter/rules/deleteTransformationRule.spec.ts
+++ b/ui/cypress/tests/adapter/rules/deleteTransformationRule.spec.ts
@@ -19,6 +19,7 @@ import { ConnectUtils } from
'../../../support/utils/connect/ConnectUtils';
import { FileManagementUtils } from
'../../../support/utils/FileManagementUtils';
import { ConnectEventSchemaUtils } from
'../../../support/utils/ConnectEventSchemaUtils';
import { AdapterBuilder } from '../../../support/builder/AdapterBuilder';
+import { ConnectBtns } from '../../../support/utils/connect/ConnectBtns';
describe('Connect delete rule transformation', () => {
beforeEach('Setup Test', () => {
@@ -72,5 +73,16 @@ describe('Connect delete rule transformation', () => {
'have.text',
'{\u00A0\u00A0\u00A0\u00A0"parent":\u00A0{},\u00A0\u00A0\u00A0\u00A0"timestamp":\u00A01667904471000}',
);
+
+ ConnectBtns.refreshSchema().click();
+
+ // Test to delete the parent property
+ ConnectEventSchemaUtils.deleteProperty('parent');
+ cy.dataCy('schema-preview-result-event')
+ .should(
+ 'have.text',
+
+ '{\u00A0\u00A0\u00A0\u00A0"timestamp":\u00A01667904471000}',
+ );
});
});