This is an automated email from the ASF dual-hosted git repository.
riemer pushed a commit to branch
3425-adapters-reduce-event-rate-will-not-work-on-edit
in repository https://gitbox.apache.org/repos/asf/streampipes.git
The following commit(s) were added to
refs/heads/3425-adapters-reduce-event-rate-will-not-work-on-edit by this push:
new 509a036d7b fix(#3425): Properly store stream transformation rules in
adapter
509a036d7b is described below
commit 509a036d7b70061bf0de132cca811d094cb32bee
Author: Dominik Riemer <[email protected]>
AuthorDate: Thu Jan 23 13:51:15 2025 +0100
fix(#3425): Properly store stream transformation rules in adapter
---
.../editAdapterTransformationRulesAreKept.ts | 67 +++++++++++++++++++
.../adapter-configuration.component.ts | 2 +-
.../event-schema/event-schema.component.ts | 2 +-
.../start-adapter-configuration.component.html | 14 +++-
.../start-adapter-configuration.component.ts | 78 ++++++++++++++++------
.../edit-unit-transformation.component.ts | 5 +-
.../services/transformation-rule.service.ts | 12 +++-
7 files changed, 154 insertions(+), 26 deletions(-)
diff --git a/ui/cypress/tests/connect/editAdapterTransformationRulesAreKept.ts
b/ui/cypress/tests/connect/editAdapterTransformationRulesAreKept.ts
new file mode 100644
index 0000000000..1885af9ea3
--- /dev/null
+++ b/ui/cypress/tests/connect/editAdapterTransformationRulesAreKept.ts
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+import { AdapterBuilder } from '../../support/builder/AdapterBuilder';
+import { ConnectUtils } from '../../support/utils/connect/ConnectUtils';
+import { ConnectBtns } from '../../support/utils/connect/ConnectBtns';
+
+describe('Test Adapter Transformation Rules are properly stored', () => {
+ beforeEach('Setup Test', () => {
+ cy.initStreamPipesTest();
+ });
+
+ it('Test configuration of adapter fields ', () => {
+ // Set up new adapter
+ const builder = AdapterBuilder.create('Machine_Data_Simulator')
+ .setName('Machine_Data_Simulator')
+ .addInput('input', 'wait-time-ms', '1000');
+ const configuration = builder.build();
+ ConnectUtils.goToConnect();
+ ConnectUtils.goToNewAdapterPage();
+ ConnectUtils.selectAdapter(configuration.adapterType);
+ cy.contains('Next').click();
+
+ cy.dataCy('sp-event-schema-next-button').click();
+ cy.dataCy('sp-adapter-name').type('Test Adapter');
+ cy.dataCy('connect-remove-duplicates-box').click();
+ cy.dataCy('connect-remove-duplicates-input').type('10000');
+ cy.dataCy('connect-reduce-event-rate-box').click();
+ cy.dataCy('connect-reduce-event-input').type('20000');
+ cy.dataCy('adapter-settings-start-adapter-btn').click();
+ ConnectUtils.closeAdapterPreview();
+
+ // Edit adapter and check if given values and added property still
provided
+ ConnectBtns.editAdapter().should('not.be.disabled');
+ ConnectBtns.editAdapter().click();
+ cy.contains('Next').click();
+ cy.dataCy('sp-event-schema-next-button').click();
+
+ cy.dataCy('connect-remove-duplicates-box')
+ .find('input')
+ .should('be.checked');
+ cy.dataCy('connect-remove-duplicates-input').should(
+ 'have.value',
+ '10000',
+ );
+
+ cy.dataCy('connect-reduce-event-rate-box')
+ .find('input')
+ .should('be.checked');
+ cy.dataCy('connect-reduce-event-input').should('have.value', '20000');
+ });
+});
diff --git
a/ui/src/app/connect/components/adapter-configuration/adapter-configuration.component.ts
b/ui/src/app/connect/components/adapter-configuration/adapter-configuration.component.ts
index 6b1ca90a7f..d87aa5fc04 100644
---
a/ui/src/app/connect/components/adapter-configuration/adapter-configuration.component.ts
+++
b/ui/src/app/connect/components/adapter-configuration/adapter-configuration.component.ts
@@ -80,7 +80,7 @@ export class AdapterConfigurationComponent implements OnInit {
this.adapter.dataStream.eventSchema = targetSchema;
this.adapter.rules =
- this.transformationRuleService.getTransformationRuleDescriptions(
+ this.transformationRuleService.makeTransformationRuleDescriptions(
originalSchema,
targetSchema,
);
diff --git
a/ui/src/app/connect/components/adapter-configuration/schema-editor/event-schema/event-schema.component.ts
b/ui/src/app/connect/components/adapter-configuration/schema-editor/event-schema/event-schema.component.ts
index da1b6c5a54..a74c30ab48 100644
---
a/ui/src/app/connect/components/adapter-configuration/schema-editor/event-schema/event-schema.component.ts
+++
b/ui/src/app/connect/components/adapter-configuration/schema-editor/event-schema/event-schema.component.ts
@@ -242,7 +242,7 @@ export class EventSchemaComponent implements OnChanges {
public updatePreview(): void {
this.isPreviewEnabled = false;
const ruleDescriptions =
- this.transformationRuleService.getTransformationRuleDescriptions(
+ this.transformationRuleService.makeTransformationRuleDescriptions(
this.originalSchema,
this.targetSchema,
);
diff --git
a/ui/src/app/connect/components/adapter-configuration/start-adapter-configuration/start-adapter-configuration.component.html
b/ui/src/app/connect/components/adapter-configuration/start-adapter-configuration/start-adapter-configuration.component.html
index d4eecdd6a7..f8fcd94bf0 100644
---
a/ui/src/app/connect/components/adapter-configuration/start-adapter-configuration/start-adapter-configuration.component.html
+++
b/ui/src/app/connect/components/adapter-configuration/start-adapter-configuration/start-adapter-configuration.component.html
@@ -64,9 +64,14 @@
optionDescription="Avoid duplicated events within a certain time
interval"
optionIcon="cleaning_services"
dataCy="connect-remove-duplicates-box"
+ [isChecked]="removeDuplicates"
(optionSelectedEmitter)="removeDuplicates = $event"
>
- <mat-form-field *ngIf="removeDuplicates" color="accent">
+ <mat-form-field
+ *ngIf="removeDuplicates"
+ color="accent"
+ class="mt-10"
+ >
<input
matInput
id="input-removeDuplicatesTime"
@@ -83,9 +88,14 @@
optionDescription="Send maximum one event in the specified time
window"
optionIcon="speed"
dataCy="connect-reduce-event-rate-box"
+ [isChecked]="eventRateReduction"
(optionSelectedEmitter)="eventRateReduction = $event"
>
- <mat-form-field *ngIf="eventRateReduction" color="accent">
+ <mat-form-field
+ *ngIf="eventRateReduction"
+ color="accent"
+ class="mt-10"
+ >
<input
type="number"
matInput
diff --git
a/ui/src/app/connect/components/adapter-configuration/start-adapter-configuration/start-adapter-configuration.component.ts
b/ui/src/app/connect/components/adapter-configuration/start-adapter-configuration/start-adapter-configuration.component.ts
index e8fc266424..9e2246a07c 100644
---
a/ui/src/app/connect/components/adapter-configuration/start-adapter-configuration/start-adapter-configuration.component.ts
+++
b/ui/src/app/connect/components/adapter-configuration/start-adapter-configuration/start-adapter-configuration.component.ts
@@ -34,6 +34,7 @@ import { AdapterStartedDialog } from
'../../../dialog/adapter-started/adapter-st
import { DialogService, PanelType } from '@streampipes/shared-ui';
import { ShepherdService } from '../../../../services/tour/shepherd.service';
import { TimestampPipe } from '../../../filter/timestamp.pipe';
+import { TransformationRuleService } from
'../../../services/transformation-rule.service';
@Component({
selector: 'sp-start-adapter-configuration',
@@ -41,6 +42,11 @@ import { TimestampPipe } from
'../../../filter/timestamp.pipe';
styleUrls: ['./start-adapter-configuration.component.scss'],
})
export class StartAdapterConfigurationComponent implements OnInit {
+ static EventRateTransformationRuleId =
+
'org.apache.streampipes.model.connect.rules.stream.EventRateTransformationRuleDescription'
as const;
+ static RemoveDuplicatesTransformationRuleId =
+
'org.apache.streampipes.model.connect.rules.stream.RemoveDuplicatesTransformationRuleDescription'
as const;
+
/**
* Adapter description the selected format is added to
*/
@@ -48,7 +54,7 @@ export class StartAdapterConfigurationComponent implements
OnInit {
@Input() eventSchema: EventSchema;
- @Input() isEditMode;
+ @Input() isEditMode: boolean;
/**
* Cancels the adapter configuration process
@@ -96,6 +102,7 @@ export class StartAdapterConfigurationComponent implements
OnInit {
private shepherdService: ShepherdService,
private _formBuilder: UntypedFormBuilder,
private timestampPipe: TimestampPipe,
+ private transformationRuleService: TransformationRuleService,
) {}
ngOnInit(): void {
@@ -115,6 +122,34 @@ export class StartAdapterConfigurationComponent implements
OnInit {
this.startAdapterSettingsFormValid = this.startAdapterForm.valid;
});
this.startAdapterSettingsFormValid = this.startAdapterForm.valid;
+
+ this.applySelectedEventRateReduction();
+ this.applySelectedRemoveDuplicates();
+ }
+
+ applySelectedEventRateReduction(): void {
+ const eventRateRule =
+
this.transformationRuleService.getExistingTransformationRule<EventRateTransformationRuleDescription>(
+ this.adapterDescription,
+
StartAdapterConfigurationComponent.EventRateTransformationRuleId,
+ );
+ if (eventRateRule !== undefined) {
+ this.eventRateReduction = true;
+ this.eventRateTime = eventRateRule.aggregationTimeWindow;
+ this.eventRateMode = eventRateRule.aggregationType;
+ }
+ }
+
+ applySelectedRemoveDuplicates(): void {
+ const removeDuplicatesRule =
+
this.transformationRuleService.getExistingTransformationRule<RemoveDuplicatesTransformationRuleDescription>(
+ this.adapterDescription,
+
StartAdapterConfigurationComponent.RemoveDuplicatesTransformationRuleId,
+ );
+ if (removeDuplicatesRule !== undefined) {
+ this.removeDuplicates = true;
+ this.removeDuplicatesTime = +removeDuplicatesRule.filterTimeWindow;
+ }
}
findDefaultTimestamp(selected: boolean) {
@@ -131,6 +166,7 @@ export class StartAdapterConfigurationComponent implements
OnInit {
}
public editAdapter() {
+ this.checkAndApplyStreamRules();
const dialogRef = this.dialogService.open(AdapterStartedDialog, {
panelType: PanelType.STANDARD_PANEL,
title: 'Adapter edit',
@@ -147,24 +183,7 @@ export class StartAdapterConfigurationComponent implements
OnInit {
}
public startAdapter() {
- if (this.removeDuplicates) {
- const removeDuplicates:
RemoveDuplicatesTransformationRuleDescription =
- new RemoveDuplicatesTransformationRuleDescription();
- removeDuplicates['@class'] =
-
'org.apache.streampipes.model.connect.rules.stream.RemoveDuplicatesTransformationRuleDescription';
- removeDuplicates.filterTimeWindow = this
- .removeDuplicatesTime as any;
- this.adapterDescription.rules.push(removeDuplicates);
- }
- if (this.eventRateReduction) {
- const eventRate: EventRateTransformationRuleDescription =
- new EventRateTransformationRuleDescription();
- eventRate['@class'] =
-
'org.apache.streampipes.model.connect.rules.stream.EventRateTransformationRuleDescription';
- eventRate.aggregationTimeWindow = this.eventRateTime;
- eventRate.aggregationType = this.eventRateMode;
- this.adapterDescription.rules.push(eventRate);
- }
+ this.checkAndApplyStreamRules();
const dialogRef = this.dialogService.open(AdapterStartedDialog, {
panelType: PanelType.STANDARD_PANEL,
@@ -185,6 +204,27 @@ export class StartAdapterConfigurationComponent implements
OnInit {
});
}
+ private checkAndApplyStreamRules(): void {
+ if (this.removeDuplicates) {
+ const removeDuplicates:
RemoveDuplicatesTransformationRuleDescription =
+ new RemoveDuplicatesTransformationRuleDescription();
+ removeDuplicates['@class'] =
+
StartAdapterConfigurationComponent.RemoveDuplicatesTransformationRuleId;
+ removeDuplicates.filterTimeWindow = this
+ .removeDuplicatesTime as any;
+ this.adapterDescription.rules.push(removeDuplicates);
+ }
+ if (this.eventRateReduction) {
+ const eventRate: EventRateTransformationRuleDescription =
+ new EventRateTransformationRuleDescription();
+ eventRate['@class'] =
+
StartAdapterConfigurationComponent.EventRateTransformationRuleId;
+ eventRate.aggregationTimeWindow = this.eventRateTime;
+ eventRate.aggregationType = this.eventRateMode;
+ this.adapterDescription.rules.push(eventRate);
+ }
+ }
+
public removeSelection() {
this.removeSelectionEmitter.emit();
}
diff --git
a/ui/src/app/connect/dialog/edit-event-property/components/edit-unit-transformation/edit-unit-transformation.component.ts
b/ui/src/app/connect/dialog/edit-event-property/components/edit-unit-transformation/edit-unit-transformation.component.ts
index 6b21a3405b..014deb91f3 100644
---
a/ui/src/app/connect/dialog/edit-event-property/components/edit-unit-transformation/edit-unit-transformation.component.ts
+++
b/ui/src/app/connect/dialog/edit-event-property/components/edit-unit-transformation/edit-unit-transformation.component.ts
@@ -29,7 +29,7 @@ import { EventPropertyPrimitive } from
'@streampipes/platform-services';
templateUrl: './edit-unit-transformation.component.html',
styleUrls: ['./edit-unit-transformation.component.scss'],
})
-export class EditUnitTransformationComponent implements OnInit {
+export class EditUnitTransformationComponent {
@Input() cachedProperty: EventPropertyPrimitive;
@Input() originalProperty: EventPropertyPrimitive;
@@ -64,6 +64,7 @@ export class EditUnitTransformationComponent implements
OnInit {
: this.allUnits.slice(),
),
);
+ this.applySelectedUnits();
});
this.currentUnitStateCtrl.valueChanges.subscribe(val => {
@@ -79,7 +80,7 @@ export class EditUnitTransformationComponent implements
OnInit {
protected open = false;
- ngOnInit() {
+ applySelectedUnits(): void {
if (this.cachedProperty.measurementUnit) {
const sourceUnit = this.cachedProperty.additionalMetadata
.toMeasurementUnit
diff --git a/ui/src/app/connect/services/transformation-rule.service.ts
b/ui/src/app/connect/services/transformation-rule.service.ts
index 5d87c36d69..f6eaf0823c 100644
--- a/ui/src/app/connect/services/transformation-rule.service.ts
+++ b/ui/src/app/connect/services/transformation-rule.service.ts
@@ -18,6 +18,7 @@
import { Injectable } from '@angular/core';
import {
+ AdapterDescription,
AddTimestampRuleDescription,
AddValueTransformationRuleDescription,
ChangeDatatypeTransformationRuleDescription,
@@ -49,7 +50,7 @@ export class TransformationRuleService {
private delimiter = '<-=>';
- public getTransformationRuleDescriptions(
+ public makeTransformationRuleDescriptions(
originalSchema: EventSchema,
targetSchema: EventSchema,
): TransformationRuleDescriptionUnion[] {
@@ -734,4 +735,13 @@ export class TransformationRuleService {
rule.replaceAll = eventProperty.additionalMetadata.replaceAll ?? false;
return rule;
}
+
+ public getExistingTransformationRule<T>(
+ adapterDescription: AdapterDescription,
+ transformationRuleType: string,
+ ): T {
+ return adapterDescription.rules.find(
+ r => r['@class'] === transformationRuleType,
+ ) as T;
+ }
}