From 5c345d8ff79fb821fdc7236896cde43900b0a4d4 Mon Sep 17 00:00:00 2001 From: argirok Date: Thu, 3 Aug 2023 12:45:39 +0300 Subject: [PATCH] show status also for direct index records job on reload keep job ids and continue show progres until they finish change get auth options method --- claims/claim-utils/service/claims.service.ts | 53 +----- claims/claimsByToken/claimsByToken.service.ts | 18 +-- .../insertClaim/insertClaim.component.ts | 153 ++++++++++++------ claims/linking/linkingGeneric.component.ts | 5 + .../selected/metadataPreview.component.html | 8 + services/servicesUtils/customOptions.class.ts | 9 +- 6 files changed, 122 insertions(+), 124 deletions(-) diff --git a/claims/claim-utils/service/claims.service.ts b/claims/claim-utils/service/claims.service.ts index 26a3d4d3..d7d46218 100644 --- a/claims/claim-utils/service/claims.service.ts +++ b/claims/claim-utils/service/claims.service.ts @@ -10,7 +10,7 @@ export class ClaimsService { } private getClaimRequest(size : number, page : number, url :string, fromCache:boolean):any { - return this.http.get(url, CustomOptions.getAuthOptions()); + return this.http.get(url, CustomOptions.getAuthOptionsWithBody()); } getClaims( size : number, page : number, keyword:string, sortby: string, descending: boolean, types: string, apiUrl:string):any { let url = apiUrl +"claims"+"?offset="+(size*(page-1) + "&limit="+size)+"&keyword="+keyword+"&sortby="+sortby+"&descending="+descending+(types.length>0?"&"+types:types); @@ -44,10 +44,7 @@ export class ClaimsService { deleteClaimById(claimId:string , apiUrl:string):any{ //console.warn('Trying to delete claim with id : '+claimId); let url = apiUrl +"claims/"+claimId; - // let headers = new Headers({ 'Content-Type': 'application/json' }); - // let options = new RequestOptions({ headers: headers }); return this.http.delete( url, CustomOptions.getAuthOptionsWithBody())//.map(request => request.json()) - // .do(request => console.info("After delete" )) .pipe(catchError(this.handleError)); } @@ -61,10 +58,7 @@ export class ClaimsService { } url= apiUrl +"claims/bulk?"+url; - // let headers = new Headers({ 'Content-Type': 'application/json' }); - // let options = new RequestOptions({ headers: headers }); - return this.http.delete( url, CustomOptions.getAuthOptions())//.map(request => request.json()) - // .do(request => console.info("After delete" )) + return this.http.delete( url, CustomOptions.getAuthOptionsWithBody())//.map(request => request.json()) .pipe(catchError(this.handleError)); } @@ -72,37 +66,16 @@ export class ClaimsService { // console.warn('Trying toinsert claims : '+claims); let url = apiUrl +"claims/bulk"; let body = JSON.stringify( claims ); - //console.warn('Json body: : '+body); - // let headers = new Headers({ 'Content-Type': 'application/json' }); - // let options = new RequestOptions({ headers: headers }); return this.http.post(url, body, CustomOptions.getAuthOptionsWithBody()) - //.map(res => res.json()) - //.do(request => console.info("Insert Response:"+request.status) ) .pipe(catchError(this.handleError)); } - insertClaim(claim, apiUrl:string):any{ - //console.warn('Trying toinsert claim : '+claim); - let url = apiUrl +"claims"; - let body = JSON.stringify( claim ); - // let headers = new Headers({ 'Content-Type': 'application/json' }); - // let options = new RequestOptions({ headers: headers }); - return this.http.post(url, body, CustomOptions.getAuthOptionsWithBody()) - //.map(res => res.json()) - //.do(request => console.info("Insert Response:"+request.status) ) - .pipe(catchError(this.handleError)); - } insertDirectRecords(records, apiUrl:string):any{ //console.warn('Trying to feedrecords : '+records); let url = apiUrl +"feed/bulk"; let body = JSON.stringify( records ); - //console.warn('Json body: : '+body); - // let headers = new Headers({ 'Content-Type': 'application/json' }); - // let options = new RequestOptions({ headers: headers }); return this.http.post(url, body, CustomOptions.getAuthOptionsWithBody()) - //.map(res => res.json()) - //.do(request => console.info("Insert Response:"+request) ) .pipe(catchError(this.handleError)); } @@ -110,9 +83,7 @@ export class ClaimsService { let url = apiUrl +"jobStatus/" + jobId; - return this.http.get(url,CustomOptions.getAuthOptions()) - //.map(res => res.json()) - //.do(request => console.info("Insert Response:"+request) ) + return this.http.get(url,CustomOptions.getAuthOptionsWithBody()) .pipe(catchError(this.handleError)); } @@ -123,22 +94,4 @@ export class ClaimsService { return observableThrowError(error || 'Server error'); } - // getClaim(id:string, apiUrl:string):any { - // let url = apiUrl+"claims/"+id; - // return new Promise((resolve, reject) => { - // this.http.get(url) - // //.map(res => res.json()) - // .subscribe( - // data => { - // resolve(data['data']); - // }, - // err => { - // reject(err); - // } - // ) - // ; - // }); - // } - - } diff --git a/claims/claimsByToken/claimsByToken.service.ts b/claims/claimsByToken/claimsByToken.service.ts index 4414065e..21b882da 100644 --- a/claims/claimsByToken/claimsByToken.service.ts +++ b/claims/claimsByToken/claimsByToken.service.ts @@ -18,26 +18,12 @@ export class ClaimsByTokenService { let key = url; - return this.http.get(url, CustomOptions.getAuthOptions()); - //.map(res => res.text()) - //.map(request => request.json()); + return this.http.get(url, CustomOptions.getAuthOptionsWithBody()); + } -/* - getClaims(email: string, token: string, user_token: string):any { - let url = OpenaireProperties.getClaimsAPIURL(); // What else? - let body = JSON.stringify( {"email": email, "token": token} ); - console.warn('Json body: : '+body); - let headers = new Headers({ 'Content-Type': 'application/json' }); - let options = new RequestOptions({ headers: headers }); - return this.http.post(url, body, options) - .map(res => res.json()) - .do(request => console.info("Insert Response:"+request.status) ) - .catch(this.handleError); - } -*/ updateClaimsCuration( selectedRight: Set, selectedWrong: Set, apiURL:string) { let url = apiURL + "curate/bulk"; diff --git a/claims/linking/insertClaim/insertClaim.component.ts b/claims/linking/insertClaim/insertClaim.component.ts index 2d1a276f..068f033c 100644 --- a/claims/linking/insertClaim/insertClaim.component.ts +++ b/claims/linking/insertClaim/insertClaim.component.ts @@ -37,8 +37,9 @@ import {map} from "rxjs/operators";
Initiating process....
-{{claimsJob.insertedIds.length}} out of {{claims2Insert}} links created.
-
{{feedRecordsJob.length}} records added in the index...
+ {{claimsJob.insertedIds.length}} out of {{claims2Insert}} links created. +
+ {{feedRecordsJob.insertedIds.length}} out of {{records2Insert}} records added in the index...
Please don't close the window, process is ongoing...
@@ -72,6 +73,32 @@ export class ClaimInsertComponent { this.subscriptions.push(this.route.queryParams.subscribe(params => { this.params = params; })); + 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; + } + } + } params = {}; @@ -99,14 +126,12 @@ export class ClaimInsertComponent { public claimsJob; public feedRecordsJob; public claims2Insert; + public records2Insert public insert() { this.confirmOpen(); } saveAndNavigate(){ - localStorage.setItem(this.localStoragePrefix + "results", JSON.stringify(this.results)); - if (this.sources != null) { - localStorage.setItem(this.localStoragePrefix + "sources", JSON.stringify(this.sources)); - } + this.saveLocalStorage(); this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, @@ -191,9 +216,12 @@ export class ClaimInsertComponent { //first call direct index service - when call is done (success or error) call isertBulkClaims method to insert claims in DB // console.log("directclaims"); // console.log(directclaims); - 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( data => { + this.feedRecordsJob = data.data; + this.records2Insert = directclaims.length; + console.log(data); // this.insertedRecords = data.insertedIds; // // this.errorInRecords = data.errorInClaims; @@ -204,12 +232,12 @@ export class ClaimInsertComponent { if (err.code && err.code == 403) { this.saveAndNavigate(); } - if (err.insertedIds && err.insertedIds.length > 0) { + /* if (err.insertedIds && err.insertedIds.length > 0) { this.insertedRecords = err.insertedIds; } if (err.errorInClaims && err.errorInClaims.length > 0) { this.errorInRecords = err.errorInClaims; - } + }*/ this.isertBulkClaims(claims); ClaimInsertComponent.handleError("Error inserting direct records: " + JSON.stringify(directclaims), err); @@ -223,35 +251,12 @@ export class ClaimInsertComponent { } private isertBulkClaims(claims: ClaimRecord2Insert[]) { - console.log("claims"); - console.log(claims); this.errors.splice(0, this.errors.length); this.subscriptions.push(this.claimService.insertBulkClaims(claims, this.properties.claimsAPIURL).subscribe( data => { - /*this.insertedClaims = data.insertedIds; - this.errorInClaims = data.errorInClaims; - //TODO remove - testing having errors in claims - // this.insertedClaims.pop(); - // this.insertedClaims.pop(); - // this.errorInClaims.push(claims[1]); - // this.insertedClaims.splice(0,this.insertedClaims.length); - // this.errorInClaims = claims; - //remove till here - - if (claims.length != 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(); - - */ - console.log(data) this.claims2Insert = claims.length; this.claimsJob = data.data; + this.saveLocalStorage(); let timerSubscription = timer(0, 10000).pipe( map(() => { this.getStatus(); // load data contains the http request @@ -360,13 +365,16 @@ export class ClaimInsertComponent { } private afterclaimsInsertion() { - - this.loading.close(); this.claiming = false; + this.loading.close(); + if (this.errorInClaims.length == 0 && this.insertedClaims.length > 0) { localStorage.removeItem(this.localStoragePrefix + "sources"); localStorage.removeItem(this.localStoragePrefix + "results"); + localStorage.removeItem(this.localStoragePrefix + "claimsJob"); + localStorage.removeItem(this.localStoragePrefix + "feedRecordsJob"); + this._router.navigate(['/myclaims'], {queryParams: this.params}); } } @@ -547,29 +555,72 @@ export class ClaimInsertComponent { } 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) { + 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 => { + console.log("feed", data); + this.feedRecordsJob = data.data; + if (this.feedRecordsJob.status == "COMPLETE" || data.data.status == "ERROR") { + this.insertedRecords = this.feedRecordsJob.insertedIds; + this.errorInRecords = this.feedRecordsJob.errorInClaims; + } + }, err => { let error: ClaimsErrorMessage = new ClaimsErrorMessage(); - error.type = "claimServiceFail2Insert"; - error.inserted = this.insertedClaims.length; - error.failed = this.errorInClaims.length; + error.type = "jobError"; this.createErrorMessagesPerEntity((this.insertedClaims.length == 0)); this.errors.push(error); + this.afterclaimsInsertion(); + this.feedRecordsJob = null; + localStorage.removeItem(this.localStoragePrefix + "feedRecordsJob"); } - this.afterclaimsInsertion(); + + )); + } + if(this.claimsJob) { + this.subscriptions.push(this.claimService.getStatus(this.claimsJob.id, this.properties.claimsAPIURL).subscribe(data => { + console.log("claim", data); + this.claimsJob = data.data; + if (this.claimsJob.status == "COMPLETE" || data.data.status == "ERROR" && (!(this.feedRecordsJob.status == "COMPLETE" || data.data.status == "ERROR")) || !this.feedRecordsJob) { + 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(); - } + } + }, 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)); + } } } diff --git a/claims/linking/linkingGeneric.component.ts b/claims/linking/linkingGeneric.component.ts index 524f3566..31efc1b5 100644 --- a/claims/linking/linkingGeneric.component.ts +++ b/claims/linking/linkingGeneric.component.ts @@ -94,6 +94,11 @@ export class LinkingGenericComponent { if(localStorage.getItem(this.localStoragePrefix + "sources")){ this.sources = JSON.parse(localStorage.getItem(this.localStoragePrefix + "sources")); } + if(localStorage.getItem(this.localStoragePrefix + "claimsJob")){ + let job = JSON.parse(localStorage.getItem(this.localStoragePrefix + "claimsJob")); + if(job.status != "COMPLETE"){ + this.showOptions.show = 'claim'; } + } } } diff --git a/claims/linking/selected/metadataPreview.component.html b/claims/linking/selected/metadataPreview.component.html index 2a8f38c3..a0723118 100644 --- a/claims/linking/selected/metadataPreview.component.html +++ b/claims/linking/selected/metadataPreview.component.html @@ -250,6 +250,14 @@ None of the links saved. +
+ +
+ The saving status of your links can't be fetched. Please check your links or start over. +
+ Manage your links here +
+