Revision 60221
Added by Konstantina Galouni about 3 years ago
resultLanding.service.ts | ||
---|---|---|
6 | 6 |
import {ParsingFunctions} from '../landing-utils/parsingFunctions.class'; |
7 | 7 |
import {map} from "rxjs/operators"; |
8 | 8 |
import {HostedByCollectedFrom, Organization} from "../../utils/result-preview/result-preview"; |
9 |
import {Dates} from "../../utils/string-utils.class"; |
|
9 |
import {Dates, Identifier} from "../../utils/string-utils.class"; |
|
10 |
import {properties} from "../../../../environments/environment"; |
|
10 | 11 |
|
11 | 12 |
@Injectable() |
12 | 13 |
export class ResultLandingService { |
... | ... | |
18 | 19 |
public parsingFunctions: ParsingFunctions; |
19 | 20 |
resultLandingInfo: ResultLandingInfo; |
20 | 21 |
|
21 |
getResultLandingInfo (id: string, type: string, provenanceActionVocabulary: any, properties: EnvProperties): any { |
|
22 |
let url = properties.searchAPIURLLAst; |
|
23 |
if (type === 'publication') { |
|
24 |
url += 'publications/'; |
|
25 |
} else if (type === 'dataset') { |
|
26 |
url += 'datasets/'; |
|
27 |
} else if (type === 'software') { |
|
28 |
url += 'software/'; |
|
29 |
} else if (type === 'orp') { |
|
30 |
url += 'other/'; |
|
31 |
} else if (type === 'result') { |
|
32 |
url += 'results/'; |
|
22 |
private buildResultLandingInfoUrl(id: string, identifier: Identifier, type: string): string { |
|
23 |
if (id) { |
|
24 |
let url = properties.searchAPIURLLAst; |
|
25 |
if (type === 'publication') { |
|
26 |
url += 'publications/'; |
|
27 |
} else if (type === 'dataset') { |
|
28 |
url += 'datasets/'; |
|
29 |
} else if (type === 'software') { |
|
30 |
url += 'software/'; |
|
31 |
} else if (type === 'orp') { |
|
32 |
url += 'other/'; |
|
33 |
} else if (type === 'result') { |
|
34 |
url += 'results/'; |
|
35 |
} |
|
36 |
url += id + '?format=json'; |
|
37 |
return url; |
|
38 |
} else if (identifier) { |
|
39 |
// pid = "10.3389/fphys.2014.00466"; |
|
40 |
let url = properties.searchAPIURLLAst + "resources2"; |
|
41 |
url += "?pid="+identifier.id + "&pidtype=" + identifier.class + "&type="; |
|
42 |
if (type === 'publication') { |
|
43 |
url += 'publications'; |
|
44 |
} else if (type === 'dataset') { |
|
45 |
url += 'datasets'; |
|
46 |
} else if (type === 'software') { |
|
47 |
url += 'software'; |
|
48 |
} else if (type === 'orp') { |
|
49 |
url += 'other'; |
|
50 |
} else if (type === 'result') { |
|
51 |
url += 'results'; |
|
52 |
} |
|
53 |
url += "&format=json"; |
|
54 |
return url; |
|
33 | 55 |
} |
34 |
url += id + '?format=json';
|
|
56 |
}
|
|
35 | 57 |
|
36 |
return this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url) |
|
58 |
getResultLandingInfo (id: string, identifier: Identifier, type: string, provenanceActionVocabulary: any, properties: EnvProperties): any { |
|
59 |
let url: string = this.buildResultLandingInfoUrl(id, identifier, type); |
|
60 |
|
|
61 |
let finalUrl: string = (properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url; |
|
62 |
return this.http.get(finalUrl) |
|
63 |
.pipe(map(res => { |
|
64 |
if(!id && identifier) { |
|
65 |
if(!res['results'] || res['results'].length == 0) { |
|
66 |
throw new HttpErrorResponse({ |
|
67 |
status: 404, |
|
68 |
statusText: "Not found", |
|
69 |
url: finalUrl, |
|
70 |
error: "Http failure response for "+finalUrl+": 404 Not Found" |
|
71 |
}); |
|
72 |
} |
|
73 |
return res['results'][0]; |
|
74 |
} else { |
|
75 |
return res; |
|
76 |
} |
|
77 |
})) |
|
37 | 78 |
.pipe(map(res => [res['result']['header']['dri:status'], res['result']['metadata']['oaf:entity'], res])) |
38 | 79 |
.pipe(map(res => [ |
39 | 80 |
res[1]['oaf:result'], // 0 |
... | ... | |
238 | 279 |
// res['result']['metadata']['oaf:entity']['oaf:result']['language'] |
239 | 280 |
if(data[6] != null) { |
240 | 281 |
this.resultLandingInfo.languages = this.parsingFunctions.parseLanguages(data[6]); |
282 |
// let languagesAndCodes: string[][] = this.parsingFunctions.parseLanguages(data[6]); |
|
283 |
// this.resultLandingInfo.languages = languagesAndCodes[0]; |
|
284 |
// this.resultLandingInfo.languageCodes = languagesAndCodes[1]; |
|
241 | 285 |
} |
242 | 286 |
|
243 | 287 |
// res['result']['metadata']['oaf:entity']['oaf:result']['country'] |
Also available in: Unified diff
[Trunk | Library]:
1. string-utils.class: Create method 'getIdentifierFromString()' to return a single Identifier.
2. resultLanding.component:
a. Add 'pid' as possible parameter in page url for persistent identifiers.
b. In method 'getResultLandingInfo()' add Identifier parameter to build the appropriate query.
c. Do not re-build url (location.go) if url parameter was "pid".
d. [For orcid - coming soon] Join all identifiers of result into a string: pidsArrayString.
3. resultLanding.service:
a. In method 'getResultLandingInfo()' add Identifier parameter to build tthe appropriate query.
b. Add method 'buildResultLandingInfoUrl()' called by 'getResultLandingInfo()'.
c. Im method 'getResultLandingInfo()', if given identifier and not id parameter, the response is search-like with array of results:
if there are no results, throw HttpErrorResponse with status 404 (like landing response, which returns 404 when no results), otherwise return first result (results['result'][0]).