[Trunk | Library]:

1. resultLanding.component.ts: Get provenanceAction vocabulary from ISVocabulariesService.
2. resultLanding.service.ts: Remove methods for "provenanceAction" vocabulary | [Bug fix] Do not stringify "dateofacceptance" when undefined.
3. ISVocabularies.service.ts: Add BehaviorSubjects for vocabularies | Add methods for provenanceAction vocabulary (called by result landing pages).
4. staticAutoComplete.module.ts: Remove ISVocabulariesService from providers (singleton service, providedIn: 'root').


git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@59072 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
konstantina.galouni 2020-07-12 22:10:43 +00:00
parent 05f3635d28
commit 9f569ac4c4
4 changed files with 102 additions and 39 deletions

View File

@ -18,6 +18,7 @@ import {IndexInfoService} from "../../utils/indexInfo.service";
import {FormBuilder, FormGroup} from "@angular/forms"; import {FormBuilder, FormGroup} from "@angular/forms";
import {StringUtils} from "../../utils/string-utils.class"; import {StringUtils} from "../../utils/string-utils.class";
import {properties} from "../../../../environments/environment"; import {properties} from "../../../../environments/environment";
import {ISVocabulariesService} from "../../utils/staticAutoComplete/ISVocabularies.service";
@Component({ @Component({
@ -102,6 +103,7 @@ export class ResultLandingComponent {
'Persistent identifiers', 'Other']; 'Persistent identifiers', 'Other'];
constructor(private _resultLaningService: ResultLandingService, constructor(private _resultLaningService: ResultLandingService,
private _vocabulariesService: ISVocabulariesService,
private _piwikService: PiwikService, private _piwikService: PiwikService,
private route: ActivatedRoute, private route: ActivatedRoute,
private router: Router, private router: Router,
@ -262,7 +264,7 @@ export class ResultLandingComponent {
this.resultLandingInfo = null; this.resultLandingInfo = null;
if (typeof document !== 'undefined') { if (typeof document !== 'undefined') {
this._resultLaningService.getProvenanceActionVocabulary(this.properties).subscribe( this._vocabulariesService.getProvenanceActionVocabulary(this.properties).subscribe(
provenanceActionVocabulary => { provenanceActionVocabulary => {
this.getResultLandingInfo(provenanceActionVocabulary); this.getResultLandingInfo(provenanceActionVocabulary);
}, err => { }, err => {

View File

@ -56,21 +56,21 @@ export class ResultLandingService {
.pipe(map(res => this.parseResultLandingInfo(res, provenanceActionVocabulary, properties))); .pipe(map(res => this.parseResultLandingInfo(res, provenanceActionVocabulary, properties)));
} }
getProvenanceActionVocabulary (properties: EnvProperties): any { // getProvenanceActionVocabulary (properties: EnvProperties): any {
let url = properties.vocabulariesAPI+"dnet:provenanceActions.json"; // let url = properties.vocabulariesAPI+"dnet:provenanceActions.json";
//
return this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url) // return this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url)
.pipe(map(res => res['terms'])) // .pipe(map(res => res['terms']))
.pipe(map(res => this.parseProvenanceActionVocabulary(res, properties))); // .pipe(map(res => this.parseProvenanceActionVocabulary(res, properties)));
} // }
//
parseProvenanceActionVocabulary(terms: any, properties: EnvProperties) { // parseProvenanceActionVocabulary(terms: any, properties: EnvProperties) {
var provenanceActionVocabulary: {} = {}; // var provenanceActionVocabulary: {} = {};
for(let term of terms) { // for(let term of terms) {
provenanceActionVocabulary[term.code] = term.englishName; // provenanceActionVocabulary[term.code] = term.englishName;
} // }
return provenanceActionVocabulary; // return provenanceActionVocabulary;
} // }
private handleError (error: HttpErrorResponse) { private handleError (error: HttpErrorResponse) {
// in a real world app, we may send the error to some remote logging infrastructure // in a real world app, we may send the error to some remote logging infrastructure
@ -88,7 +88,7 @@ export class ResultLandingService {
// res['result']['metadata']['oaf:entity']['oaf:result'] // res['result']['metadata']['oaf:entity']['oaf:result']
if (data[0] != null) { if (data[0] != null) {
let date: string = (data[0].dateofacceptance) + ''; // transform to string in case it is an integer let date: string = (data[0].dateofacceptance ? data[0].dateofacceptance : '') + ''; // transform to string in case it is an integer
this.resultLandingInfo.date = (date && (date).indexOf('-') !== -1) ? date.split('-')[0] : date; this.resultLandingInfo.date = (date && (date).indexOf('-') !== -1) ? date.split('-')[0] : date;
this.resultLandingInfo.dateofacceptance = data[0].dateofacceptance?new Date(data[0].dateofacceptance):null; this.resultLandingInfo.dateofacceptance = data[0].dateofacceptance?new Date(data[0].dateofacceptance):null;
this.resultLandingInfo.publisher = data[0].publisher; this.resultLandingInfo.publisher = data[0].publisher;

View File

@ -1,18 +1,20 @@
import {Injectable} from '@angular/core'; import {Injectable} from '@angular/core';
import {HttpClient, HttpErrorResponse} from "@angular/common/http"; import {HttpClient, HttpErrorResponse} from "@angular/common/http";
import {Observable, throwError, of} from 'rxjs'; import {Observable, throwError, of, BehaviorSubject, from} from 'rxjs';
import {AutoCompleteValue} from '../../searchPages/searchUtils/searchHelperClasses.class'; import {AutoCompleteValue} from '../../searchPages/searchUtils/searchHelperClasses.class';
import 'rxjs/add/observable/zip'; import 'rxjs/add/observable/zip';
import {EnvProperties} from '../properties/env-properties'; import {EnvProperties} from '../properties/env-properties';
import {catchError, map} from "rxjs/operators"; import {catchError, map} from "rxjs/operators";
@Injectable() @Injectable({ providedIn: 'root' })
export class ISVocabulariesService { export class ISVocabulariesService {
constructor(private http: HttpClient) { private vocabularies: Map<string, BehaviorSubject<AutoCompleteValue[]>> = new Map<string, BehaviorSubject<AutoCompleteValue[]>>();
} private provenanceActionVocabulary: BehaviorSubject<{}> = new BehaviorSubject(null);
constructor(private http: HttpClient) {}
getVocabularyByType(field: string, entity: string, properties: EnvProperties): any { getVocabularyByType(field: string, entity: string, properties: EnvProperties): Observable<any> {
//console.log("getVocabulary field: "+ field + " for entity: "+ entity); //console.log("getVocabulary field: "+ field + " for entity: "+ entity);
var file = ""; var file = "";
var vocabulary = ""; var vocabulary = "";
@ -20,55 +22,77 @@ export class ISVocabulariesService {
// file="languages.json"; // file="languages.json";
// return this.getVocabularyFromFile(file); // return this.getVocabularyFromFile(file);
vocabulary = "dnet:languages.json"; vocabulary = "dnet:languages.json";
return this.getVocabularyFromService(vocabulary, properties); //return this.getVocabularyFromService(vocabulary, properties);
return from(this.getVocabularyFromServiceAsync(vocabulary, properties));
} else if (field == "type" && (entity == "publication")) { } else if (field == "type" && (entity == "publication")) {
// file = "publicationTypes.json"; // file = "publicationTypes.json";
// return this.getVocabularyFromFile(file); // return this.getVocabularyFromFile(file);
vocabulary = "dnet:publication_resource.json"; vocabulary = "dnet:publication_resource.json";
return this.getVocabularyFromService(vocabulary, properties); //return this.getVocabularyFromService(vocabulary, properties);
return from(this.getVocabularyFromServiceAsync(vocabulary, properties));
} else if (field == "type" && (entity == "dataset")) { } else if (field == "type" && (entity == "dataset")) {
// file = "dnet:dataCite_resource.json"; // file = "dnet:dataCite_resource.json";
// return this.getVocabularyFromFile(file); // return this.getVocabularyFromFile(file);
vocabulary = "dnet:dataCite_resource.json"; vocabulary = "dnet:dataCite_resource.json";
return this.getVocabularyFromService(vocabulary, properties); //return this.getVocabularyFromService(vocabulary, properties);
return from(this.getVocabularyFromServiceAsync(vocabulary, properties));
} else if (field == "type" && (entity == "software" || entity == "other")) { } else if (field == "type" && (entity == "software" || entity == "other")) {
return of([]); return of([]);
} else if (field == "type" && entity == "result" ) { } else if (field == "type" && entity == "result" ) {
return Observable.zip(this.getVocabularyFromService("dnet:publication_resource.json", properties),this.getVocabularyFromService("dnet:dataCite_resource.json", properties)); //return Observable.zip(this.getVocabularyFromService("dnet:publication_resource.json", properties),this.getVocabularyFromService("dnet:dataCite_resource.json", properties));
return Observable.zip(from(this.getVocabularyFromServiceAsync("dnet:publication_resource.json", properties)),from(this.getVocabularyFromServiceAsync("dnet:dataCite_resource.json", properties)));
} else if (field == "access" && (entity == "publication" || entity == "dataset" || entity == "software" || entity == "other" || entity == "result")) { } else if (field == "access" && (entity == "publication" || entity == "dataset" || entity == "software" || entity == "other" || entity == "result")) {
// file= "accessMode.json"; // file= "accessMode.json";
// return this.getVocabularyFromFile(file); // return this.getVocabularyFromFile(file);
vocabulary = "dnet:access_modes.json"; vocabulary = "dnet:access_modes.json";
return this.getVocabularyFromService(vocabulary, properties); //return this.getVocabularyFromService(vocabulary, properties);
return from(this.getVocabularyFromServiceAsync(vocabulary, properties));
} else if ((field == "type") && (entity == "dataprovider")) { } else if ((field == "type") && (entity == "dataprovider")) {
// file = "dataProviderType.json"; // file = "dataProviderType.json";
// return this.getVocabularyFromFile(file); // return this.getVocabularyFromFile(file);
vocabulary = "dnet:datasource_typologies.json"; vocabulary = "dnet:datasource_typologies.json";
return this.getVocabularyFromService(vocabulary, properties); //return this.getVocabularyFromService(vocabulary, properties);
return from(this.getVocabularyFromServiceAsync(vocabulary, properties));
} else if (field == "compatibility" && (entity == "dataprovider")) { } else if (field == "compatibility" && (entity == "dataprovider")) {
// file = "dataProviderCompatibility.json"; // file = "dataProviderCompatibility.json";
// return this.getVocabularyFromFile(file); // return this.getVocabularyFromFile(file);
vocabulary = "dnet:datasourceCompatibilityLevel.json"; vocabulary = "dnet:datasourceCompatibilityLevel.json";
return this.getVocabularyFromService(vocabulary, properties); //return this.getVocabularyFromService(vocabulary, properties);
return from(this.getVocabularyFromServiceAsync(vocabulary, properties));
} else if (field == "country") { } else if (field == "country") {
// file = "countries.json"; // file = "countries.json";
// return this.getVocabularyFromFile(file); // return this.getVocabularyFromFile(file);
vocabulary = "dnet:countries.json"; vocabulary = "dnet:countries.json";
return this.getVocabularyFromService(vocabulary, properties); //return this.getVocabularyFromService(vocabulary, properties);
return from(this.getVocabularyFromServiceAsync(vocabulary, properties));
} }
return null; return null;
} }
getVocabularyFromService(vocabularyName: string, properties: EnvProperties): any { async getVocabularyFromServiceAsync(vocabularyName: string, properties: EnvProperties): Promise<AutoCompleteValue[]> {
if(!this.vocabularies.has(vocabularyName)) {
await new Promise<any>(resolve => {
this.vocabularies.set(vocabularyName, new BehaviorSubject<any>(null));
this.getVocabularyFromService(vocabularyName, properties).subscribe(
vocabularyRes => {
this.vocabularies.get(vocabularyName).next(vocabularyRes);
resolve();
}
);
});
}
return this.vocabularies.get(vocabularyName).getValue();
}
getVocabularyFromService(vocabularyName: string, properties: EnvProperties): Observable<AutoCompleteValue[]> {
let url = properties.vocabulariesAPI + vocabularyName; let url = properties.vocabulariesAPI + vocabularyName;
return this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url) return this.http.get((properties.useLongCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url)
//.map(res => <any> res.json()) //.map(res => <any> res.json())
.pipe(map(res => res['terms'])) .pipe(map(res => res['terms']))
.pipe(map(res => this.parse(res, vocabularyName))) .pipe(map(res => this.parse(res, vocabularyName)))
@ -91,7 +115,44 @@ export class ISVocabulariesService {
return array; return array;
} }
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.getProvenanceActionVocabularyFromService(vocabularyName, properties).subscribe(
vocabularyRes => {
this.provenanceActionVocabulary.next(vocabularyRes);
resolve();
}
);
});
}
console.debug(this.provenanceActionVocabulary.getValue());
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;
}
private handleError(error: HttpErrorResponse) { private handleError(error: HttpErrorResponse) {
// in a real world app, we may send the error to some remote logging infrastructure // in a real world app, we may send the error to some remote logging infrastructure
// instead of just logging it to the console // instead of just logging it to the console

View File

@ -4,7 +4,7 @@ import { FormsModule } from '@angular/forms';
import {StaticAutoCompleteComponent} from './staticAutoComplete.component'; import {StaticAutoCompleteComponent} from './staticAutoComplete.component';
import {RefineFieldResultsServiceModule} from '../../services/refineFieldResultsService.module'; import {RefineFieldResultsServiceModule} from '../../services/refineFieldResultsService.module';
import {ISVocabulariesService} from './ISVocabularies.service'; //import {ISVocabulariesService} from './ISVocabularies.service';
@NgModule({ @NgModule({
@ -17,6 +17,6 @@ import {ISVocabulariesService} from './ISVocabularies.service';
exports: [ exports: [
StaticAutoCompleteComponent StaticAutoCompleteComponent
], ],
providers:[ ISVocabulariesService] providers:[ /*ISVocabulariesService*/ ]
}) })
export class StaticAutocompleteModule { } export class StaticAutocompleteModule { }