use cache service in all services - fix issues with filters in search pages

git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-portal/trunk@44638 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
argiro.kokogiannaki 2016-11-23 10:34:47 +00:00
parent 34d56e4fb0
commit 9a2427f69b
26 changed files with 646 additions and 172 deletions

View File

@ -12,7 +12,7 @@ import { Filter, Value} from './searchHelperClasses.class';
<span *ngIf="showAll" class="glyphicon glyphicon-triangle-top" aria-hidden="true"></span>
</a>
<div class="values">
<div>
<div *ngIf = "filter.countSelectedValues > 0">
<div *ngFor = "let value of filter.values.slice(0,filter.countSelectedValues)" >
<p>
<input [(ngModel)]="value.selected" type="checkbox" (ngModelChange)="filterChange(value.selected)" />
@ -61,7 +61,6 @@ import { Filter, Value} from './searchHelperClasses.class';
export class SearchFilterComponent {
@Input() test:{value:number} ;
@Input() filter:Filter;
@Input() showResultCount:boolean = true;
private showAll:boolean = false;
@ -99,8 +98,6 @@ export class SearchFilterComponent {
}
reorderFilterValues() {
let values: Value[] = [];
for(let value of this.filter.values) {
if(value.selected) {
let index: number = this.filter.values.indexOf(value);

View File

@ -21,11 +21,14 @@ import {SearchUtilsClass} from './searchUtils.class';
<search-form [(keyword)]="searchUtils.keyword" (keywordChange)="keywordChanged($event)"></search-form>
<div>
<span *ngIf = "searchUtils.keyword.length > 0">Keywords:
<span>{{searchUtils.keyword}}<a (click) = "clearKeywords() "> <span class="glyphicon glyphicon-remove" aria-hidden="true"></span></a></span>
</span>
<span *ngFor="let filter of filters " >
<span *ngIf = "filter.countSelectedValues > 0"> {{filter.title}}: </span>
<span *ngFor="let value of filter.values.slice(0,filter.countSelectedValues); let i = index; let end = last; " >
{{value.name}} <a (click) = "removeFilter(value, filter) "> <span class="glyphicon glyphicon-remove" aria-hidden="true"></span></a>
<span *ngIf="i != end">,</span>
<span *ngIf="!end">,</span>
</span>
</span>
<a *ngIf="isFiltered()" (click)="clearFilters()" class = "btn text-right"> Clear Filters</a>
@ -79,11 +82,11 @@ export class SearchPageComponent {
private sub: any;
constructor (private location: Location ) {
console.info("constructor of SearchPage");
}
ngOnInit() {
console.info("ngOnInit of SearchPage");
this.updateBaseUrlWithParameters(this.filters);
}
ngAfterViewChecked(){
@ -141,18 +144,25 @@ export class SearchPageComponent {
* Mark as check the new filters that are selected, when you get them from search
*/
public checkSelectedFilters(filters:Filter[]){
this.filters = filters;
for(var i=0; i< filters.length ; i++){
var filter:Filter = filters[i];
filter.countSelectedValues = 0;
if(this.queryParameters[filter.filterId] != undefined) {
let values = decodeURIComponent(this.queryParameters[filter.filterId]).split(",");
for(let value of values) {
for(let filterValue of filter.values) {
if(filterValue.id == value) {
if(values.indexOf(filterValue.id) > -1) {
filterValue.selected = true;
filter.countSelectedValues++;
}else{
filterValue.selected = false;
}
}
}
}else{
for(let filterValue of filter.values) {
filterValue.selected = false;
}
}
}
@ -247,40 +257,45 @@ export class SearchPageComponent {
}
return filtered;
}
clearFilters(){
for (let filter of this.filters){
if(filter.countSelectedValues > 0){
for (let value of filter.values){
if(value.selected == true){
value.selected = false;
}
}
filter.countSelectedValues = 0;
}
}
private clearKeywords(){
if(this.searchUtils.keyword.length > 0 ){
this.searchUtils.keyword ='';
}
this.location.go(location.pathname);
this.goTo(1);
}
removeFilter(value:Value,filter:Filter){
private clearFilters(){
for (var i =0 ; i < this.filters.length; i++){
for (var j=0; j < this.filters[i].countSelectedValues; j++){
if(this.filters[i].values[j].selected){
this.filters[i].values[j].selected = false;
}
this.filters[i].countSelectedValues = 0;
}
}
this.clearKeywords();
}
private removeFilter(value:Value,filter:Filter){
filter.countSelectedValues--;
value.selected = false;
if(value.selected == true){
value.selected = false;
}
this.goTo(1);
}
goTo(page:number = 1){
this.searchUtils.page = page;
console.info("searchUtils.page goto = "+this.searchUtils.page);
// console.info("searchUtils.page goto = "+this.searchUtils.page);
this.queryParameters = new Map<string,string>();
var urlParameters = this.createUrlParameters(this.filters,true);
console.info("urlParams : "+urlParameters);
// console.info("urlParams : "+urlParameters);
this.updateBaseUrlWithParameters(this.filters);
var queryParameters = this.createSearchQueryParameters(this.filters);
console.info("queryParams : "+queryParameters);
// console.info("queryParams : "+queryParameters);
var indexQuery = this.createIndexQueryParameters(this.filters);
this.location.go(location.pathname,urlParameters);
console.info("SearchPAGE::page "+this.searchUtils.page);
// console.info("SearchPAGE::page "+this.searchUtils.page);
this.queryChange.emit({
value: queryParameters,
@ -290,6 +305,7 @@ export class SearchPageComponent {
}
filterChanged($event){
console.log("HEEEEERE");
this.goTo(1);
}
keywordChanged($event) {

View File

@ -3,5 +3,6 @@ export class SearchUtilsClass{
size:number = 10;
status:number = 1;
keyword:string = "";
baseUrl:string = "";
}

View File

@ -17,7 +17,7 @@ import {SearchUtilsClass} from '../searchUtils/searchUtils.class';
<search-page pageTitle="Search Publications" type="publication" [(filters)] = "filters"
[(results)] = "results" [(totalResults)] = "totalResults"
[(searchUtils)] = "searchUtils" [baseUrl] = "baseUrl" (queryChange)="queryChanged($event)" >
[(searchUtils)] = "searchUtils" [(baseUrl)] = baseUrl (queryChange)="queryChanged($event)" >
</search-page>
`
@ -27,9 +27,8 @@ export class SearchPublicationsComponent {
public results =[];
private filters =[];
public totalResults:number = 0 ;
private baseUrl:string;
private searchUtils:SearchUtilsClass = new SearchUtilsClass();
private baseUrl:string = "";
private sub: any;
private subResults: any;
private searchFields:SearchFields = new SearchFields();
@ -44,6 +43,7 @@ export class SearchPublicationsComponent {
var errorCodes:ErrorCodes = new ErrorCodes();
this.searchUtils.status =errorCodes.LOADING;
this.baseUrl = OpenaireProperties.getLinkToSearchPublications();
console.log("SP con: "+this.baseUrl);
}
@ -55,6 +55,8 @@ export class SearchPublicationsComponent {
this.sub = this.route.queryParams.subscribe(params => {
this.searchUtils.keyword = (params['keyword']?params['keyword']:'');
this.searchUtils.page = (params['page']=== undefined)?1:+params['page'];
console.log("SP init: "+this.baseUrl);
var queryParameters = this.searchPage.getQueryParametersFromUrl(params);
this._getResults(queryParameters, true, this.searchUtils.page, this.searchUtils.size);
@ -183,6 +185,7 @@ private _getResults(parameters:string,refine:boolean, page: number, size: number
this.filters = data[2];
this.searchPage.checkSelectedFilters(this.filters);
this.searchPage.updateBaseUrlWithParameters(this.filters);
console.log("SP getResults: "+this.baseUrl);
var errorCodes:ErrorCodes = new ErrorCodes();
this.searchUtils.status = errorCodes.DONE;
if(this.totalResults == 0 ){

View File

@ -2,10 +2,15 @@ import {Injectable} from '@angular/core';
import {Http, Response} from '@angular/http';
import {Observable} from 'rxjs/Observable';
import {AutoCompleteValue} from '../searchPages/searchUtils/searchHelperClasses.class';
import 'rxjs/add/observable/of';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/share';
import { CacheService } from '../shared/cache.service';
@Injectable()
export class ISVocabulariesService {
private api ="https://beta.services.openaire.eu/provision/mvc/vocabularies/";
constructor(private http: Http) {}
constructor(private http: Http, public _cache: CacheService) {}
getVocabularyByType(field:string,entity:string):AutoCompleteValue[]{
console.log("getVocabulary field: "+ field + " for entity: "+ entity);
@ -29,10 +34,17 @@ export class ISVocabulariesService {
}
getLanguages ():any {
let url = this.api+"dnet:languages.json";
let key = url;
if (this._cache.has(key)) {
return Observable.of(this._cache.get(key));
}
return this.http.get(url)
.map(res => <any> res.json())
.map(res => res['terms'])
.map(res => this.parse(res));
.map(res => this.parse(res))
.do(res => {
this._cache.set(key, res);
});
}
@ -44,10 +56,17 @@ export class ISVocabulariesService {
getPublicationTypes ():any {
let url = this.api+"dnet:publication_resource.json";
let key = url;
if (this._cache.has(key)) {
return Observable.of(this._cache.get(key));
}
return this.http.get(url)
.map(res => <any> res.json())
.map(res => res['terms'])
.map(res => this.parse(res));
.map(res => this.parse(res))
.do(res => {
this._cache.set(key, res);
});
}
@ -58,10 +77,17 @@ export class ISVocabulariesService {
getDatasetTypes ():any {
let url = this.api+"dnet:dataCite_resource.json";
let key = url;
if (this._cache.has(key)) {
return Observable.of(this._cache.get(key));
}
return this.http.get(url)
.map(res => <any> res.json())
.map(res => res['terms'])
.map(res => this.parse(res));
.map(res => this.parse(res))
.do(res => {
this._cache.set(key, res);
});
}
@ -73,10 +99,17 @@ export class ISVocabulariesService {
getAccessMode ():any {
console.info("Get AccessMode from IS");
let url = this.api+"dnet:access_modes.json";
let key = url;
if (this._cache.has(key)) {
return Observable.of(this._cache.get(key));
}
return this.http.get(url)
.map(res => <any> res.json())
.map(res => res['terms'])
.map(res => this.parse(res));
.map(res => this.parse(res))
.do(res => {
this._cache.set(key, res);
});
}
@ -86,10 +119,17 @@ export class ISVocabulariesService {
}
getDataProviderTypes ():any {
let url = this.api+"dnet:datasource_typologies.json";
let key = url;
if (this._cache.has(key)) {
return Observable.of(this._cache.get(key));
}
return this.http.get(url)
.map(res => <any> res.json())
.map(res => res['terms'])
.map(res => this.parse(res));
.map(res => this.parse(res))
.do(res => {
this._cache.set(key, res);
});
}
@ -99,10 +139,17 @@ export class ISVocabulariesService {
}
getDataProviderCompatibility ():any {
let url = this.api+"dnet:datasourceCompatibilityLevel.json";
let key = url;
if (this._cache.has(key)) {
return Observable.of(this._cache.get(key));
}
return this.http.get(url)
.map(res => <any> res.json())
.map(res => res['terms'])
.map(res => this.parse(res));
.map(res => this.parse(res))
.do(res => {
this._cache.set(key, res);
});
}
@ -126,10 +173,17 @@ export class ISVocabulariesService {
getCountryCompatibility ():any {
let url = this.api+"dnet:countries.json";
let key = url;
if (this._cache.has(key)) {
return Observable.of(this._cache.get(key));
}
return this.http.get(url)
.map(res => <any> res.json())
.map(res => res['terms'])
.map(res => this.parse(res));
.map(res => this.parse(res))
.do(res => {
this._cache.set(key, res);
});
}

View File

@ -4,20 +4,31 @@ import {Http, Response} from '@angular/http';
import {Observable} from 'rxjs/Observable';
import {Claim} from '../utils/entities/claim';
import {OpenaireProperties} from '../utils/properties/openaireProperties';
import 'rxjs/add/observable/of';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/share';
import { CacheService } from '../shared/cache.service';
@Injectable()
export class ClaimsService {
private baseUrl;
constructor(private jsonp: Jsonp, private http: Http) {
constructor(private jsonp: Jsonp, private http: Http, public _cache: CacheService) {
this.baseUrl = OpenaireProperties.getClaimsAPIURL();
}
private getClaimRequest(size : number, page : number, url :string):any {
console.info('ClaimsService: Claims request: '+url);
let key = url;
if (this._cache.has(key)) {
return Observable.of(this._cache.get(key));
}
return this.http.get( url)
.map(request => <any> request.json())
.do(request => console.info("Get claims: offset = "+(size*(page-1)) + " limit ="+size ))
.catch(this.handleError);
.catch(this.handleError)
.do(res => {
this._cache.set(key, res);
});
}
getClaims( size : number, page : number, keyword:string, sortby: string, descending: boolean, types: string):any {
console.info('ClaimsService: getClaims ' );

View File

@ -5,38 +5,66 @@ import {Observable} from 'rxjs/Observable';
import {Claim} from '../utils/entities/claim';
import {OpenaireProperties} from '../utils/properties/openaireProperties';
import {AutoCompleteValue} from '../searchPages/searchUtils/searchHelperClasses.class';
import 'rxjs/add/observable/of';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/share';
import { CacheService } from '../shared/cache.service';
@Injectable()
export class ContextsService {
private baseUrl;
constructor(private http: Http) {
constructor(private http: Http, public _cache: CacheService) {
this.baseUrl = OpenaireProperties.getClaimsAPIURL();
}
public getCommunities():any {
let url = this.baseUrl + 'communities';
let key = url;
if (this._cache.has(key)) {
return Observable.of(this._cache.get(key));
}
console.info('ContextsService: request communities '+url);
return this.http.get( url)
.map(request => <any> request.json().data)
.do(request => console.info("Get claims: offset = "))
.catch(this.handleError);
.catch(this.handleError)
.do(res => {
this._cache.set(key, res);
});
}
public getCategories(communityId :string):any {
console.info('ContextsService: request categories for community with id '+communityId);
let url= this.baseUrl + 'communities/' + communityId + '/categories';
let key = url;
if (this._cache.has(key)) {
return Observable.of(this._cache.get(key));
}
return this.http.get( url)
.map(request => <any> request.json().data)
.do(request => console.info("Get claims: offset = " ))
.catch(this.handleError);
.catch(this.handleError)
.do(res => {
this._cache.set(key, res);
});
}
public getConcepts(categoryId :string, keyword: string):any {
console.info('ContextsService: request concept for category with id '+categoryId + ' and keyword '+ keyword);
let url= this.baseUrl + 'categories/' + categoryId+ "/concepts";
let key = url;
if (this._cache.has(key)) {
return Observable.of(this._cache.get(key));
}
return this.http.get( url)
.map(request => <any> request.json().data)
.map(res => this.parse(res.concept))
.do(res => console.info(res ))
.catch(this.handleError);
.catch(this.handleError)
.do(res => {
this._cache.set(key, res);
});
}
parse (data: any):AutoCompleteValue[] {
var array:AutoCompleteValue[] =[]

View File

@ -3,18 +3,25 @@ import {Http, Response} from '@angular/http';
import {Observable} from 'rxjs/Observable';
import {DataProviderInfo} from '../utils/entities/dataProviderInfo';
import {OpenaireProperties} from '../utils/properties/openaireProperties';
import 'rxjs/add/observable/of';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/share';
import { CacheService } from '../shared/cache.service';
@Injectable()
export class DataProviderService {
constructor(private http: Http) {}
constructor(private http: Http, public _cache: CacheService) {}
dataProviderInfo: DataProviderInfo;
getPublicationInfo (id: string):any {
console.info("getDataProviderInfo in service");
let url = OpenaireProperties.getSearchAPIURL() + 'datasources/' +id;
let key = url;
if (this._cache.has(key)) {
return Observable.of(this._cache.get(key));
}
return this.http.get(url)
.map(res => <any> res.json())
.map(res => res['result']['metadata']['oaf:entity'])
@ -23,8 +30,12 @@ export class DataProviderService {
res['oaf:datasource']['openairecompatibility'],
res['oaf:datasource']['accessinfopackage'],
res['oaf:datasource']['rels']['rel']
])
.map(res => this.parseDataProviderInfo(res));
]).map(res => this.parseDataProviderInfo(res)).do(res => {
this._cache.set(key, res);
})
.do(res => {
this._cache.set(key, res);
});
}

View File

@ -3,11 +3,15 @@ import {Http, Response} from '@angular/http';
import {Observable} from 'rxjs/Observable';
import {DatasetInfo} from '../utils/entities/datasetInfo';
import {OpenaireProperties} from '../utils/properties/openaireProperties';
import 'rxjs/add/observable/of';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/share';
import { CacheService } from '../shared/cache.service';
@Injectable()
export class DatasetService {
constructor(private http: Http) {}
constructor(private http: Http, public _cache: CacheService) {}
datasetInfo: DatasetInfo;
@ -15,7 +19,10 @@ export class DatasetService {
console.info("getDatasetInfo in service");
let url = OpenaireProperties.getSearchAPIURL()+'datasets/'+id;
let key = url;
if (this._cache.has(key)) {
return Observable.of(this._cache.get(key));
}
return this.http.get(url)
.map(res => <any> res.json())
@ -32,7 +39,10 @@ export class DatasetService {
res['context'],
res['resulttype']
])
.map(res => this.parseDatasetInfo(res));
.map(res => this.parseDatasetInfo(res))
.do(res => {
this._cache.set(key, res);
});
}

View File

@ -3,11 +3,15 @@ import {Http, Response} from '@angular/http';
import {Observable} from 'rxjs/Observable';
import {AutoCompleteValue} from '../searchPages/searchUtils/searchHelperClasses.class';
import {OpenaireProperties} from '../utils/properties/openaireProperties';
import 'rxjs/add/observable/of';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/share';
import { CacheService } from '../shared/cache.service';
@Injectable()
export class EntitiesSearchService {
private api ="https://beta.services.openaire.eu/provision/mvc/vocabularies/";
constructor(private http: Http) {}
constructor(private http: Http, public _cache: CacheService) {}
searchByType(keyword:string,type:string,funderId:string){
if( type = "project"){

View File

@ -1,38 +1,61 @@
import {Injectable} from '@angular/core';
import {Http, Response} from '@angular/http';
import {Observable} from 'rxjs/Observable';
import {OpenaireProperties} from '../utils/properties/openaireProperties';
import 'rxjs/add/observable/of';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/share';
import { CacheService } from '../shared/cache.service';
@Injectable()
export class OpenaireProjectsService {
private searchUrl;
constructor( private http: Http) {
constructor( private http: Http, public _cache: CacheService) {
this.searchUrl = OpenaireProperties.getSearchServiceURL();
}
getFunders():any {
let url = this.searchUrl+'search?action=refine&rTransformer=results_openaire_browse&fields=funderid&query=%28oaftype+exact+project%29&locale=en_GB&format=json';
let key = url;
if (this._cache.has(key)) {
return Observable.of(this._cache.get(key));
}
return this.http.get( url)
.map(request => <any> request.json().response.browseResults.result)
.do(funders => console.log("getFunders : "+funders))
.catch(this.handleError);
.catch(this.handleError)
.do(res => {
this._cache.set(key, res);
});
}
searchForProjects(keyword:string, funderId:string):any {
let url = this.searchUrl+'search?action=search&sTransformer=projects_openaire&query='+
'%28oaftype+exact+project%29+and+%28%28projecttitle+%3D+%22'+keyword+'%22%29+or+%28projectacronym+%3D+%22'+keyword+'%22%29+or+%28projectcode+%3D+%22'+keyword+'%22%29%29+and+%28funderid+exact+'+funderId+'%29&size=10&locale=en_GB&format=json';
let key = url;
if (this._cache.has(key)) {
return Observable.of(this._cache.get(key));
}
return this.http.get( url)
.map(request => <any> (request.json().response.results)?request.json().response.results.result:request.json().response.results)
.do(funders => console.log("getFunders : "+funders))
.catch(this.handleError);
.catch(this.handleError)
.do(res => {
this._cache.set(key, res);
});
}
searchForProjectsObs(keyword:string, funderId:string):any {
let url = this.searchUrl+'search?action=search&sTransformer=projects_openaire&query='+
'%28oaftype+exact+project%29+and+%28%28projecttitle+%3D+%22'+keyword+'%22%29+or+%28projectacronym+%3D+%22'+keyword+'%22%29+or+%28projectcode+%3D+%22'+keyword+'%22%29%29+and+%28funderid+exact+'+funderId+'%29&size=10&locale=en_GB&format=json';
let key = url;
if (this._cache.has(key)) {
return Observable.of(this._cache.get(key));
}
return this.http.get(url).toPromise()
.then(request =>{

View File

@ -3,11 +3,14 @@ import {Http, Response} from '@angular/http';
import {Observable} from 'rxjs/Observable';
import {OrganizationInfo} from '../utils/entities/organizationInfo';
import {OpenaireProperties} from '../utils/properties/openaireProperties';
import 'rxjs/add/observable/of';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/share';
import { CacheService } from '../shared/cache.service';
@Injectable()
export class OrganizationService {
constructor(private http: Http) {}
constructor(private http: Http, public _cache: CacheService) {}
organizationInfo: OrganizationInfo;
@ -15,12 +18,18 @@ export class OrganizationService {
console.info("getOrganizationInfo in service");
let url = OpenaireProperties.getSearchAPIURL()+'organizations/'+id;
let key = url;
if (this._cache.has(key)) {
return Observable.of(this._cache.get(key));
}
return this.http.get(url)
.map(res => <any> res.json())
.map(res => res['result']['metadata']['oaf:entity']['oaf:organization'])
.map(res => [res, res['rels']['rel']])
.map(res => this.parseOrganizationInfo(res));
.map(res => this.parseOrganizationInfo(res))
.do(res => {
this._cache.set(key, res);
});
}

View File

@ -1,25 +1,54 @@
import {Injectable} from '@angular/core';
import {Http, Response} from '@angular/http';
import {Observable} from 'rxjs/Observable';
import 'rxjs/add/observable/of';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/share';
import { CacheService } from '../shared/cache.service';
import {PersonInfo} from '../utils/entities/personInfo';
import {OpenaireProperties} from '../utils/properties/openaireProperties'
export function hashCodeString(str: string): string {
let hash = 0;
if (str.length === 0) {
return hash + '';
}
for (let i = 0; i < str.length; i++) {
let char = str.charCodeAt(i);
hash = ((hash << 5) - hash) + char;
hash = hash & hash; // Convert to 32bit integer
}
return hash + '';
}
@Injectable()
export class PersonService {
constructor(private http: Http) {}
constructor(private http: Http, public _cache: CacheService) {}
personInfo: PersonInfo;
getPersonInfo (id: string):any {
console.info("Cache: NOT in cache ");
console.info("getPersonInfo in service");
let url = OpenaireProperties.getSearchAPIURL()+'people/'+id;
let key = url;
if (this._cache.has(key)) {
return Observable.of(this._cache.get(key));
}
return this.http.get(url)
.map(res => <any> res.json())
.map(res => res['result']['metadata']['oaf:entity']['oaf:person'])
.map(res => this.parsePersonInfo(res));
.map(res => this.parsePersonInfo(res))
.do(res => {
this._cache.set(key, res);
});
}

View File

@ -3,11 +3,14 @@ import {Http, Response} from '@angular/http';
import {Observable} from 'rxjs/Observable';
import {ProjectInfo} from '../utils/entities/projectInfo';
import {OpenaireProperties} from '../utils/properties/openaireProperties';
import 'rxjs/add/observable/of';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/share';
import { CacheService } from '../shared/cache.service';
@Injectable()
export class ProjectService {
constructor(private http: Http) {}
constructor(private http: Http, public _cache: CacheService) {}
projectInfo: ProjectInfo;
@ -15,14 +18,20 @@ export class ProjectService {
console.info("getProjectInfo in service");
let url = OpenaireProperties.getSearchAPIURL() + 'projects/'+id;
let key = url;
if (this._cache.has(key)) {
return Observable.of(this._cache.get(key));
}
return this.http.get(url)
.map(res => <any> res.json())
.map(res => res['result']['metadata']['oaf:entity']['oaf:project'])
.map(res => [res,
res['fundingtree'],
res['rels']['rel']])
.map(res => this.parseProjectInfo(res));
.map(res => this.parseProjectInfo(res))
.do(res => {
this._cache.set(key, res);
});
}
/*
@ -31,13 +40,19 @@ export class ProjectService {
getProjectDates (id: string):any {
let url = OpenaireProperties.getSearchAPIURL()+'projects/'+id;
let key = url+'_projectDates';
if (this._cache.has(key)) {
return Observable.of(this._cache.get(key));
}
return this.http.get(url)
.map(res => <any> res.json())
.map(res => [res['result']['metadata']['oaf:entity']['oaf:project'],
res['result']['metadata']['oaf:entity']['oaf:project']['fundingtree'],
res['result']['metadata']['oaf:entity']['oaf:project']['rels']['rel']])
.map(res => this.parseProjectDates(id,res));
.map(res => this.parseProjectDates(id,res))
.do(res => {
this._cache.set(key, res);
});
}
private handleError (error: Response) {

View File

@ -3,18 +3,24 @@ import {Http, Response} from '@angular/http';
import {Observable} from 'rxjs/Observable';
import {PublicationInfo} from '../utils/entities/publicationInfo';
import {OpenaireProperties} from '../utils/properties/openaireProperties';
import 'rxjs/add/observable/of';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/share';
import { CacheService } from '../shared/cache.service';
@Injectable()
export class PublicationService {
constructor(private http: Http) {}
constructor(private http: Http, public _cache: CacheService) {}
publicationInfo: PublicationInfo;
getPublicationInfo (id: string):any {
console.info("getPublicationInfo in service");
let url = OpenaireProperties.getSearchAPIURL() + 'publications/' +id;
let key = url;
if (this._cache.has(key)) {
return Observable.of(this._cache.get(key));
}
return this.http.get(url)
.map(res => <any> res.json())
.map(res => res['result']['metadata']['oaf:entity'])
@ -31,7 +37,10 @@ export class PublicationService {
(res['extraInfo']!= undefined && res['extraInfo']['citations']!= undefined)? res['extraInfo']['citations']['citation']:null,
res['oaf:result']['context']
])
.map(res => this.parsePublicationInfo(res));
.map(res => this.parsePublicationInfo(res))
.do(res => {
this._cache.set(key, res);
});
}
private handleError (error: Response) {

View File

@ -3,25 +3,35 @@ import {Http, Response} from '@angular/http';
import {Observable} from 'rxjs/Observable';
import {AutoCompleteValue} from '../searchPages/searchUtils/searchHelperClasses.class';
import {OpenaireProperties} from '../utils/properties/openaireProperties';
import 'rxjs/add/observable/of';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/share';
import { CacheService } from '../shared/cache.service';
@Injectable()
export class RefineFieldResultsService {
// scoobydoo.di.uoa.gr:8181/dnet-functionality-services-2.0.0-SNAPSHOT/rest/v2/api/projects?refine=true&fields=funderid&page=1&size=0
constructor(private http: Http) {}
constructor(private http: Http, public _cache: CacheService) {}
getRefineFieldResultsByFieldName(fieldName:string, entityName:string):any{
let link = OpenaireProperties.getSearchAPIURLForEntity(entityName)+"?fields="+fieldName;
return this.getField(link,fieldName)
return this.getField(link,fieldName)
}
getField (link:string,fieldName:string):any{
let url = link+"&refine=true&page=1&size=0";
let key = url;
if (this._cache.has(key)) {
return Observable.of(this._cache.get(key));
}
return this.http.get(url)
.map(res => <any> res.json())
.map(res => res['refineResults'])
// .do(res => console.info(res))
.map(res => this.parse(res,fieldName));
.map(res => this.parse(res,fieldName))
.do(res => {
this._cache.set(key, res);
});
}
parse(data: any,fieldName:string):any {

View File

@ -1,30 +1,45 @@
import {Injectable} from '@angular/core';
// import {Http, Response, Headers} from '@angular/http';
import {Http, Response} from '@angular/http';
import {Observable} from 'rxjs/Observable';
// import {Publication} from '../utils/entities/publication';
import {OpenaireProperties} from '../utils/properties/openaireProperties';
import 'rxjs/add/observable/of';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/share';
import { CacheService } from '../shared/cache.service';
@Injectable()
export class SearchCrossrefService {
constructor( private http: Http) {}
constructor( private http: Http, public _cache: CacheService) {}
searchCrossrefResults (term: string, size : number, page : number):any {
let url = OpenaireProperties.getSearchCrossrefAPIURL()+'?query='+term+'&rows='+size+'&offset='+(size*(page-1));
////"&rows=".$size."&offset=".($page-1)*$size
let key = url;
if (this._cache.has(key)) {
return Observable.of(this._cache.get(key));
}
return this.http.get( url)
.map(request => <any> request.json().message)
.do(items => console.log("Crossref Results: total results = "+items['total-results']+" keyword = "+term))
.do(res => {
this._cache.set(key, res);
});
//.catch(this.handleError);
}
searchCrossrefByDOI(doi: string):any {
let url = OpenaireProperties.getSearchCrossrefAPIURL()+'?filter=doi:'+doi;
////"&rows=".$size."&offset=".($page-1)*$size
let key = url;
if (this._cache.has(key)) {
return Observable.of(this._cache.get(key));
}
return this.http.get( url)
.map(request => <any> request.json().message)
.do(items => console.log("Crossref Results: total results = "+items['total-results']+" for doi = "+doi))
.do(res => {
this._cache.set(key, res);
});
//.catch(this.handleError);
}
@ -34,10 +49,17 @@ export class SearchCrossrefService {
url=url+(url.length==0?'':',')+'doi:'+dois[i];
}
url = OpenaireProperties.getSearchCrossrefAPIURL()+'?filter='+url;
////"&rows=".$size."&offset=".($page-1)*$size
let key = url;
if (this._cache.has(key)) {
return Observable.of(this._cache.get(key));
}
return this.http.get( url)
.map(request => <any> request.json().message)
.do(items => console.log("Crossref Results: total results = "+items['total-results']))
.do(items => console.log("Crossref Results: total results = "+items['total-results'])).
do(res => {
this._cache.set(key, res);
});
//.catch(this.handleError);
}

View File

@ -1,20 +1,28 @@
import {Injectable} from '@angular/core';
import {Jsonp, URLSearchParams} from '@angular/http';
import {Http, Response} from '@angular/http';
import {Observable} from 'rxjs/Observable';
import {OpenaireProperties} from '../utils/properties/openaireProperties';
import 'rxjs/add/observable/of';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/share';
import { CacheService } from '../shared/cache.service';
@Injectable()
export class SearchDataciteService {
constructor(private jsonp: Jsonp, private http: Http) {}
constructor(private http: Http, public _cache: CacheService) {}
searchDataciteResults (term: string, size : number, page : number):any {
console.info("In search datacite results "+term);
let url = OpenaireProperties.getSearchDataciteAPIURL()+'?q='+term+'&fl=doi,title,creator,publisher&wt=json&rows='+size+'&start='+(size*(page-1));
let key = url;
if (this._cache.has(key)) {
return Observable.of(this._cache.get(key));
}
return this.http.get( url)
.map(request => <any> request.json().response)
.do(items => console.log("Datacite Results: total results = "+items['numFound']+" keyword = "+term))
.do(res => {
this._cache.set(key, res);
});
//.catch(this.handleError);
}

View File

@ -4,10 +4,13 @@ import {Observable} from 'rxjs/Observable';
import {OpenaireProperties} from '../utils/properties/openaireProperties';
import {SearchResult} from '../utils/entities/searchResult';
import {RefineResultsUtils} from './servicesUtils/refineResults.class';
import 'rxjs/add/observable/of';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/share';
import { CacheService } from '../shared/cache.service';
@Injectable()
export class SearchDataprovidersService {
constructor(private http: Http) {}
constructor(private http: Http, public _cache: CacheService) {}
searchDataproviders (params: string, refineParams:string, page: number, size: number, refineFields:string[] ):any {
@ -22,11 +25,17 @@ export class SearchDataprovidersService {
}
url += "&page="+page+"&size="+size;
let key = url;
if (this._cache.has(key)) {
return Observable.of(this._cache.get(key));
}
return this.http.get(url)
.map(res => <any> res.json())
//.do(res => console.info(res))
.map(res => [res['meta'].total, this.parseResults(res['results']),RefineResultsUtils.parse(res['refineResults'],refineFields)]);
.map(res => [res['meta'].total, this.parseResults(res['results']),RefineResultsUtils.parse(res['refineResults'],refineFields)])
.do(res => {
this._cache.set(key, res);
});
}
searchCompatibleDataproviders (params: string,refineParams:string, page: number, size: number, refineFields:string[] ):any {
@ -39,10 +48,17 @@ export class SearchDataprovidersService {
url += refineParams;
}
url += "&page="+page+"&size="+size;
let key = url;
if (this._cache.has(key)) {
return Observable.of(this._cache.get(key));
}
return this.http.get(url)
.map(res => <any> res.json())
//.do(res => console.info(res))
.map(res => [res['meta'].total, this.parseResults(res['results']),RefineResultsUtils.parse(res['refineResults'],refineFields)]);
.map(res => [res['meta'].total, this.parseResults(res['results']),RefineResultsUtils.parse(res['refineResults'],refineFields)])
.do(res => {
this._cache.set(key, res);
});
}
searchEntityRegistries (params: string,refineParams:string, page: number, size: number, refineFields:string[] ):any {
let url = OpenaireProperties.getSearchResourcesAPIURL();
@ -54,10 +70,17 @@ export class SearchDataprovidersService {
url += refineParams;
}
url += "&page="+page+"&size="+size;
let key = url;
if (this._cache.has(key)) {
return Observable.of(this._cache.get(key));
}
return this.http.get(url)
.map(res => <any> res.json())
//.do(res => console.info(res))
.map(res => [res['meta'].total, this.parseResults(res['results']),RefineResultsUtils.parse(res['refineResults'],refineFields)]);
.map(res => [res['meta'].total, this.parseResults(res['results']),RefineResultsUtils.parse(res['refineResults'],refineFields)])
.do(res => {
this._cache.set(key, res);
});
}
searchDataprovidersForDeposit (id: string,type:string, page: number, size: number):any {
@ -69,17 +92,31 @@ export class SearchDataprovidersService {
compatibilities = " and (datasourcecompatibilityid <> UNKNOWN) and (datasourcecompatibilityid <> openaire2.0_data)"
}
let url = link+"?query=(((deletedbyinference = false) AND (oaftype exact datasource)) "+((compatibilities && compatibilities.length > 0)?" "+compatibilities+" ":"")+") and (relorganizationid exact "+id+")";
let key = url;
if (this._cache.has(key)) {
return Observable.of(this._cache.get(key));
}
return this.http.get(url)
.map(res => <any> res.json())
.map(res => [res['meta'].total, this.parseResults(res['results'])]);
.map(res => [res['meta'].total, this.parseResults(res['results'])])
.do(res => {
this._cache.set(key, res);
});
}
searchDataprovidersForEntity (params: string, page: number, size: number):any {
let link = OpenaireProperties.getSearchAPIURL();
let url = link+params+"/datasources";
let key = url;
if (this._cache.has(key)) {
return Observable.of(this._cache.get(key));
}
return this.http.get(url)
.map(res => <any> res.json())
.map(res => [res['meta'].total, this.parseResults(res['results'])]);
.map(res => [res['meta'].total, this.parseResults(res['results'])])
.do(res => {
this._cache.set(key, res);
});
}
searchDataprovidersCSV (params: string, refineParams:string, page: number, size: number):any {
@ -95,11 +132,17 @@ export class SearchDataprovidersService {
}
url += "&page="+page+"&size="+size;
let key = url;
if (this._cache.has(key)) {
return Observable.of(this._cache.get(key));
}
return this.http.get(url)
.map(res => <any> res.json())
//.do(res => console.info(res))
.map(res => this.parseResultsCSV(res['results']));
.map(res => this.parseResultsCSV(res['results']))
.do(res => {
this._cache.set(key, res);
});
}
parseResults(data: any): SearchResult[] {
@ -227,10 +270,16 @@ export class SearchDataprovidersService {
//OpenaireProperties.getSearchAPIURL()
//"http://rudie.di.uoa.gr:8080/dnet-functionality-services-2.0.0-SNAPSHOT/rest/v2/api/"
let url = OpenaireProperties.getSearchAPIURL()+params;
let key = url;
if (this._cache.has(key)) {
return Observable.of(this._cache.get(key));
}
return this.http.get(url)
.map(res => <any> res.json())
.map(res => res.total);
.map(res => res.total)
.do(res => {
this._cache.set(key, res);
});
}
private quote(word: any): string {

View File

@ -4,12 +4,15 @@ import {Observable} from 'rxjs/Observable';
import {OpenaireProperties} from '../utils/properties/openaireProperties';
import {SearchResult} from '../utils/entities/searchResult';
import {RefineResultsUtils} from './servicesUtils/refineResults.class';
import 'rxjs/add/observable/of';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/share';
import { CacheService } from '../shared/cache.service';
@Injectable()
export class SearchDatasetsService {
private sizeOfDescription: number = 497;
constructor(private http: Http) {}
constructor(private http: Http, public _cache: CacheService) {}
searchDatasets (params: string, refineParams:string, page: number, size: number, refineFields:string[] ):any {
@ -24,28 +27,48 @@ export class SearchDatasetsService {
}
url += "&page="+page+"&size="+size;
let key = url;
if (this._cache.has(key)) {
return Observable.of(this._cache.get(key));
}
return this.http.get(url)
.map(res => <any> res.json())
//.do(res => console.info(res))
.map(res => [res['meta'].total, this.parseResults(res['results']),RefineResultsUtils.parse(res['refineResults'],refineFields)]);
.map(res => [res['meta'].total, this.parseResults(res['results']),RefineResultsUtils.parse(res['refineResults'],refineFields)])
.do(res => {
this._cache.set(key, res);
});
}
searchDatasetsForEntity (params: string, page: number, size: number):any {
let link = OpenaireProperties.getSearchAPIURL();
let url = link+params+"/datasets";
let key = url;
if (this._cache.has(key)) {
return Observable.of(this._cache.get(key));
}
return this.http.get(url)
.map(res => <any> res.json())
.map(res => [res['meta'].total, this.parseResults(res['results'])]);
.map(res => [res['meta'].total, this.parseResults(res['results'])])
.do(res => {
this._cache.set(key, res);
});
}
searchDatasetsForDataproviders(params: string, page: number, size: number):any {
let link = OpenaireProperties.getSearchAPIURL();
let url = link+params;
let key = url;
if (this._cache.has(key)) {
return Observable.of(this._cache.get(key));
}
return this.http.get(url)
.map(res => <any> res.json())
.map(res => [res['meta'].total, this.parseResults(res['results'])]);
.map(res => [res['meta'].total, this.parseResults(res['results'])])
.do(res => {
this._cache.set(key, res);
});
}
parseResults(data: any): SearchResult[] {
@ -163,10 +186,16 @@ export class SearchDatasetsService {
//OpenaireProperties.getSearchAPIURL()
//"http://rudie.di.uoa.gr:8080/dnet-functionality-services-2.0.0-SNAPSHOT/rest/v2/api/"
let url = OpenaireProperties.getSearchAPIURL()+entity+id+"/datasets/count"
let key = url;
if (this._cache.has(key)) {
return Observable.of(this._cache.get(key));
}
return this.http.get(url)
.map(res => <any> res.json())
.map(res => res.total);
.map(res => res.total)
.do(res => {
this._cache.set(key, res);
});
}
numOfSearchDatasets(params: string):any {
@ -174,9 +203,15 @@ export class SearchDatasetsService {
//OpenaireProperties.getSearchAPIURL()
//"http://rudie.di.uoa.gr:8080/dnet-functionality-services-2.0.0-SNAPSHOT/rest/v2/api/"
let url = OpenaireProperties.getSearchAPIURL()+"datasets/count?q="+params;
let key = url;
if (this._cache.has(key)) {
return Observable.of(this._cache.get(key));
}
return this.http.get(url)
.map(res => <any> res.json())
.map(res => res.total);
.map(res => res.total)
.do(res => {
this._cache.set(key, res);
});
}
}

View File

@ -1,13 +1,16 @@
import {Injectable} from '@angular/core';
import {Jsonp, URLSearchParams} from '@angular/http';
import {URLSearchParams} from '@angular/http';
import {Http, Response} from '@angular/http';
import { Headers, RequestOptions } from '@angular/http';
import {Observable} from 'rxjs/Observable';
import {OpenaireProperties} from '../utils/properties/openaireProperties';
import 'rxjs/add/observable/of';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/share';
import { CacheService } from '../shared/cache.service';
@Injectable()
export class SearchOrcidService {
constructor(private jsonp: Jsonp, private http: Http) {}
constructor( private http: Http, public _cache: CacheService) {}
searchOrcidAuthor (term: string, authorIds: string[],
authorGivenNames: string[], authorFamilyNames: string[]):any {
@ -17,13 +20,19 @@ export class SearchOrcidService {
headers.append('Accept', 'application/orcid+json');
let url = OpenaireProperties.getSearchOrcidURL()+term+'/orcid-bio';
let key = url;
if (this._cache.has(key)) {
return Observable.of(this._cache.get(key));
}
return this.http.get(url, { headers: headers })
.map(res => res.json()['orcid-profile'])
.map(res => [res['orcid-bio']['personal-details']['given-names'],
res['orcid-bio']['personal-details']['family-name'],
res['orcid-identifier']])
.map(res => this.parseOrcidAuthor(res, authorIds, authorGivenNames, authorFamilyNames));
.map(res => this.parseOrcidAuthor(res, authorIds, authorGivenNames, authorFamilyNames))
.do(res => {
this._cache.set(key, res);
});
}
searchOrcidAuthors (term: string, authorIds: string[],
@ -34,17 +43,17 @@ export class SearchOrcidService {
headers.append('Accept', 'application/orcid+json');
let url = OpenaireProperties.getSearchOrcidURL()+'search/orcid-bio?defType=edismax&q='+term+'&qf=given-name^1.0+family-name^2.0+other-names^1.0+credit-name^1.0&start=0&rows=10';
let key = url;
if (this._cache.has(key)) {
return Observable.of(this._cache.get(key));
}
return this.http.get(url, { headers: headers })
.map(res => res.json()['orcid-search-results']['orcid-search-result'])
.map(res => this.parseOrcidAuthors(res, authorIds, authorGivenNames, authorFamilyNames));
/*
.flatMap(res => res['orcid-search-result'])
.map(res => res['orcid-profile'])
.map(res => [res['orcid-bio']['personal-details']['given-names'],
res['orcid-bio']['personal-details']['family-name'],
res['orcid-identifier']]);
*/
.map(res => this.parseOrcidAuthors(res, authorIds, authorGivenNames, authorFamilyNames))
.do(res => {
this._cache.set(key, res);
});
}
searchOrcidPublications (id: string):any {
@ -54,9 +63,15 @@ export class SearchOrcidService {
headers.append('Accept', 'application/orcid+json');
let url = OpenaireProperties.getSearchOrcidURL()+id+'/orcid-works';
let key = url;
if (this._cache.has(key)) {
return Observable.of(this._cache.get(key));
}
return this.http.get(url, { headers: headers })
.map(res => res.json()['orcid-profile']['orcid-activities']['orcid-works']);
.map(res => res.json()['orcid-profile']['orcid-activities']['orcid-works'])
.do(res => {
this._cache.set(key, res);
});
//.map(res => res['orcid-work']);
}

View File

@ -1,6 +1,10 @@
import {Injectable} from '@angular/core';
import {Http, Response} from '@angular/http';
import {Observable} from 'rxjs/Observable';
import 'rxjs/add/observable/of';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/share';
import { CacheService } from '../shared/cache.service';
import {OpenaireProperties} from '../utils/properties/openaireProperties';
import {SearchResult} from '../utils/entities/searchResult';
import {RefineResultsUtils} from './servicesUtils/refineResults.class';
@ -8,7 +12,7 @@ import {RefineResultsUtils} from './servicesUtils/refineResults.class';
@Injectable()
export class SearchOrganizationsService {
constructor(private http: Http) {}
constructor(private http: Http, public _cache: CacheService) {}
searchOrganizationsForDeposit (params: string, collectedFrom: string, page: number, size: number):any {
@ -21,20 +25,23 @@ export class SearchOrganizationsService {
url += "((oaftype exact organization and deletedbyinference=false and "+
"(reldatasourcecompatibilityid=driver or reldatasourcecompatibilityid=driver-openaire2.0 or reldatasourcecompatibilityid=openaire2.0 or reldatasourcecompatibilityid=openaire3.0 or reldatasourcecompatibilityid=openaire2.0_data or reldatasourcecompatibilityid=hostedBy or relprojectid=*))"+
" and ((organizationlegalname all "+this.quote(params)+") or (organizationlegalshortname all "+this.quote(params)+")) and (collectedfromdatasourcename exact "+collectedFrom+")) "
// if(collectedFrom == "OpenDOAR") {
//'contenttype='+this.quote(params)+'&cn=and&compatibility='+this.quote(params)+'&cm=or';
// } else if(collectedFrom == "Registry of Research Data Repository") {
// url += 'contenttype='+this.quote(params)+'&cn=and&compatibility='+this.quote(params)+'&cm=or';
// }
}
url += "&page="+page+"&size="+size;
let key = url;
if (this._cache.has(key)) {
return Observable.of(this._cache.get(key));
}
return this.http.get(url)
.map(res => <any> res.json())
.do(res => console.info(res))
.map(res => this.parseResultsForDeposit(res['results']));
.map(res => this.parseResultsForDeposit(res['results']))
.do(res => {
this._cache.set(key, res);
});
//.map(res => [res['meta'].total, this.parseResults(res['results']),RefineResultsUtils.parse(res['refineResults'],refineFields)]);
}
@ -80,11 +87,18 @@ export class SearchOrganizationsService {
}
url += "&page="+page+"&size="+size;
let key = url;
console.log("Org: "+key);
if (this._cache.has(key)) {
return Observable.of(this._cache.get(key));
}
return this.http.get(url)
.map(res => <any> res.json())
//.do(res => console.info(res))
.map(res => [res['meta'].total, this.parseResults(res['results']),RefineResultsUtils.parse(res['refineResults'],refineFields)]);
.map(res => [res['meta'].total, this.parseResults(res['results']),RefineResultsUtils.parse(res['refineResults'],refineFields)])
.do(res => {
this._cache.set(key, res);
});
}
parseResults(data: any): SearchResult[] {
@ -171,10 +185,16 @@ export class SearchOrganizationsService {
//OpenaireProperties.getSearchAPIURL()
//"http://rudie.di.uoa.gr:8080/dnet-functionality-services-2.0.0-SNAPSHOT/rest/v2/api/"
let url = OpenaireProperties.getSearchAPIURL()+entity+id+"/organizations/count"
let key = url;
if (this._cache.has(key)) {
return Observable.of(this._cache.get(key));
}
return this.http.get(url)
.map(res => <any> res.json())
.map(res => res.total);
.map(res => res.total)
.do(res => {
this._cache.set(key, res);
});
}
numOfSearchOrganizations(params: string):any {
@ -182,9 +202,15 @@ export class SearchOrganizationsService {
//OpenaireProperties.getSearchAPIURL()
//"http://rudie.di.uoa.gr:8080/dnet-functionality-services-2.0.0-SNAPSHOT/rest/v2/api/"
let url = OpenaireProperties.getSearchAPIURL()+"organizations/count?q="+params;
let key = url;
if (this._cache.has(key)) {
return Observable.of(this._cache.get(key));
}
return this.http.get(url)
.map(res => <any> res.json())
.map(res => res.total);
.map(res => res.total)
.do(res => {
this._cache.set(key, res);
});
}
}

View File

@ -1,6 +1,10 @@
import {Injectable} from '@angular/core';
import {Http, Response} from '@angular/http';
import {Observable} from 'rxjs/Observable';
import 'rxjs/add/observable/of';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/share';
import { CacheService } from '../shared/cache.service';
import {OpenaireProperties} from '../utils/properties/openaireProperties';
import {SearchResult} from '../utils/entities/searchResult';
import {RefineResultsUtils} from './servicesUtils/refineResults.class';
@ -8,7 +12,7 @@ import {RefineResultsUtils} from './servicesUtils/refineResults.class';
@Injectable()
export class SearchPeopleService {
constructor(private http: Http) {}
constructor(private http: Http, public _cache: CacheService) {}
searchPeople (params: string, refineParams:string, page: number, size: number, refineFields:string[] ):any {
@ -24,12 +28,18 @@ export class SearchPeopleService {
url += refineParams;
}
url += "&page="+page+"&size="+size;
let key = url;
if (this._cache.has(key)) {
return Observable.of(this._cache.get(key));
}
return this.http.get(url)
.map(res => <any> res.json())
//.do(res => console.info(res))
.map(res => [res['meta'].total, this.parseResults(res['results']),RefineResultsUtils.parse(res['refineResults'],refineFields)]);
.map(res => [res['meta'].total, this.parseResults(res['results']),RefineResultsUtils.parse(res['refineResults'],refineFields)])
.do(res => {
this._cache.set(key, res);
});
}
parseResults(data: any): SearchResult[] {
@ -60,10 +70,16 @@ export class SearchPeopleService {
//OpenaireProperties.getSearchAPIURL()
//"http://rudie.di.uoa.gr:8080/dnet-functionality-services-2.0.0-SNAPSHOT/rest/v2/api/"
let url = OpenaireProperties.getSearchAPIURL()+entity+id+"/people/count"
let key = url;
if (this._cache.has(key)) {
return Observable.of(this._cache.get(key));
}
return this.http.get(url)
.map(res => <any> res.json())
.map(res => res.total);
.map(res => res.total)
.do(res => {
this._cache.set(key, res);
});
}
numOfSearchPeople(params: string):any {
@ -71,9 +87,15 @@ export class SearchPeopleService {
//OpenaireProperties.getSearchAPIURL()
//"http://rudie.di.uoa.gr:8080/dnet-functionality-services-2.0.0-SNAPSHOT/rest/v2/api/"
let url = OpenaireProperties.getSearchAPIURL()+"people/count?q="+params;
let key = url;
if (this._cache.has(key)) {
return Observable.of(this._cache.get(key));
}
return this.http.get(url)
.map(res => <any> res.json())
.map(res => res.total);
.map(res => res.total)
.do(res => {
this._cache.set(key, res);
});
}
}

View File

@ -1,6 +1,10 @@
import {Injectable} from '@angular/core';
import {Http, Response} from '@angular/http';
import {Observable} from 'rxjs/Observable';
import 'rxjs/add/observable/of';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/share';
import { CacheService } from '../shared/cache.service';
import {OpenaireProperties} from '../utils/properties/openaireProperties';
import {SearchResult} from '../utils/entities/searchResult';
import {RefineResultsUtils} from './servicesUtils/refineResults.class';
@ -9,7 +13,7 @@ import {RefineResultsUtils} from './servicesUtils/refineResults.class';
export class SearchProjectsService {
private sizeOfDescription: number = 497;
constructor(private http: Http) {}
constructor(private http: Http, public _cache: CacheService) {}
searchProjects (params: string, refineParams:string, page: number, size: number, refineFields:string[] ):any {
@ -25,19 +29,32 @@ export class SearchProjectsService {
url += refineParams;
}
url += "&page="+page+"&size="+size;
let key = url;
if (this._cache.has(key)) {
return Observable.of(this._cache.get(key));
}
return this.http.get(url)
.map(res => <any> res.json())
//.do(res => console.info(res))
.map(res => [res['meta'].total, this.parseResults(res['results']),RefineResultsUtils.parse(res['refineResults'],refineFields)]);
.map(res => [res['meta'].total, this.parseResults(res['results']),RefineResultsUtils.parse(res['refineResults'],refineFields)])
.do(res => {
this._cache.set(key, res);
});
}
getFunders():any {
let url = OpenaireProperties.getSearchAPIURL()+"projects?refine=true&fields=funderid&size=0";
let key = url;
if (this._cache.has(key)) {
return Observable.of(this._cache.get(key));
}
return this.http.get(url)
.map(res => <any> res.json())
.map(res => [res['meta'].total, res['refineResults']['funderid']]);
.map(res => [res['meta'].total, res['refineResults']['funderid']])
.do(res => {
this._cache.set(key, res);
});
}
@ -45,16 +62,15 @@ export class SearchProjectsService {
searchForProjectsObs(keyword:string, funderId:string):any {
let url = 'search?action=search&sTransformer=projects_openaire&query='+
'%28oaftype+exact+project%29+and+%28%28projecttitle+%3D+%22'+keyword+'%22%29+or+%28projectacronym+%3D+%22'+keyword+'%22%29+or+%28projectcode+%3D+%22'+keyword+'%22%29%29+and+%28funderid+exact+'+funderId+'%29&size=10&locale=en_GB&format=json';
let key = url;
if (this._cache.has(key)) {
return Observable.of(this._cache.get(key));
}
return this.http.get(url).toPromise()
.then(request =>{
return (request.json().response.results)?request.json().response.results.result:request.json().response.result;
// var valid:boolean= this.isJsonString(request);
// if(valid==true){
return (request.json().response.results)?request.json().response.results.result:request.json().response.result;
// }else{
// return [];
// }
})
}) ;
}
parseResults(data: any): SearchResult[] {
let results: SearchResult[] = [];
@ -147,10 +163,16 @@ export class SearchProjectsService {
//OpenaireProperties.getSearchAPIURL()
//"http://rudie.di.uoa.gr:8080/dnet-functionality-services-2.0.0-SNAPSHOT/rest/v2/api/"
let url = OpenaireProperties.getSearchAPIURL()+entity+id+"/projects/count"
let key = url;
if (this._cache.has(key)) {
return Observable.of(this._cache.get(key));
}
return this.http.get(url)
.map(res => <any> res.json())
.map(res => res.total);
.map(res => res.total)
.do(res => {
this._cache.set(key, res);
});
}
numOfSearchProjects(params: string):any {
@ -158,9 +180,15 @@ export class SearchProjectsService {
//OpenaireProperties.getSearchAPIURL()
//"http://rudie.di.uoa.gr:8080/dnet-functionality-services-2.0.0-SNAPSHOT/rest/v2/api/"
let url = OpenaireProperties.getSearchAPIURL()+"projects/count?q="+params;
let key = url;
if (this._cache.has(key)) {
return Observable.of(this._cache.get(key));
}
return this.http.get(url)
.map(res => <any> res.json())
.map(res => res.total);
.map(res => res.total)
.do(res => {
this._cache.set(key, res);
});
}
}

View File

@ -1,6 +1,11 @@
import {Injectable} from '@angular/core';
import {Http, Response} from '@angular/http';
import {Observable} from 'rxjs/Observable';
import 'rxjs/add/observable/of';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/share';
import { CacheService } from '../shared/cache.service';
import {OpenaireProperties} from '../utils/properties/openaireProperties';
import {SearchResult} from '../utils/entities/searchResult';
import {RefineResultsUtils} from './servicesUtils/refineResults.class';
@ -9,7 +14,7 @@ import {RefineResultsUtils} from './servicesUtils/refineResults.class';
export class SearchPublicationsService {
private sizeOfDescription: number = 497;
constructor(private http: Http) {}
constructor(private http: Http, public _cache: CacheService) {}
searchPublications (params: string, refineParams:string, page: number, size: number, refineFields:string[] ):any {
@ -24,28 +29,51 @@ export class SearchPublicationsService {
}
url += "&page="+page+"&size="+size;
let key = url;
if (this._cache.has(key)) {
return Observable.of(this._cache.get(key));
}
return this.http.get(url)
.map(res => <any> res.json())
//.do(res => console.info(res))
.map(res => [res['meta'].total, this.parseResults(res['results']),RefineResultsUtils.parse(res['refineResults'],refineFields)]);
.map(res => [res['meta'].total, this.parseResults(res['results']),RefineResultsUtils.parse(res['refineResults'],refineFields)])
.do(res => {
this._cache.set(key, res);
});
}
searchPublicationsForEntity (params: string, page: number, size: number):any {
let link = OpenaireProperties.getSearchAPIURL();
let url = link+params+"/publications";
let key = url;
if (this._cache.has(key)) {
return Observable.of(this._cache.get(key));
}
return this.http.get(url)
.map(res => <any> res.json())
.map(res => [res['meta'].total, this.parseResults(res['results'])]);
.map(res => [res['meta'].total, this.parseResults(res['results'])])
.do(res => {
this._cache.set(key, res);
});
}
searchPublicationsForDataproviders(params: string, page: number, size: number):any {
let link = OpenaireProperties.getSearchAPIURL();
let url = link+params;
let key = url;
if (this._cache.has(key)) {
return Observable.of(this._cache.get(key));
}
return this.http.get(url)
.map(res => <any> res.json())
.map(res => [res['meta'].total, this.parseResults(res['results'])]);
.map(res => [res['meta'].total, this.parseResults(res['results'])])
.do(res => {
this._cache.set(key, res);
});
}
@ -156,10 +184,15 @@ export class SearchPublicationsService {
//OpenaireProperties.getSearchAPIURL()
//"http://rudie.di.uoa.gr:8080/dnet-functionality-services-2.0.0-SNAPSHOT/rest/v2/api/"
let url = OpenaireProperties.getSearchAPIURL()+entity+id+"/publications/count"
let key = url;
if (this._cache.has(key)) {
return Observable.of(this._cache.get(key));
}
return this.http.get(url)
.map(res => <any> res.json())
.map(res => res.total);
.map(res => res.total).do(res => {
this._cache.set(key, res);
});
}
numOfSearchPublications(params: string):any {
@ -167,9 +200,14 @@ export class SearchPublicationsService {
//OpenaireProperties.getSearchAPIURL()
//"http://rudie.di.uoa.gr:8080/dnet-functionality-services-2.0.0-SNAPSHOT/rest/v2/api/"
let url = OpenaireProperties.getSearchAPIURL()+"publications/count?q="+params;
let key = url;
if (this._cache.has(key)) {
return Observable.of(this._cache.get(key));
}
return this.http.get(url)
.map(res => <any> res.json())
.map(res => res.total);
.map(res => res.total).do(res => {
this._cache.set(key, res);
});
}
}

View File

@ -28,6 +28,7 @@ export class CacheService {
* get our cached value
*/
get(key: string | number): any {
console.debug("Cache get :"+key);
let _key = this.normalizeKey(key);
return this._cache.get(_key);
}