From fd27e88386bd4d22f9ca156a834efd1920709212 Mon Sep 17 00:00:00 2001 From: "argiro.kokogiannaki" Date: Wed, 15 Jul 2020 13:59:09 +0000 Subject: [PATCH] [Library|Trunk] JSONLD changes: Add id in every jsonld Home page: remove search action from Organization Add description in Organization Add Website with search action Add Organization and Website in every page In every search page add is part of the Website In result landing (Type Dataset) when there is no description add title in description git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@59134 d315682c-612b-4755-9ff5-7f18f6832af3 --- .../schema2jsonld/model/jsonld-document.ts | 1 + .../schema2jsonld/schema2jsonld.component.ts | 9 ++- .../jsonld-document-serializer.service.ts | 1 + .../open-aire-jsonld-converter.service.ts | 74 ++++++++++++------- .../result-preview.component.html | 2 +- 5 files changed, 57 insertions(+), 30 deletions(-) diff --git a/sharedComponents/schema2jsonld/model/jsonld-document.ts b/sharedComponents/schema2jsonld/model/jsonld-document.ts index 05f45d21..851c2c33 100644 --- a/sharedComponents/schema2jsonld/model/jsonld-document.ts +++ b/sharedComponents/schema2jsonld/model/jsonld-document.ts @@ -1,4 +1,5 @@ export class JsonldDocument { + id: string; title: String[]; description: String[]; identifier: Identifier[]; diff --git a/sharedComponents/schema2jsonld/schema2jsonld.component.ts b/sharedComponents/schema2jsonld/schema2jsonld.component.ts index 0c96eee5..518ac4f5 100644 --- a/sharedComponents/schema2jsonld/schema2jsonld.component.ts +++ b/sharedComponents/schema2jsonld/schema2jsonld.component.ts @@ -1,4 +1,4 @@ -import {Component, ElementRef, Input} from '@angular/core'; +import {Component, Input} from '@angular/core'; import {OpenAireJsonldConverterService} from './service/open-aire-jsonld-converter.service'; import {JsonldDocumentSerializerService} from './service/jsonld-document-serializer.service'; @@ -16,6 +16,7 @@ export class Schema2jsonldComponent { @Input() name; @Input() searchAction = true; @Input() type = "result"; + @Input() description; public json; constructor(private documentParser: OpenAireJsonldConverterService, @@ -35,14 +36,14 @@ export class Schema2jsonldComponent { docOvject = this.documentParser.convertDatasource(this.data, this.URL, this.otherURL); this.json = this.documentSerializer.serializeOrganization(docOvject); } else if (this.type == 'home') { - this.json = this.documentParser.createHome(this.name, this.URL, this.logoURL); + this.json = this.documentParser.createHome(this.name, this.URL, this.logoURL, this.description); } else if (this.type == 'search') { - this.json = this.documentParser.createSearchPage(this.name, this.URL, this.logoURL, this.searchAction); + this.json = this.documentParser.createSearchPage(this.name, this.URL, this.logoURL, this.searchAction, this.description); } else if (this.type == 'result') { docOvject = this.documentParser.convertResult(this.data, this.URL); this.json = this.documentSerializer.serializeDataset(docOvject); } else { - this.json = this.documentParser.createSimplePage(this.name, this.URL); + this.json = this.documentParser.createSimplePage(this.name, this.URL, this.description); } } } diff --git a/sharedComponents/schema2jsonld/service/jsonld-document-serializer.service.ts b/sharedComponents/schema2jsonld/service/jsonld-document-serializer.service.ts index b245fccf..8c95ccc1 100644 --- a/sharedComponents/schema2jsonld/service/jsonld-document-serializer.service.ts +++ b/sharedComponents/schema2jsonld/service/jsonld-document-serializer.service.ts @@ -24,6 +24,7 @@ export class JsonldDocumentSerializerService { serializeDocument(doc:JsonldDocument, buffer):any{ buffer["@context"] = "http://schema.org"; + buffer["@id"] = doc.id; this.serializeName(doc, buffer); this.serializeDescription(doc, buffer); this.serializeIdentifier(doc, buffer); diff --git a/sharedComponents/schema2jsonld/service/open-aire-jsonld-converter.service.ts b/sharedComponents/schema2jsonld/service/open-aire-jsonld-converter.service.ts index 97fa5bc7..e8ae6f8c 100644 --- a/sharedComponents/schema2jsonld/service/open-aire-jsonld-converter.service.ts +++ b/sharedComponents/schema2jsonld/service/open-aire-jsonld-converter.service.ts @@ -1,57 +1,80 @@ import { Injectable } from "@angular/core"; import { JsonldDocument, Identifier, Person, License, Citation, Dataset, Organization } from "../model/jsonld-document"; import * as _ from "lodash"; +import {properties} from "../../../../../environments/environment"; @Injectable() export class OpenAireJsonldConverterService { - constructor() { } - createHome(name, URL, logoURL): any { - const buffer = {}; - buffer["@context"] = "http://schema.org"; - buffer["@type"] = "Organization"; - buffer["name"] = name; - buffer["url"] = URL; - buffer["logo"] = logoURL; + constructor() { + + } + + createHome(name, URL, logoURL, description:string = null): any { + const organization = {}; + const searchPage = {}; + organization["@context"] = "http://schema.org"; + organization["@id"] = properties.baseLink+"/#organization"; + organization["@type"] = "Organization"; + organization["name"] = name; + organization["url"] = properties.baseLink; + organization["logo"] = logoURL; + if(description){ + organization["description"] = description; + } + const sameAs =["https://www.openaire.eu", + "https://www.facebook.com/groups/openaire/", + "https://www.twitter.com/OpenAIRE_eu", + "https://www.linkedin.com/groups/OpenAIRE-3893548", + "https://www.slideshare.net/OpenAIRE_eu", + "https://www.youtube.com/channel/UChFYqizc-S6asNjQSoWuwjw"]; + organization["sameAs"] = sameAs; + + searchPage["@context"] = "http://schema.org"; + searchPage["@id"] = properties.baseLink+"/#search"; + searchPage["@type"] = "Website"; + searchPage["name"] = name; + searchPage["url"] = properties.baseLink+"/search/find/"; + searchPage["logo"] = logoURL; const action ={}; action["@type"]= "SearchAction"; - action["target"]= URL+"/search/find/?keyword={search_term_string}"; + action["@id"]= properties.baseLink+"/#search-action"; + action["target"]= properties.baseLink+"/search/find/?fv0={search_term_string}&f0=q"; action["query-input"]= "required name=search_term_string"; - buffer["potentialAction"] = action; - const sameAs =["https://www.openaire.eu", - "https://www.facebook.com/groups/openaire/", - "https://www.twitter.com/OpenAIRE_eu", - "https://www.linkedin.com/groups/OpenAIRE-3893548", - "https://www.slideshare.net/OpenAIRE_eu", - "https://www.youtube.com/channel/UChFYqizc-S6asNjQSoWuwjw"]; - - buffer["sameAs"] = sameAs; - return buffer; + searchPage["potentialAction"] = action; + return [organization, searchPage]; } - createSimplePage(name, URL): any { + createSimplePage(name, URL, description:string = null): any { const buffer = {}; buffer["@context"] = "http://schema.org"; buffer["@type"] = "WebPage"; buffer["name"] = name; buffer["url"] = URL; - + if(description){ + buffer["description"] = description; + } buffer["@id"] = URL; return buffer; } - createSearchPage(name, URL, logoURL, searchAction:boolean = true): any { + createSearchPage(name, URL, logoURL, searchAction:boolean = true, description:string = null): any { const buffer = {}; buffer["@context"] = "http://schema.org"; buffer["@type"] = "SearchResultsPage"; buffer["name"] = name; + if(description){ + buffer["description"] = description; + } buffer["url"] = URL; + buffer["@id"] = URL; buffer["logo"] = logoURL; - if(searchAction){ + buffer["isPartOf"] = properties.baseLink+"/#search"; + /*if(searchAction){ const action ={}; action["@type"]= "SearchAction"; action["target"]= URL+"?keyword={search_term_string}"; action["query-input"]= "required name=search_term_string"; buffer["potentialAction"] = action; - } + }*/ return buffer; } convertResult(result: any, URL): Dataset { @@ -65,6 +88,7 @@ export class OpenAireJsonldConverterService { doc.issn = this.getISSN(result); doc.description = this.getDescription(result); doc.identifier = this.getIdentifier(result); + doc.id = URL doc.url = URL; doc.sameAs = this.getSameAs(result); doc.creator = this.getCreator(result); @@ -150,7 +174,7 @@ convertDatasource(datasource: any, URL, otherUrl): Organization { } private getDescription(result: any): String[] { const item = _.get(result, "result.metadata.oaf:entity.oaf:result.description", null); - if (!item) return null; + if (!item) return this.getTitle(result); let descr = Array.isArray(item) ? item[0]:item; return [(descr.substring(0,4997)+(descr.substring(0,4997).length == 4997?'...':'')) as String]; } diff --git a/utils/result-preview/result-preview.component.html b/utils/result-preview/result-preview.component.html index 741deff9..afc490b9 100644 --- a/utils/result-preview/result-preview.component.html +++ b/utils/result-preview/result-preview.component.html @@ -1,7 +1,7 @@
- +