Skip to content
Snippets Groups Projects
Commit c8da0376 authored by Jonas Schlabertz's avatar Jonas Schlabertz
Browse files

Small fixes and improvements after first eval.

parent 12526ee4
Branches
No related tags found
No related merge requests found
Pipeline #158492 passed
No preview for this file type
...@@ -108,7 +108,14 @@ export default class TypeDefinition { ...@@ -108,7 +108,14 @@ export default class TypeDefinition {
} }
validateData(data: Record<string, unknown>): boolean { 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 { toJSONLDWithData(data: Record<string, unknown>): NodeObject {
......
{
"name": "batteryLevel",
"description": "Measured battery level."
}
\ No newline at end of file
{
"name": "calibration",
"description": "Calibration value list."
}
\ No newline at end of file
{
"name": "calibrationDate",
"description": "Date of when sensor was last calibrated."
}
\ No newline at end of file
{
"name": "temperature",
"description": "Measured temperature value in degree Celsius."
}
\ No newline at end of file
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
import { Router } from "express"; import express from "express";
import { Connection } from "typeorm"; import { Connection } from "typeorm";
abstract class GenericRouter { abstract class GenericRouter {
public expressRouter = Router({ mergeParams: true }) public expressRouter: express.Router = express.Router({ mergeParams: true })
connection: Connection connection: Connection
constructor(connection: Connection) { constructor(connection: Connection) {
......
...@@ -6,6 +6,7 @@ import VocabularyRouter from "./VocabularyRouter"; ...@@ -6,6 +6,7 @@ import VocabularyRouter from "./VocabularyRouter";
import ComponentRelationRouter from "./ComponentRelationRouter"; import ComponentRelationRouter from "./ComponentRelationRouter";
import TypeDefinitionRouter from "./TypeDefinitionRouter"; import TypeDefinitionRouter from "./TypeDefinitionRouter";
import MeasurementRouter from "./MeasurementRouter"; import MeasurementRouter from "./MeasurementRouter";
import ContextRouter from "./ContextRouter";
class MainRouter extends GenericRouter { class MainRouter extends GenericRouter {
...@@ -15,6 +16,7 @@ class MainRouter extends GenericRouter { ...@@ -15,6 +16,7 @@ class MainRouter extends GenericRouter {
private relationRouter: ComponentRelationRouter private relationRouter: ComponentRelationRouter
private typeDefinitionRouter: TypeDefinitionRouter private typeDefinitionRouter: TypeDefinitionRouter
private measurementRouter: MeasurementRouter private measurementRouter: MeasurementRouter
private contextRouter: ContextRouter
constructor(connection: Connection) { constructor(connection: Connection) {
super(connection); super(connection);
...@@ -24,6 +26,7 @@ class MainRouter extends GenericRouter { ...@@ -24,6 +26,7 @@ class MainRouter extends GenericRouter {
this.relationRouter = new ComponentRelationRouter(this.connection); this.relationRouter = new ComponentRelationRouter(this.connection);
this.typeDefinitionRouter = new TypeDefinitionRouter(this.connection); this.typeDefinitionRouter = new TypeDefinitionRouter(this.connection);
this.measurementRouter = new MeasurementRouter(this.connection); this.measurementRouter = new MeasurementRouter(this.connection);
this.contextRouter = new ContextRouter(this.connection);
this.setup(); this.setup();
} }
...@@ -35,6 +38,7 @@ class MainRouter extends GenericRouter { ...@@ -35,6 +38,7 @@ class MainRouter extends GenericRouter {
this.expressRouter.use("/relation", this.relationRouter.expressRouter); this.expressRouter.use("/relation", this.relationRouter.expressRouter);
this.expressRouter.use("/type", this.typeDefinitionRouter.expressRouter); this.expressRouter.use("/type", this.typeDefinitionRouter.expressRouter);
this.expressRouter.use("/measurement", this.measurementRouter.expressRouter); this.expressRouter.use("/measurement", this.measurementRouter.expressRouter);
this.expressRouter.use("/context", this.contextRouter.expressRouter);
} }
} }
......
...@@ -3,14 +3,14 @@ import ComponentInformation from "../entity/ComponentInformation"; ...@@ -3,14 +3,14 @@ import ComponentInformation from "../entity/ComponentInformation";
const component = { const component = {
"id": { "@id": "https://schema.org/url", "@type": "@id"}, "id": { "@id": "https://schema.org/url", "@type": "@id"},
"dateCreated": "https://schema.org/dateCreated", "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 = { const componentRelation = {
"id": { "@id": "https://schema.org/url", "@type": "@id"}, "id": { "@id": "https://schema.org/url", "@type": "@id"},
"from": "https://schema.org/DateTime", "from": "https://schema.org/DateTime",
"to": "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> { 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 ...@@ -19,11 +19,10 @@ const information = function(metadataContext: unknown, previousVersion: Componen
"component": { "@id": "https://schema.org/url", "@type": "@id"}, "component": { "@id": "https://schema.org/url", "@type": "@id"},
"dateCreated": "https://schema.org/dateCreated", "dateCreated": "https://schema.org/dateCreated",
"name": "https://schema.org/name", "name": "https://schema.org/name",
"comment": "http://schema.org/comment", "comment": "https://schema.org/comment",
"informationLicense": "http://www.w3.org/1999/xhtml/vocab#license", "informationLicense": "https://www.w3.org/1999/xhtml/vocab#license",
"measurementLicense": "http://www.w3.org/1999/xhtml/vocab#license", "measurementLicense": "https://www.w3.org/1999/xhtml/vocab#license",
"topic": "https://schema.org/text", "topic": "https://schema.org/text"
"metadata": metadataContext
}; };
if(previousVersion) { if(previousVersion) {
...@@ -41,7 +40,7 @@ const measurement = function(valueContext: unknown, metadataContext: unknown | u ...@@ -41,7 +40,7 @@ const measurement = function(valueContext: unknown, metadataContext: unknown | u
const result: Record<string, unknown> = { const result: Record<string, unknown> = {
"id": { "@id": "https://schema.org/url", "@type": "@id"}, "id": { "@id": "https://schema.org/url", "@type": "@id"},
"dateCreated": "https://schema.org/dateCreated", "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 "value": valueContext
}; };
...@@ -55,9 +54,9 @@ const measurement = function(valueContext: unknown, metadataContext: unknown | u ...@@ -55,9 +54,9 @@ const measurement = function(valueContext: unknown, metadataContext: unknown | u
const typeDefinition = { const typeDefinition = {
"name": { "@id": "https://schema.org/url", "@type": "@id"}, "name": { "@id": "https://schema.org/url", "@type": "@id"},
"dateCreated": "https://schema.org/dateCreated", "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", "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 { export default {
......
...@@ -220,13 +220,14 @@ const createTypeDefinitionBaseSchema: Schema = { ...@@ -220,13 +220,14 @@ const createTypeDefinitionBaseSchema: Schema = {
name: { name: {
in: ["body"], in: ["body"],
errorMessage: "No name set.", errorMessage: "No name set.",
isString: true isString: true,
notEmpty: true
}, },
comment: { comment: {
in: ["body"], in: ["body"],
errorMessage: "Comment must be a string.", errorMessage: "Comment must be a string.",
isString: true, isString: true,
optional: true optional: true,
}, },
schema: { schema: {
in: ["body"], in: ["body"],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment