diff --git a/API.paw b/API.paw index a6f9d7b8a2c00fc507fc48ad9a1fc741754e977a..2d3ca1276dd1269f090933f967d23a08ac493761 100644 Binary files a/API.paw and b/API.paw differ diff --git a/src/controller/ComponentController.ts b/src/controller/ComponentController.ts index 8fca5ec7a7bac88582cf4c77fc9c6ca4490aef98..449fc88abc95d4fa3386425b70a842499cca96fa 100644 --- a/src/controller/ComponentController.ts +++ b/src/controller/ComponentController.ts @@ -3,7 +3,6 @@ import Component from "../entity/Component"; import { Connection, Repository } from "typeorm"; import logService from "../services/logger"; import ComponentRelation from "../entity/ComponentRelation"; -import { NodeObject } from "jsonld"; import BaseController from "./BaseController"; import TypeDefinition from "../entity/TypeDefinition"; import ComponentInformation from "../entity/ComponentInformation"; @@ -95,7 +94,7 @@ export default class ComponentController extends BaseController { findRoots = async (request: Request, response: Response) => { const roots = await Component.findRoots(this.componentRepository, this.getMementoDate(request)); if(roots) { - const result: NodeObject[] = roots.map((root) => { return root.toJSONLD(); }); + const result: Record<string, unknown>[] = roots.map((root) => { return root.toJSONLD(); }); this.setJSONLDResponseType(response); response.send(result); } else { diff --git a/src/entity/Component.ts b/src/entity/Component.ts index 90aab338c0c55393e75e2c9ab8cb651c6efe9670..680465555d1a86eb5eb6f2af18b72d9d076a0f0a 100644 --- a/src/entity/Component.ts +++ b/src/entity/Component.ts @@ -13,7 +13,6 @@ import ComponentInformation from "./ComponentInformation"; import TypeDefinition from "./TypeDefinition"; import ComponentRelation from "./ComponentRelation"; import config from "../config"; -import { NodeObject } from "jsonld"; import ContextDefinitions from "../util/ContextDefinitions"; import Measurement from "./Measurement"; @@ -185,8 +184,8 @@ export default class Component { return new ComponentRelation(parent, child, relationLicense); } - toJSONLD(): NodeObject { - const document: NodeObject = { + toJSONLD(): Record<string, unknown> { + const document: Record<string, unknown> = { "@context": ContextDefinitions.component, "@type": "Component", "identifier": { "@id": `${config.baseURL}/component/${this.id.toString()}`}, @@ -195,7 +194,7 @@ export default class Component { }; if (this.isComponentOf) { - const relationJSONLD: NodeObject[] = this.isComponentOf.map((relation) => { return relation.toJSONLD(); }); + const relationJSONLD: Record<string, unknown>[] = this.isComponentOf.map((relation) => { return relation.toJSONLD(); }); if (relationJSONLD.length == 1) { document.isComponentOf = relationJSONLD[0]; } else { diff --git a/src/entity/ComponentInformation.ts b/src/entity/ComponentInformation.ts index 26d3641e06688434b1d9960eacd6033a2f6b862f..82c5801084f5f1456f27c50059f2ab6726e3ee8c 100644 --- a/src/entity/ComponentInformation.ts +++ b/src/entity/ComponentInformation.ts @@ -15,7 +15,6 @@ import { } from "typeorm"; import Component from "./Component"; import Measurement from "./Measurement"; -import { NodeObject } from "jsonld"; import config from "../config"; import ContextDefinitions from "../util/ContextDefinitions"; import TypeDefinition from "./TypeDefinition"; @@ -153,7 +152,8 @@ export default class ComponentInformation { "nextVersion", "previousVersion", "measurements", - "type" + "type", + "measurementTargets" ] } ); @@ -166,19 +166,32 @@ export default class ComponentInformation { // JSONLD Serializer - toJSONLD(): NodeObject { - const document: NodeObject = { - "@context": ContextDefinitions.information, + toJSONLD(): Record<string, unknown> { + const document: Record<string, unknown> = { + "@context": ContextDefinitions.information(this.type.context, this.previousVersion, this.nextVersion), "@type": "ComponentInformation", "identifier": { "@id": `${config.baseURL}/information/${this.id.toString()}` }, "dateCreated": this.dateCreated.toISOString(), "name": this.name, "comment": this.comment, "metadata": this.type.toJSONLD(this.metadata), + "topic": this.topic, + "component": { "@id": `${config.baseURL}/component/${this.component.id.toString()}` }, "informationLicense": this.informationLicense, - "measurementLicense": this.measurementLicense + "measurementLicense": this.measurementLicense, + "measurementTargets": this.measurementTargets.map((component) => { + return { "@id": `${config.baseURL}/component/${component.id.toString()}` }; + }) }; + if(this.nextVersion) { + document.nextVersion = { "@id": `${config.baseURL}/information/${this.nextVersion.id.toString()}` }; + } + + if(this.previousVersion) { + document.previousVersion = { "@id": `${config.baseURL}/information/${this.previousVersion.id.toString()}` }; + } + return document; } diff --git a/src/util/ContextDefinitions.ts b/src/util/ContextDefinitions.ts index c2bc4d941a2efd3d48217f40d847d620b141aed6..bca51469ce70078f520ab39a7d1d02285a2e3f07 100644 --- a/src/util/ContextDefinitions.ts +++ b/src/util/ContextDefinitions.ts @@ -1,3 +1,5 @@ +import ComponentInformation from "../entity/ComponentInformation"; + const component = { "id": { "@id": "https://schema.org/url", "@type": "@id"}, "dateCreated": "https://schema.org/DateTime", @@ -11,13 +13,28 @@ const componentRelation = { "license": "https://schema.org/license" }; -const information = { - "id": { "@id": "https://schema.org/url", "@type": "@id"}, - "dateCreated": "https://schema.org/DateTime", - "name": "https://schema.org/name", - "comment": "http://schema.org/comment", - "informationLicense": "https://schema.org/license", - "measurementLicense": "https://schema.org/license" +const information = function(metadataContext: unknown, previousVersion: ComponentInformation | undefined, nextVersion: ComponentInformation | undefined): Record<string, unknown> { + const result: Record<string, unknown> = { + "id": { "@id": "https://schema.org/url", "@type": "@id"}, + "component": { "@id": "https://schema.org/url", "@type": "@id"}, + "dateCreated": "https://schema.org/DateTime", + "name": "https://schema.org/name", + "comment": "http://schema.org/comment", + "informationLicense": "https://schema.org/license", + "measurementLicense": "https://schema.org/license", + "topic": "https://schema.org/text", + "metadata": metadataContext + }; + + if(previousVersion) { + result.previousVersion = { "@id": "https://schema.org/url", "@type": "@id"}; + } + + if(nextVersion) { + result.nextVersion = { "@id": "https://schema.org/url", "@type": "@id"}; + } + + return result; }; const measurement = function(valueContext: unknown, metadataContext: unknown | undefined): Record<string, unknown> {