Skip to content

Commit

Permalink
refactor(#2615): Change datatypes from class to string (#2616)
Browse files Browse the repository at this point in the history
* refactor(#2615): Change datatypes from class to string

* refactor(#2615): Move and rename data-type.service

* refactor(#2615): Moving all data types to the data type service

* refactor(#2615): Make semantic data type service static

* refactor(#2615): Change data type names to upper case

* refactor(#2615): Add geo variables to semantic type service

* refactor(#2615): Rename classes semantic type and data type

* fix: Fix linting

* fix(#2651): Change import to platform-service

* fix(#2651): Remove circular dependency
  • Loading branch information
tenthe authored Apr 6, 2024
1 parent 223aa0a commit 45528b2
Show file tree
Hide file tree
Showing 22 changed files with 190 additions and 243 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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.
*
*/

export class DataType {
public static readonly XSD: string = 'http://www.w3.org/2001/XMLSchema#';

public static readonly INTEGER = this.XSD + 'integer';
public static readonly LONG = this.XSD + 'long';
public static readonly FLOAT = this.XSD + 'float';
public static readonly BOOLEAN = this.XSD + 'boolean';
public static readonly STRING = this.XSD + 'string';
public static readonly DOUBLE = this.XSD + 'double';
public static readonly NUMBER = this.XSD + 'number';

public static isNumberType(datatype: string): boolean {
return (
datatype === DataType.DOUBLE ||
datatype === DataType.INTEGER ||
datatype === DataType.LONG ||
datatype === DataType.FLOAT ||
datatype === DataType.NUMBER
);
}

public static isBooleanType(datatype: string): boolean {
return datatype === DataType.BOOLEAN;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* 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 { EventProperty } from '../gen/streampipes-model';

export class SemanticType {
public static readonly SO: string = 'http://schema.org/';
public static readonly GEO: string = 'http://www.w3.org/2003/01/geo/';

public static readonly TIMESTAMP: string = SemanticType.SO + 'DateTime';

public static readonly SO_NUMBER: string = SemanticType.SO + 'Number';
public static readonly SO_URL: string = SemanticType.SO + 'URL';

public static readonly IMAGE: string = 'https://image.com';

public static readonly GEO_LAT: string = SemanticType.GEO + 'wgs84_pos#lat';
public static readonly GEO_LONG: string =
SemanticType.GEO + 'wgs84_pos#long';

public static getValue(inputValue: any, semanticType: string) {
if (semanticType === SemanticType.TIMESTAMP) {
return new Date(inputValue).toLocaleString();
} else {
return inputValue;
}
}

public static isTimestamp(property: EventProperty): boolean {
return property.domainProperties.includes(SemanticType.TIMESTAMP);
}

public static isImage(property: EventProperty): boolean {
return property.domainProperties.includes(SemanticType.IMAGE);
}

public static isNumber(property: EventProperty): boolean {
return property.domainProperties.includes(SemanticType.SO_NUMBER);
}
}
3 changes: 3 additions & 0 deletions ui/projects/streampipes/platform-services/src/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,6 @@ export * from './lib/model/user/user.model';

export * from './lib/model/assets/asset.model';
export * from './lib/model/labels/labels.model';

export * from './lib/model/types/data-type';
export * from './lib/model/types/semantic-type';
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import { Component, EventEmitter, Input, Output } from '@angular/core';
import { SpServiceConfiguration } from '@streampipes/platform-services';
import { SemanticTypeService } from '../../../../core-services/types/semantic-type.service';

@Component({
selector: 'sp-service-configs',
Expand All @@ -29,7 +28,7 @@ export class ServiceConfigsComponent {
@Output() updateServiceConfiguration: EventEmitter<SpServiceConfiguration> =
new EventEmitter<SpServiceConfiguration>();

constructor(public semanticTypeService: SemanticTypeService) {}
constructor() {}

updateConfiguration(): void {
this.updateServiceConfiguration.emit(this.serviceConfiguration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { TreeNode } from '@ali-hm/angular-tree-component';
import {
DataType,
EventProperty,
EventPropertyList,
EventPropertyNested,
EventPropertyPrimitive,
EventPropertyUnion,
EventSchema,
SemanticType,
FieldStatusInfo,
} from '@streampipes/platform-services';
import { EditEventPropertyComponent } from '../../../../dialog/edit-event-property/edit-event-property.component';
Expand All @@ -33,7 +35,6 @@ import { StaticValueTransformService } from '../../../../services/static-value-t
import { EventPropertyUtilsService } from '../../../../services/event-property-utils.service';
import { ShepherdService } from '../../../../../services/tour/shepherd.service';
import { IdGeneratorService } from '../../../../../core-services/id-generator/id-generator.service';
import { SemanticTypeService } from '../../../../../core-services/types/semantic-type.service';

@Component({
selector: 'sp-event-property-row',
Expand Down Expand Up @@ -75,7 +76,6 @@ export class EventPropertyRowComponent implements OnInit {
private epUtils: EventPropertyUtilsService,
private shepherdService: ShepherdService,
private idGeneratorService: IdGeneratorService,
private semanticTypeService: SemanticTypeService,
) {}

ngOnInit() {
Expand Down Expand Up @@ -161,11 +161,9 @@ export class EventPropertyRowComponent implements OnInit {
isTimestampProperty(node) {
if (
node.domainProperties &&
node.domainProperties.some(
dp => dp === this.semanticTypeService.TIMESTAMP,
)
node.domainProperties.some(dp => dp === SemanticType.TIMESTAMP)
) {
node.runtimeType = this.semanticTypeService.XS_LONG;
node.runtimeType = DataType.LONG;
return true;
} else {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import {
} from '@angular/core';
import { RestService } from '../../../../services/rest.service';
import { ITreeOptions, TreeComponent } from '@ali-hm/angular-tree-component';
import { DataTypesService } from '../../../../services/data-type.service';
import {
AdapterDescription,
DataType,
EventPropertyNested,
EventPropertyPrimitive,
EventPropertyUnion,
Expand All @@ -43,7 +43,7 @@ import { UserErrorMessage } from '../../../../../core-model/base/UserErrorMessag
import { TransformationRuleService } from '../../../../services/transformation-rule.service';
import { StaticValueTransformService } from '../../../../services/static-value-transform.service';
import { IdGeneratorService } from '../../../../../core-services/id-generator/id-generator.service';
import { SemanticTypeService } from '../../../../../core-services/types/semantic-type.service';
import { SemanticType } from '@streampipes/platform-services';

@Component({
selector: 'sp-event-schema',
Expand All @@ -53,11 +53,9 @@ import { SemanticTypeService } from '../../../../../core-services/types/semantic
export class EventSchemaComponent implements OnChanges {
constructor(
private restService: RestService,
private dataTypesService: DataTypesService,
private transformationRuleService: TransformationRuleService,
private staticValueTransformService: StaticValueTransformService,
private idGeneratorService: IdGeneratorService,
private semanticTypeService: SemanticTypeService,
) {}

@Input()
Expand Down Expand Up @@ -230,7 +228,7 @@ export class EventSchemaComponent implements OnChanges {
this.staticValueTransformService.makeDefaultElementId();

eventProperty.runtimeName = runtimeName;
eventProperty.runtimeType = this.dataTypesService.getStringTypeUrl();
eventProperty.runtimeType = DataType.STRING;
eventProperty.domainProperties = [];
eventProperty.propertyScope = 'DIMENSION_PROPERTY';
eventProperty.additionalMetadata = {};
Expand All @@ -250,9 +248,9 @@ export class EventSchemaComponent implements OnChanges {
eventProperty.runtimeName = 'timestamp';
eventProperty.label = 'Timestamp';
eventProperty.description = 'The current timestamp value';
eventProperty.domainProperties = [this.semanticTypeService.TIMESTAMP];
eventProperty.domainProperties = [SemanticType.TIMESTAMP];
eventProperty.propertyScope = 'HEADER_PROPERTY';
eventProperty.runtimeType = this.semanticTypeService.XS_LONG;
eventProperty.runtimeType = DataType.LONG;
eventProperty.additionalMetadata = {};

this.targetSchema.eventProperties.push(eventProperty);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ import {
import { UntypedFormControl } from '@angular/forms';
import { Observable } from 'rxjs';
import { ShepherdService } from '../../../../../services/tour/shepherd.service';
import { SemanticTypesRestService } from '../../../../../../../projects/streampipes/platform-services/src/lib/apis/semantic-types-rest.service';
import { SemanticTypeService } from '../../../../../core-services/types/semantic-type.service';
import {
DataType,
SemanticType,
SemanticTypesRestService,
} from '@streampipes/platform-services';

@Component({
selector: 'sp-edit-schema-transformation',
Expand All @@ -51,7 +54,6 @@ export class EditSchemaTransformationComponent implements OnInit {

constructor(
private semanticTypesRestService: SemanticTypesRestService,
private semanticTypeService: SemanticTypeService,
private shepherdService: ShepherdService,
) {}

Expand All @@ -71,11 +73,9 @@ export class EditSchemaTransformationComponent implements OnInit {
editTimestampDomainProperty(checked: boolean) {
if (checked) {
this.isTimestampProperty = true;
this.cachedProperty.domainProperties = [
this.semanticTypeService.TIMESTAMP,
];
this.cachedProperty.domainProperties = [SemanticType.TIMESTAMP];
this.cachedProperty.propertyScope = 'HEADER_PROPERTY';
this.cachedProperty.runtimeType = this.semanticTypeService.XS_LONG;
this.cachedProperty.runtimeType = DataType.LONG;
} else {
this.cachedProperty.domainProperties = [];
this.cachedProperty.propertyScope = 'MEASUREMENT_PROPERTY';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ import {
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';
import { EditUnitTransformationComponent } from './components/edit-unit-transformation/edit-unit-transformation.component';
import { ShepherdService } from '../../../services/tour/shepherd.service';
import { SemanticTypeService } from '../../../core-services/types/semantic-type.service';

@Component({
selector: 'sp-edit-event-property',
Expand Down Expand Up @@ -70,19 +70,16 @@ export class EditEventPropertyComponent implements OnInit {

private propertyForm: UntypedFormGroup;

private runtimeDataTypes;

constructor(
public dialogRef: DialogRef<EditEventPropertyComponent>,
private formBuilder: UntypedFormBuilder,
private dataTypeService: DataTypesService,
private semanticTypeUtilsService: SemanticTypeService,
private shepherdService: ShepherdService,
) {}

ngOnInit(): void {
this.cachedProperty = this.copyEp(this.property);
this.isTimestampProperty = this.semanticTypeUtilsService.isTimestamp(
this.isTimestampProperty = SemanticType.isTimestamp(
this.cachedProperty,
);
this.isEventPropertyList = this.property instanceof EventPropertyList;
Expand All @@ -91,7 +88,7 @@ export class EditEventPropertyComponent implements OnInit {
this.isEventPropertyNested =
this.property instanceof EventPropertyNested;
this.isNumericProperty =
this.semanticTypeUtilsService.isNumber(this.cachedProperty) ||
SemanticType.isNumber(this.cachedProperty) ||
this.dataTypeService.isNumeric(
(this.cachedProperty as any).runtimeType,
);
Expand Down
12 changes: 6 additions & 6 deletions ui/src/app/connect/filter/timestamp.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@
*/

import { Pipe, PipeTransform } from '@angular/core';
import { EventPropertyUnion } from '@streampipes/platform-services';
import { SemanticTypeService } from '../../core-services/types/semantic-type.service';
import {
EventPropertyUnion,
SemanticType,
} from '@streampipes/platform-services';

@Pipe({
name: 'timestampFilter',
pure: false,
})
export class TimestampPipe implements PipeTransform {
constructor(private semanticTypeService: SemanticTypeService) {}
constructor() {}

transform(items: EventPropertyUnion[]): EventPropertyUnion[] {
return items.filter(item =>
item.domainProperties.some(
dp => dp === this.semanticTypeService.TIMESTAMP,
),
item.domainProperties.some(dp => dp === SemanticType.TIMESTAMP),
);
}
}
5 changes: 2 additions & 3 deletions ui/src/app/connect/services/transformation-rule.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,18 @@ import {
EventSchema,
MoveRuleDescription,
RenameRuleDescription,
SemanticType,
TimestampTranfsformationRuleDescription,
TransformationRuleDescriptionUnion,
UnitTransformRuleDescription,
} from '@streampipes/platform-services';
import { TimestampTransformationRuleMode } from '../model/TimestampTransformationRuleMode';
import { StaticValueTransformService } from './static-value-transform.service';
import { SemanticTypeService } from '../../core-services/types/semantic-type.service';

@Injectable({ providedIn: 'root' })
export class TransformationRuleService {
constructor(
private staticValueTransformService: StaticValueTransformService,
private semanticTypeService: SemanticTypeService,
) {}

public getTransformationRuleDescriptions(
Expand Down Expand Up @@ -585,7 +584,7 @@ export class TransformationRuleService {

isTimestampProperty(property: EventPropertyPrimitive) {
return property.domainProperties.some(
dp => dp === this.semanticTypeService.TIMESTAMP,
dp => dp === SemanticType.TIMESTAMP,
);
}

Expand Down
Loading

0 comments on commit 45528b2

Please sign in to comment.