2017-12-19 13:53:46 +01:00
|
|
|
import {Injectable} from '@angular/core';
|
|
|
|
import {Http, Response} from '@angular/http';
|
|
|
|
import {Observable} from 'rxjs/Observable';
|
|
|
|
import {SoftwareInfo} from '../../utils/entities/softwareInfo';
|
|
|
|
import 'rxjs/add/observable/of';
|
|
|
|
import 'rxjs/add/operator/do';
|
|
|
|
import 'rxjs/add/operator/share';
|
2018-02-05 14:14:59 +01:00
|
|
|
import{EnvProperties} from '../../utils/properties/env-properties';
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
import { ParsingFunctions } from '../landing-utils/parsingFunctions.class';
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class SoftwareService {
|
|
|
|
|
|
|
|
constructor(private http: Http ) {
|
|
|
|
this.parsingFunctions = new ParsingFunctions();
|
|
|
|
}
|
|
|
|
|
|
|
|
public parsingFunctions: ParsingFunctions;
|
|
|
|
softwareInfo: SoftwareInfo;
|
|
|
|
|
2018-02-05 14:14:59 +01:00
|
|
|
getSoftwareInfo (id: string, properties:EnvProperties):any {
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2018-02-05 14:14:59 +01:00
|
|
|
let url = properties.searchAPIURLLAst+'software/'+id+"?format=json";
|
2017-12-19 13:53:46 +01:00
|
|
|
let key = url;
|
|
|
|
|
|
|
|
|
2018-02-05 14:14:59 +01:00
|
|
|
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
|
2017-12-19 13:53:46 +01:00
|
|
|
.map(res => <any> res.json())
|
2018-05-17 10:29:22 +02:00
|
|
|
.map(res => [res['result']['header']['dri:status'], res['result']['metadata']['oaf:entity']['oaf:result'], res])
|
2017-12-19 13:53:46 +01:00
|
|
|
.map(res => [res[1],
|
|
|
|
res[1]['title'],
|
|
|
|
res[1]['rels']['rel'],
|
|
|
|
res[1]['children'],
|
|
|
|
res[1]['pid'],
|
|
|
|
res[1]['subject'],
|
|
|
|
res[1]['bestaccessright'],
|
|
|
|
res[1]['collectedfrom'],
|
|
|
|
res[1]['context'],
|
|
|
|
//res[1]['resulttype'],
|
|
|
|
res[0],
|
2018-02-13 15:52:23 +01:00
|
|
|
res[1]['creator'],
|
|
|
|
res[1]['language'],
|
2018-06-28 16:52:45 +02:00
|
|
|
res[1]['country'],
|
|
|
|
res[1]['programmingLanguage'],
|
2018-05-17 10:29:22 +02:00
|
|
|
res[2]
|
2017-12-19 13:53:46 +01:00
|
|
|
]).map(res => this.parseSoftwareInfo(res));
|
|
|
|
}
|
|
|
|
|
|
|
|
private handleError (error: Response) {
|
|
|
|
// in a real world app, we may send the error to some remote logging infrastructure
|
|
|
|
// instead of just logging it to the console
|
|
|
|
console.log(error);
|
|
|
|
return Observable.throw(error || 'Server error');
|
|
|
|
}
|
|
|
|
|
|
|
|
parseSoftwareInfo (data: any):any {
|
|
|
|
this.softwareInfo = new SoftwareInfo();
|
2018-06-28 16:52:45 +02:00
|
|
|
this.softwareInfo.record = data[14];
|
2017-12-19 13:53:46 +01:00
|
|
|
if(data[0] != null) {
|
|
|
|
var date:string = (data[0].dateofacceptance)+""; // transform to string in case it is an integer
|
|
|
|
this.softwareInfo.date = (date && (date).indexOf('-') !== -1)?date.split('-')[0]:date;
|
|
|
|
this.softwareInfo.dateofacceptance = data[0].dateofacceptance;
|
|
|
|
this.softwareInfo.publisher = data[0].publisher;
|
|
|
|
if(!Array.isArray(data[0].description)) {
|
|
|
|
this.softwareInfo.description = data[0].description;
|
|
|
|
} else {
|
|
|
|
this.softwareInfo.description = data[0].description[0];
|
|
|
|
}
|
|
|
|
this.softwareInfo.embargoEndDate = data[0].embargoenddate;
|
|
|
|
}
|
2018-06-28 16:52:45 +02:00
|
|
|
/*
|
2017-12-19 13:53:46 +01:00
|
|
|
this.softwareInfo.title = {"name": "", "url": "", "accessMode": ""};
|
2018-02-13 15:52:23 +01:00
|
|
|
if(data[0]['bestaccessright'] && data[0]['bestaccessright'] && data[0]['bestaccessright'].hasOwnProperty("classid")) {
|
2017-12-19 13:53:46 +01:00
|
|
|
this.softwareInfo.title.accessMode = data[0]['bestaccessright'].classid;
|
|
|
|
}
|
|
|
|
if(data[1] != null) {
|
|
|
|
if(Array.isArray(data[1])) {
|
|
|
|
this.softwareInfo.title['name'] = data[1][0].content;
|
|
|
|
} else {
|
|
|
|
this.softwareInfo.title['name'] = data[1].content;
|
|
|
|
}
|
|
|
|
}
|
2018-06-28 16:52:45 +02:00
|
|
|
*/
|
|
|
|
if(data[0]['bestaccessright'] && data[0]['bestaccessright'] && data[0]['bestaccessright'].hasOwnProperty("classid")) {
|
|
|
|
this.softwareInfo.accessMode = data[0]['bestaccessright'].classid;
|
|
|
|
}
|
|
|
|
if(data[1] != null) {
|
|
|
|
if(Array.isArray(data[1])) {
|
|
|
|
this.softwareInfo.title = data[1][0].content;
|
|
|
|
} else {
|
|
|
|
this.softwareInfo.title = data[1].content;
|
|
|
|
}
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
if(data[2] != null) {
|
|
|
|
let relation;
|
|
|
|
let length = data[2].length!=undefined ? data[2].length : 1;
|
|
|
|
|
|
|
|
for(let i=0; i<length; i++) {
|
|
|
|
relation = data[2].length!=undefined ? data[2][i] : data[2];
|
|
|
|
if(relation.hasOwnProperty("to")) {
|
|
|
|
if(relation['to'].class == "isProducedBy") {
|
|
|
|
this.softwareInfo.fundedByProjects = this.parsingFunctions.parseFundingByProjects(this.softwareInfo.fundedByProjects, relation, this.softwareInfo.projectsProvenanceVocabulary);
|
|
|
|
} else if(relation['to'].class == "isRelatedTo") {
|
|
|
|
let provenanceAction: string;
|
|
|
|
if(relation.provenanceaction in this.softwareInfo.researchResultsProvenanceVocabulary) {
|
|
|
|
provenanceAction = this.softwareInfo.researchResultsProvenanceVocabulary[relation.provenanceaction];
|
|
|
|
} else {
|
|
|
|
provenanceAction = "Other"
|
|
|
|
}
|
|
|
|
|
|
|
|
this.softwareInfo.relatedResearchResults = this.parsingFunctions.parseRelatedResearchResults(this.softwareInfo.relatedResearchResults, relation, provenanceAction);
|
|
|
|
|
|
|
|
} else if(relation['to'].class == "hasAmongTopNSimilarDocuments") {
|
|
|
|
this.softwareInfo.similarResearchResults = this.parsingFunctions.parseSimilarResearchResults(this.softwareInfo.similarResearchResults, relation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(data[3] != null) {
|
|
|
|
if(data[3].hasOwnProperty("instance")) {
|
|
|
|
this.softwareInfo.hostedBy_collectedFrom = new Array<{ "downloadName": string, "downloadUrl": string[],
|
|
|
|
"collectedName": string, "collectedId": string,
|
|
|
|
"accessMode": string[], "bestAccessMode": string,
|
|
|
|
"type": string, "year":string}>();
|
|
|
|
|
|
|
|
this.softwareInfo.types = new Array<string>();
|
|
|
|
let types = new Set<string>();
|
|
|
|
|
|
|
|
let counter = 0;
|
|
|
|
let instance;
|
|
|
|
|
|
|
|
let length = data[3]['instance'].length!=undefined ? data[3]['instance'].length : 1;
|
|
|
|
|
|
|
|
for(let i=0; i<length; i++) {
|
|
|
|
instance = data[3]['instance'].length!=undefined ? data[3]['instance'][i] : data[3]['instance'];
|
|
|
|
|
|
|
|
this.parsingFunctions.parseTypes(this.softwareInfo.types, types, instance);
|
|
|
|
|
|
|
|
if(instance.hasOwnProperty("webresource")) {
|
|
|
|
let url;
|
|
|
|
if(instance['webresource'].length == undefined) {
|
|
|
|
url = instance['webresource'].url;
|
|
|
|
} else{
|
|
|
|
url = instance['webresource'][0].url;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(instance.hasOwnProperty("hostedby")) {
|
2018-06-28 16:52:45 +02:00
|
|
|
counter = this.parsingFunctions.parseHostedBy_collectedFrom(this.softwareInfo.hostedBy_collectedFrom, instance, data[0], url, counter/*, this.softwareInfo.title*/, this.softwareInfo.accessMode);
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(data[4] != null) {
|
|
|
|
this.softwareInfo.identifiers = this.parsingFunctions.parseIdentifiers(data[4]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(data[5] != null) {
|
|
|
|
let subjectResults: [string[], Map<string, string[]>, Map<string, string[]>] = this.parsingFunctions.parseAllSubjects(data[5]);
|
|
|
|
this.softwareInfo.subjects = subjectResults[0];
|
|
|
|
this.softwareInfo.otherSubjects = subjectResults[1];
|
|
|
|
this.softwareInfo.classifiedSubjects = subjectResults[2];
|
|
|
|
}
|
|
|
|
|
|
|
|
// null argument is for journal
|
|
|
|
this.softwareInfo.hostedBy_collectedFrom = this.parsingFunctions.addPublisherToHostedBy_collectedFrom(
|
|
|
|
this.softwareInfo.hostedBy_collectedFrom, this.softwareInfo.publisher,
|
2018-06-28 16:52:45 +02:00
|
|
|
null, this.softwareInfo.identifiers/*, this.softwareInfo.title*/);
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
if(data[8] != null) {
|
|
|
|
this.softwareInfo.contexts = this.parsingFunctions.parseContexts(data[8]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// if(data[9] != null && this.softwareInfo.type == undefined) {
|
|
|
|
// if(data[9].hasOwnProperty('classname')) {
|
|
|
|
// this.softwareInfo.type = data[9].classname;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
if(data[9] != null && data[9] == "under curation") {
|
|
|
|
this.softwareInfo.underCurationMessage = true;
|
|
|
|
} else {
|
|
|
|
this.softwareInfo.underCurationMessage = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(data[10] != null) {
|
|
|
|
if(this.softwareInfo.authors == undefined) {
|
|
|
|
this.softwareInfo.authors = new Array<string>();
|
|
|
|
}
|
|
|
|
|
|
|
|
let authors = data[10];
|
|
|
|
let length = Array.isArray(authors) ? authors.length : 1;
|
|
|
|
|
|
|
|
for(let i=0; i<length; i++) {
|
|
|
|
let author = Array.isArray(authors) ? authors[i] : authors;
|
2019-01-24 12:39:24 +01:00
|
|
|
this.softwareInfo.authors[author.rank] = author.content;
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
this.softwareInfo.authors = this.softwareInfo.authors.filter(function (item) {
|
|
|
|
return (item != undefined);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-02-13 15:52:23 +01:00
|
|
|
if(data[11] != null) {
|
|
|
|
this.softwareInfo.languages = this.parsingFunctions.parseLanguages(data[11]);
|
|
|
|
}
|
2018-06-28 16:52:45 +02:00
|
|
|
if(data[12] != null) {
|
|
|
|
this.softwareInfo.countries = this.parsingFunctions.parseCountries(data[12]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(data[13] != null) {
|
|
|
|
this.softwareInfo.programmingLanguages = this.parsingFunctions.parseProgrammingLanguages(data[13]);
|
|
|
|
}
|
2018-02-13 15:52:23 +01:00
|
|
|
|
2018-05-21 14:31:19 +02:00
|
|
|
if(this.softwareInfo.relatedResearchResults) {
|
|
|
|
let self = this;
|
|
|
|
this.softwareInfo.relatedResearchResults.forEach(function (value, key, map) {
|
|
|
|
self.softwareInfo.relatedResearchResults.set(key, self.parsingFunctions.sortByPercentage(value));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
this.softwareInfo.similarResearchResults = this.parsingFunctions.sortByPercentage(this.softwareInfo.similarResearchResults);
|
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
return this.softwareInfo;
|
|
|
|
}
|
|
|
|
}
|