Project

General

Profile

1
import {Injectable} from '@angular/core';
2
import {HttpClient} from "@angular/common/http";
3
import {OrganizationInfo} from '../../../utils/entities/organizationInfo';
4
import {EnvProperties} from '../../../utils/properties/env-properties';
5
import {ParsingFunctions} from '../../landing-utils/parsingFunctions.class';
6
import {map} from "rxjs/operators";
7

    
8
@Injectable()
9
export class OrganizationsDeletedByInferenceService {
10
  constructor(private http: HttpClient) {
11
    this.parsingFunctions = new ParsingFunctions();
12
  }
13

    
14
  public parsingFunctions: ParsingFunctions;
15

    
16
  getDeletedByInferenceResults(id: string, size: string, properties: EnvProperties): any {
17
    let url = properties.searchAPIURLLAst + 'deletedByInferenceOrganizations/' + id + "?format=json&size=" + size;
18

    
19
    return this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url)
20
      .pipe(map(res => res['results']))
21
      .pipe(map(res => this.parseDeletedByInferenceResults(res, properties)));
22
  }
23

    
24
  parseDeletedByInferenceResults(_results: any, properties: EnvProperties): OrganizationInfo[] {
25
    let results: OrganizationInfo[] = [];
26
    if (_results) {
27
      let organization: OrganizationInfo;
28

    
29
      let length = Array.isArray(_results) ? _results.length : 1;
30
      for (let i = 0; i < length; i++) {
31
        organization = new OrganizationInfo();
32

    
33
        var _result = Array.isArray(_results) ? _results[i]['result']['metadata']['oaf:entity'] : _results['result']['metadata']['oaf:entity'];
34
        organization.objIdentifier = Array.isArray(_results) ? _results[i]['result']["header"]["dri:objIdentifier"] :  _results['result']["header"]["dri:objIdentifier"];
35

    
36
        if (_result) {
37
          if (_result['oaf:organization']) {
38
            let data = _result['oaf:organization'];
39

    
40
            if(data.hasOwnProperty("websiteurl")) {
41
              organization.title = {"name": data.legalshortname, "url": data.websiteurl};
42
            } else {
43
              organization.title = {"name": data.legalshortname, "url": ''};
44
            }
45

    
46
            organization.name = data.legalname;
47

    
48

    
49
            if(organization.title.name == '') {
50
              organization.title.name = organization.name;
51
            }
52

    
53
            if(data.hasOwnProperty("country")) {
54
              organization.country = data['country'].classname;
55
            }
56

    
57
          }
58
          results.push(organization);
59
        }
60
      }
61

    
62
      return results;
63
    }
64
  }
65
}
(3-3/3)