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" > - + - + ( + 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( + 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( + adapterDescription: AdapterDescription, + transformationRuleType: string, + ): T { + return adapterDescription.rules.find( + r => r['@class'] === transformationRuleType, + ) as T; + } }