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

Proper JSON-LD annotations for ComponentInformation.

parent 0a52c858
No related branches found
No related tags found
No related merge requests found
Pipeline #153436 passed
No preview for this file type
...@@ -3,7 +3,6 @@ import Component from "../entity/Component"; ...@@ -3,7 +3,6 @@ import Component from "../entity/Component";
import { Connection, Repository } from "typeorm"; import { Connection, Repository } from "typeorm";
import logService from "../services/logger"; import logService from "../services/logger";
import ComponentRelation from "../entity/ComponentRelation"; import ComponentRelation from "../entity/ComponentRelation";
import { NodeObject } from "jsonld";
import BaseController from "./BaseController"; import BaseController from "./BaseController";
import TypeDefinition from "../entity/TypeDefinition"; import TypeDefinition from "../entity/TypeDefinition";
import ComponentInformation from "../entity/ComponentInformation"; import ComponentInformation from "../entity/ComponentInformation";
...@@ -95,7 +94,7 @@ export default class ComponentController extends BaseController { ...@@ -95,7 +94,7 @@ export default class ComponentController extends BaseController {
findRoots = async (request: Request, response: Response) => { findRoots = async (request: Request, response: Response) => {
const roots = await Component.findRoots(this.componentRepository, this.getMementoDate(request)); const roots = await Component.findRoots(this.componentRepository, this.getMementoDate(request));
if(roots) { 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); this.setJSONLDResponseType(response);
response.send(result); response.send(result);
} else { } else {
......
...@@ -13,7 +13,6 @@ import ComponentInformation from "./ComponentInformation"; ...@@ -13,7 +13,6 @@ import ComponentInformation from "./ComponentInformation";
import TypeDefinition from "./TypeDefinition"; import TypeDefinition from "./TypeDefinition";
import ComponentRelation from "./ComponentRelation"; import ComponentRelation from "./ComponentRelation";
import config from "../config"; import config from "../config";
import { NodeObject } from "jsonld";
import ContextDefinitions from "../util/ContextDefinitions"; import ContextDefinitions from "../util/ContextDefinitions";
import Measurement from "./Measurement"; import Measurement from "./Measurement";
...@@ -185,8 +184,8 @@ export default class Component { ...@@ -185,8 +184,8 @@ export default class Component {
return new ComponentRelation(parent, child, relationLicense); return new ComponentRelation(parent, child, relationLicense);
} }
toJSONLD(): NodeObject { toJSONLD(): Record<string, unknown> {
const document: NodeObject = { const document: Record<string, unknown> = {
"@context": ContextDefinitions.component, "@context": ContextDefinitions.component,
"@type": "Component", "@type": "Component",
"identifier": { "@id": `${config.baseURL}/component/${this.id.toString()}`}, "identifier": { "@id": `${config.baseURL}/component/${this.id.toString()}`},
...@@ -195,7 +194,7 @@ export default class Component { ...@@ -195,7 +194,7 @@ export default class Component {
}; };
if (this.isComponentOf) { 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) { if (relationJSONLD.length == 1) {
document.isComponentOf = relationJSONLD[0]; document.isComponentOf = relationJSONLD[0];
} else { } else {
......
...@@ -15,7 +15,6 @@ import { ...@@ -15,7 +15,6 @@ import {
} from "typeorm"; } from "typeorm";
import Component from "./Component"; import Component from "./Component";
import Measurement from "./Measurement"; import Measurement from "./Measurement";
import { NodeObject } from "jsonld";
import config from "../config"; import config from "../config";
import ContextDefinitions from "../util/ContextDefinitions"; import ContextDefinitions from "../util/ContextDefinitions";
import TypeDefinition from "./TypeDefinition"; import TypeDefinition from "./TypeDefinition";
...@@ -153,7 +152,8 @@ export default class ComponentInformation { ...@@ -153,7 +152,8 @@ export default class ComponentInformation {
"nextVersion", "nextVersion",
"previousVersion", "previousVersion",
"measurements", "measurements",
"type" "type",
"measurementTargets"
] ]
} }
); );
...@@ -166,19 +166,32 @@ export default class ComponentInformation { ...@@ -166,19 +166,32 @@ export default class ComponentInformation {
// JSONLD Serializer // JSONLD Serializer
toJSONLD(): NodeObject { toJSONLD(): Record<string, unknown> {
const document: NodeObject = { const document: Record<string, unknown> = {
"@context": ContextDefinitions.information, "@context": ContextDefinitions.information(this.type.context, this.previousVersion, this.nextVersion),
"@type": "ComponentInformation", "@type": "ComponentInformation",
"identifier": { "@id": `${config.baseURL}/information/${this.id.toString()}` }, "identifier": { "@id": `${config.baseURL}/information/${this.id.toString()}` },
"dateCreated": this.dateCreated.toISOString(), "dateCreated": this.dateCreated.toISOString(),
"name": this.name, "name": this.name,
"comment": this.comment, "comment": this.comment,
"metadata": this.type.toJSONLD(this.metadata), "metadata": this.type.toJSONLD(this.metadata),
"topic": this.topic,
"component": { "@id": `${config.baseURL}/component/${this.component.id.toString()}` },
"informationLicense": this.informationLicense, "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; return document;
} }
......
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/DateTime", "dateCreated": "https://schema.org/DateTime",
...@@ -11,13 +13,28 @@ const componentRelation = { ...@@ -11,13 +13,28 @@ const componentRelation = {
"license": "https://schema.org/license" "license": "https://schema.org/license"
}; };
const information = { 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"}, "id": { "@id": "https://schema.org/url", "@type": "@id"},
"component": { "@id": "https://schema.org/url", "@type": "@id"},
"dateCreated": "https://schema.org/DateTime", "dateCreated": "https://schema.org/DateTime",
"name": "https://schema.org/name", "name": "https://schema.org/name",
"comment": "http://schema.org/comment", "comment": "http://schema.org/comment",
"informationLicense": "https://schema.org/license", "informationLicense": "https://schema.org/license",
"measurementLicense": "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> { const measurement = function(valueContext: unknown, metadataContext: unknown | undefined): Record<string, unknown> {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment