From a8f4a8f438e1017e755fd005ffd057d318445d70 Mon Sep 17 00:00:00 2001 From: "konstantina.galouni" Date: Wed, 2 Oct 2019 14:15:08 +0000 Subject: [PATCH] [Trunk | Library]: Original versions in Organization Landing Page 1. landingPages/organization/deletedByInference: Create folder and files for organizations deleted by Inference (original versions). 2. organizationInfo.ts: Add string array field 'deletedByInferenceIds'. 3. organization.service.ts: Parse deletedByInferenceIds (children which are organizations). 4. organization.component: Show (only in 'non production' environments) original versions and request them on click. git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@57238 d315682c-612b-4755-9ff5-7f18f6832af3 --- .../deletedByInference.component.ts | 130 ++++++++++++++++++ .../deletedByInference.module.ts | 31 +++++ .../deletedByInference.service.ts | 65 +++++++++ .../organization/organization.component.html | 14 +- .../organization/organization.component.ts | 11 ++ .../organization/organization.module.ts | 5 +- services/organization.service.ts | 13 ++ utils/entities/organizationInfo.ts | 2 + 8 files changed, 268 insertions(+), 3 deletions(-) create mode 100644 landingPages/organization/deletedByInference/deletedByInference.component.ts create mode 100644 landingPages/organization/deletedByInference/deletedByInference.module.ts create mode 100644 landingPages/organization/deletedByInference/deletedByInference.service.ts diff --git a/landingPages/organization/deletedByInference/deletedByInference.component.ts b/landingPages/organization/deletedByInference/deletedByInference.component.ts new file mode 100644 index 00000000..eac73dd3 --- /dev/null +++ b/landingPages/organization/deletedByInference/deletedByInference.component.ts @@ -0,0 +1,130 @@ +import {Component, ViewChild} from '@angular/core'; +import {ElementRef, Input} from '@angular/core'; +import {ActivatedRoute, Router} from '@angular/router'; + +import {EnvProperties} from '../../../utils/properties/env-properties'; +import {OrganizationInfo} from '../../../utils/entities/organizationInfo'; +import {RouterHelper} from '../../../utils/routerHelper.class'; +import {ErrorCodes} from '../../../utils/properties/errorCodes'; + +import {OrganizationsDeletedByInferenceService} from './deletedByInference.service'; + +@Component({ + selector: 'deletedByInference', + template: ` + + +
+
+ {{results.length | number}} {{type}}, page {{page | number}} of {{totalPages(results.length) | number}} + +
+ + +
+ ` +}) + +export class OrganizationsDeletedByInferenceComponent { + public results: OrganizationInfo[] = []; + @Input() id: string; + @Input() ids: string[] = []; + @Input() type: string; + + // Custom tab paging variables + public page: number = 1; + public pageSize: number = 5; + + public status: number; + public routerHelper:RouterHelper = new RouterHelper(); + public errorCodes:ErrorCodes = new ErrorCodes(); + + sub: any; + properties:EnvProperties; + + constructor ( private element: ElementRef, + private _deletedByInferenceService: OrganizationsDeletedByInferenceService, + private route: ActivatedRoute, + private _router: Router) { + } + + ngOnInit() { + this.route.data + .subscribe((data: { envSpecific: EnvProperties }) => { + this.properties = data.envSpecific; + + }); + this.sub = this.route.queryParams.subscribe(data => { + this.errorCodes = new ErrorCodes(); + this.status = this.errorCodes.LOADING; + + this.getDeletedByInference(); + }); + } + + ngOnDestroy() {} + + getDeletedByInference() { + this.results = []; + this.status = this.errorCodes.LOADING; + + this._deletedByInferenceService.getDeletedByInferenceResults(this.id, String(this.ids.length), this.properties).subscribe( + data => { + this.results = data; + this.status = this.errorCodes.DONE; + }, + error => { + if(error.status == '404') { + this.status = this.errorCodes.NOT_FOUND; + } else if(error.status == '500') { + this.status = this.errorCodes.ERROR; + } else { + this.status = this.errorCodes.NOT_AVAILABLE; + } + } + ); + } + + public totalPages(totalResults: number): number { + let totalPages:any = totalResults/this.pageSize; + if(!(Number.isInteger(totalPages))) { + totalPages = (parseInt(totalPages, this.pageSize) + 1); + } + return totalPages; + } + + public updatePage($event) { + this.page = $event.value; + } +} diff --git a/landingPages/organization/deletedByInference/deletedByInference.module.ts b/landingPages/organization/deletedByInference/deletedByInference.module.ts new file mode 100644 index 00000000..b792d420 --- /dev/null +++ b/landingPages/organization/deletedByInference/deletedByInference.module.ts @@ -0,0 +1,31 @@ +import { NgModule} from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { FormsModule } from '@angular/forms'; + + import { OrganizationsDeletedByInferenceComponent } from './deletedByInference.component'; + import { OrganizationsDeletedByInferenceService } from './deletedByInference.service'; + +import {ResultLandingUtilsModule} from '../../landing-utils/resultLandingUtils.module'; + + import {PagingModule} from '../../../utils/paging.module'; + + import {ErrorMessagesModule} from '../../../utils/errorMessages.module'; +import {ShowAuthorsModule} from "../../../utils/authors/showAuthors.module"; +import {LandingModule} from "../../landing-utils/landing.module"; + +@NgModule({ + imports: [ + CommonModule, FormsModule, ResultLandingUtilsModule, + PagingModule, ErrorMessagesModule, ShowAuthorsModule, LandingModule + ], + declarations: [ + OrganizationsDeletedByInferenceComponent + ], + providers:[ + OrganizationsDeletedByInferenceService + ], + exports: [ + OrganizationsDeletedByInferenceComponent + ] +}) +export class OrganizationsDeletedByInferenceModule { } diff --git a/landingPages/organization/deletedByInference/deletedByInference.service.ts b/landingPages/organization/deletedByInference/deletedByInference.service.ts new file mode 100644 index 00000000..fc07dafa --- /dev/null +++ b/landingPages/organization/deletedByInference/deletedByInference.service.ts @@ -0,0 +1,65 @@ +import {Injectable} from '@angular/core'; +import {HttpClient} from "@angular/common/http"; +import {OrganizationInfo} from '../../../utils/entities/organizationInfo'; +import {EnvProperties} from '../../../utils/properties/env-properties'; +import {ParsingFunctions} from '../../landing-utils/parsingFunctions.class'; +import {map} from "rxjs/operators"; + +@Injectable() +export class OrganizationsDeletedByInferenceService { + constructor(private http: HttpClient) { + this.parsingFunctions = new ParsingFunctions(); + } + + public parsingFunctions: ParsingFunctions; + + getDeletedByInferenceResults(id: string, size: string, properties: EnvProperties): any { + let url = properties.searchAPIURLLAst + 'deletedByInferenceOrganizations/' + id + "?format=json&size=" + size; + + return this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url) + .pipe(map(res => res['results'])) + .pipe(map(res => this.parseDeletedByInferenceResults(res, properties))); + } + + parseDeletedByInferenceResults(_results: any, properties: EnvProperties): OrganizationInfo[] { + let results: OrganizationInfo[] = []; + if (_results) { + let organization: OrganizationInfo; + + let length = Array.isArray(_results) ? _results.length : 1; + for (let i = 0; i < length; i++) { + organization = new OrganizationInfo(); + + var _result = Array.isArray(_results) ? _results[i]['result']['metadata']['oaf:entity'] : _results['result']['metadata']['oaf:entity']; + organization.objIdentifier = Array.isArray(_results) ? _results[i]['result']["header"]["dri:objIdentifier"] : _results['result']["header"]["dri:objIdentifier"]; + + if (_result) { + if (_result['oaf:organization']) { + let data = _result['oaf:organization']; + + if(data.hasOwnProperty("websiteurl")) { + organization.title = {"name": data.legalshortname, "url": data.websiteurl}; + } else { + organization.title = {"name": data.legalshortname, "url": ''}; + } + + organization.name = data.legalname; + + + if(organization.title.name == '') { + organization.title.name = organization.name; + } + + if(data.hasOwnProperty("country")) { + organization.country = data['country'].classname; + } + + } + results.push(organization); + } + } + + return results; + } + } +} diff --git a/landingPages/organization/organization.component.html b/landingPages/organization/organization.component.html index b2ef64d9..4e5f48e7 100644 --- a/landingPages/organization/organization.component.html +++ b/landingPages/organization/organization.component.html @@ -19,7 +19,14 @@ [URL]="properties.baseLink+'/search/organization?organizationId='+organizationId" type="organization"> - + + + +
+ The following information is the result of merging + {{organizationInfo.deletedByInferenceIds.length}} original versions +
{{organizationInfo.name}}
Organization{{" "}} @@ -193,6 +200,11 @@ + + + diff --git a/landingPages/organization/organization.component.ts b/landingPages/organization/organization.component.ts index 971d016a..744079d0 100644 --- a/landingPages/organization/organization.component.ts +++ b/landingPages/organization/organization.component.ts @@ -100,6 +100,9 @@ export class OrganizationComponent { downloadProjectPublSub: any; properties: EnvProperties; + @ViewChild('AlertModalDeletedByInference') alertModalDeletedByInference; + public deleteByInferenceOpened: boolean = false; + //private ngUnsubscribe: Subject = new Subject(); constructor(private element: ElementRef, @@ -552,4 +555,12 @@ export class OrganizationComponent { private handleError(message: string, error) { console.error("Organizaton Landing Page: " + message, error); } + + openDeletedByInference() { + this.deleteByInferenceOpened = true; + this.alertModalDeletedByInference.cancelButton = false; + this.alertModalDeletedByInference.okButton = false; + this.alertModalDeletedByInference.alertTitle = "Original sources"; + this.alertModalDeletedByInference.open(); + } } diff --git a/landingPages/organization/organization.module.ts b/landingPages/organization/organization.module.ts index 2f8e22fe..30d6e501 100644 --- a/landingPages/organization/organization.module.ts +++ b/landingPages/organization/organization.module.ts @@ -22,6 +22,7 @@ import {IsRouteEnabled} from '../../error/isRouteEnabled.guard'; import {Schema2jsonldModule} from '../../sharedComponents/schema2jsonld/schema2jsonld.module'; import {SEOServiceModule} from '../../sharedComponents/SEO/SEOService.module'; import {HelperModule} from "../../utils/helper/helper.module"; +import {OrganizationsDeletedByInferenceModule} from "./deletedByInference/deletedByInference.module"; @NgModule({ @@ -37,8 +38,8 @@ import {HelperModule} from "../../utils/helper/helper.module"; OrganizationServiceModule, SearchResearchResultsServiceModule, ProjectsServiceModule, - Schema2jsonldModule, SEOServiceModule, HelperModule - + Schema2jsonldModule, SEOServiceModule, HelperModule, + OrganizationsDeletedByInferenceModule ], declarations: [ OrganizationComponent, diff --git a/services/organization.service.ts b/services/organization.service.ts index 779bcc2e..4cd65c8a 100644 --- a/services/organization.service.ts +++ b/services/organization.service.ts @@ -75,6 +75,19 @@ export class OrganizationService { if(organization.hasOwnProperty("country")) { this.organizationInfo.country = organization['country'].classname; } + + if (organization.hasOwnProperty("children")) { + let children = organization['children']; + if( children.hasOwnProperty("organization")) { + this.organizationInfo.deletedByInferenceIds = []; + let length = Array.isArray(children['organization']) ? children['organization'].length : 1; + + for (let i = 0; i < length; i++) { + let result = Array.isArray(children['organization']) ? children['organization'][i] : children['organization']; + this.organizationInfo.deletedByInferenceIds.push(result.objidentifier); + } + } + } } //Comment Parsing Projects info diff --git a/utils/entities/organizationInfo.ts b/utils/entities/organizationInfo.ts index 6550d91e..5a6d3854 100644 --- a/utils/entities/organizationInfo.ts +++ b/utils/entities/organizationInfo.ts @@ -11,4 +11,6 @@ export class OrganizationInfo { "sc39": string, "startDate": string, "endDate": string }[]>; //dataProviders: { "name": string, "url": string, "type": string, "websiteUrl": string, // "organizations": {"name": string, "url": string}[]}[]; + + deletedByInferenceIds: string[]; }