From 95a87dcefd5b40f729fecf5dcd2d9f3d241b48a7 Mon Sep 17 00:00:00 2001 From: "konstantina.galouni" Date: Mon, 13 Feb 2023 19:39:08 +0200 Subject: [PATCH] [Library | data-transfer-v2]: Use new transfer API to get destinations, do the transfer, request status of transfer | Updated messages and checks for buttons. --- .../dataTransfer/transferData.component.html | 61 +++--- utils/dataTransfer/transferData.component.ts | 207 ++++++++++++------ 2 files changed, 170 insertions(+), 98 deletions(-) diff --git a/utils/dataTransfer/transferData.component.html b/utils/dataTransfer/transferData.component.html index 972da1ae..96e524a7 100644 --- a/utils/dataTransfer/transferData.component.html +++ b/utils/dataTransfer/transferData.component.html @@ -9,8 +9,8 @@ -
@@ -31,7 +31,7 @@

Available DOI URLs:

-
+
{{this.downloadElements.length}} files found:
    @@ -45,16 +45,16 @@
    - Testing:
    - https://dcache-demo.desy.de:2443 -
    - /Demonstrators/EOSC-Future/EGI/ -
    + + + + +

    Please select the Destination Storage technology:

    + [options]="destinationOptions" (valueChange)="folders = {}">

    Provide the corresponding storage destination url:

    @@ -69,7 +69,7 @@
    -
@@ -79,8 +79,9 @@
-

or browse to +

or browse to select a folder.

@@ -93,29 +94,33 @@
-
-
- - - + + +
+
+ + + +
+
+ + + +
-
-
+
-
- -
+ + + +
Transfer of ` + this.downloadElements.length + ` files to `+this.selectedDestination.description+` has began.`; @@ -237,27 +262,33 @@ export class EGIDataTransferComponent { this.message += `
` - // this.getStatus(true) + + this.cdr.detectChanges(); + HelperFunctions.scrollToId("transferAlert"); + + // this.getStatus(true) }, error => { - this.status = "errorTransfer"; - this.message = "Couldn't transfer files"; - UIkit.notification("Couldn't transfer files", { - status: 'error', - timeout: 6000, - pos: 'bottom-right' - }); + this.status = "failed"; + this.message = "Files could not be transfered."; + this.statusMessage = "danger"; + // UIkit.notification("Couldn't transfer files", { + // status: 'error', + // timeout: 6000, + // pos: 'bottom-right' + // }); } )); }, error => { this.status = "errorUser"; - this.message = "User can't be authenticated!"; - UIkit.notification("User can't be authenticated!", { - status: 'error', - timeout: 6000, - pos: 'bottom-right' - }); + this.message = "User cannot be authenticated."; + this.statusMessage = "danger"; + // UIkit.notification("User can't be authenticated!", { + // status: 'error', + // timeout: 6000, + // pos: 'bottom-right' + // }); } )); @@ -269,49 +300,82 @@ export class EGIDataTransferComponent { let headers = new HttpHeaders({'Authorization': 'Bearer '+this.accessToken}); let source = this.http.get(this.APIURL + "/transfer/" +this.jobId , {headers: headers}).pipe(delay(5000)); - this.subscriptions.push(source.pipe(repeat(3)).subscribe( - res => { - this.jobStatus = res; - this.message = ` - -
Transfer of ` + this.downloadElements.length + ` files to ` + this.selectedDestination.description+` has began.`; - /*this.message += `
-
    - `; - // TODO LATER we can call status for each file and see if the transfer has been complete - for(let element of this.downloadElements){ - // console.log(element) - // this.message += `
  • `+ element.name+ `
  • `; - this.message += `
  • `+ element.name+ `
  • `; - } - this.message += ` -
-
-
`*/ - this.message += ` - -
`; - console.log(res) - this.statusMessage = res['jobState'] + (res['reason']?(" :" + res['reason']):""); - UIkit.notification('got status! ', { - status: 'success', - timeout: 6000, - pos: 'bottom-right' - }); - + let source2 = interval(5000) // request status every 5 secs + .pipe( + startWith(2000), // first call after 2 secs + switchMap(() => this.http.get(this.APIURL + "/transfer/" +this.jobId , {headers: headers})) + ); + // this.subscriptions.push(source.pipe(repeat(3)).subscribe( + this.statusSub = source2.subscribe( + (res: any) => { + if(this.status != res.jobState) { + this.status = res.jobState; + this.jobStatus = res; + this.message = ` + +
Transfer of ` + this.downloadElements.length + ` files to ` + this.selectedDestination.description + ` has began.`; + /*this.message += `
+
    + `; + // TODO LATER we can call status for each file and see if the transfer has been complete + for(let element of this.downloadElements){ + // console.log(element) + // this.message += `
  • `+ element.name+ `
  • `; + this.message += `
  • `+ element.name+ `
  • `; + } + this.message += ` +
+
+
`*/ + this.message += ` + +
`; + this.statusMessage = "primary"; + this.statusMessage = res['jobState'] + (res['reason'] ? (" :" + res['reason']) : ""); + if(this.status == "succeeded") { + this.message = "Transfer successfully completed!"; + this.statusMessage = "success"; + this.statusSub.unsubscribe(); + // UIkit.notification('Transfer successfully completed! ', { + // status: 'success', + // timeout: 6000, + // pos: 'bottom-right' + // }); + } else if(this.status == "failed") { + this.message = "Transfer failed."; + this.statusMessage = "danger"; + this.statusSub.unsubscribe(); + // UIkit.notification('Transfer failed', { + // status: 'danger', + // timeout: 6000, + // pos: 'bottom-right' + // }); + } else if(this.status != "active") { + this.message = "Transfer completed with status: "+this.status+"."; + this.statusMessage = "warning"; + this.statusSub.unsubscribe(); + // UIkit.notification('Transfer completed with status: '+this.status, { + // status: 'warning', + // timeout: 6000, + // pos: 'bottom-right' + // }); + } + } }, error => { - this.status = "errorTransfer"; - this.message = "Couldn't get status "; - UIkit.notification("Couldn't get status", { - status: 'error', - timeout: 6000, - pos: 'bottom-right' - }); + this.status = "failed"; + this.message = "Status of the transfer could not be retrieved."; + this.statusMessage = "danger"; + this.statusSub.unsubscribe(); + // UIkit.notification("Couldn't get status", { + // status: 'error', + // timeout: 6000, + // pos: 'bottom-right' + // }); } - )); + ); } } @@ -321,7 +385,6 @@ export class EGIDataTransferComponent { let headers = new HttpHeaders({'Authorization': 'Bearer '+this.accessToken}); this.subscriptions.push(this.http.delete(this.APIURL + "/transfer/" +this.jobId , {headers: headers}).subscribe( res => { - console.log(res); this.jobStatus = res; this.statusMessage = res['jobState'] + (res['reason']?(" :" + res['reason']):""); this.jobId = null; @@ -401,4 +464,8 @@ export class EGIDataTransferComponent { return (this.destinationPath.length > 0 && this.destinationPath.match(exp1) != null) } + + validateDestinationUrl():boolean { + return (this.destinationUrl.length > 0 && StringUtils.isValidUrl(this.destinationUrl)); + } }