This is an automated email from the ASF dual-hosted git repository.
zehnder pushed a commit to branch rel/0.95.0
in repository https://gitbox.apache.org/repos/asf/streampipes.git
The following commit(s) were added to refs/heads/rel/0.95.0 by this push:
new 984f71c0b6 fix(#2886): Fix the deletion of nested properties in
connect (#2889)
984f71c0b6 is described below
commit 984f71c0b6b1065390d29ccc3e85dc46be81cdce
Author: Philipp Zehnder <[email protected]>
AuthorDate: Wed May 22 08:53:44 2024 +0200
fix(#2886): Fix the deletion of nested properties in connect (#2889)
* fix(#2886): Fix the deletion of nested properties in connect
* fix(#2886): Fix test to validate deletion works as expected
* fix(#2886): Fix linting
---
.../SupportsNestedTransformationRule.java | 5 ++++-
.../transform/schema/DeleteTransformationRule.java | 2 ++
.../schema/DeleteTransformationRuleTest.java | 26 ++++++++++++++++++++++
.../adapter/rules/deleteTransformationRule.spec.ts | 11 +++++++++
4 files changed, 43 insertions(+), 1 deletion(-)
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..a0494cff34 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 && !newSubEvent.isEmpty()) {
+ 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..e8d5e1feb8 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
@@ -44,13 +44,39 @@ public class DeleteTransformationRuleTest {
public void transformNested() {
var child = new HashMap<String, Object>();
child.put("child", "value");
+ child.put("secondChild", "value");
var event = new HashMap<String, Object>();
event.put("parent", child);
+ event.put("keepProperty", "test");
+
+ 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 child = new HashMap<String, Object>();
+ child.put("child", "value");
+ var event = new HashMap<String, Object>();
+ event.put("parent", child);
+ event.put("keepProperty", "test");
var deleteRule = new DeleteTransformationRule(Arrays.asList("parent",
"child"));
var result = deleteRule.apply(event);
assertEquals(1, result.keySet().size());
+ assertEquals("test", result.get("keepProperty"));
}
+
}
diff --git a/ui/cypress/tests/adapter/rules/deleteTransformationRule.spec.ts
b/ui/cypress/tests/adapter/rules/deleteTransformationRule.spec.ts
index debbc5473f..2ece7e9a38 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,15 @@ 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}',
+ );
});
});