diff --git a/API.paw b/API.paw index dc3148a5f0d1e74cfdec34e6647cdfcf68903757..d46362bc99ceb9250c2009a15003f9fd9b6e879f 100644 Binary files a/API.paw and b/API.paw differ diff --git a/src/entity/TypeDefinition.ts b/src/entity/TypeDefinition.ts index 081efdc50fe1d913f110f91436d986d7f2a72cb5..3f4b112f1222bb304e7ebaed896d9ecda0a628e9 100644 --- a/src/entity/TypeDefinition.ts +++ b/src/entity/TypeDefinition.ts @@ -108,7 +108,14 @@ export default class TypeDefinition { } validateData(data: Record<string, unknown>): boolean { - return ajv.validate(this.schema, data); + const result = ajv.validate(this.schema, data); + + if(result) { + return true; + } else { + logger.error(`Error while validating: ${JSON.stringify(ajv.errors)}`); + return false; + } } toJSONLDWithData(data: Record<string, unknown>): NodeObject { diff --git a/src/public/batteryLevel.json b/src/public/batteryLevel.json new file mode 100644 index 0000000000000000000000000000000000000000..45848da11cb2db7514e3fd84e7e423be6018b946 --- /dev/null +++ b/src/public/batteryLevel.json @@ -0,0 +1,4 @@ +{ + "name": "batteryLevel", + "description": "Measured battery level." +} \ No newline at end of file diff --git a/src/public/calibration.json b/src/public/calibration.json new file mode 100644 index 0000000000000000000000000000000000000000..8ddaf56e0c1eb62e334832daf8d04f6273cef323 --- /dev/null +++ b/src/public/calibration.json @@ -0,0 +1,4 @@ +{ + "name": "calibration", + "description": "Calibration value list." +} \ No newline at end of file diff --git a/src/public/calibrationDate.json b/src/public/calibrationDate.json new file mode 100644 index 0000000000000000000000000000000000000000..0940a7ccd1aef64dbb170350a73b1d8d7987711c --- /dev/null +++ b/src/public/calibrationDate.json @@ -0,0 +1,4 @@ +{ + "name": "calibrationDate", + "description": "Date of when sensor was last calibrated." +} \ No newline at end of file diff --git a/src/public/temperature.json b/src/public/temperature.json new file mode 100644 index 0000000000000000000000000000000000000000..1d1af718650e97a8ff0625e26cc54f65b362e38d --- /dev/null +++ b/src/public/temperature.json @@ -0,0 +1,4 @@ +{ + "name": "temperature", + "description": "Measured temperature value in degree Celsius." +} \ No newline at end of file diff --git a/src/router/ContextRouter.ts b/src/router/ContextRouter.ts new file mode 100644 index 0000000000000000000000000000000000000000..b4fed0bbca152c5411823ec081ddfa9e463d854d --- /dev/null +++ b/src/router/ContextRouter.ts @@ -0,0 +1,23 @@ +import GenericRouter from "./GenericRouter"; +import { Connection } from "typeorm"; +import express from "express"; + +class ContextRouter extends GenericRouter { + + constructor(connection: Connection) { + super(connection); + this.setup(); + } + + setup(): void { + const staticRouter = express.static("public", { + extensions: ["json"] + }); + + this.expressRouter.use("/", staticRouter); + } + + +} + +export default ContextRouter; \ No newline at end of file diff --git a/src/router/GenericRouter.ts b/src/router/GenericRouter.ts index bfbb47a8c0479fc7f578eda93c9c3a7bfaca9558..32634516c5516bc736e3b4d7f4515395f8e7445a 100644 --- a/src/router/GenericRouter.ts +++ b/src/router/GenericRouter.ts @@ -1,9 +1,9 @@ -import { Router } from "express"; +import express from "express"; import { Connection } from "typeorm"; abstract class GenericRouter { - public expressRouter = Router({ mergeParams: true }) + public expressRouter: express.Router = express.Router({ mergeParams: true }) connection: Connection constructor(connection: Connection) { diff --git a/src/router/MainRouter.ts b/src/router/MainRouter.ts index 765285373f4f85f2e5a678bdb057a678653846c2..5f153c4957f66e79be1fa335d4938014366ce6a6 100644 --- a/src/router/MainRouter.ts +++ b/src/router/MainRouter.ts @@ -6,6 +6,7 @@ import VocabularyRouter from "./VocabularyRouter"; import ComponentRelationRouter from "./ComponentRelationRouter"; import TypeDefinitionRouter from "./TypeDefinitionRouter"; import MeasurementRouter from "./MeasurementRouter"; +import ContextRouter from "./ContextRouter"; class MainRouter extends GenericRouter { @@ -15,6 +16,7 @@ class MainRouter extends GenericRouter { private relationRouter: ComponentRelationRouter private typeDefinitionRouter: TypeDefinitionRouter private measurementRouter: MeasurementRouter + private contextRouter: ContextRouter constructor(connection: Connection) { super(connection); @@ -24,6 +26,7 @@ class MainRouter extends GenericRouter { this.relationRouter = new ComponentRelationRouter(this.connection); this.typeDefinitionRouter = new TypeDefinitionRouter(this.connection); this.measurementRouter = new MeasurementRouter(this.connection); + this.contextRouter = new ContextRouter(this.connection); this.setup(); } @@ -35,6 +38,7 @@ class MainRouter extends GenericRouter { this.expressRouter.use("/relation", this.relationRouter.expressRouter); this.expressRouter.use("/type", this.typeDefinitionRouter.expressRouter); this.expressRouter.use("/measurement", this.measurementRouter.expressRouter); + this.expressRouter.use("/context", this.contextRouter.expressRouter); } } diff --git a/src/util/ContextDefinitions.ts b/src/util/ContextDefinitions.ts index dec5d971faa55a13ebba22930e2af9d3a20facb9..61f614d59bc7c755a6ad1eb6b84df1bbb0ec6e6b 100644 --- a/src/util/ContextDefinitions.ts +++ b/src/util/ContextDefinitions.ts @@ -3,14 +3,14 @@ import ComponentInformation from "../entity/ComponentInformation"; const component = { "id": { "@id": "https://schema.org/url", "@type": "@id"}, "dateCreated": "https://schema.org/dateCreated", - "license": "http://www.w3.org/1999/xhtml/vocab#license" + "license": "https://www.w3.org/1999/xhtml/vocab#license" }; const componentRelation = { "id": { "@id": "https://schema.org/url", "@type": "@id"}, "from": "https://schema.org/DateTime", "to": "https://schema.org/DateTime", - "license": "http://www.w3.org/1999/xhtml/vocab#license" + "license": "https://www.w3.org/1999/xhtml/vocab#license" }; const information = function(metadataContext: unknown, previousVersion: ComponentInformation | undefined, nextVersion: ComponentInformation | undefined): Record<string, unknown> { @@ -19,11 +19,10 @@ const information = function(metadataContext: unknown, previousVersion: Componen "component": { "@id": "https://schema.org/url", "@type": "@id"}, "dateCreated": "https://schema.org/dateCreated", "name": "https://schema.org/name", - "comment": "http://schema.org/comment", - "informationLicense": "http://www.w3.org/1999/xhtml/vocab#license", - "measurementLicense": "http://www.w3.org/1999/xhtml/vocab#license", - "topic": "https://schema.org/text", - "metadata": metadataContext + "comment": "https://schema.org/comment", + "informationLicense": "https://www.w3.org/1999/xhtml/vocab#license", + "measurementLicense": "https://www.w3.org/1999/xhtml/vocab#license", + "topic": "https://schema.org/text" }; if(previousVersion) { @@ -41,7 +40,7 @@ const measurement = function(valueContext: unknown, metadataContext: unknown | u const result: Record<string, unknown> = { "id": { "@id": "https://schema.org/url", "@type": "@id"}, "dateCreated": "https://schema.org/dateCreated", - "license": "http://www.w3.org/1999/xhtml/vocab#license", + "license": "https://www.w3.org/1999/xhtml/vocab#license", "value": valueContext }; @@ -55,9 +54,9 @@ const measurement = function(valueContext: unknown, metadataContext: unknown | u const typeDefinition = { "name": { "@id": "https://schema.org/url", "@type": "@id"}, "dateCreated": "https://schema.org/dateCreated", - "comment": "http://schema.org/comment", + "comment": "https://schema.org/comment", "schema": "https://json-schema.org/draft/2020-12/json-schema-core.html", - "license": "http://www.w3.org/1999/xhtml/vocab#license", + "license": "https://www.w3.org/1999/xhtml/vocab#license", }; export default { diff --git a/src/util/SchemaDefinitions.ts b/src/util/SchemaDefinitions.ts index 11db23e442a9670c8fd54130ac13278a5d139b5f..86005efaccae856d38c0aee0bae4d8006bae0608 100644 --- a/src/util/SchemaDefinitions.ts +++ b/src/util/SchemaDefinitions.ts @@ -220,13 +220,14 @@ const createTypeDefinitionBaseSchema: Schema = { name: { in: ["body"], errorMessage: "No name set.", - isString: true + isString: true, + notEmpty: true }, comment: { in: ["body"], errorMessage: "Comment must be a string.", isString: true, - optional: true + optional: true, }, schema: { in: ["body"],