From 665480f3167aced8da6a10289c301e99cfd5b3bd Mon Sep 17 00:00:00 2001 From: jcomedouteau Date: Wed, 25 Oct 2023 12:04:14 +0200 Subject: [PATCH 1/3] #1920 - remove timeout logic for import and augment timeout --- shanoir-ng-front/package-lock.json | 6 ++++++ .../notifications/notifications.service.ts | 18 +++++++++--------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/shanoir-ng-front/package-lock.json b/shanoir-ng-front/package-lock.json index 99aa6ab67a..b0654525b6 100644 --- a/shanoir-ng-front/package-lock.json +++ b/shanoir-ng-front/package-lock.json @@ -21,6 +21,7 @@ "@angular/router": "^15.1.5", "@stomp/ng2-stompjs": "^7.2.0", "@types/node": "^12.11.1", + "@types/wicg-file-system-access": "^2020.9.6", "file-saver-es": "^2.0.5", "git-describe": "4.0.4", "http-status-codes": "^2.1.4", @@ -4170,6 +4171,11 @@ "@types/node": "*" } }, + "node_modules/@types/wicg-file-system-access": { + "version": "2020.9.8", + "resolved": "https://registry.npmjs.org/@types/wicg-file-system-access/-/wicg-file-system-access-2020.9.8.tgz", + "integrity": "sha512-ggMz8nOygG7d/stpH40WVaNvBwuyYLnrg5Mbyf6bmsj/8+gb6Ei4ZZ9/4PNpcPNTT8th9Q8sM8wYmWGjMWLX/A==" + }, "node_modules/@types/ws": { "version": "8.5.4", "resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.4.tgz", diff --git a/shanoir-ng-front/src/app/shared/notifications/notifications.service.ts b/shanoir-ng-front/src/app/shared/notifications/notifications.service.ts index 365a5d528d..cb6c744ee0 100644 --- a/shanoir-ng-front/src/app/shared/notifications/notifications.service.ts +++ b/shanoir-ng-front/src/app/shared/notifications/notifications.service.ts @@ -2,12 +2,12 @@ * Shanoir NG - Import, manage and share neuroimaging data * Copyright (C) 2009-2019 Inria - https://www.inria.fr/ * Contact us on https://project.inria.fr/shanoir/ - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see https://www.gnu.org/licenses/gpl-3.0.html */ @@ -23,7 +23,7 @@ import { SuperTimeout } from 'src/app/utils/super-timeout'; @Injectable() export class NotificationsService { - + public nbNew: number = 0; public nbNewError: number = 0; private tasks: Task[] = []; @@ -42,7 +42,7 @@ export class NotificationsService { readonly readInterval: number = 1000; readonly persistenceTime: number = 1800000; private freshTimeouts: SuperTimeout[] = []; - private readonly TIMEOUT: number = 30000; + private readonly TIMEOUT: number = 300000; constructor(private taskService: TaskService, private keycloakService: KeycloakService) { @@ -93,13 +93,13 @@ export class NotificationsService { this.emitTasks(); } }); - } + } updateStatusVars() { let tmpTasksInProgress = []; let tmpTasksInWait = []; for (let task of this.allTasks) { - if ((task.status == 2 || task.status == 4 || task.status == 5) && task.lastUpdate) { + if (task.eventType.startsWith("downloadDataset") && (( task.status == 2 || task.status == 4 || task.status == 5) && task.lastUpdate)) { if (Date.now() - new Date(task.lastUpdate).getTime() > this.TIMEOUT) { task.status = -1; task.message = 'timeout'; @@ -163,7 +163,7 @@ export class NotificationsService { this.refresh(); } }); - this.refresh(); + this.refresh(); }); } @@ -174,7 +174,7 @@ export class NotificationsService { pushLocalTask(task: Task) { this.createOrUpdateTask(task.clone()); } - + private createOrUpdateTask(task: Task) { this.newLocalTasksQueue = this.newLocalTasksQueue.filter(t => t.id != task.id); this.newLocalTasksQueue.push(task); @@ -219,4 +219,4 @@ export class NotificationsService { this.tasksInProgress.forEach(task => total += task.progress); return total/this.tasksInProgress.length; } -} \ No newline at end of file +} From 883727ffa3551c46688973800cd96b3333619a9c Mon Sep 17 00:00:00 2001 From: jcomedouteau Date: Wed, 25 Oct 2023 12:05:44 +0200 Subject: [PATCH 2/3] #1920 - remove package-lock.json --- shanoir-ng-front/package-lock.json | 6 ------ 1 file changed, 6 deletions(-) diff --git a/shanoir-ng-front/package-lock.json b/shanoir-ng-front/package-lock.json index b0654525b6..99aa6ab67a 100644 --- a/shanoir-ng-front/package-lock.json +++ b/shanoir-ng-front/package-lock.json @@ -21,7 +21,6 @@ "@angular/router": "^15.1.5", "@stomp/ng2-stompjs": "^7.2.0", "@types/node": "^12.11.1", - "@types/wicg-file-system-access": "^2020.9.6", "file-saver-es": "^2.0.5", "git-describe": "4.0.4", "http-status-codes": "^2.1.4", @@ -4171,11 +4170,6 @@ "@types/node": "*" } }, - "node_modules/@types/wicg-file-system-access": { - "version": "2020.9.8", - "resolved": "https://registry.npmjs.org/@types/wicg-file-system-access/-/wicg-file-system-access-2020.9.8.tgz", - "integrity": "sha512-ggMz8nOygG7d/stpH40WVaNvBwuyYLnrg5Mbyf6bmsj/8+gb6Ei4ZZ9/4PNpcPNTT8th9Q8sM8wYmWGjMWLX/A==" - }, "node_modules/@types/ws": { "version": "8.5.4", "resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.4.tgz", From e65fe4de98fea8a12f40aed6afa7051ce5c0476a Mon Sep 17 00:00:00 2001 From: jcomedouteau Date: Mon, 30 Oct 2023 10:05:11 +0100 Subject: [PATCH 3/3] #1602 - folder creation correction --- .../mass-download/mass-download.service.ts | 39 ++++++++++--------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/shanoir-ng-front/src/app/shared/mass-download/mass-download.service.ts b/shanoir-ng-front/src/app/shared/mass-download/mass-download.service.ts index 4a31b2251c..ae4740a017 100644 --- a/shanoir-ng-front/src/app/shared/mass-download/mass-download.service.ts +++ b/shanoir-ng-front/src/app/shared/mass-download/mass-download.service.ts @@ -2,17 +2,17 @@ * Shanoir NG - Import, manage and share neuroimaging data * Copyright (C) 2009-2019 Inria - https://www.inria.fr/ * Contact us on https://project.inria.fr/shanoir/ - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see https://www.gnu.org/licenses/gpl-3.0.html */ -import { HttpResponse } from '@angular/common/http'; +import {HttpClient, HttpResponse} from '@angular/common/http'; import { ComponentRef, Injectable } from '@angular/core'; import { Observable, Subject, Subscription } from 'rxjs-compat'; import { Task, TaskState, TaskStatus } from 'src/app/async-tasks/task.model'; @@ -28,6 +28,8 @@ import { SuperPromise } from 'src/app/utils/super-promise'; import { DownloadSetupAltComponent } from './download-setup-alt/download-setup-alt.component'; import { ConsoleService } from '../console/console.service'; import { formatDate } from '@angular/common'; +import {DatasetDTO} from "../../datasets/shared/dataset.dto"; +import * as AppUtils from "../../utils/app.utils"; declare var JSZip: any; @@ -157,6 +159,8 @@ export class MassDownloadService { } else { directoryHandlePromise = this.getFolderHandle(); } + let path :string = "Datasets-" + formatDate(new Date(), "yyyyMMddHHmmss", "en-US") + '/'; + return directoryHandlePromise.then(parentFolderHandle => { // ask the user's parent directory if (!task) task = this.createTask(datasetIds.length); return this.downloadQueue.waitForTurn().then(releaseQueue => { @@ -170,7 +174,7 @@ export class MassDownloadService { let promises: Promise[] = []; for (let queueIndex = 0; queueIndex < nbQueues; queueIndex++) { // build the dl queues promises.push( - this.recursiveSave(ids.shift(), format, parentFolderHandle, ids, report, task) + this.recursiveSave(ids.shift(), format, parentFolderHandle, ids, report, task, path) ); } return Promise.all(promises).then(() => { @@ -267,7 +271,9 @@ export class MassDownloadService { if (datasets.length == 0) return; return this.getFolderHandle().then(parentFolderHandle => { // ask the user's parent directory let task: Task = this.createTask(datasets.length); - if (downloadState) downloadState.status = task.status; + if (downloadState) downloadState.status = task.status; + let path :string = "Datasets-" + formatDate(new Date(), "yyyyMMddHHmmss", "en-US") + '/'; + return this.downloadQueue.waitForTurn().then(releaseQueue => { try { task.status = 2; @@ -279,7 +285,7 @@ export class MassDownloadService { let j = 0; for (let queueIndex = 0; queueIndex < nbQueues; queueIndex++) { // build the dl queues promises.push( - this.recursiveSave(ids.shift(), format, parentFolderHandle, ids, report, task, datasets) + this.recursiveSave(ids.shift(), format, parentFolderHandle, ids, report, task, path, datasets) ); } return Promise.all(promises).then(() => { @@ -324,24 +330,24 @@ export class MassDownloadService { this.notificationService.pushLocalTask(task); } - private recursiveSave(id: number, format: Format, userFolderHandle: FileSystemDirectoryHandle, remainingIds: number[], report: Report, task: Task, datasets?: Dataset[]): Promise { + private recursiveSave(id: number, format: Format, userFolderHandle: FileSystemDirectoryHandle, remainingIds: number[], report: Report, task: Task, path: string, datasets?: Dataset[]): Promise { if (!id) return Promise.resolve(); - return this.saveDataset(id, format, userFolderHandle, report, task, datasets?.find(ds => ds.id == id)).then(() => { + return this.saveDataset(id, format, userFolderHandle, report, task, path, datasets?.find(ds => ds.id == id)).then(() => { if (remainingIds.length > 0) { - return this.recursiveSave(remainingIds.shift(), format, userFolderHandle, remainingIds, report, task, datasets); + return this.recursiveSave(remainingIds.shift(), format, userFolderHandle, remainingIds, report, task, path, datasets); } else { return Promise.resolve(); } }); } - private saveDataset(id: number, format: Format, userFolderHandle: FileSystemDirectoryHandle, report: Report, task: Task, dataset?: Dataset): Promise { + private saveDataset(id: number, format: Format, userFolderHandle: FileSystemDirectoryHandle, report: Report, task: Task, rootPath: string, dataset?: Dataset): Promise { const metadataPromise: Promise = (dataset?.id == id && dataset.datasetAcquisition?.examination?.subject) ? Promise.resolve(dataset) : this.datasetService.get(id, 'lazy'); const downloadPromise: Promise> = this.datasetService.downloadToBlob(id, format); return Promise.all([metadataPromise, downloadPromise]).then(([dataset, httpResponse]) => { const blob: Blob = httpResponse.body; const filename: string = this.getFilename(httpResponse) || 'dataset_' + id; - const path: string = this.buildDatasetPath(dataset) + filename; + const path: string = this.buildDatasetPath(dataset, rootPath) + filename; // Check ERRORS file in zip var zip = new JSZip(); @@ -388,11 +394,8 @@ export class MassDownloadService { }); } - private buildDatasetPath(dataset: Dataset): string { - let currentDate = new Date(); - return "Datasets-" - + formatDate(currentDate, "yyyyMMddHHmmss", "en-US") - + '/' + private buildDatasetPath(dataset: Dataset, rootPath: string): string { + return rootPath + "/" + dataset.datasetAcquisition?.examination?.subject?.name + '_' + dataset.datasetAcquisition?.examination?.subject?.id + '/' @@ -421,7 +424,7 @@ export class MassDownloadService { } else { // if no dir to create userFolderHandle.getFileHandle(filename, { create: true }).then(fileHandler => { this.writeFile(fileHandler, content); - }); + }); } } @@ -520,7 +523,7 @@ export class MassDownloadService { private waitForEnd(modalRef: ComponentRef): Promise { let resPromise: SuperPromise = new SuperPromise(); let result: Observable = Observable.race([ - modalRef.instance.go, + modalRef.instance.go, modalRef.instance.close.map(() => 'cancel') ]); result.pipe(take(1)).subscribe(ret => {