Project

General

Profile

1
import {Injectable} from '@angular/core';
2
import {Http, Response} from '@angular/http';
3
import {Observable}     from 'rxjs/Observable';
4
import {DatasetInfo} from '../../utils/entities/datasetInfo';
5
import {OpenaireProperties} from '../../utils/properties/openaireProperties';
6
import 'rxjs/add/observable/of';
7
import 'rxjs/add/operator/do';
8
import 'rxjs/add/operator/share';
9
import { CacheService  } from '../../shared/cache.service';
10

    
11
@Injectable()
12
export class DatasetService {
13

    
14
    constructor(private http: Http, public _cache: CacheService) {}
15

    
16
    datasetInfo: DatasetInfo;
17

    
18
    getDatasetInfo (id: string):any {
19
        console.info("getDatasetInfo in service");
20

    
21
        let url = OpenaireProperties. getSearchAPIURLLast()+'datasets/'+id+"?format=json";
22
        let key = url;
23
        if (this._cache.has(key)) {
24
          return Observable.of(this._cache.get(key)).map(res => this.parseDatasetInfo(res));
25
        }
26

    
27
        return this.http.get(url)
28
                    .map(res => <any> res.json())
29
                    .do(res => console.info(res['result']['metadata']['oaf:entity']))
30
                    .map(res => res['result']['metadata']['oaf:entity']['oaf:result'])
31
                    .map(res => [res,
32
                                 res['title'],
33
                                 res['rels']['rel'],
34
                                 res['children'],
35
                                 res['pid'],
36
                                 res['subject'],
37
                                 res['bestlicense'],
38
                                 res['collectedfrom'],
39
                                 res['context'],
40
                                 res['resulttype']
41
                    ]).do(res => {
42
                      this._cache.set(key, res);
43
                    })
44
                    .map(res => this.parseDatasetInfo(res));
45
    }
46

    
47
    private handleError (error: Response) {
48
    // in a real world app, we may send the error to some remote logging infrastructure
49
    // instead of just logging it to the console
50
        console.log(error);
51
        return Observable.throw(error  || 'Server error');
52
    }
53

    
54
    parseDatasetInfo (data: any):any {
55
        this.datasetInfo = new DatasetInfo();
56

    
57
        if(data[0] != null) {
58
            this.datasetInfo.date = data[0].dateofacceptance.substring(0,4);
59
            this.datasetInfo.dateofacceptance = data[0].dateofacceptance;
60
            this.datasetInfo.publisher = data[0].publisher;
61
            if(!Array.isArray(data[0].description)) {
62
                this.datasetInfo.description = data[0].description;
63
            } else {
64
                this.datasetInfo.description = data[0].description[0];
65
            }
66
            this.datasetInfo.embargoEndDate = data[0].embargoenddate;
67
        }
68
        this.datasetInfo.title = {"name": "", "url": "", "accessMode": ""};
69
        if(data[0]['bestlicense'].hasOwnProperty("classid")) {
70
            this.datasetInfo.title.accessMode = data[0]['bestlicense'].classid;
71
        }
72
        if(data[1] != null) {
73
            if(Array.isArray(data[1])) {
74
                this.datasetInfo.title['name'] = data[1][0].content;
75
            } else {
76
                this.datasetInfo.title['name'] = data[1].content;
77
            }
78
        }
79

    
80
        if(data[2] != null) {
81
            let mydata;
82
            let counter = 0;
83
            let length = data[2].length!=undefined ? data[2].length : 1;
84

    
85
            for(let i=0; i<length; i++) {
86
                mydata = data[2].length!=undefined ? data[2][i] : data[2];
87
                if(mydata.hasOwnProperty("to")) {
88
                    if(mydata['to'].class == "hasAuthor") {
89
                        if(this.datasetInfo.authors == undefined) {
90
                            this.datasetInfo.authors = new Array<{"name": string, "id": string}>();
91
                        }
92

    
93
                        this.datasetInfo.authors[mydata.ranking-1] = {"name": "", "id": ""};
94
                        this.datasetInfo.authors[mydata.ranking-1]['name'] = mydata.fullname;
95
                        this.datasetInfo.authors[mydata.ranking-1]['id'] = /*OpenaireProperties.getsearchLinkToPerson()+*/mydata['to'].content;
96
                    } else if(mydata['to'].class == "isProducedBy") {
97
                        if(this.datasetInfo.fundedByProjects == undefined) {
98
                            this.datasetInfo.fundedByProjects = new Array<
99
                                { "id": string, "acronym": string, "title": string,
100
                                  "funderShortname": string, "funderName": string,
101
                                  "funding": string, "inline": boolean
102
                                }>();
103
                        }
104

    
105
                        counter = this.datasetInfo.fundedByProjects.length;
106

    
107
                        this.datasetInfo.fundedByProjects[counter] = {
108
                            "id": "", "acronym": "", "title": "",
109
                            "funderShortname": "", "funderName": "",
110
                            "funding": "", "inline": false
111
                        }
112

    
113
                        this.datasetInfo.fundedByProjects[counter]['id'] =
114
                            /*OpenaireProperties.getsearchLinkToProject()+*/mydata['to'].content;
115
                        this.datasetInfo.fundedByProjects[counter]['acronym'] = mydata.acronym;
116
                        this.datasetInfo.fundedByProjects[counter]['title'] = mydata.title;
117

    
118
                        if(mydata.hasOwnProperty("funding")) {
119
                            let length1 = Array.isArray(mydata['funding']) ? mydata['funding'].length : 1;
120

    
121
                            for(let j=0; j<length1; j++) {
122
                                let funding;
123
                                let mydata1 = Array.isArray(mydata['funding']) ? mydata['funding'][j] : mydata['funding'];
124

    
125
                                if(mydata1.hasOwnProperty("funder")) {
126
                                    this.datasetInfo.fundedByProjects[counter]['funderShortname'] = mydata1['funder'].shortname;
127
                                    this.datasetInfo.fundedByProjects[counter]['funderName'] = mydata1['funder'].name;
128
                                }
129

    
130
                                if(mydata1.hasOwnProperty("funding_level_2")) {
131
                                    funding = mydata1['funding_level_2'].content;
132
                                } else if(mydata1.hasOwnProperty("funding_level_1")) {
133
                                    funding = mydata1['funding_level_1'].content;
134
                                } else if(mydata1.hasOwnProperty("funding_level_0")) {
135
                                    funding = mydata1['funding_level_0'].content;
136
                                }
137

    
138
                                if(funding != undefined) {
139
                                    funding = funding.split("::");
140

    
141
                                    if(this.datasetInfo.fundedByProjects[counter]['funding'] != "") {
142
                                        this.datasetInfo.fundedByProjects[counter]['funding'] += ", "+funding[1];
143
                                    } else {
144
                                        this.datasetInfo.fundedByProjects[counter]['funding'] = funding[1];
145
                                    }
146
                                    for(let i=2; i<funding.length; i++) {
147
                                        this.datasetInfo.fundedByProjects[counter]['funding'] += " | " + funding[i];
148
                                    }
149
                                }
150
                            }
151
                        }
152
                    } else if(mydata['to'].class == "isRelatedTo") {
153
                        let provenanceAction: string;
154
                        if(mydata.provenanceaction in this.datasetInfo.provenanceVocabulary) {
155
                            provenanceAction = this.datasetInfo.provenanceVocabulary[mydata.provenanceaction];
156
                        } else {
157
                            provenanceAction = "Other"
158
                        }
159
                        /*
160
                        if(this.datasetInfo.relatedResearchResults == undefined) {
161
                            this.datasetInfo.relatedResearchResults = new Array<{
162
                                "name": string, "id": string, "date": string,
163
                                "trust": string, "class": string}>();
164
                        }
165
                        */
166
                        if(this.datasetInfo.relatedResearchResults == undefined) {
167
                            this.datasetInfo.relatedResearchResults =
168
                                new Map<string, { "name": string, "id": string, "date": string,
169
                                                  "trust": string, "class": string}[]>();
170
                        }
171

    
172
                        if(!this.datasetInfo.relatedResearchResults.has(provenanceAction)) {
173
                            this.datasetInfo.relatedResearchResults.set(provenanceAction,
174
                                new Array<{ "name": string, "id": string, "date": string,
175
                                            "trust": string, "class": string}>());
176
                        }
177

    
178
                        counter = this.datasetInfo.relatedResearchResults.get(provenanceAction).length;
179
                        this.datasetInfo.relatedResearchResults.get(provenanceAction)[counter] = {"name": "", "id": "", "date": "", "trust": "", "class": ""}
180

    
181
                        //let url;
182
                        if(mydata['resulttype'].classname == "publication") {
183
                            //url = OpenaireProperties.getsearchLinkToPublication()+mydata['to'].content;
184
                            this.datasetInfo.relatedResearchResults.get(provenanceAction)[counter]['class'] = "publication";
185
                        } else {
186
                            //url = OpenaireProperties.getsearchLinkToDataset()+mydata['to'].content;
187
                            this.datasetInfo.relatedResearchResults.get(provenanceAction)[counter]['class'] = "dataset";
188
                        }
189

    
190
                        this.datasetInfo.relatedResearchResults.get(provenanceAction)[counter]['id'] = mydata['to'].content;
191
                        //this.datasetInfo.relatedResearchResults[counter]['url'] = url;
192
                        let titleName = Array.isArray(mydata['title']) ? mydata['title'][0].content : mydata['title'].content;
193
                        this.datasetInfo.relatedResearchResults.get(provenanceAction)[counter]['name'] = titleName;
194
                        this.datasetInfo.relatedResearchResults.get(provenanceAction)[counter]['date'] = mydata.dateofacceptance.substring(0,4);;
195
                        this.datasetInfo.relatedResearchResults.get(provenanceAction)[counter]['trust'] = Math.round(mydata.trust*100)+"%";
196

    
197
                    } else if(mydata['to'].class == "hasAmongTopNSimilarDocuments") {
198
                        if(this.datasetInfo.similarResearchResults == undefined) {
199
                            this.datasetInfo.similarResearchResults = new Array<{
200
                                "name": string, "id": string, "date": string,
201
                                "trust": string, "class": string}>();
202
                        }
203

    
204
                        counter = this.datasetInfo.similarResearchResults.length;
205
                        this.datasetInfo.similarResearchResults[counter] = {"name": "", "id": "", "date": "", "trust": "", "class": ""}
206

    
207
                        //let url;
208
                        if(mydata['resulttype'].classname == "publication") {
209
                            //url = OpenaireProperties.getsearchLinkToPublication()+mydata['to'].content;
210
                            this.datasetInfo.similarResearchResults[counter]['class'] = "publication";
211
                        } else {
212
                            //url = OpenaireProperties.getsearchLinkToDataset()+mydata['to'].content;
213
                            this.datasetInfo.similarResearchResults[counter]['class'] = "dataset";
214
                        }
215

    
216
                        this.datasetInfo.similarResearchResults[counter]['id'] = mydata['to'].content;
217
                        //this.datasetInfo.similarResearchResults[counter]['url'] = url;
218
                        let titleName = Array.isArray(mydata['title']) ? mydata['title'][0].content : mydata['title'].content;
219
                        this.datasetInfo.similarResearchResults[counter]['name'] = titleName;
220
                        this.datasetInfo.similarResearchResults[counter]['date'] = mydata.dateofacceptance.substring(0,4);;
221
                        this.datasetInfo.similarResearchResults[counter]['trust'] = Math.round(mydata.trust*100)+"%";
222

    
223

    
224
                    }
225
                }
226
            }
227

    
228
            if(this.datasetInfo.authors != undefined) {
229
                this.datasetInfo.authors = this.datasetInfo.authors.filter(function (item) {
230
                    return (item != undefined);
231
                });
232
            }
233
        }
234

    
235
        if(data[3] != null) {
236
            if(data[3].hasOwnProperty("instance")) {
237
                this.datasetInfo.downloadFrom = new Map<string, {"url": string[], "accessMode": string[], "bestAccessMode": string}>();
238
                this.datasetInfo.publishedIn = new Map<string, {"url": string[], "accessMode": string[], "bestAccessMode": string}>()
239

    
240
                let length = data[3]['instance'].length!=undefined ? data[3]['instance'].length : 1;
241

    
242
                let counter = 0;
243
                let counter1 = 0;
244
                let counter2 = 0;
245
                let mydata;
246
                for(let i=0; i<length; i++) {
247
                    mydata = data[3]['instance'].length!=undefined ? data[3]['instance'][i] : data[3]['instance'];
248

    
249
                    if(this.datasetInfo.type == undefined) {
250
                        if(mydata.hasOwnProperty("instancetype")) {
251
                            if(mydata['instancetype'].classname != null
252
                                && mydata['instancetype'].classname != ""
253
                                && mydata['instancetype'].classname != "Unknown"){
254
                                this.datasetInfo.type = mydata['instancetype'].classname;
255
                            }
256
                        }
257
                    }
258

    
259
                    if(mydata.hasOwnProperty("webresource")) {
260
                        let url;
261
                        if(mydata['webresource'].length == undefined) {
262
                            url = mydata['webresource'].url;
263
                        } else{
264
                            url = mydata['webresource'][0].url;
265
                        }
266

    
267
                        if(!this.datasetInfo.downloadFrom.has(url) && mydata.hasOwnProperty("hostedby")) {
268
                            if(mydata['hostedby'].name != "other resources" && mydata['hostedby'].name != "Unknown Repository") {
269
                                let key: string = mydata['hostedby'].name;
270

    
271
                                if(!this.datasetInfo.downloadFrom.has(key)) {
272
                                    this.datasetInfo.downloadFrom.set(key, {"url": null, "accessMode": null, "bestAccessMode": null});
273
                                }
274

    
275
                                if(this.datasetInfo.downloadFrom.get(key)['url'] == null) {
276
                                    this.datasetInfo.downloadFrom.get(key)['url'] = new Array<string>();
277
                                }
278

    
279
                                counter2 = this.datasetInfo.downloadFrom.get(key)['url'].length;
280
                                this.datasetInfo.downloadFrom.get(key)['url'][counter2] = url;
281

    
282
                                if(this.datasetInfo.downloadFrom.get(key)['accessMode'] == null) {
283
                                    this.datasetInfo.downloadFrom.get(key)['accessMode'] = new Array<string>();
284
                                }
285

    
286
                                if(mydata.hasOwnProperty("licence")) {
287
                                    this.datasetInfo.downloadFrom.get(key)['accessMode'].push(mydata['licence'].classid);
288
                                    //this.datasetInfo.downloadFrom.get(mydata['hostedby'].name)['accessMode'][counter2] = mydata['licence'].classid;
289

    
290
                                    switch (this.datasetInfo.downloadFrom.get(key)['bestAccessMode']) {
291
                                        case null:
292
                                            this.datasetInfo.downloadFrom.get(key)['bestAccessMode'] = mydata['licence'].classid;
293
                                            break;
294
                                        case "CLOSED":
295
                                            if(mydata['licence'].classid == "OPEN" ||
296
                                                mydata['licence'].classid == "EMBARGO" ||
297
                                                mydata['licence'].classid == "RESTRICTED") {
298
                                                    this.datasetInfo.downloadFrom.get(key)['bestAccessMode'] = mydata['licence'].classid;
299
                                            }
300
                                            break;
301
                                        case "RESTRICTED":
302
                                            if(mydata['licence'].classid == "OPEN" ||
303
                                                mydata['licence'].classid == "EMBARGO") {
304
                                                    this.datasetInfo.downloadFrom.get(key)['bestAccessMode'] = mydata['licence'].classid;
305
                                            }
306
                                            break;
307
                                        case "EMBARGO":
308
                                            if(mydata['licence'].classid == "OPEN") {
309
                                                    this.datasetInfo.downloadFrom.get(key)['bestAccessMode'] = mydata['licence'].classid;
310
                                            }
311
                                            break;
312
                                    }
313
                                } else {
314
                                    //this.datasetInfo.downloadFrom.get(mydata['hostedby'].name)['accessMode'][counter2] = "";
315
                                    this.datasetInfo.downloadFrom.get(key)['accessMode'].push("");
316
                                }
317
                            } else {
318
                                if(data[0] != null && data[0].hasOwnProperty("source")) {
319
                                    let key: string;
320
                                    if(Array.isArray(data[0].source)) {
321
                                        if(!this.datasetInfo.publishedIn.has(data[0]['source'][counter1])) {
322
                                            key = data[0]['source'][counter1];
323
                                        }
324
                                    } else {
325
                                        if(!this.datasetInfo.publishedIn.has(data[0]['source'])) {
326
                                            key = data[0]['source'];
327
                                        }
328
                                    }
329

    
330
                                    this.datasetInfo.publishedIn.set(key, {"url": null, "accessMode": null, "bestAccessMode": null});
331

    
332
                                    if(this.datasetInfo.publishedIn.get(key)['url'] == null) {
333
                                        this.datasetInfo.publishedIn.get(key)['url'] = new Array<string>();
334
                                    }
335

    
336
                                    counter2 = this.datasetInfo.publishedIn.get(key)['url'].length;
337
                                    this.datasetInfo.publishedIn.get(key)['url'][counter2] = url;
338

    
339
                                    if(this.datasetInfo.publishedIn.get(key)['accessMode'] == null) {
340
                                        this.datasetInfo.publishedIn.get(key)['accessMode'] = new Array<string>();
341
                                    }
342

    
343
                                    if(mydata.hasOwnProperty("licence")) {
344
                                        //this.datasetInfo.publishedIn.get(key)['accessMode'][counter2] = mydata['licence'].classid;
345
                                        this.datasetInfo.publishedIn.get(key)['accessMode'].push(mydata['licence'].classid);
346
                                        switch (this.datasetInfo.publishedIn.get(key)['bestAccessMode']) {
347
                                            case null:
348
                                                this.datasetInfo.publishedIn.get(key)['bestAccessMode'] = mydata['licence'].classid;
349
                                                break;
350
                                            case "CLOSED":
351
                                                if(mydata['licence'].classid == "OPEN" ||
352
                                                    mydata['licence'].classid == "EMBARGO" ||
353
                                                    mydata['licence'].classid == "RESTRICTED") {
354
                                                        this.datasetInfo.publishedIn.get(key)['bestAccessMode'] = mydata['licence'].classid;
355
                                                }
356
                                                break;
357
                                            case "RESTRICTED":
358
                                                if(mydata['licence'].classid == "OPEN" ||
359
                                                    mydata['licence'].classid == "EMBARGO") {
360
                                                        this.datasetInfo.publishedIn.get(key)['bestAccessMode'] = mydata['licence'].classid;
361
                                                }
362
                                                break;
363
                                            case "EMBARGO":
364
                                                if(mydata['licence'].classid == "OPEN") {
365
                                                        this.datasetInfo.publishedIn.get(key)['bestAccessMode'] = mydata['licence'].classid;
366
                                                }
367
                                                break;
368
                                        }
369
                                    } else {
370
                                        //this.datasetInfo.publishedIn.get(key)['accessMode'][counter2] = "";
371
                                        this.datasetInfo.publishedIn.get(key)['accessMode'].push("");
372
                                    }
373
                                    counter1++;
374
                                }
375
                            }
376
                            if(this.datasetInfo.title != undefined) {
377
                                if(this.datasetInfo.title['url'] == undefined) {
378
                                    this.datasetInfo.title['url'] = url;
379
                                }
380

    
381
                                switch (this.datasetInfo.title['licence']) {
382
                                    case undefined:
383
                                        this.datasetInfo.title['licence'] = mydata['licence'].classid;
384
                                        this.datasetInfo.title['url'] = url;
385
                                        break;
386
                                    case "CLOSED":
387
                                        if(mydata['licence'].classid == "OPEN" ||
388
                                            mydata['licence'].classid == "EMBARGO" ||
389
                                            mydata['licence'].classid == "RESTRICTED") {
390
                                                this.datasetInfo.title['licence'] = mydata['licence'].classid;
391
                                                this.datasetInfo.title['url'] = url;
392
                                        }
393
                                        break;
394
                                    case "RESTRICTED":
395
                                        if(mydata['licence'].classid == "OPEN" ||
396
                                            mydata['licence'].classid == "EMBARGO") {
397
                                                this.datasetInfo.title['licence'] = mydata['licence'].classid;
398
                                                this.datasetInfo.title['url'] = url;
399
                                        }
400
                                        break;
401
                                    case "EMBARGO":
402
                                        if(mydata['licence'].classid == "OPEN") {
403
                                                this.datasetInfo.title['licence'] = mydata['licence'].classid;
404
                                                this.datasetInfo.title['url'] = url;
405
                                        }
406
                                        break;
407
                                }
408
                            }
409
                        }
410
                    }
411
                }
412
            }
413
        }
414

    
415
        if(data[4] != null) {
416
            let counter = 0;
417
            this.datasetInfo.identifiers = new Map<string, string[]>();
418

    
419
            if(data[4].hasOwnProperty("classname") && data[4]['classname'] != "") {
420
                if(data[4].classname == "doi" || data[4].classname == "pmc") {
421
                    if(!this.datasetInfo.identifiers.has(data[4].classname)) {
422
                        this.datasetInfo.identifiers.set(data[4].classname, new Array<string>());
423
                    }
424
                    counter = this.datasetInfo.identifiers.get(data[4].classname).length;
425
                    this.datasetInfo.identifiers.get(data[4].classname)[counter] = data[4].content;
426
                }
427
            } else {
428
                for(let i=0; i<data[4].length; i++) {
429
                    if(data[4][i].classname == "doi" || data[4][i].classname == "pmc") {
430
                        if(!this.datasetInfo.identifiers.has(data[4][i].classname)) {
431
                            this.datasetInfo.identifiers.set(data[4][i].classname, new Array<string>());
432
                        }
433
                        counter = this.datasetInfo.identifiers.get(data[4][i].classname).length;
434
                        this.datasetInfo.identifiers.get(data[4][i].classname)[counter] = data[4][i].content;
435
                    }
436
                }
437
            }
438
        }
439

    
440
        if(data[5] != null) {
441
            let mydata;
442
            let length = data[7].length!=undefined ? data[5].length : 1;
443

    
444
            for(let i=0; i<length; i++) {
445
                mydata = data[7].length!=undefined ? data[5][i] : data[5];
446

    
447
                if(mydata.classid != "") {
448
                    if(mydata.inferred == true) {
449
                        if(this.datasetInfo.classifiedSubjects == undefined) {
450
                            this.datasetInfo.classifiedSubjects = new Map<string, string[]>();
451
                        }
452

    
453
                        if(!this.datasetInfo.classifiedSubjects.has(mydata.classname)) {
454
                            this.datasetInfo.classifiedSubjects.set(mydata.classname, new Array<string>());
455
                        }
456

    
457
                        this.datasetInfo.classifiedSubjects.get(mydata.classname).push(mydata.content);
458
                    } else {
459
                        if(mydata.classid == "keyword") {
460
                            if(this.datasetInfo.subjects == undefined) {
461
                                this.datasetInfo.subjects = new Array<string>();
462
                            }
463

    
464
                            this.datasetInfo.subjects.push(mydata.content);
465
                        } else {
466
                            if(this.datasetInfo.otherSubjects == undefined) {
467
                                this.datasetInfo.otherSubjects = new Map<string, string[]>();
468
                            }
469

    
470
                            if(!this.datasetInfo.otherSubjects.has(mydata.classname)) {
471
                                this.datasetInfo.otherSubjects.set(mydata.classname, new Array<string>());
472
                            }
473
                            this.datasetInfo.otherSubjects.get(mydata.classname).push(mydata.content);
474
                        }
475
                    }
476
                }
477
            }
478
        }
479

    
480
        if(data[6] != null) {
481
            this.datasetInfo.bestlicense = data[6].classid;
482
        }
483

    
484
        if(data[7] != null) {
485
            this.datasetInfo.collectedFrom = new Array<{"name": string, "id": string}>();
486

    
487
            let mydata;
488
            let length = data[7].length!=undefined ? data[7].length : 1;
489
            for(let i=0; i<length; i++) {
490
                mydata = data[7].length!=undefined ? data[7][i] : data[7];
491
                //let link = OpenaireProperties.getsearchLinkToDataProvider();
492
                this.datasetInfo.collectedFrom[i] = {"name": "", "id": ""};
493
                this.datasetInfo.collectedFrom[i]['name'] = mydata.name;
494
                this.datasetInfo.collectedFrom[i]['id'] = /*link+*/mydata.id;
495
            }
496
        }
497

    
498
        if(this.datasetInfo.publisher != null
499
            && this.datasetInfo.identifiers != null
500
            && this.datasetInfo.identifiers.has("doi")) {
501

    
502
            if( this.datasetInfo.downloadFrom == null) {
503
                this.datasetInfo.downloadFrom = new Map<string,{"url": string[], "accessMode": string[], "bestAccessMode": string}>();
504
            }
505

    
506
            this.datasetInfo.downloadFrom.set(this.datasetInfo.publisher, {"url": null, "accessMode": null, "bestAccessMode": null});
507

    
508
            let url = OpenaireProperties.getDoiURL()+this.datasetInfo.identifiers.get("doi");
509
            this.datasetInfo.downloadFrom.get(this.datasetInfo.publisher)['url'] = new Array<string>();
510
            this.datasetInfo.downloadFrom.get(this.datasetInfo.publisher)['accessMode'] = new Array<string>();
511

    
512
            this.datasetInfo.downloadFrom.get(this.datasetInfo.publisher)['url'][0] = url;
513
            this.datasetInfo.downloadFrom.get(this.datasetInfo.publisher)['accessMode'][0] = "";
514

    
515
            if(this.datasetInfo.title != undefined && this.datasetInfo.title['url'] == "") {
516
                this.datasetInfo.title['url'] = url;
517
            }
518
        }
519

    
520
        if(data[8] != null) {
521
            this.datasetInfo.contexts = new Array<
522
                { "labelContext": string, "labelCategory": string, "labelConcept": string, "inline": boolean}>();
523

    
524
            let position = 0;
525
            let labels = "";
526
            let mydata;
527
            let length = data[8].length!=undefined ? data[8].length : 1;
528
            for(let i=0; i<length; i++) {
529
                mydata = data[8].length!=undefined ? data[8][i] : data[8];
530

    
531
                if(mydata.hasOwnProperty("type") && mydata['type'] == "community") {
532
                    if(mydata.hasOwnProperty("category")) {
533
                        if(mydata['category'].hasOwnProperty("concept")) {
534
                            let mydata1;
535
                            let length1 = mydata['category']['concept'].length!=undefined ? mydata['category']['concept'].length : 1;
536
                            for(let j=0; j<length1; j++) {
537
                                mydata1 = length1 > 1 ? mydata['category']['concept'][j] : mydata['category']['concept'];
538

    
539
                                this.datasetInfo.contexts[position] = {"labelContext": "", "labelCategory": "", "labelConcept": "", inline: false};
540
                                this.datasetInfo.contexts[position]['labelContext'] = mydata.label;
541
                                this.datasetInfo.contexts[position]['labelCategory'] = mydata['category'].label;;
542
                                this.datasetInfo.contexts[position]['labelConcept'] = mydata1.label;
543

    
544
                                position++;
545
                            }
546
                        } else {
547
                            this.datasetInfo.contexts[position] = {"labelContext": "", "labelCategory": "", "labelConcept": "", inline: false};
548
                            this.datasetInfo.contexts[position]['labelContext'] = mydata.label;
549
                            this.datasetInfo.contexts[position]['labelCategory'] = mydata['category'].label;;
550
                            this.datasetInfo.contexts[position]['labelConcept'] = null;
551
                        }
552
                    } else {
553
                        this.datasetInfo.contexts[position] = {"labelContext": "", "labelCategory": "", "labelConcept": "", inline: false};
554
                        this.datasetInfo.contexts[position]['labelContext'] = mydata.label;
555
                        this.datasetInfo.contexts[position]['labelCategory'] = null;
556
                        this.datasetInfo.contexts[position]['labelConcept'] = null;
557
                    }
558
                }
559
            }
560
        }
561

    
562
        if(data[9] != null && this.datasetInfo.type == undefined) {
563
            if(data[9].hasOwnProperty('classname')) {
564
                this.datasetInfo.type = data[9].classname;
565
            }
566
        }
567

    
568

    
569
        //this.printdatasetInfo();
570
        return this.datasetInfo;
571

    
572
    }
573

    
574
    printDatasetInfo() {
575
        console.info("DATE: "+this.datasetInfo.date);
576
        console.info("PUBLISHER: "+this.datasetInfo.publisher);
577
        console.info("DESCRIPTION: "+this.datasetInfo.description);
578

    
579
        console.info("TITLE: "+this.datasetInfo.title);
580

    
581
        console.info("AUTHORS: "+this.datasetInfo.authors);
582
        console.info("\nFUNDED BY PROJECTS:");
583
        if(this.datasetInfo.fundedByProjects != undefined) {
584
            this.datasetInfo.fundedByProjects.forEach(function (value, key, map) {
585
                console.info(key + " = " + value);
586
            });
587
        } else {
588
            console.info("undefined");
589
        }
590
        console.info("\n");
591
/*
592
        console.info("\nRELATED RESEARCH DATA:");
593
        if(this.datasetInfo.relatedResearchData != undefined) {
594
            this.datasetInfo.relatedResearchData.forEach(function (value, key, map) {
595
                console.info(key + " = " + value);
596
            });
597
        } else {
598
            console.info("undefined");
599
        }
600
        console.info("\n");
601

    
602
        console.info("\nSIMILAR datasetS:");
603
        if(this.datasetInfo.similarPublications != undefined) {
604
            this.datasetInfo.similarPublications.forEach(function (value, key, map) {
605
                console.info(key + " = " + value);
606
            });
607
        } else {
608
            console.info("undefined");
609
        }
610
        console.info("\n");
611
*/
612
        console.info("TYPE: "+this.datasetInfo.type);
613
        console.info("\nDOWNLOAD FROM:");
614
        if(this.datasetInfo.downloadFrom != undefined) {
615
            this.datasetInfo.downloadFrom.forEach(function (value, key, map) {
616
                console.info(key + " = " + value);
617
            });
618
        } else {
619
            console.info("undefined");
620
        }
621
        console.info("\n");
622

    
623
        console.info("\nIDENTIFIERS:");
624
        if(this.datasetInfo.identifiers != undefined) {
625
            this.datasetInfo.identifiers.forEach(function (value, key, map) {
626
                console.info(key + " = " + value);
627
            });
628
        } else {
629
            console.info("undefined");
630
        }
631
        console.info("\n");
632

    
633
        console.info("SUBJECTS: "+this.datasetInfo.subjects);
634
        console.info("\nCLASSIFIED OBJECTS:");
635
        if(this.datasetInfo.classifiedSubjects != undefined) {
636
            this.datasetInfo.classifiedSubjects.forEach(function (value, key, map) {
637
                console.info(key + " = " + value);
638
            });
639
        } else {
640
            console.info("undefined");
641
        }
642
        console.info("\n");
643

    
644
        console.info("BEST LICENSE: "+this.datasetInfo.bestlicense);
645

    
646
        console.info("\nCOLLECTED FROM:");
647
        if(this.datasetInfo.collectedFrom != undefined) {
648
            this.datasetInfo.collectedFrom.forEach(function (value, key, map) {
649
                console.info(key + " = " + value);
650
            });
651
        } else {
652
            console.info("undefined");
653
        }
654
        console.info("\n");
655

    
656
        console.info("\nDOWNLOAD FROM:");
657
        if(this.datasetInfo.downloadFrom != undefined) {
658
            this.datasetInfo.downloadFrom.forEach(function (value, key, map) {
659
                console.info(key + " = " + value);
660
            });
661
        } else {
662
            console.info("undefined");
663
        }
664
        console.info("\n");
665
    }
666
}
(5-5/5)