updated claims api: submit job and get status

This commit is contained in:
argirok 2023-07-28 12:15:54 +03:00
parent 4e3df67f7e
commit 21c70d6d62
2 changed files with 69 additions and 8 deletions

View File

@ -106,6 +106,16 @@ export class ClaimsService {
.pipe(catchError(this.handleError)); .pipe(catchError(this.handleError));
} }
getStatus(jobId, apiUrl:string):any{
let url = apiUrl +"jobStatus/" + jobId;
return this.http.get(url,CustomOptions.getAuthOptions())
//.map(res => res.json())
//.do(request => console.info("Insert Response:"+request) )
.pipe(catchError(this.handleError));
}
private handleError (error: Response) { private handleError (error: Response) {
// in a real world app, we may send the error to some remote logging infrastructure // in a real world app, we may send the error to some remote logging infrastructure
// instead of just logging it to the console // instead of just logging it to the console

View File

@ -14,7 +14,8 @@ import {
Message Message
} from "../../claim-utils/claimHelper.class"; } from "../../claim-utils/claimHelper.class";
import {UserManagementService} from "../../../services/user-management.service"; import {UserManagementService} from "../../../services/user-management.service";
import {Subscriber} from "rxjs"; import {Subscriber, timer} from "rxjs";
import {map} from "rxjs/operators";
@Component({ @Component({
selector: 'claim-insert', selector: 'claim-insert',
@ -30,7 +31,18 @@ import {Subscriber} from "rxjs";
<div class="uk-width-expand uk-margin-small-left">CONFIRM LINKING</div> <div class="uk-width-expand uk-margin-small-left">CONFIRM LINKING</div>
</button> </button>
</div> </div>
<modal-loading [message]="'Please wait...'"></modal-loading> <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">
{{claimsJob.insertedIds.length}} out of {{claims2Insert}} links created.</div>
<div *ngIf="feedRecordsJob" class="uk-text-meta uk-text-small">{{feedRecordsJob.length}} records added in the index...</div>
<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>
<modal-alert (alertOutput)="confirmClose()"> <modal-alert (alertOutput)="confirmClose()">
<h4 class="modal-title uk-text-bold " id="myModalLabel">Confirmation notice</h4> <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> <p>All the links you provided will be published in the OpenAIRE platform. <br>
@ -84,7 +96,9 @@ export class ClaimInsertComponent {
private errorInClaims: ClaimRecord2Insert[] = []; private errorInClaims: ClaimRecord2Insert[] = [];
private insertedRecords = []; private insertedRecords = [];
private errorInRecords = []; private errorInRecords = [];
public claimsJob;
public feedRecordsJob;
public claims2Insert;
public insert() { public insert() {
this.confirmOpen(); this.confirmOpen();
} }
@ -180,9 +194,9 @@ export class ClaimInsertComponent {
if (directclaims.length > 0 && this.properties.environment != "development"){ if (directclaims.length > 0 && this.properties.environment != "development"){
this.subscriptions.push(this.claimService.insertDirectRecords(directclaims, this.properties.claimsAPIURL).subscribe( this.subscriptions.push(this.claimService.insertDirectRecords(directclaims, this.properties.claimsAPIURL).subscribe(
data => { data => {
this.insertedRecords = data.insertedIds; // this.insertedRecords = data.insertedIds;
//
this.errorInRecords = data.errorInClaims; // this.errorInRecords = data.errorInClaims;
this.isertBulkClaims(claims); this.isertBulkClaims(claims);
}, },
err => { err => {
@ -214,7 +228,7 @@ export class ClaimInsertComponent {
this.errors.splice(0, this.errors.length); this.errors.splice(0, this.errors.length);
this.subscriptions.push(this.claimService.insertBulkClaims(claims, this.properties.claimsAPIURL).subscribe( this.subscriptions.push(this.claimService.insertBulkClaims(claims, this.properties.claimsAPIURL).subscribe(
data => { data => {
this.insertedClaims = data.insertedIds; /*this.insertedClaims = data.insertedIds;
this.errorInClaims = data.errorInClaims; this.errorInClaims = data.errorInClaims;
//TODO remove - testing having errors in claims //TODO remove - testing having errors in claims
// this.insertedClaims.pop(); // this.insertedClaims.pop();
@ -233,6 +247,17 @@ export class ClaimInsertComponent {
this.errors.push(error); this.errors.push(error);
} }
this.afterclaimsInsertion(); this.afterclaimsInsertion();
*/
console.log(data)
this.claims2Insert = claims.length;
this.claimsJob = data.data;
let timerSubscription = timer(0, 10000).pipe(
map(() => {
this.getStatus(); // load data contains the http request
})
).subscribe();
this.subscriptions.push(timerSubscription);
}, },
err => { err => {
err = err && err.error?err.error:err; err = err && err.error?err.error:err;
@ -520,5 +545,31 @@ export class ClaimInsertComponent {
} }
return buttonClass + "uk-text-center "; return buttonClass + "uk-text-center ";
} }
getStatus(){
console.log("TODO status fetch")
this.subscriptions.push(this.claimService.getStatus(this.claimsJob.id, this.properties.claimsAPIURL).subscribe(data => {
console.log(data);
this.claimsJob = data.data;
if(this.claimsJob.status == "COMPLETE" || data.data.status == "ERROR"){
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();
}
}));
}
} }