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

View File

@ -56,21 +56,21 @@ export class ResultLandingService {
.pipe(map(res => this.parseResultLandingInfo(res, provenanceActionVocabulary, properties)));
}
getProvenanceActionVocabulary (properties: EnvProperties): any {
let url = properties.vocabulariesAPI+"dnet:provenanceActions.json";
return this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url)
.pipe(map(res => res['terms']))
.pipe(map(res => this.parseProvenanceActionVocabulary(res, properties)));
}
parseProvenanceActionVocabulary(terms: any, properties: EnvProperties) {
var provenanceActionVocabulary: {} = {};
for(let term of terms) {
provenanceActionVocabulary[term.code] = term.englishName;
}
return provenanceActionVocabulary;
}
// getProvenanceActionVocabulary (properties: EnvProperties): any {
// let url = properties.vocabulariesAPI+"dnet:provenanceActions.json";
//
// return this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url)
// .pipe(map(res => res['terms']))
// .pipe(map(res => this.parseProvenanceActionVocabulary(res, properties)));
// }
//
// parseProvenanceActionVocabulary(terms: any, properties: EnvProperties) {
// var provenanceActionVocabulary: {} = {};
// for(let term of terms) {
// provenanceActionVocabulary[term.code] = term.englishName;
// }
// return provenanceActionVocabulary;
// }
private handleError (error: HttpErrorResponse) {
// 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']
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.dateofacceptance = data[0].dateofacceptance?new Date(data[0].dateofacceptance):null;
this.resultLandingInfo.publisher = data[0].publisher;

View File

@ -1,18 +1,20 @@
import {Injectable} from '@angular/core';
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 'rxjs/add/observable/zip';
import {EnvProperties} from '../properties/env-properties';
import {catchError, map} from "rxjs/operators";
@Injectable()
@Injectable({ providedIn: 'root' })
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);
var file = "";
var vocabulary = "";
@ -20,55 +22,77 @@ export class ISVocabulariesService {
// file="languages.json";
// return this.getVocabularyFromFile(file);
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")) {
// file = "publicationTypes.json";
// return this.getVocabularyFromFile(file);
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")) {
// file = "dnet:dataCite_resource.json";
// return this.getVocabularyFromFile(file);
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")) {
return of([]);
} 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")) {
// file= "accessMode.json";
// return this.getVocabularyFromFile(file);
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")) {
// file = "dataProviderType.json";
// return this.getVocabularyFromFile(file);
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")) {
// file = "dataProviderCompatibility.json";
// return this.getVocabularyFromFile(file);
vocabulary = "dnet:datasourceCompatibilityLevel.json";
return this.getVocabularyFromService(vocabulary, properties);
//return this.getVocabularyFromService(vocabulary, properties);
return from(this.getVocabularyFromServiceAsync(vocabulary, properties));
} else if (field == "country") {
// file = "countries.json";
// return this.getVocabularyFromFile(file);
vocabulary = "dnet:countries.json";
return this.getVocabularyFromService(vocabulary, properties);
//return this.getVocabularyFromService(vocabulary, properties);
return from(this.getVocabularyFromServiceAsync(vocabulary, properties));
}
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;
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())
.pipe(map(res => res['terms']))
.pipe(map(res => this.parse(res, vocabularyName)))
@ -91,7 +115,44 @@ export class ISVocabulariesService {
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) {
// in a real world app, we may send the error to some remote logging infrastructure
// 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 {RefineFieldResultsServiceModule} from '../../services/refineFieldResultsService.module';
import {ISVocabulariesService} from './ISVocabularies.service';
//import {ISVocabulariesService} from './ISVocabularies.service';
@NgModule({
@ -17,6 +17,6 @@ import {ISVocabulariesService} from './ISVocabularies.service';
exports: [
StaticAutoCompleteComponent
],
providers:[ ISVocabulariesService]
providers:[ /*ISVocabulariesService*/ ]
})
export class StaticAutocompleteModule { }