2017-12-19 13:53:46 +01:00
|
|
|
import {Component, Input, Output, EventEmitter, ViewChild} from '@angular/core';
|
2018-03-13 17:02:22 +01:00
|
|
|
import {Router, ActivatedRoute} from '@angular/router';
|
2017-12-19 13:53:46 +01:00
|
|
|
import {ClaimsService} from '../../claim-utils/service/claims.service';
|
|
|
|
import {ModalLoading} from '../../../utils/modal/loading.component';
|
|
|
|
import {AlertModal} from '../../../utils/modal/alert';
|
|
|
|
import {Md5} from 'ts-md5/dist/md5';
|
2018-11-01 18:20:05 +01:00
|
|
|
import {LoginErrorCodes} from '../../../login/utils/guardHelper.class';
|
2019-07-23 14:23:12 +02:00
|
|
|
import {EnvProperties} from '../../../utils/properties/env-properties';
|
|
|
|
import {
|
|
|
|
ClaimEntity,
|
|
|
|
ClaimRecord2Insert,
|
|
|
|
ClaimsErrorMessage,
|
|
|
|
DirectIndexRecord,
|
|
|
|
Message
|
|
|
|
} from "../../claim-utils/claimHelper.class";
|
2019-09-13 09:01:19 +02:00
|
|
|
import {UserManagementService} from "../../../services/user-management.service";
|
2023-07-28 11:15:54 +02:00
|
|
|
import {Subscriber, timer} from "rxjs";
|
|
|
|
import {map} from "rxjs/operators";
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
@Component({
|
2019-07-23 14:23:12 +02:00
|
|
|
selector: 'claim-insert',
|
|
|
|
template: `
|
2022-07-18 17:56:59 +02:00
|
|
|
<div (click)="insert()" class="uk-card-footer uk-flex uk-flex-center clickable"
|
|
|
|
[class.uk-tile-primary]="(results.length > 0 && (sources.length > 0 || inlineEntity))"
|
|
|
|
[class.uk-background-muted]="!(results.length > 0 && (sources.length > 0 || inlineEntity))"
|
|
|
|
[class.uk-disabled]="!(results.length > 0 && (sources.length > 0 || inlineEntity))">
|
|
|
|
<button class="uk-flex uk-flex-middle uk-button uk-button-text"
|
|
|
|
[class.uk-disabled]="!(results.length > 0 && (sources.length > 0 || inlineEntity))"
|
|
|
|
[disabled]="!(results.length > 0 && (sources.length > 0 || inlineEntity))">
|
|
|
|
<icon name="link" visuallyHidden="link" [flex]="true"></icon>
|
|
|
|
<div class="uk-width-expand uk-margin-small-left">CONFIRM LINKING</div>
|
|
|
|
</button>
|
2019-07-23 14:23:12 +02:00
|
|
|
</div>
|
2023-07-28 11:15:54 +02:00
|
|
|
<modal-loading [message]="'Please wait...'">
|
|
|
|
|
|
|
|
<div *ngIf="claimsJob">
|
|
|
|
<div *ngIf="claimsJob && claimsJob.insertedIds.length <1" class="uk-text-meta uk-text-small">
|
|
|
|
Initiating process....</div>
|
|
|
|
<div *ngIf="claimsJob && claimsJob.insertedIds.length >0" class="uk-text-meta uk-text-small">
|
2023-08-03 11:45:39 +02:00
|
|
|
{{claimsJob.insertedIds.length}} out of {{claims2Insert}} links created.</div>
|
|
|
|
<div *ngIf="feedRecordsJob && feedRecordsJob.insertedIds.length >0" class="uk-text-meta uk-text-small">
|
|
|
|
{{feedRecordsJob.insertedIds.length}} out of {{records2Insert}} records added in the index...</div>
|
2023-07-28 11:15:54 +02:00
|
|
|
<div *ngIf="claimsJob.status != 'COMPLETE'" class="uk-text-meta uk-text-small">
|
|
|
|
Please don't close the window, process is ongoing...</div>
|
|
|
|
</div>
|
|
|
|
</modal-loading>
|
2022-07-18 17:56:59 +02:00
|
|
|
<modal-alert (alertOutput)="confirmClose()">
|
|
|
|
<h4 class="modal-title uk-text-bold " id="myModalLabel">Confirmation notice</h4>
|
|
|
|
<p>All the links you provided will be published in the OpenAIRE platform. <br>
|
|
|
|
Please make sure that the information is valid.<br>
|
|
|
|
<span class="uk-text-bold">In some cases, links take some time to be published.</span><br>
|
|
|
|
For more information please check the linking status in My-Links page.
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
Do you confirm the information you provide is valid?
|
|
|
|
</p>
|
|
|
|
</modal-alert>
|
2019-07-23 14:23:12 +02:00
|
|
|
`
|
2017-12-19 13:53:46 +01:00
|
|
|
})
|
|
|
|
export class ClaimInsertComponent {
|
2019-09-13 09:01:19 +02:00
|
|
|
constructor(private claimService: ClaimsService, private _router: Router, private route: ActivatedRoute,
|
|
|
|
private userManagementService: UserManagementService) {
|
2019-07-23 14:23:12 +02:00
|
|
|
}
|
2020-11-11 15:43:13 +01:00
|
|
|
subscriptions = [];
|
|
|
|
ngOnDestroy() {
|
|
|
|
this.subscriptions.forEach(subscription => {
|
|
|
|
if (subscription instanceof Subscriber) {
|
|
|
|
subscription.unsubscribe();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
ngOnInit() {
|
2020-11-11 15:43:13 +01:00
|
|
|
this.subscriptions.push(this.route.queryParams.subscribe(params => {
|
2018-03-13 17:02:22 +01:00
|
|
|
this.params = params;
|
2020-11-11 15:43:13 +01:00
|
|
|
}));
|
2023-08-03 11:45:39 +02:00
|
|
|
if(localStorage.getItem(this.localStoragePrefix + "claimsJob")){
|
|
|
|
this.claimsJob = JSON.parse(localStorage.getItem(this.localStoragePrefix + "claimsJob"));
|
|
|
|
this.feedRecordsJob = JSON.parse(localStorage.getItem(this.localStoragePrefix + "feedRecordsJob"));
|
|
|
|
if(this.claimsJob.status != "COMPLETE"){
|
|
|
|
this.claiming = true;
|
|
|
|
let loadingTimerSubscription = timer(0, 1000).pipe(
|
|
|
|
map(() => {
|
|
|
|
if(this.loading) {
|
|
|
|
this.loading.open();
|
|
|
|
loadingTimerSubscription.unsubscribe();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
).subscribe();
|
|
|
|
this.subscriptions.push(loadingTimerSubscription);
|
|
|
|
|
|
|
|
let timerSubscription = timer(0, 10000).pipe(
|
|
|
|
map(() => {
|
|
|
|
this.getStatus(); // load data contains the http request
|
|
|
|
})
|
|
|
|
).subscribe();
|
|
|
|
this.subscriptions.push(timerSubscription);
|
|
|
|
}else{
|
|
|
|
this.claimsJob = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
params = {};
|
|
|
|
|
|
|
|
@Input() public results: ClaimEntity[];
|
|
|
|
@Input() inlineEntity: ClaimEntity = null;
|
|
|
|
@Input() sources: ClaimEntity[] = null;
|
|
|
|
@Input() public properties: EnvProperties;
|
|
|
|
@Input() localStoragePrefix: string;
|
|
|
|
@ViewChild(ModalLoading) loading: ModalLoading;
|
2017-12-19 13:53:46 +01:00
|
|
|
@ViewChild(AlertModal) alert;
|
2019-07-23 14:23:12 +02:00
|
|
|
@Input() errors: ClaimsErrorMessage[];
|
|
|
|
@Output() insertFinished = new EventEmitter();
|
2019-08-27 15:19:58 +02:00
|
|
|
@Input() defaultColors:boolean;
|
2019-10-16 12:58:04 +02:00
|
|
|
@Input() communityId:string= null;
|
2019-07-23 14:23:12 +02:00
|
|
|
public claiming = false;
|
|
|
|
|
|
|
|
public claims: number = 0;
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
private servicesRespond: number = 0;
|
|
|
|
private insertedClaims = [];
|
|
|
|
private errorInClaims: ClaimRecord2Insert[] = [];
|
|
|
|
private insertedRecords = [];
|
|
|
|
private errorInRecords = [];
|
2023-07-28 11:15:54 +02:00
|
|
|
public claimsJob;
|
|
|
|
public feedRecordsJob;
|
|
|
|
public claims2Insert;
|
2023-08-03 11:45:39 +02:00
|
|
|
public records2Insert
|
2019-07-23 14:23:12 +02:00
|
|
|
public insert() {
|
2022-04-05 17:36:08 +02:00
|
|
|
this.confirmOpen();
|
2019-07-23 14:23:12 +02:00
|
|
|
}
|
2020-03-26 13:18:18 +01:00
|
|
|
saveAndNavigate(){
|
2023-08-03 11:45:39 +02:00
|
|
|
this.saveLocalStorage();
|
2020-03-26 13:18:18 +01:00
|
|
|
this._router.navigate(['/user-info'], {
|
|
|
|
queryParams: {
|
|
|
|
"errorCode": LoginErrorCodes.NOT_VALID,
|
|
|
|
"redirectUrl": this._router.url
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2019-07-23 14:23:12 +02:00
|
|
|
private insertActions() {
|
|
|
|
this.servicesRespond = 0;
|
|
|
|
this.insertedClaims = [];
|
|
|
|
this.errorInClaims = [];
|
|
|
|
this.insertedRecords = [];
|
|
|
|
this.errorInRecords = [];
|
2020-11-11 15:43:13 +01:00
|
|
|
this.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => {
|
2019-09-13 09:01:19 +02:00
|
|
|
if (!user) {
|
2020-03-26 13:18:18 +01:00
|
|
|
this.saveAndNavigate();
|
2019-09-13 09:01:19 +02:00
|
|
|
} else {
|
|
|
|
this.claiming = true;
|
|
|
|
this.loading.open();
|
|
|
|
let claims: ClaimRecord2Insert[] = [];
|
|
|
|
let directclaims: DirectIndexRecord[] = [];
|
2019-10-16 12:58:04 +02:00
|
|
|
let dashboard = this.properties.environment+"_"+this.properties.dashboard + (this.communityId?("_"+this.communityId):'');
|
2019-09-13 09:01:19 +02:00
|
|
|
for (let j = 0; j < this.sources.length; j++) { // if an external result -> direct insert in the index
|
|
|
|
const result: ClaimEntity = this.sources[j];
|
|
|
|
if (result.result && ["crossref", "datacite", "orcid"].indexOf(result.result.source) != -1) {
|
2019-07-23 14:23:12 +02:00
|
|
|
directclaims.push({
|
2019-09-13 09:01:19 +02:00
|
|
|
"id": result.id,
|
|
|
|
"record": ClaimInsertComponent.createDirectClaim(result, this.results)
|
2019-07-23 14:23:12 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2019-09-13 09:01:19 +02:00
|
|
|
for (let i = 0; i < this.results.length; i++) {
|
|
|
|
const entity: ClaimEntity = this.results[i]; // this is a research result, a project or a context
|
|
|
|
|
|
|
|
if (entity.result && ["crossref", "datacite", "orcid"].indexOf(entity.result.source) != -1) { // if an external result -> direct insert in the index
|
|
|
|
if (this.sources.length > 0) {
|
|
|
|
directclaims.push({
|
|
|
|
"id": entity.id,
|
|
|
|
"record": ClaimInsertComponent.createDirectClaim(entity, this.sources)
|
|
|
|
});
|
|
|
|
} else if (this.inlineEntity) {
|
|
|
|
directclaims.push({
|
|
|
|
"id": entity.id,
|
|
|
|
"record": ClaimInsertComponent.createDirectClaim(entity, [this.inlineEntity])
|
|
|
|
});
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
}
|
2019-07-23 14:23:12 +02:00
|
|
|
|
2019-09-13 09:01:19 +02:00
|
|
|
for (let j = 0; j < this.sources.length; j++) {
|
|
|
|
const result: ClaimEntity = this.sources[j]; // this is a research result
|
2019-07-23 14:23:12 +02:00
|
|
|
if (entity.result) {
|
2019-10-16 12:40:19 +02:00
|
|
|
claims.push(ClaimInsertComponent.createResultClaim(result, entity, user.email, dashboard));
|
2019-07-23 14:23:12 +02:00
|
|
|
} else if (entity.context) {
|
2019-10-16 12:40:19 +02:00
|
|
|
claims.push(ClaimInsertComponent.createContextClaim(result, entity, user.email, dashboard));
|
2019-07-23 14:23:12 +02:00
|
|
|
} else if (entity.project) {
|
2019-10-16 12:40:19 +02:00
|
|
|
claims.push(ClaimInsertComponent.createProjectClaim(result, entity, user.email, dashboard));
|
2019-07-23 14:23:12 +02:00
|
|
|
}
|
2019-09-13 09:01:19 +02:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
if (this.inlineEntity) {
|
|
|
|
if (this.inlineEntity.result) {
|
|
|
|
if (entity.result) {
|
2019-10-16 12:40:19 +02:00
|
|
|
|
|
|
|
claims.push(ClaimInsertComponent.createResultClaim(this.inlineEntity, entity, user.email, dashboard));
|
2019-09-13 09:01:19 +02:00
|
|
|
} else if (entity.context) {
|
2019-10-16 12:40:19 +02:00
|
|
|
claims.push(ClaimInsertComponent.createContextClaim(this.inlineEntity, entity, user.email, dashboard));
|
2019-09-13 09:01:19 +02:00
|
|
|
} else if (entity.project) {
|
2019-10-16 12:40:19 +02:00
|
|
|
claims.push(ClaimInsertComponent.createProjectClaim(this.inlineEntity, entity, user.email, dashboard));
|
2019-09-13 09:01:19 +02:00
|
|
|
}
|
|
|
|
} else if (this.inlineEntity.project) {
|
|
|
|
if (entity.result) {
|
2019-10-16 12:40:19 +02:00
|
|
|
claims.push(ClaimInsertComponent.createProjectClaim(entity, this.inlineEntity, user.email, dashboard));
|
2019-09-13 09:01:19 +02:00
|
|
|
}
|
2019-07-23 14:23:12 +02:00
|
|
|
}
|
2018-03-13 17:02:22 +01:00
|
|
|
}
|
2019-07-23 14:23:12 +02:00
|
|
|
|
|
|
|
|
2019-09-13 09:01:19 +02:00
|
|
|
}
|
2019-07-23 14:23:12 +02:00
|
|
|
|
2019-09-13 09:01:19 +02:00
|
|
|
//first call direct index service - when call is done (success or error) call isertBulkClaims method to insert claims in DB
|
2020-03-13 10:16:44 +01:00
|
|
|
// console.log("directclaims");
|
|
|
|
// console.log(directclaims);
|
2023-08-03 11:45:39 +02:00
|
|
|
if (directclaims.length > 0/* && this.properties.environment != "development"*/){
|
2020-11-11 15:43:13 +01:00
|
|
|
this.subscriptions.push(this.claimService.insertDirectRecords(directclaims, this.properties.claimsAPIURL).subscribe(
|
2019-09-13 09:01:19 +02:00
|
|
|
data => {
|
2023-08-03 11:45:39 +02:00
|
|
|
this.feedRecordsJob = data.data;
|
|
|
|
this.records2Insert = directclaims.length;
|
|
|
|
console.log(data);
|
2023-07-28 11:15:54 +02:00
|
|
|
// this.insertedRecords = data.insertedIds;
|
|
|
|
//
|
|
|
|
// this.errorInRecords = data.errorInClaims;
|
2019-09-13 09:01:19 +02:00
|
|
|
this.isertBulkClaims(claims);
|
|
|
|
},
|
|
|
|
err => {
|
2020-03-26 13:18:18 +01:00
|
|
|
err = err && err.error?err.error:err;
|
|
|
|
if (err.code && err.code == 403) {
|
|
|
|
this.saveAndNavigate();
|
2019-09-13 09:01:19 +02:00
|
|
|
}
|
2023-08-03 11:45:39 +02:00
|
|
|
/* if (err.insertedIds && err.insertedIds.length > 0) {
|
2019-09-13 09:01:19 +02:00
|
|
|
this.insertedRecords = err.insertedIds;
|
|
|
|
}
|
|
|
|
if (err.errorInClaims && err.errorInClaims.length > 0) {
|
|
|
|
this.errorInRecords = err.errorInClaims;
|
2023-08-03 11:45:39 +02:00
|
|
|
}*/
|
2019-09-13 09:01:19 +02:00
|
|
|
this.isertBulkClaims(claims);
|
|
|
|
|
|
|
|
ClaimInsertComponent.handleError("Error inserting direct records: " + JSON.stringify(directclaims), err);
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2020-11-11 15:43:13 +01:00
|
|
|
));
|
2019-09-13 09:01:19 +02:00
|
|
|
} else {
|
|
|
|
this.isertBulkClaims(claims);
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2020-11-11 15:43:13 +01:00
|
|
|
}));
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
private isertBulkClaims(claims: ClaimRecord2Insert[]) {
|
|
|
|
this.errors.splice(0, this.errors.length);
|
2020-11-11 15:43:13 +01:00
|
|
|
this.subscriptions.push(this.claimService.insertBulkClaims(claims, this.properties.claimsAPIURL).subscribe(
|
2019-07-23 14:23:12 +02:00
|
|
|
data => {
|
2023-07-28 11:15:54 +02:00
|
|
|
this.claims2Insert = claims.length;
|
|
|
|
this.claimsJob = data.data;
|
2023-08-03 11:45:39 +02:00
|
|
|
this.saveLocalStorage();
|
2023-07-28 11:15:54 +02:00
|
|
|
let timerSubscription = timer(0, 10000).pipe(
|
|
|
|
map(() => {
|
|
|
|
this.getStatus(); // load data contains the http request
|
|
|
|
})
|
|
|
|
).subscribe();
|
|
|
|
this.subscriptions.push(timerSubscription);
|
2019-07-23 14:23:12 +02:00
|
|
|
},
|
|
|
|
err => {
|
2020-03-26 13:18:18 +01:00
|
|
|
err = err && err.error?err.error:err;
|
|
|
|
if (err.code && err.code == 403) {
|
|
|
|
this.saveAndNavigate();
|
2019-07-23 14:23:12 +02:00
|
|
|
}
|
|
|
|
let error: ClaimsErrorMessage = new ClaimsErrorMessage();
|
|
|
|
error.type = "claimServiceFail";
|
|
|
|
if (err.insertedIds && err.insertedIds.length > 0) {
|
|
|
|
this.insertedClaims = err.insertedIds;
|
|
|
|
error.inserted = err.insertedIds.length;
|
|
|
|
}
|
|
|
|
if (err.errorInClaims && err.errorInClaims.length > 0) {
|
|
|
|
this.errorInClaims = err.errorInClaims;
|
|
|
|
error.failed = err.errorInClaims.length;
|
|
|
|
} else {
|
|
|
|
error.failed = claims.length;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.results != null) {
|
|
|
|
localStorage.setItem(this.localStoragePrefix + "results", JSON.stringify(this.results));
|
|
|
|
}
|
|
|
|
if (this.sources != null) {
|
|
|
|
localStorage.setItem(this.localStoragePrefix + "sources", JSON.stringify(this.sources));
|
|
|
|
}
|
|
|
|
console.log(error);
|
|
|
|
this.createErrorMessagesPerEntity((this.insertedClaims.length == 0));
|
|
|
|
this.errors.push(error);
|
|
|
|
this.afterclaimsInsertion();
|
|
|
|
|
|
|
|
ClaimInsertComponent.handleError("Error inserting bulk claims: " + JSON.stringify(claims), err);
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2020-11-11 15:43:13 +01:00
|
|
|
));
|
2019-07-23 14:23:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
createErrorMessagesPerEntity(applyToAll: boolean) {
|
|
|
|
let errorsInIds: string[] = [];
|
|
|
|
let savedIds: string[] = [];
|
|
|
|
if (!applyToAll) {
|
|
|
|
for (let claim of this.errorInClaims) {
|
|
|
|
errorsInIds.push(claim.sourceId);
|
|
|
|
errorsInIds.push(claim.targetId);
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
}
|
2019-07-23 14:23:12 +02:00
|
|
|
for (let i = 0; i < this.sources.length; i++) {
|
|
|
|
let entity: ClaimEntity = this.sources[i];
|
|
|
|
if (errorsInIds.indexOf(entity.id) != -1 || applyToAll) {
|
|
|
|
let error: Message = new Message();
|
|
|
|
error.type = "fail2Insert";
|
|
|
|
entity.errorMessages.push(error);
|
|
|
|
} else {
|
|
|
|
savedIds.push(entity.id);
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2019-07-23 14:23:12 +02:00
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
for (let entity of this.results) {
|
|
|
|
if (errorsInIds.indexOf(entity.id) != -1 || applyToAll) {
|
|
|
|
let error: Message = new Message();
|
|
|
|
error.type = "fail2Insert";
|
|
|
|
entity.errorMessages.push(error);
|
|
|
|
} else {
|
|
|
|
savedIds.push(entity.id);
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2019-07-23 14:23:12 +02:00
|
|
|
if (this.inlineEntity && (errorsInIds.indexOf(this.inlineEntity.id) != -1 || applyToAll)) {
|
|
|
|
let error: Message = new Message();
|
|
|
|
error.type = "fail2Insert";
|
|
|
|
this.inlineEntity.errorMessages.push(error);
|
|
|
|
}
|
|
|
|
//remove entities that have been saved
|
|
|
|
for (let id of savedIds) {
|
|
|
|
|
|
|
|
//remove sources
|
|
|
|
let sourceIndex = -1;
|
|
|
|
for (let i = 0; i < this.sources.length; i++) {
|
|
|
|
if (this.sources[i].id == id) {
|
|
|
|
sourceIndex = i;
|
|
|
|
break;
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
}
|
2019-07-23 14:23:12 +02:00
|
|
|
if (sourceIndex != -1) {
|
|
|
|
this.sources.splice(sourceIndex, 1);
|
|
|
|
} else {
|
|
|
|
//remove results
|
|
|
|
let resutsIndex = -1;
|
|
|
|
for (let i = 0; i < this.results.length; i++) {
|
|
|
|
if (this.results[i].id == id) {
|
|
|
|
resutsIndex = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (resutsIndex != -1) {
|
|
|
|
this.results.splice(resutsIndex, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2019-07-23 14:23:12 +02:00
|
|
|
this.insertFinished.emit();
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
private afterclaimsInsertion() {
|
2017-12-19 13:53:46 +01:00
|
|
|
this.claiming = false;
|
2023-08-03 11:45:39 +02:00
|
|
|
this.loading.close();
|
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
if (this.errorInClaims.length == 0 && this.insertedClaims.length > 0) {
|
|
|
|
localStorage.removeItem(this.localStoragePrefix + "sources");
|
2018-07-25 15:56:02 +02:00
|
|
|
localStorage.removeItem(this.localStoragePrefix + "results");
|
2023-08-03 11:45:39 +02:00
|
|
|
localStorage.removeItem(this.localStoragePrefix + "claimsJob");
|
|
|
|
localStorage.removeItem(this.localStoragePrefix + "feedRecordsJob");
|
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
this._router.navigate(['/myclaims'], {queryParams: this.params});
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2019-07-23 14:23:12 +02:00
|
|
|
}
|
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2019-10-16 12:40:19 +02:00
|
|
|
private static createContextClaim(resultEntity: ClaimEntity, contextEntity: ClaimEntity, user: any, dashboard:string): ClaimRecord2Insert {
|
2019-07-23 14:23:12 +02:00
|
|
|
return {
|
|
|
|
claimedBy: user,
|
|
|
|
sourceId: contextEntity.context.concept.id,
|
|
|
|
sourceType: "context",
|
|
|
|
sourceCollectedFrom: "openaire",
|
|
|
|
sourceAccessRights: "OPEN",
|
|
|
|
sourceEmbargoEndDate: "",
|
|
|
|
targetId: resultEntity.id,
|
|
|
|
targetType: resultEntity.type,
|
|
|
|
targetCollectedFrom: resultEntity.result.source,
|
|
|
|
targetAccessRights: resultEntity.result.accessRights,
|
2019-10-16 12:40:19 +02:00
|
|
|
targetEmbargoEndDate: ClaimInsertComponent.getEmbargoEndDate(resultEntity),
|
|
|
|
claimedInDashboard : dashboard
|
2019-07-23 14:23:12 +02:00
|
|
|
};
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
|
2019-10-16 12:40:19 +02:00
|
|
|
private static createProjectClaim(resultEntity: ClaimEntity, projectEntity: ClaimEntity, user: any, dashboard:string): ClaimRecord2Insert {
|
2019-07-23 14:23:12 +02:00
|
|
|
return {
|
|
|
|
claimedBy: user,
|
|
|
|
sourceId: projectEntity.id,
|
|
|
|
sourceType: "project",
|
|
|
|
sourceCollectedFrom: "openaire",
|
|
|
|
sourceAccessRights: "OPEN",
|
|
|
|
sourceEmbargoEndDate: "",
|
|
|
|
targetId: resultEntity.id,
|
|
|
|
targetType: resultEntity.type,
|
|
|
|
targetCollectedFrom: resultEntity.result.source,
|
|
|
|
targetAccessRights: resultEntity.result.accessRights,
|
2019-10-16 12:40:19 +02:00
|
|
|
targetEmbargoEndDate: ClaimInsertComponent.getEmbargoEndDate(resultEntity),
|
|
|
|
claimedInDashboard : dashboard
|
2019-07-23 14:23:12 +02:00
|
|
|
};
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2019-10-16 12:40:19 +02:00
|
|
|
private static createResultClaim(inlineResult: ClaimEntity, resultEntity: ClaimEntity, user: string, dashboard:string): ClaimRecord2Insert {
|
2019-07-23 14:23:12 +02:00
|
|
|
|
|
|
|
return {
|
|
|
|
claimedBy: user,
|
|
|
|
sourceId: resultEntity.id,
|
|
|
|
sourceType: resultEntity.type,
|
|
|
|
sourceCollectedFrom: resultEntity.result.source,
|
|
|
|
sourceAccessRights: resultEntity.result.accessRights,
|
|
|
|
sourceEmbargoEndDate: ClaimInsertComponent.getEmbargoEndDate(resultEntity),
|
|
|
|
targetId: inlineResult.id,
|
|
|
|
targetType: inlineResult.type,
|
|
|
|
targetCollectedFrom: inlineResult.result.source,
|
|
|
|
targetAccessRights: inlineResult.result.accessRights,
|
2019-10-16 12:40:19 +02:00
|
|
|
targetEmbargoEndDate: ClaimInsertComponent.getEmbargoEndDate(inlineResult),
|
|
|
|
claimedInDashboard : dashboard
|
2019-07-23 14:23:12 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
static getEmbargoEndDate(resultEntity: ClaimEntity): string {
|
|
|
|
if (resultEntity.result && resultEntity.result.accessRights == "EMBARGO" && resultEntity.result.embargoEndDate != null) {
|
|
|
|
return resultEntity.result.embargoEndDate;
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2019-07-23 14:23:12 +02:00
|
|
|
return ""
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
static createDirectClaim(resultEntity: ClaimEntity, results: ClaimEntity[]) {
|
|
|
|
let entity = {};
|
|
|
|
const md5_id = Md5.hashStr(resultEntity.id);
|
|
|
|
entity["originalId"] = "userclaim___::" + md5_id;
|
|
|
|
entity["openaireId"] = "userclaim___::" + md5_id;
|
|
|
|
entity["title"] = resultEntity.title;
|
|
|
|
entity["title"] = (Array.isArray(resultEntity.title) && resultEntity.title.length > 0) ? resultEntity.title[0] : resultEntity.title;
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
if (resultEntity.result.authors && resultEntity.result.authors.length > 0) {
|
|
|
|
entity["authors"] = resultEntity.result.authors;
|
|
|
|
}
|
|
|
|
if (resultEntity.result.publisher) {
|
|
|
|
entity["publisher"] = resultEntity.result.publisher;
|
|
|
|
}
|
|
|
|
if (resultEntity.result.description) {
|
|
|
|
entity["description"] = resultEntity.result.description;
|
|
|
|
}
|
|
|
|
// entity["language"]=""; no info
|
|
|
|
entity["type"] = resultEntity.type;
|
|
|
|
if (resultEntity.result.source == "crossref" || resultEntity.result.source == "datacite") {
|
|
|
|
entity["pids"] = [];//{type:string, value:string}[];
|
|
|
|
entity["pids"].push({type: "doi", value: resultEntity.id})
|
|
|
|
}
|
|
|
|
entity["licenseCode"] = resultEntity.result.accessRights;
|
|
|
|
if (resultEntity.result.accessRights == "EMBARGO") {
|
|
|
|
entity["embargoEndDate"] = resultEntity.result.embargoEndDate;
|
|
|
|
}
|
|
|
|
if (resultEntity.type == "publication") {
|
|
|
|
entity["resourceType"] = "0001";
|
|
|
|
} else if (resultEntity.type == "dataset") {
|
|
|
|
entity["resourceType"] = "0021";
|
|
|
|
} else if (resultEntity.type == "software") {
|
|
|
|
entity["resourceType"] = "0029";
|
|
|
|
} else if (resultEntity.type == "other") {
|
|
|
|
entity["resourceType"] = "0020";
|
|
|
|
}
|
|
|
|
entity["url"] = resultEntity.result.url;
|
|
|
|
entity["hostedById"] = "openaire____::1256f046-bf1f-4afc-8b47-d0b147148b18";
|
|
|
|
if (resultEntity.result.source == "crossref") {
|
|
|
|
entity["collectedFromId"] = "openaire____::crossref";
|
|
|
|
} else if (resultEntity.result.source == "datacite") {
|
|
|
|
entity["collectedFromId"] = "openaire____::datacite";
|
|
|
|
} else if (resultEntity.result.source == "orcid") {
|
|
|
|
entity["collectedFromId"] = "openaire____::orcid";
|
|
|
|
} else if (resultEntity.result.source == "orpenaire") {
|
|
|
|
entity["collectedFromId"] = "openaire____::driver";
|
|
|
|
}
|
|
|
|
for (let i = 0; i < results.length; i++) {
|
|
|
|
if (results[i].project) {
|
|
|
|
if (!entity["linksToProjects"]) {
|
|
|
|
entity["linksToProjects"] = [];
|
|
|
|
}
|
|
|
|
let project: ClaimEntity = results[i];
|
|
|
|
entity["linksToProjects"].push("info:eu-repo/grantAgreement/" + project.project.funderName + "/" + project.project.fundingLevel0 + "/" + project.project.code + "/" + project.project.jurisdiction + "/" + project.title + "/" + project.project.acronym);
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
} else if (results[i].context) {
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
if (!entity["contexts"]) {
|
|
|
|
entity["contexts"] = [];
|
|
|
|
}
|
|
|
|
let context: ClaimEntity = results[i];
|
|
|
|
entity["contexts"].push(context.context.concept.id);
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2019-07-23 14:23:12 +02:00
|
|
|
// var json = JSON.stringify(entity);
|
|
|
|
//console.log("\nJSON:\n"+json);
|
|
|
|
return entity;
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
confirmOpen() {
|
2017-12-19 13:53:46 +01:00
|
|
|
this.alert.cancelButton = true;
|
|
|
|
this.alert.okButton = true;
|
2019-07-23 14:23:12 +02:00
|
|
|
this.alert.alertTitle = "";//"Final Confirmation notice";
|
|
|
|
this.alert.okButtonLeft = false;
|
|
|
|
// this.alert.message = "<div>All the links you provided will be published in the OpenAIRE platform. " +
|
|
|
|
// "<br>Make sure you have checked all the information you provided. In some cases some links take more time to be published. " +
|
|
|
|
// "<br>For more information please check the linking status in My-Links page. " +
|
|
|
|
// "<br><br>Do you confirm the information you provide are valid?</div>";
|
|
|
|
this.alert.okButtonText = "CONFIRM";
|
|
|
|
this.alert.cancelButtonText = "CANCEL";
|
2017-12-19 13:53:46 +01:00
|
|
|
this.alert.open();
|
|
|
|
}
|
2019-07-23 14:23:12 +02:00
|
|
|
|
|
|
|
confirmClose() {
|
2017-12-19 13:53:46 +01:00
|
|
|
this.insertActions();
|
|
|
|
}
|
2019-02-18 15:00:43 +01:00
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
private static handleError(message: string, error) {
|
|
|
|
|
|
|
|
console.error("Insert Claim (component): " + message, error);
|
2019-02-18 15:00:43 +01:00
|
|
|
}
|
2019-08-27 15:19:58 +02:00
|
|
|
|
|
|
|
getButtonClass(){
|
|
|
|
// [class]="(((sources.length>0||inlineEntity) && results.length > 0 && (!claiming && errors.length == 0))?' ':'uk-disabled')+ ' uk-button uk-button-large uk-text-center'+((defaultColors)?'':'')">CONFIRM LINKING
|
|
|
|
// <span class=" uk-margin-small-top uk-icon uk-float-right uk-text-bold uk-margin-small-right"> }
|
|
|
|
// [class]="(((sources.length>0||inlineEntity) && results.length > 0 && (!claiming && errors.length == 0))?'linksbaskettitlesPortalColor ':'uk-disabled')+ ' linksbaskettitles uk-padding-small uk-text-center'">CONFIRM LINKING
|
|
|
|
// <span class="uk-icon uk-float-right uk-text-bold uk-margin-small-right">
|
|
|
|
let buttonClass= "";
|
|
|
|
if((this.sources.length>0||this.inlineEntity) && this.results.length > 0 && (!this.claiming && this.errors.length == 0)){
|
|
|
|
if(this.defaultColors){
|
|
|
|
buttonClass+=" linksbaskettitlesPortalColor ";
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
buttonClass+=" uk-disabled ";
|
|
|
|
|
|
|
|
}
|
|
|
|
if(this.defaultColors){
|
|
|
|
buttonClass+=" linksbaskettitles uk-padding-small ";
|
2023-07-28 11:15:54 +02:00
|
|
|
}
|
2019-08-27 15:19:58 +02:00
|
|
|
return buttonClass + "uk-text-center ";
|
|
|
|
}
|
2023-07-28 11:15:54 +02:00
|
|
|
|
|
|
|
getStatus(){
|
2023-08-03 11:45:39 +02:00
|
|
|
if(this.feedRecordsJob && ! (this.feedRecordsJob.status == "COMPLETE" || this.feedRecordsJob.status == "ERROR") ) {
|
|
|
|
this.subscriptions.push(this.claimService.getStatus(this.feedRecordsJob.id, this.properties.claimsAPIURL).subscribe(data => {
|
|
|
|
this.feedRecordsJob = data.data;
|
2023-12-08 13:36:42 +01:00
|
|
|
// console.log("feed", this.feedRecordsJob.status);
|
2023-08-03 11:45:39 +02:00
|
|
|
if (this.feedRecordsJob.status == "COMPLETE" || data.data.status == "ERROR") {
|
|
|
|
this.insertedRecords = this.feedRecordsJob.insertedIds;
|
|
|
|
this.errorInRecords = this.feedRecordsJob.errorInClaims;
|
|
|
|
}
|
|
|
|
}, err => {
|
2023-07-28 11:15:54 +02:00
|
|
|
let error: ClaimsErrorMessage = new ClaimsErrorMessage();
|
2023-08-03 11:45:39 +02:00
|
|
|
error.type = "jobError";
|
2023-07-28 11:15:54 +02:00
|
|
|
this.createErrorMessagesPerEntity((this.insertedClaims.length == 0));
|
|
|
|
this.errors.push(error);
|
2023-08-03 11:45:39 +02:00
|
|
|
this.afterclaimsInsertion();
|
|
|
|
this.feedRecordsJob = null;
|
|
|
|
localStorage.removeItem(this.localStoragePrefix + "feedRecordsJob");
|
2023-07-28 11:15:54 +02:00
|
|
|
}
|
|
|
|
|
2023-08-03 11:45:39 +02:00
|
|
|
));
|
|
|
|
}
|
|
|
|
if(this.claimsJob) {
|
|
|
|
this.subscriptions.push(this.claimService.getStatus(this.claimsJob.id, this.properties.claimsAPIURL).subscribe(data => {
|
|
|
|
this.claimsJob = data.data;
|
2023-12-08 13:36:42 +01:00
|
|
|
// console.log("claim: ", this.claimsJob.status, this.feedRecordsJob.status?this.feedRecordsJob.status:" no feed job");
|
|
|
|
if ((this.claimsJob.status == "COMPLETE" || data.data.status == "ERROR") && ( !this.feedRecordsJob || (this.feedRecordsJob.status == "COMPLETE" || data.data.status == "ERROR")) ) {
|
2023-08-03 11:45:39 +02:00
|
|
|
this.insertedClaims = this.claimsJob.insertedIds;
|
|
|
|
this.errorInClaims = this.claimsJob.errorInClaims;
|
|
|
|
|
|
|
|
if (this.claims2Insert != this.insertedClaims.length) {
|
|
|
|
let error: ClaimsErrorMessage = new ClaimsErrorMessage();
|
|
|
|
error.type = "claimServiceFail2Insert";
|
|
|
|
error.inserted = this.insertedClaims.length;
|
|
|
|
error.failed = this.errorInClaims.length;
|
|
|
|
this.createErrorMessagesPerEntity((this.insertedClaims.length == 0));
|
|
|
|
this.errors.push(error);
|
|
|
|
}
|
|
|
|
this.afterclaimsInsertion();
|
2023-07-28 11:15:54 +02:00
|
|
|
|
|
|
|
|
2023-08-03 11:45:39 +02:00
|
|
|
}
|
|
|
|
}, err => {
|
|
|
|
let error: ClaimsErrorMessage = new ClaimsErrorMessage();
|
|
|
|
error.type = "jobError";
|
|
|
|
this.createErrorMessagesPerEntity((this.insertedClaims.length == 0));
|
|
|
|
this.errors.push(error);
|
|
|
|
this.afterclaimsInsertion();
|
|
|
|
this.claimsJob = null;
|
|
|
|
localStorage.removeItem(this.localStoragePrefix + "claimsJob");
|
|
|
|
|
|
|
|
}
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
saveLocalStorage(){
|
|
|
|
if (this.results != null) {
|
|
|
|
localStorage.setItem(this.localStoragePrefix + "results", JSON.stringify(this.results));
|
|
|
|
}
|
|
|
|
if (this.sources != null) {
|
|
|
|
localStorage.setItem(this.localStoragePrefix + "sources", JSON.stringify(this.sources));
|
|
|
|
}
|
|
|
|
if (this.claimsJob != null) {
|
|
|
|
localStorage.setItem(this.localStoragePrefix + "claimsJob", JSON.stringify(this.claimsJob));
|
|
|
|
}
|
|
|
|
if (this.feedRecordsJob != null) {
|
|
|
|
localStorage.setItem(this.localStoragePrefix + "feedRecordsJob", JSON.stringify(this.feedRecordsJob));
|
|
|
|
}
|
2023-07-28 11:15:54 +02:00
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2019-08-27 15:19:58 +02:00
|
|
|
|