openaire-library/utils/staticAutoComplete/ISVocabularies.service.ts

312 lines
12 KiB
TypeScript
Raw Normal View History

import {Injectable} from '@angular/core';
import {HttpClient, HttpErrorResponse} from '@angular/common/http';
import {BehaviorSubject, from, Observable, of, Subscriber, throwError, zip} from 'rxjs';
import {AutoCompleteValue} from '../../searchPages/searchUtils/searchHelperClasses.class';
import {EnvProperties} from '../properties/env-properties';
import {catchError, map} from 'rxjs/operators';
@Injectable({ providedIn: 'root' })
export class ISVocabulariesService {
private vocabularies: Map<string, BehaviorSubject<AutoCompleteValue[]>> = new Map<string, BehaviorSubject<AutoCompleteValue[]>>();
private provenanceActionVocabulary: BehaviorSubject<{}> = new BehaviorSubject(null);
[Explore & Library & openaire-theme | new-theme]: Updated parsing of classified subjects by using a vocabulary | Added parsing of instance.license in Download from | Added feedback functionality for fos and sdgs in landing | #7509 Parsing both citations and references fields | In "view all/less" links added chervon-right icon with class "view-more-less-link". 1. fos.component.ts & sdg.component.ts: Added method "urlEncodeAndQuote()" to encode and then quote a string. 2. fos.component.html & sdg.component.html: a. "Beta" badge was updated to yellow uk-text-large. b. Link to the simple search page instead of the advanced and urlEncodeAndQuote the parameter used in url. 3. link.css: Added class "view-more-less-link" to set on ::after "chevron_right" icon (not underlined on hover) - used in "view all/more/less" links. 4. dataProvider.component.html & project.component.html & fundedBy.component.ts & relatedTo.component.ts & showIdentifiers.component.ts & showAuthors.component.ts: In "view all/less" links added class "view-more-less-link" | Renamed "view more" to "view all". 5. feedback.component.html: Rename wording to be more positive: issues -> feedback, issue -> comment, report -> feedback. 6. feedback.component.ts: Added @Input() preSelectedField: string = ""; and set with it "field" on "addIssue()" (fos/sdg preselected for feedback). 7. availableOn.component.ts: a. In "view all/less" links added class "view-more-less-link". b. #7833 - Show instance.license information (as link when recognized as url, string otherwise). 8. landing-utils/fos.component.ts & landing-utils/sdg.component.ts: a. "Beta" word was updated to yellow uk-text-xsmall. b. In "view all/less" links added class "view-more-less-link". c. Added feedback functionality: link to feedback form. 9. showSubjects.component.ts: a. In "view all/less" links added class "view-more-less-link". b. Added "view all" functionality for classified subjects too. 10. resultLanding.component.html: a. In "view all/less" links added class "view-more-less-link" | Renamed "view more" to "view all" b. Added feedback functionality: link to feedback form - preselect in feedback form fos/sdg. 11. resultLanding.component.ts: a. Added public feedbackPreSelectedField: string = ""; field. b. Added method "feedbackClicked()". c. [Bug fix] In hasPrimaryInfo() added check for classifiedSubjects. d. Renamed getProvenanceVocabularyAndResultLandingInfo() to getVocabulariesAndResultLandingInfo() and call also this._vocabulariesService.getSubjectsVocabulary(). 12. parsingFunctions.class.ts: a. #7196 - Updated parsing of subjects in method "parseAllSubjects()". b. #7833 - In method "parseHostedBy_collectedFrom()", added parsing for "license" field. 13. orcid-work.component.ts: On calling method "this.resultLandingService.getResultLandingInfo()", added null parameter for subject vocabulary. 14. searchFilter.module.ts: Import IconsModule. 15. searchFilter.component.html: Removed +/- form "view all/less" links and added class "view-more-less-link". 16. result-preview.ts: Added "licence?: string" in HostedByCollectedFrom. 17. ISVocabularies.service.ts: a. Added "private subjectsVocabulary: BehaviorSubject<any> = new BehaviorSubject<any>(null);" field and methods "getSubjectsVocabulary()", "getSubjectsVocabularyFromService()". b. Commented this.clearSubscriptions() from "getProvenanceActionVocabularyFromServiceAsync()". 18. resultLanding.service.ts: a. On subjects parsing, use subjectsVocabulary. b. #7509- Added if/then/else case for parsing citations (new name: references).
2022-06-09 15:45:39 +02:00
private subjectsVocabulary: BehaviorSubject<any> = new BehaviorSubject<any>(null);
[Explore | Library | new-theme]: Added more refine filters in Repositories, Journals, Registries pages | Search & Datasource landing: Show not compatible datasources | Result Landing: get relations names by relationsVocabulary (dnet:relation_relClass.json). 1. env-properties.ts & environments/: Removed old properties searchLinkToEntityRegistriesDataProvidersTable and searchLinkToJournalsTable. 2. fetchDataproviders.class.ts & searchDataproviders.service.ts: Removed old unused methods related to subjects/ tables/ csv. 3. searchFields.ts: Added more refine filters in Repositories, Journals, Registries pages (COMPATIBLE_DATAPROVIDER_FIELDS, ENTITY_REGISTRIES_FIELDS, JOURNAL_FIELDS). 4. result-preview.component.ts: Added field @Input() deposit: boolean = false; 5. result-preview.component.html: a. Added link to landing page even for not compatible datasources. b. Added class "uk-label-danger" when compatibility = "not available" only when deposit=true. 6. searchResultsInDeposit.component.html: In <result-preview> added parameter deposit="true". 7. dataProvider.component.html: a. Added class "uk-label-danger" when compatibility = "not available". b. Show custom "Not yet registered" compatibility label when compatibility = "not available". 8. ISVocabularies.service.ts: Added methods for getting relationsVocabulary (dnet:relation_relClass.json). 9. resultLanding.service.ts & parsingFunctions.class.ts: When parsing relations, get relationName from relationsVocabulary. 10. resultLanding.component.ts: Get relationsVocabulary and pass it to "getResultLandingInfo()". 11. orcid-work.component.ts: When calling "getResultLandingInfo()", added null parameter for relationsVocabulary. 12. configuration.service.ts: [Bug fix] Added more checks in method "isPageEnabledByStateAsync()".
2022-08-03 17:21:14 +02:00
private relationsVocabulary: BehaviorSubject<any> = new BehaviorSubject<any>(null);
private subscriptions = [];
private vocabulariesPromises: Map<string, Promise<any>> = new Map<string, Promise<any>>();
constructor(private http: HttpClient) {}
ngOnDestroy() {
this.clearSubscriptions();
}
clearSubscriptions() {
this.subscriptions.forEach(subscription => {
if (subscription instanceof Subscriber) {
subscription.unsubscribe();
}
});
}
getVocabularyByType(field: string, entity: string, properties: EnvProperties): Observable<any> {
let file = "";
let vocabulary = "";
if (field == "lang") {
vocabulary = "dnet:languages.json";
return this.getVocabularyFromServiceAsync(vocabulary, properties);
} else if (field == "type" && (entity == "publication")) {
vocabulary = "dnet:publication_resource.json";
return this.getVocabularyFromServiceAsync(vocabulary, properties);
} else if (field == "type" && (entity == "dataset")) {
vocabulary = "dnet:dataCite_resource.json";
return this.getVocabularyFromServiceAsync(vocabulary, properties);
} else if (field == "type" && (entity == "software" || entity == "other")) {
return of([]);
} else if (field == "type" && entity == "result" ) {
2022-01-13 15:47:33 +01:00
return zip(this.getVocabularyFromService("dnet:publication_resource.json", properties),this.getVocabularyFromService("dnet:dataCite_resource.json", properties));
} else if (field == "access" && (entity == "publication" || entity == "dataset" || entity == "software" || entity == "other" || entity == "result")) {
vocabulary = "dnet:access_modes.json";
return this.getVocabularyFromServiceAsync(vocabulary, properties);
} else if ((field == "type") && (entity == "dataprovider")) {
vocabulary = "dnet:datasource_typologies.json";
return this.getVocabularyFromServiceAsync(vocabulary, properties);
2022-01-13 15:47:33 +01:00
} else if (field == "compatibility" && (entity == "dataprovider")) {
vocabulary = "dnet:datasourceCompatibilityLevel.json";
return this.getVocabularyFromServiceAsync(vocabulary, properties);
} else if (field == "country") {
vocabulary = "dnet:countries.json";
return this.getVocabularyFromServiceAsync(vocabulary, properties);
} else if (field == "fos") {
vocabulary = "fos";
return this.getVocabularyFromServiceAsync(vocabulary, properties);
} else if (field == "sdg") {
vocabulary = "sdg";
return this.getVocabularyFromServiceAsync(vocabulary, properties);
}
return null;
2022-01-13 15:47:33 +01:00
}
getVocabularyFromServiceAsync(vocabularyName: string, properties: EnvProperties) {
if(!this.vocabularies.has(vocabularyName)) {
this.vocabularies.set(vocabularyName, new BehaviorSubject<any>(null));
if(!this.vocabulariesPromises.has(vocabularyName)) {
this.vocabulariesPromises.set(vocabularyName,
new Promise<any>(resolve => {
this.subscriptions.push(this.getVocabularyFromService(vocabularyName, properties).subscribe(
vocabularyRes => {
this.vocabularies.get(vocabularyName).next(vocabularyRes);
resolve();
}, error => {
this.vocabularies.get(vocabularyName).next(null);
resolve();
}
));
}));
}
}
return from(this.getAsync(vocabularyName));
}
async getAsync(vocabularyName: string): Promise<AutoCompleteValue[]> {
await this.vocabulariesPromises.get(vocabularyName);
return this.vocabularies.get(vocabularyName).getValue();
}
getVocabularyFromService(vocabularyName: string, properties: EnvProperties): Observable<AutoCompleteValue[]> {
let url = properties.vocabulariesAPI + vocabularyName;
if(vocabularyName == 'fos' || vocabularyName == 'sdg'){
return this.getLocalVocabularyFromService(vocabularyName, properties);
}
return this.http.get((properties.useLongCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url)
//.map(res => <any> res.json())
.pipe(map(res => res['terms']))
.pipe(map(res => this.parse(res, vocabularyName)))
.pipe(catchError(this.handleError));
2022-01-13 15:47:33 +01:00
}
2022-01-13 15:47:33 +01:00
getLocalVocabularyFromService(vocabularyName: string, properties: EnvProperties): Observable<AutoCompleteValue[]> {
if(vocabularyName == "sdg"){
let url = properties.domain+"/assets/vocabulary/sdg.json";
return this.http.get((properties.useLongCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url)
//.map(res => <any> res.json())
.pipe(map(res => res['sdg']))
.pipe(map(res => this.parseSDGs(res)))
.pipe(catchError(this.handleError));
}else if( vocabularyName == "fos"){
let url = properties.domain+"/assets/vocabulary/fos.json";
return this.http.get((properties.useLongCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url)
//.map(res => <any> res.json())
.pipe(map(res => res['fos']))
.pipe(map(res => this.parseFOS(res)))
.pipe(catchError(this.handleError));
}
}
parseSDGs(data: any): AutoCompleteValue[] {
var array: AutoCompleteValue[] = []
for (var i = 0; i < data.length; i++) {
var value: AutoCompleteValue = new AutoCompleteValue();
value.id = data[i].id;//data[i].code;
value.label = data[i].id;
array.push(value);
}
return array;
}
parseFOS(data: any): AutoCompleteValue[] {
let array: AutoCompleteValue[] = []
for (let fos of data) {
let value: AutoCompleteValue = new AutoCompleteValue();
value.id = fos.id;//data[i].code;
value.label = fos.label;
array.push(value);
if(fos.children) {
for (let fos2 of fos.children) {
let value: AutoCompleteValue = new AutoCompleteValue();
value.id = fos2.id;//data[i].code;
value.label = fos2.label;
array.push(value);
if(fos2.children) {
for (let fos3 of fos2.children) {
let value: AutoCompleteValue = new AutoCompleteValue();
value.id = fos3.id;//data[i].code;
value.label = fos3.label;
array.push(value);
}
}
}
}
}
return array;
}
parse(data: any, vocabularyName: string): AutoCompleteValue[] {
var array: AutoCompleteValue[] = []
for (var i = 0; i < data.length; i++) {
var value: AutoCompleteValue = new AutoCompleteValue();
value.id = data[i].englishName;//data[i].code;
if (vocabularyName == 'dnet:countries.json') { //use Country code instead of country name
value.id = data[i].code;
}
value.label = data[i].englishName;
array.push(value);
}
2022-01-13 15:47:33 +01:00
return array;
2022-01-13 15:47:33 +01:00
}
getProvenanceActionVocabulary(properties: EnvProperties): Observable<any> {
let vocabulary = "dnet:provenanceActions.json";
return from(this.getProvenanceActionVocabularyFromServiceAsync(vocabulary, properties));
}
async getProvenanceActionVocabularyFromServiceAsync (vocabularyName: string, properties: EnvProperties): Promise<{}> {
if(!this.provenanceActionVocabulary || !this.provenanceActionVocabulary.getValue()) {
await new Promise<any>(resolve => {
this.subscriptions.push(this.getProvenanceActionVocabularyFromService(vocabularyName, properties).subscribe(
vocabularyRes => {
this.provenanceActionVocabulary.next(vocabularyRes);
resolve();
},
error => {
this.provenanceActionVocabulary.next(null);
resolve();
}
));
});
[Explore & Library & openaire-theme | new-theme]: Updated parsing of classified subjects by using a vocabulary | Added parsing of instance.license in Download from | Added feedback functionality for fos and sdgs in landing | #7509 Parsing both citations and references fields | In "view all/less" links added chervon-right icon with class "view-more-less-link". 1. fos.component.ts & sdg.component.ts: Added method "urlEncodeAndQuote()" to encode and then quote a string. 2. fos.component.html & sdg.component.html: a. "Beta" badge was updated to yellow uk-text-large. b. Link to the simple search page instead of the advanced and urlEncodeAndQuote the parameter used in url. 3. link.css: Added class "view-more-less-link" to set on ::after "chevron_right" icon (not underlined on hover) - used in "view all/more/less" links. 4. dataProvider.component.html & project.component.html & fundedBy.component.ts & relatedTo.component.ts & showIdentifiers.component.ts & showAuthors.component.ts: In "view all/less" links added class "view-more-less-link" | Renamed "view more" to "view all". 5. feedback.component.html: Rename wording to be more positive: issues -> feedback, issue -> comment, report -> feedback. 6. feedback.component.ts: Added @Input() preSelectedField: string = ""; and set with it "field" on "addIssue()" (fos/sdg preselected for feedback). 7. availableOn.component.ts: a. In "view all/less" links added class "view-more-less-link". b. #7833 - Show instance.license information (as link when recognized as url, string otherwise). 8. landing-utils/fos.component.ts & landing-utils/sdg.component.ts: a. "Beta" word was updated to yellow uk-text-xsmall. b. In "view all/less" links added class "view-more-less-link". c. Added feedback functionality: link to feedback form. 9. showSubjects.component.ts: a. In "view all/less" links added class "view-more-less-link". b. Added "view all" functionality for classified subjects too. 10. resultLanding.component.html: a. In "view all/less" links added class "view-more-less-link" | Renamed "view more" to "view all" b. Added feedback functionality: link to feedback form - preselect in feedback form fos/sdg. 11. resultLanding.component.ts: a. Added public feedbackPreSelectedField: string = ""; field. b. Added method "feedbackClicked()". c. [Bug fix] In hasPrimaryInfo() added check for classifiedSubjects. d. Renamed getProvenanceVocabularyAndResultLandingInfo() to getVocabulariesAndResultLandingInfo() and call also this._vocabulariesService.getSubjectsVocabulary(). 12. parsingFunctions.class.ts: a. #7196 - Updated parsing of subjects in method "parseAllSubjects()". b. #7833 - In method "parseHostedBy_collectedFrom()", added parsing for "license" field. 13. orcid-work.component.ts: On calling method "this.resultLandingService.getResultLandingInfo()", added null parameter for subject vocabulary. 14. searchFilter.module.ts: Import IconsModule. 15. searchFilter.component.html: Removed +/- form "view all/less" links and added class "view-more-less-link". 16. result-preview.ts: Added "licence?: string" in HostedByCollectedFrom. 17. ISVocabularies.service.ts: a. Added "private subjectsVocabulary: BehaviorSubject<any> = new BehaviorSubject<any>(null);" field and methods "getSubjectsVocabulary()", "getSubjectsVocabularyFromService()". b. Commented this.clearSubscriptions() from "getProvenanceActionVocabularyFromServiceAsync()". 18. resultLanding.service.ts: a. On subjects parsing, use subjectsVocabulary. b. #7509- Added if/then/else case for parsing citations (new name: references).
2022-06-09 15:45:39 +02:00
// this.clearSubscriptions();
}
return this.provenanceActionVocabulary.getValue();
}
getProvenanceActionVocabularyFromService (vocabularyName: string, properties: EnvProperties): any {
let url = properties.vocabulariesAPI+vocabularyName;
return this.http.get((properties.useLongCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url)
.pipe(map(res => res['terms']))
.pipe(map(res => this.parseProvenanceActionVocabulary(res)));
}
parseProvenanceActionVocabulary(terms: any) {
var provenanceActionVocabulary: {} = {};
for(let term of terms) {
provenanceActionVocabulary[term.code] = term.englishName;
}
return provenanceActionVocabulary;
}
[Explore & Library & openaire-theme | new-theme]: Updated parsing of classified subjects by using a vocabulary | Added parsing of instance.license in Download from | Added feedback functionality for fos and sdgs in landing | #7509 Parsing both citations and references fields | In "view all/less" links added chervon-right icon with class "view-more-less-link". 1. fos.component.ts & sdg.component.ts: Added method "urlEncodeAndQuote()" to encode and then quote a string. 2. fos.component.html & sdg.component.html: a. "Beta" badge was updated to yellow uk-text-large. b. Link to the simple search page instead of the advanced and urlEncodeAndQuote the parameter used in url. 3. link.css: Added class "view-more-less-link" to set on ::after "chevron_right" icon (not underlined on hover) - used in "view all/more/less" links. 4. dataProvider.component.html & project.component.html & fundedBy.component.ts & relatedTo.component.ts & showIdentifiers.component.ts & showAuthors.component.ts: In "view all/less" links added class "view-more-less-link" | Renamed "view more" to "view all". 5. feedback.component.html: Rename wording to be more positive: issues -> feedback, issue -> comment, report -> feedback. 6. feedback.component.ts: Added @Input() preSelectedField: string = ""; and set with it "field" on "addIssue()" (fos/sdg preselected for feedback). 7. availableOn.component.ts: a. In "view all/less" links added class "view-more-less-link". b. #7833 - Show instance.license information (as link when recognized as url, string otherwise). 8. landing-utils/fos.component.ts & landing-utils/sdg.component.ts: a. "Beta" word was updated to yellow uk-text-xsmall. b. In "view all/less" links added class "view-more-less-link". c. Added feedback functionality: link to feedback form. 9. showSubjects.component.ts: a. In "view all/less" links added class "view-more-less-link". b. Added "view all" functionality for classified subjects too. 10. resultLanding.component.html: a. In "view all/less" links added class "view-more-less-link" | Renamed "view more" to "view all" b. Added feedback functionality: link to feedback form - preselect in feedback form fos/sdg. 11. resultLanding.component.ts: a. Added public feedbackPreSelectedField: string = ""; field. b. Added method "feedbackClicked()". c. [Bug fix] In hasPrimaryInfo() added check for classifiedSubjects. d. Renamed getProvenanceVocabularyAndResultLandingInfo() to getVocabulariesAndResultLandingInfo() and call also this._vocabulariesService.getSubjectsVocabulary(). 12. parsingFunctions.class.ts: a. #7196 - Updated parsing of subjects in method "parseAllSubjects()". b. #7833 - In method "parseHostedBy_collectedFrom()", added parsing for "license" field. 13. orcid-work.component.ts: On calling method "this.resultLandingService.getResultLandingInfo()", added null parameter for subject vocabulary. 14. searchFilter.module.ts: Import IconsModule. 15. searchFilter.component.html: Removed +/- form "view all/less" links and added class "view-more-less-link". 16. result-preview.ts: Added "licence?: string" in HostedByCollectedFrom. 17. ISVocabularies.service.ts: a. Added "private subjectsVocabulary: BehaviorSubject<any> = new BehaviorSubject<any>(null);" field and methods "getSubjectsVocabulary()", "getSubjectsVocabularyFromService()". b. Commented this.clearSubscriptions() from "getProvenanceActionVocabularyFromServiceAsync()". 18. resultLanding.service.ts: a. On subjects parsing, use subjectsVocabulary. b. #7509- Added if/then/else case for parsing citations (new name: references).
2022-06-09 15:45:39 +02:00
getSubjectsVocabulary(properties: EnvProperties): Observable<any> {
let vocabulary = "dnet:subject_classification_typologies.json";
return from(this.getSubjectsVocabularyFromServiceAsync(vocabulary, properties));
}
async getSubjectsVocabularyFromServiceAsync (vocabularyName: string, properties: EnvProperties): Promise<{}> {
if(!this.subjectsVocabulary || !this.subjectsVocabulary.getValue()) {
await new Promise<any>(resolve => {
this.subscriptions.push(this.getSubjectsVocabularyFromService(vocabularyName, properties).subscribe(
vocabularyRes => {
// console.log(vocabularyRes);
this.subjectsVocabulary.next(vocabularyRes);
resolve();
},
error => {
this.subjectsVocabulary.next(null);
resolve();
}
));
});
// this.clearSubscriptions();
}
return this.subjectsVocabulary.getValue();
}
getSubjectsVocabularyFromService (vocabularyName: string, properties: EnvProperties): any {
let url = properties.vocabulariesAPI+vocabularyName;
return this.http.get((properties.useLongCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url)
.pipe(map(res => res['terms']))
// .pipe(map(res => res.code))
.pipe(map(res => this.parseSubjectsVocabulary(res)));
}
parseSubjectsVocabulary(terms: any) {
var subjectsVocabulary: {} = {};
for(let term of terms) {
if(term.code != "keyword") {
subjectsVocabulary[term.code] = term.englishName;
}
}
return subjectsVocabulary;
}
[Explore | Library | new-theme]: Added more refine filters in Repositories, Journals, Registries pages | Search & Datasource landing: Show not compatible datasources | Result Landing: get relations names by relationsVocabulary (dnet:relation_relClass.json). 1. env-properties.ts & environments/: Removed old properties searchLinkToEntityRegistriesDataProvidersTable and searchLinkToJournalsTable. 2. fetchDataproviders.class.ts & searchDataproviders.service.ts: Removed old unused methods related to subjects/ tables/ csv. 3. searchFields.ts: Added more refine filters in Repositories, Journals, Registries pages (COMPATIBLE_DATAPROVIDER_FIELDS, ENTITY_REGISTRIES_FIELDS, JOURNAL_FIELDS). 4. result-preview.component.ts: Added field @Input() deposit: boolean = false; 5. result-preview.component.html: a. Added link to landing page even for not compatible datasources. b. Added class "uk-label-danger" when compatibility = "not available" only when deposit=true. 6. searchResultsInDeposit.component.html: In <result-preview> added parameter deposit="true". 7. dataProvider.component.html: a. Added class "uk-label-danger" when compatibility = "not available". b. Show custom "Not yet registered" compatibility label when compatibility = "not available". 8. ISVocabularies.service.ts: Added methods for getting relationsVocabulary (dnet:relation_relClass.json). 9. resultLanding.service.ts & parsingFunctions.class.ts: When parsing relations, get relationName from relationsVocabulary. 10. resultLanding.component.ts: Get relationsVocabulary and pass it to "getResultLandingInfo()". 11. orcid-work.component.ts: When calling "getResultLandingInfo()", added null parameter for relationsVocabulary. 12. configuration.service.ts: [Bug fix] Added more checks in method "isPageEnabledByStateAsync()".
2022-08-03 17:21:14 +02:00
getRelationsVocabulary(properties: EnvProperties): Observable<any> {
let vocabulary = "dnet:relation_relClass.json";
return from(this.getRelationsVocabularyFromServiceAsync(vocabulary, properties));
}
async getRelationsVocabularyFromServiceAsync (vocabularyName: string, properties: EnvProperties): Promise<{}> {
if(!this.relationsVocabulary || !this.relationsVocabulary.getValue()) {
await new Promise<any>(resolve => {
this.subscriptions.push(this.getRelationsVocabularyFromService(vocabularyName, properties).subscribe(
vocabularyRes => {
this.relationsVocabulary.next(vocabularyRes);
resolve();
},
error => {
this.relationsVocabulary.next(null);
resolve();
}
));
});
}
return this.relationsVocabulary.getValue();
}
getRelationsVocabularyFromService (vocabularyName: string, properties: EnvProperties): any {
let url = properties.vocabulariesAPI+vocabularyName;
return this.http.get((properties.useLongCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url)
.pipe(map(res => res['terms']))
.pipe(map(res => this.parseRelationsVocabulary(res)));
}
parseRelationsVocabulary(terms: any) {
var relationsVocabulary: {} = {};
for(let term of terms) {
if(term.code != "keyword") {
relationsVocabulary[term.code] = term.englishName;
}
}
return relationsVocabulary;
}
private handleError(error: HttpErrorResponse) {
// in a real world app, we may send the error to some remote logging infrastructure
// instead of just logging it to the console
console.log(error);
return throwError(error || 'Server error');
}
}