From f619d82efbe54676b8bb4a8e6879aeb9aaebdfb9 Mon Sep 17 00:00:00 2001 From: Philipp Zehnder Date: Wed, 17 Apr 2024 08:35:00 +0200 Subject: [PATCH] refactor: Remove legacy data type service in connect (#2739) * refactor: Remove legacy data type service in connect * refactor: Fix linting --- .../edit-data-type.component.ts | 38 ++++++++--- .../edit-event-property.component.ts | 9 +-- .../app/connect/services/data-type.service.ts | 65 ------------------- 3 files changed, 32 insertions(+), 80 deletions(-) delete mode 100644 ui/src/app/connect/services/data-type.service.ts diff --git a/ui/src/app/connect/dialog/edit-event-property/components/edit-schema-transformation/edit-data-type/edit-data-type.component.ts b/ui/src/app/connect/dialog/edit-event-property/components/edit-schema-transformation/edit-data-type/edit-data-type.component.ts index 9bb08cfbe7..caa576bf28 100644 --- a/ui/src/app/connect/dialog/edit-event-property/components/edit-schema-transformation/edit-data-type/edit-data-type.component.ts +++ b/ui/src/app/connect/dialog/edit-event-property/components/edit-schema-transformation/edit-data-type/edit-data-type.component.ts @@ -16,24 +16,44 @@ * */ -import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; -import { DataTypesService } from '../../../../../services/data-type.service'; +import { Component, EventEmitter, Input, Output } from '@angular/core'; +import { DataType } from '@streampipes/platform-services'; @Component({ selector: 'sp-edit-data-type', templateUrl: './edit-data-type.component.html', styleUrls: ['./edit-data-type.component.scss'], }) -export class EditDataTypeComponent implements OnInit { +export class EditDataTypeComponent { @Input() cachedProperty: any; @Output() dataTypeChanged = new EventEmitter(); - runtimeDataTypes; - constructor(private dataTypeService: DataTypesService) {} - - ngOnInit() { - this.runtimeDataTypes = this.dataTypeService.dataTypes; - } + runtimeDataTypes: { label: string; url: string }[] = [ + { + label: "String - A textual datatype, e.g., 'machine1'", + url: DataType.STRING, + }, + { + label: 'Boolean - A true/false value', + url: DataType.BOOLEAN, + }, + { + label: "Double - A number, e.g., '1.25'", + url: DataType.DOUBLE, + }, + { + label: "Float - A number, e.g., '1.25'", + url: DataType.FLOAT, + }, + { + label: "Integer - A number, e.g., '2'", + url: DataType.INTEGER, + }, + { + label: "Long - A number, e.g., '1623871455232'", + url: DataType.LONG, + }, + ]; valueChanged() { this.dataTypeChanged.emit(true); diff --git a/ui/src/app/connect/dialog/edit-event-property/edit-event-property.component.ts b/ui/src/app/connect/dialog/edit-event-property/edit-event-property.component.ts index 8004dfe958..f5b527b7e1 100644 --- a/ui/src/app/connect/dialog/edit-event-property/edit-event-property.component.ts +++ b/ui/src/app/connect/dialog/edit-event-property/edit-event-property.component.ts @@ -30,13 +30,13 @@ import { Validators, } from '@angular/forms'; import { + DataType, EventPropertyList, EventPropertyNested, EventPropertyPrimitive, EventPropertyUnion, SemanticType, } from '@streampipes/platform-services'; -import { DataTypesService } from '../../services/data-type.service'; import { DialogRef } from '@streampipes/shared-ui'; import { EditSchemaTransformationComponent } from './components/edit-schema-transformation/edit-schema-transformation.component'; import { EditValueTransformationComponent } from './components/edit-value-transformation/edit-value-transformation.component'; @@ -73,7 +73,6 @@ export class EditEventPropertyComponent implements OnInit { constructor( public dialogRef: DialogRef, private formBuilder: UntypedFormBuilder, - private dataTypeService: DataTypesService, private shepherdService: ShepherdService, ) {} @@ -89,9 +88,7 @@ export class EditEventPropertyComponent implements OnInit { this.property instanceof EventPropertyNested; this.isNumericProperty = SemanticType.isNumber(this.cachedProperty) || - this.dataTypeService.isNumeric( - (this.cachedProperty as any).runtimeType, - ); + DataType.isNumberType((this.cachedProperty as any).runtimeType); this.createForm(); } @@ -188,7 +185,7 @@ export class EditEventPropertyComponent implements OnInit { } handleDataTypeChange(changed: boolean) { - this.isNumericProperty = this.dataTypeService.isNumeric( + this.isNumericProperty = DataType.isNumberType( (this.cachedProperty as any).runtimeType, ); } diff --git a/ui/src/app/connect/services/data-type.service.ts b/ui/src/app/connect/services/data-type.service.ts deleted file mode 100644 index aad5dd6c3d..0000000000 --- a/ui/src/app/connect/services/data-type.service.ts +++ /dev/null @@ -1,65 +0,0 @@ -/* - * 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 { Injectable } from '@angular/core'; - -@Injectable({ providedIn: 'root' }) -export class DataTypesService { - public dataTypes: { label: string; url: string }[] = [ - { - label: "String - A textual datatype, e.g., 'machine1'", - url: 'http://www.w3.org/2001/XMLSchema#string', - }, - { - label: 'Boolean - A true/false value', - url: 'http://www.w3.org/2001/XMLSchema#boolean', - }, - { - label: "Double - A number, e.g., '1.25'", - url: 'http://www.w3.org/2001/XMLSchema#double', - }, - { - label: "Float - A number, e.g., '1.25'", - url: 'http://www.w3.org/2001/XMLSchema#float', - }, - { - label: "Integer - A number, e.g., '2'", - url: 'http://www.w3.org/2001/XMLSchema#integer', - }, - { - label: "Long - A number, e.g., '1623871455232'", - url: 'http://www.w3.org/2001/XMLSchema#long', - }, - ]; - - constructor() {} - - getStringTypeUrl(): string { - return String(this.dataTypes[0].url); - } - - isNumeric(uri: string) { - const numericDataTypes = [ - 'http://www.w3.org/2001/XMLSchema#float', - 'http://www.w3.org/2001/XMLSchema#double', - 'http://www.w3.org/2001/XMLSchema#integer', - 'http://www.w3.org/2001/XMLSchema#long', - ]; - return numericDataTypes.includes(uri); - } -}