You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by ri...@apache.org on 2020/02/17 20:10:58 UTC

[incubator-streampipes] branch dev updated: Add annotation to support serialization of float values from numbers in tsonLd

This is an automated email from the ASF dual-hosted git repository.

riemer pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes.git


The following commit(s) were added to refs/heads/dev by this push:
     new 9500c5b  Add annotation to support serialization of float values from numbers in tsonLd
9500c5b is described below

commit 9500c5b11055991dad1f7e863257173c8e33e60e
Author: Dominik Riemer <ri...@fzi.de>
AuthorDate: Mon Feb 17 21:10:46 2020 +0100

    Add annotation to support serialization of float values from numbers in tsonLd
---
 .../connect/schema-editor/model/QuantitativeValue.ts |  6 ++++--
 .../sdk/extractor/static-property-extractor.ts       |  2 +-
 ui/src/app/platform-services/tsonld/Float.ts         | 20 ++++++++++++++++++++
 ui/src/app/platform-services/tsonld/tsonld.ts        |  7 ++++++-
 4 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/ui/src/app/connect/schema-editor/model/QuantitativeValue.ts b/ui/src/app/connect/schema-editor/model/QuantitativeValue.ts
index 3fb047d..b429212 100644
--- a/ui/src/app/connect/schema-editor/model/QuantitativeValue.ts
+++ b/ui/src/app/connect/schema-editor/model/QuantitativeValue.ts
@@ -19,8 +19,7 @@
 import { RdfsClass } from '../../../platform-services/tsonld/RdfsClass';
 import { RdfProperty } from '../../../platform-services/tsonld/RdfsProperty';
 import { RdfId } from '../../../platform-services/tsonld/RdfId';
-import { EventSchema } from './EventSchema';
-import { DomainPropertyProbabilityList } from './DomainPropertyProbabilityList';
+import { Float } from '../../../platform-services/tsonld/Float';
 
 @RdfsClass('http://schema.org/QuantitativeValue')
 export class QuantitativeValue {
@@ -30,12 +29,15 @@ export class QuantitativeValue {
     public id: string;
 
     @RdfProperty('http://schema.org/minValue')
+    @Float
     public minValue: Number;
 
     @RdfProperty('http://schema.org/maxValue')
+    @Float
     public maxValue: Number;
 
     @RdfProperty('http://schema.org/step')
+    @Float
     public step: Number;
 
     constructor() {}
diff --git a/ui/src/app/dashboard-v2/sdk/extractor/static-property-extractor.ts b/ui/src/app/dashboard-v2/sdk/extractor/static-property-extractor.ts
index ae73495..93d0adb 100644
--- a/ui/src/app/dashboard-v2/sdk/extractor/static-property-extractor.ts
+++ b/ui/src/app/dashboard-v2/sdk/extractor/static-property-extractor.ts
@@ -72,7 +72,7 @@ export class StaticPropertyExtractor {
 
 
     removePrefix(propertyValue: string) {
-        return propertyValue.split("::")[1];
+        return propertyValue.split("::").length > 1 ? propertyValue.split("::")[1] : propertyValue;
     }
 
 }
\ No newline at end of file
diff --git a/ui/src/app/platform-services/tsonld/Float.ts b/ui/src/app/platform-services/tsonld/Float.ts
new file mode 100644
index 0000000..75d3ba8
--- /dev/null
+++ b/ui/src/app/platform-services/tsonld/Float.ts
@@ -0,0 +1,20 @@
+/*
+ *   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 function Float(target: any, key: string) {
+    Reflect.defineMetadata('Float', 'float', target, key);
+}
\ No newline at end of file
diff --git a/ui/src/app/platform-services/tsonld/tsonld.ts b/ui/src/app/platform-services/tsonld/tsonld.ts
index 3a2bf5c..540af80 100644
--- a/ui/src/app/platform-services/tsonld/tsonld.ts
+++ b/ui/src/app/platform-services/tsonld/tsonld.ts
@@ -120,7 +120,12 @@ export class TsonLd {
         } else if (typeof jsObject[property] === 'object') {
           jsObject[newProperty] = this.toJsonLd(jsObject[property], false, allIds);
         } else {
-          jsObject[newProperty] = jsObject[property];
+          let parseHint = Reflect.hasMetadata('Float', object);
+          if (parseHint) {
+            jsObject[newProperty] = parseFloat(jsObject[property]);
+          } else {
+            jsObject[newProperty] = jsObject[property];
+          }
         }
       } else {
         jsObject['@id'] = jsObject[property];