Add searchEntries folder and Move search service funtions, Move community.service in utils folder, Change Imports

git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-connect-portal/trunk@51051 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
sofia.baltzi 2018-03-06 13:54:17 +00:00
parent a7df9c7826
commit cabb1d9550
12 changed files with 127 additions and 129 deletions

View File

@ -5,7 +5,7 @@ import {ActivatedRoute} from '@angular/router';
import { EnvProperties} from './openaireLibrary/utils/properties/env-properties';
import{MenuItem, RootMenuItem} from './openaireLibrary/sharedComponents/menu';
import { EnvironmentSpecificService} from './openaireLibrary/utils/properties/environment-specific.service';
import {CommunityService} from "./community/community.service";
import {CommunityService} from "./utils/services/community.service";
@Component({

View File

@ -21,7 +21,7 @@ import { ErrorModule} from './openaireLibrary/error/error.module';
import { OpenaireErrorPageComponent } from './error/errorPage.component';
import { AppRoutingModule } from './app-routing.module';
import { CommunityService } from './community/community.service';
import { CommunityService } from './utils/services/community.service';
import { CommunitiesService } from './communities/communities.service';
//import { LibSearchProjectsModule } from './searchPages/simple/searchProjects.module';

View File

@ -6,10 +6,10 @@ import "rxjs/add/observable/zip";
import { EnvProperties} from '../openaireLibrary/utils/properties/env-properties';
import { ErrorCodes} from '../openaireLibrary/utils/properties/errorCodes';
import {Properties} from '../utils/properties';
import {PiwikService} from '../openaireLibrary/utils/piwik/piwik.service';
import {Meta} from '../openaireLibrary/sharedComponents/metaService';
import {ConfigurationService} from '../openaireLibrary/utils/configuration/configuration.service';
import {CommunitiesService} from './communities.service';
@Component({
@ -25,14 +25,14 @@ export class CommunitiesComponent {
public communitiesResults = null;
constructor (
private route: ActivatedRoute,
private _router: Router,
private location: Location, private _meta: Meta,private _piwikService:PiwikService, private _communitiesService:CommunitiesService,
private location: Location, private _meta: Meta,
private _piwikService:PiwikService,
private _communitiesService:CommunitiesService,
private config: ConfigurationService
) {
var description = "open access, research, scientific publication, European Commission, EC, FP7, ERC, Horizon 2020, H2020, search, projects ";
var title = "OpenAIRE";
@ -41,9 +41,6 @@ export class CommunitiesComponent {
this._meta.updateMeta("description", description);
this._meta.updateProperty("og:description", description);
this._meta.updateProperty("og:title", title);
}
public ngOnInit() {
@ -57,8 +54,7 @@ export class CommunitiesComponent {
}
});
this._communitiesService.getResults('https://dev-openaire.d4science.org/openaire/community/communities').subscribe(
this._communitiesService.getCommunities('https://dev-openaire.d4science.org/openaire/community/communities').subscribe(
communitiesResults => {
this.communitiesResults = communitiesResults;
//console.log(communitiesResults);
@ -66,13 +62,9 @@ export class CommunitiesComponent {
}
public ngOnDestroy() {
if(this.piwiksub){
this.piwiksub.unsubscribe();
}
}
}

View File

@ -10,11 +10,11 @@ export class CommunitiesService {
constructor(private http:Http) {
}
getResults(url: string) {
return this.http.get(url).map(res => <any> res.json()).map(res => this.parseResults(res));
getCommunities(url: string) {
return this.http.get(url).map(res => <any> res.json()).map(res => this.parseCommunities(res));
}
parseResults(data: any): CommunityInfo[] {
parseCommunities(data: any): CommunityInfo[] {
let communities: CommunityInfo[] = [];
let length = Array.isArray(data) ? data.length :1;

View File

@ -5,13 +5,13 @@ import {Location} from '@angular/common';
import "rxjs/add/observable/zip";
import { EnvProperties} from '../openaireLibrary/utils/properties/env-properties';
import { ErrorCodes} from '../openaireLibrary/utils/properties/errorCodes';
import {Properties} from '../utils/properties';
import {CommunityService} from "./community.service";
import {CommunitiesService} from "../communities/communities.service";
import {CommunityService} from "../utils/services/community.service";
import {PiwikService} from '../openaireLibrary/utils/piwik/piwik.service';
import {Meta} from '../openaireLibrary/sharedComponents/metaService';
import {ConfigurationService} from '../openaireLibrary/utils/configuration/configuration.service';
import {SearchEntriesService} from '../searchEntries/searchEntries.service';
@Component({
@ -44,22 +44,19 @@ export class CommunityComponent {
constructor (
private route: ActivatedRoute,
private _router: Router,
private location: Location, private _meta: Meta, private _piwikService:PiwikService,
private location: Location, private _meta: Meta,
private _piwikService:PiwikService,
private config: ConfigurationService,
private _communityService:CommunityService, private _communitiesService:CommunitiesService
private _communityService:CommunityService,
private _searchEntriesService:SearchEntriesService,
) {
var description = "open access, research, scientific publication, European Commission, EC, FP7, ERC, Horizon 2020, H2020, search, projects ";
var title = "OpenAIRE";
this._meta.setTitle(title);
this._meta.updateMeta("description", description);
this._meta.updateProperty("og:description", description);
this._meta.updateProperty("og:title", title);
}
public ngOnInit() {
@ -74,7 +71,6 @@ export class CommunityComponent {
});
this.route.queryParams.subscribe(
communityId => {
this.communityId = communityId['communityId'];
@ -84,67 +80,64 @@ export class CommunityComponent {
community => {
this.community = community;
this.params = {community: encodeURIComponent('"'+community.queryId+'"')};
console.log(community);
//console.log(community);
});
this._communityService.getTotal('http://beta.services.openaire.eu:8480/search/rest/v2/api/publications/count?format=json&fq=communityid='+this.communityId).subscribe(
this._searchEntriesService.getTotal('http://beta.services.openaire.eu:8480/search/rest/v2/api/publications/count?format=json&fq=communityid='+this.communityId).subscribe(
publicationTotal => {
this.publicationTotal = publicationTotal;
});
this._communityService.getTotal('http://beta.services.openaire.eu:8480/search/rest/v2/api/datasets/count?format=json&fq=communityid='+this.communityId).subscribe(
this._searchEntriesService.getTotal('http://beta.services.openaire.eu:8480/search/rest/v2/api/datasets/count?format=json&fq=communityid='+this.communityId).subscribe(
researchDataTotal => {
this.researchDataTotal = researchDataTotal;
});
this._communityService.getTotal('http://beta.services.openaire.eu:8480/search/rest/v2/api/software/count?format=json&fq=communityid='+this.communityId).subscribe(
this._searchEntriesService.getTotal('http://beta.services.openaire.eu:8480/search/rest/v2/api/software/count?format=json&fq=communityid='+this.communityId).subscribe(
softwareTotal => {
this.softwareTotal = softwareTotal;
});
this._communityService.countTotal('https://dev-openaire.d4science.org/openaire/community/'+this.communityId+'/projects').subscribe(
this._searchEntriesService.countTotal('https://dev-openaire.d4science.org/openaire/community/'+this.communityId+'/projects').subscribe(
projectTotal => {
this.projectTotal = projectTotal;
//console.log(projectTotal);
});
this._communityService.countTotal('https://dev-openaire.d4science.org/openaire/community/'+this.communityId+'/contentproviders').subscribe(
this._searchEntriesService.countTotal('https://dev-openaire.d4science.org/openaire/community/'+this.communityId+'/contentproviders').subscribe(
contentProviderTotal => {
this.contentProviderTotal = contentProviderTotal;
//console.log(contentProviderTotal);
});
// this._communityService.countTotal('https://dev-openaire.d4science.org/openaire/community/'+this.communityId+'/organizations').subscribe(
// this._searchEntriesService.countTotal('https://dev-openaire.d4science.org/openaire/community/'+this.communityId+'/organizations').subscribe(
// organizationTotal => {
// this.organizationTotal = organizationTotal;
// console.log(organizationTotal);
// });
this._communityService.getResults('http://beta.services.openaire.eu:8480/search/rest/v2/api/publications?fq=communityid%20exact%20%22'+this.communityId+'%22&sortBy=resultdateofacceptance,descending&format=json&size=5').subscribe(
this._searchEntriesService.getResults('http://beta.services.openaire.eu:8480/search/rest/v2/api/publications?fq=communityid%20exact%20%22'+this.communityId+'%22&sortBy=resultdateofacceptance,descending&format=json&size=5').subscribe(
publicationResults => {
this.publicationResults = publicationResults;
//console.log(publicationResults);
});
this._communityService.getResults('http://beta.services.openaire.eu:8480/search/rest/v2/api/datasets?fq=communityid%20exact%20%22'+this.communityId+'%22&sortBy=resultdateofacceptance,descending&format=json&size=5').subscribe(
this._searchEntriesService.getResults('http://beta.services.openaire.eu:8480/search/rest/v2/api/datasets?fq=communityid%20exact%20%22'+this.communityId+'%22&sortBy=resultdateofacceptance,descending&format=json&size=5').subscribe(
researchDataResults => {
this.researchDataResults = researchDataResults;
});
this._communityService.getResults('http://beta.services.openaire.eu:8480/search/rest/v2/api/software?fq=communityid%20exact%20%22'+this.communityId+'%22&sortBy=resultdateofacceptance,descending&format=json&size=5').subscribe(
this._searchEntriesService.getResults('http://beta.services.openaire.eu:8480/search/rest/v2/api/software?fq=communityid%20exact%20%22'+this.communityId+'%22&sortBy=resultdateofacceptance,descending&format=json&size=5').subscribe(
softwareResults => {
this.softwareResults = softwareResults;
});
}
public ngOnDestroy() {
if(this.piwiksub){
this.piwiksub.unsubscribe();
}
}
}

View File

@ -5,15 +5,13 @@ import { RouterModule } from '@angular/router';
import{CommunityRoutingModule} from './community-routing.module';
import{CommunityComponent} from './community.component';
import { CommunityService } from './community.service';
import { CommunitiesService } from '../communities/communities.service';
import {ResultsComponent} from './results/results.component';
import {ResultsComponent} from '../searchEntries/results/results.component';
import {PiwikService} from '../openaireLibrary/utils/piwik/piwik.service';
import {Meta} from '../openaireLibrary/sharedComponents/metaService';
import {ConfigurationService} from '../openaireLibrary/utils/configuration/configuration.service';
import {SearchEntriesService} from '../searchEntries/searchEntries.service';
import { CommunityService } from '../utils/services/community.service';
import {FreeGuard} from '../openaireLibrary/login/freeGuard.guard';
import {PreviousRouteRecorder} from '../openaireLibrary/utils/piwik/previousRouteRecorder.guard';
@ -28,7 +26,8 @@ import {SubscribeModule} from '../utils/subscribe/subscribe.module';
CommunityComponent, ResultsComponent
],
providers:[
FreeGuard, PreviousRouteRecorder, ConfigurationService, Meta, PiwikService, CommunityService, CommunitiesService
FreeGuard, PreviousRouteRecorder, ConfigurationService, Meta,
PiwikService, CommunityService, SearchEntriesService
],
exports: [
CommunityComponent

View File

@ -0,0 +1,91 @@
import { Injectable } from '@angular/core';
import { Http, Response, Headers, RequestOptions } from '@angular/http';
import { Observable } from 'rxjs/Rx';
import { ResultInfo } from './results/resultInfo';
import { CommunityInfo } from '../utils/communityInfo';
@Injectable()
export class SearchEntriesService {
private sizeOfDescription: number = 135;
constructor(private http:Http) {
}
getTotal(url: string) {
return this.http.get(url).map(res => <any> res.json()).map(res => res.total);
//.do(res => {console.log(res)});
}
countTotal(url:string) {
return this.http.get(url).map(res => <any> res.json()).map(res => res.length);
}
getResults(url: string) {
return this.http.get(url).map(res => <any> res.json()).map(res => this.parseResults(res['results']));
}
parseResults(data: any): ResultInfo[] {
let results: ResultInfo[] = [];
let length = Array.isArray(data) ? data.length :1;
for (let i=0; i<length; i++) {
let resData = Array.isArray(data) ? data[i]['result']['metadata']['oaf:entity']['oaf:result'] : data['result']['metadata']['oaf:entity']['oaf:result'];
var result: ResultInfo = new ResultInfo();
if(Array.isArray(resData['title'])) {
result['title'] = resData['title'][0].content;
} else {
result['title'] = resData['title'].content;
}
result['id'] = Array.isArray(data) ? data[i]['result']['header']['dri:objIdentifier'] : data['result']['header']['dri:objIdentifier'];
if(resData['bestaccessright'].hasOwnProperty("classid")) {
result['accessRights'] = resData['bestaccessright'].classid;
}
if(resData['resulttype'].hasOwnProperty("classid")) {
result['type'] = resData['resulttype'].classid;
}
if(resData.hasOwnProperty("creator") && resData['creator'] != null) {
if(result['authors'] == undefined) {
result['authors'] = new Array<string>();
}
let authors = resData['creator'];
let length = Array.isArray(authors) ? authors.length : 1;
for(let i=0; i<length; i++) {
let author = Array.isArray(authors) ? authors[i] : authors;
result.authors[author.rank-1] = author.content;
}
result.authors = result.authors.filter(function (item) {
return (item != undefined);
});
}
var date:string = (resData.dateofacceptance)+""; // transform to string in case it is an integer
result.year = (date && (date).indexOf('-') !== -1)?date.split('-')[0]:date;
if(!Array.isArray(resData.description)) {
result.description = resData.description;
} else {
result.description = resData.description[0];
}
if(result.description.length > this.sizeOfDescription) {
result.description = result.description.substring(0, this.sizeOfDescription) + "...";
}
results.push(result);
}
return results;
}
}

View File

@ -8,7 +8,7 @@ import { EnvProperties} from '../openaireLibrary/utils/properties/env-properties
import { ErrorCodes} from '../openaireLibrary/utils/properties/errorCodes';
import {Properties} from '../utils/properties';
import {CommunityService} from "../community/community.service";
import {CommunityService} from "../utils/services/community.service";
import {CommunitiesService} from "../communities/communities.service";
import {PiwikService} from '../openaireLibrary/utils/piwik/piwik.service';
import {Meta} from '../openaireLibrary/sharedComponents/metaService';

View File

@ -6,7 +6,7 @@ import { RouterModule } from '@angular/router';
import{StatisticsRoutingModule} from './statistics-routing.module';
import{StatisticsComponent} from './statistics.component';
import { StatisticsService } from '../utils/services/statistics.service';
import { CommunityService } from '../community/community.service';
import { CommunityService } from '../utils/services/community.service';
import { CommunitiesService } from '../communities/communities.service';
import {IFrameModule} from '../openaireLibrary/utils/iframe.module';

View File

@ -2,92 +2,15 @@ import { Injectable } from '@angular/core';
import { Http, Response, Headers, RequestOptions } from '@angular/http';
import { Observable } from 'rxjs/Rx';
import { ResultInfo } from './results/resultInfo';
import { CommunityInfo } from '../utils/communityInfo';
import { ResultInfo } from '../../searchEntries/results/resultInfo';
import { CommunityInfo } from '../communityInfo';
@Injectable()
export class CommunityService {
private sizeOfDescription: number = 135;
constructor(private http:Http) {
}
getTotal(url: string) {
return this.http.get(url).map(res => <any> res.json()).map(res => res.total).do(res => {console.log(res)});
}
countTotal(url:string) {
return this.http.get(url).map(res => <any> res.json()).map(res => res.length);
}
getResults(url: string) {
return this.http.get(url).map(res => <any> res.json()).map(res => this.parseResults(res['results']));
}
parseResults(data: any): ResultInfo[] {
let results: ResultInfo[] = [];
let length = Array.isArray(data) ? data.length :1;
for (let i=0; i<length; i++) {
let resData = Array.isArray(data) ? data[i]['result']['metadata']['oaf:entity']['oaf:result'] : data['result']['metadata']['oaf:entity']['oaf:result'];
var result: ResultInfo = new ResultInfo();
if(Array.isArray(resData['title'])) {
result['title'] = resData['title'][0].content;
} else {
result['title'] = resData['title'].content;
}
result['id'] = Array.isArray(data) ? data[i]['result']['header']['dri:objIdentifier'] : data['result']['header']['dri:objIdentifier'];
if(resData['bestaccessright'].hasOwnProperty("classid")) {
result['accessRights'] = resData['bestaccessright'].classid;
}
if(resData['resulttype'].hasOwnProperty("classid")) {
result['type'] = resData['resulttype'].classid;
}
if(resData.hasOwnProperty("creator") && resData['creator'] != null) {
if(result['authors'] == undefined) {
result['authors'] = new Array<string>();
}
let authors = resData['creator'];
let length = Array.isArray(authors) ? authors.length : 1;
for(let i=0; i<length; i++) {
let author = Array.isArray(authors) ? authors[i] : authors;
result.authors[author.rank-1] = author.content;
}
result.authors = result.authors.filter(function (item) {
return (item != undefined);
});
}
var date:string = (resData.dateofacceptance)+""; // transform to string in case it is an integer
result.year = (date && (date).indexOf('-') !== -1)?date.split('-')[0]:date;
if(!Array.isArray(resData.description)) {
result.description = resData.description;
} else {
result.description = resData.description[0];
}
if(result.description.length > this.sizeOfDescription) {
result.description = result.description.substring(0, this.sizeOfDescription) + "...";
}
results.push(result);
}
return results;
}
getCommunity(url: string) {
return this.http.get(url).map(res => <any> res.json()).map(res => this.parseCommunity(res));
}