From 0704ef1588eacde7885624206738089cf2dfc960 Mon Sep 17 00:00:00 2001 From: "aliaksei.bykau" Date: Wed, 30 Aug 2023 09:56:08 +0200 Subject: [PATCH 01/17] [DSC-1209] fixed wrong error in suggestions-page.component.ts --- .../builders/remote-data-build.service.ts | 60 ++++++++++--------- src/app/core/data/base/delete-data.ts | 47 +++++++++++++++ ...ality-assurance-suggestion-data.service.ts | 5 ++ .../suggestions.service.ts | 23 ++++++- .../suggestions-page.component.ts | 15 +++++ 5 files changed, 120 insertions(+), 30 deletions(-) diff --git a/src/app/core/cache/builders/remote-data-build.service.ts b/src/app/core/cache/builders/remote-data-build.service.ts index 8f48dd767b9..ec124ac9b03 100644 --- a/src/app/core/cache/builders/remote-data-build.service.ts +++ b/src/app/core/cache/builders/remote-data-build.service.ts @@ -1,31 +1,26 @@ -import { Injectable } from '@angular/core'; -import { - AsyncSubject, - combineLatest as observableCombineLatest, - Observable, - of as observableOf, -} from 'rxjs'; -import { map, switchMap, filter, distinctUntilKeyChanged, startWith } from 'rxjs/operators'; -import { hasValue, isEmpty, isNotEmpty, hasNoValue, isUndefined } from '../../../shared/empty.util'; -import { createSuccessfulRemoteDataObject$ } from '../../../shared/remote-data.utils'; -import { followLink, FollowLinkConfig } from '../../../shared/utils/follow-link-config.model'; -import { PaginatedList } from '../../data/paginated-list.model'; -import { RemoteData } from '../../data/remote-data'; -import { RequestService } from '../../data/request.service'; -import { ObjectCacheService } from '../object-cache.service'; -import { LinkService } from './link.service'; -import { HALLink } from '../../shared/hal-link.model'; -import { GenericConstructor } from '../../shared/generic-constructor'; -import { getClassForType } from './build-decorators'; -import { HALResource } from '../../shared/hal-resource.model'; -import { PAGINATED_LIST } from '../../data/paginated-list.resource-type'; -import { getUrlWithoutEmbedParams } from '../../index/index.selectors'; -import { getResourceTypeValueFor } from '../object-cache.reducer'; -import { hasSucceeded, isStale, RequestEntryState } from '../../data/request-entry-state.model'; -import { getRequestFromRequestHref, getRequestFromRequestUUID } from '../../shared/request.operators'; -import { RequestEntry } from '../../data/request-entry.model'; -import { ResponseState } from '../../data/response-state.model'; -import { getFirstCompletedRemoteData } from '../../shared/operators'; +import {Injectable} from '@angular/core'; +import {AsyncSubject, combineLatest as observableCombineLatest, lastValueFrom, Observable, of as observableOf,} from 'rxjs'; +import {distinctUntilKeyChanged, filter, map, startWith, switchMap} from 'rxjs/operators'; +import {hasNoValue, hasValue, isEmpty, isNotEmpty, isUndefined} from '../../../shared/empty.util'; +import {createSuccessfulRemoteDataObject$} from '../../../shared/remote-data.utils'; +import {followLink, FollowLinkConfig} from '../../../shared/utils/follow-link-config.model'; +import {PaginatedList} from '../../data/paginated-list.model'; +import {RemoteData} from '../../data/remote-data'; +import {RequestService} from '../../data/request.service'; +import {ObjectCacheService} from '../object-cache.service'; +import {LinkService} from './link.service'; +import {HALLink} from '../../shared/hal-link.model'; +import {GenericConstructor} from '../../shared/generic-constructor'; +import {getClassForType} from './build-decorators'; +import {HALResource} from '../../shared/hal-resource.model'; +import {PAGINATED_LIST} from '../../data/paginated-list.resource-type'; +import {getUrlWithoutEmbedParams} from '../../index/index.selectors'; +import {getResourceTypeValueFor} from '../object-cache.reducer'; +import {hasSucceeded, isStale, RequestEntryState} from '../../data/request-entry-state.model'; +import {getRequestFromRequestHref, getRequestFromRequestUUID} from '../../shared/request.operators'; +import {RequestEntry} from '../../data/request-entry.model'; +import {ResponseState} from '../../data/response-state.model'; +import {getFirstCompletedRemoteData} from '../../shared/operators'; @Injectable() export class RemoteDataBuildService { @@ -233,6 +228,15 @@ export class RemoteDataBuildService { ); } + async buildFromRequestUUIDAsync(requestUUID$: string | Observable, callback: (rd?: RemoteData) => Observable, ...linksToFollow: FollowLinkConfig[]): Promise> { + const response$ = this.buildFromRequestUUID(requestUUID$, ...linksToFollow); + + const callbackDone$ = new AsyncSubject(); + return await lastValueFrom(response$.pipe( + getFirstCompletedRemoteData() + )); + } + /** * Creates a {@link RemoteData} object for a rest request and its response * diff --git a/src/app/core/data/base/delete-data.ts b/src/app/core/data/base/delete-data.ts index 807d9d838e9..e7a99a41fcd 100644 --- a/src/app/core/data/base/delete-data.ts +++ b/src/app/core/data/base/delete-data.ts @@ -40,6 +40,27 @@ export interface DeleteData { * Only emits once all request related to the DSO has been invalidated. */ deleteByHref(href: string, copyVirtualMetadata?: string[]): Observable>; + + /** + * Delete an existing object on the server in async way + * @param objectId The id of the object to be removed + * @param copyVirtualMetadata (optional parameter) the identifiers of the relationship types for which the virtual + * metadata should be saved as real metadata + * @return A RemoteData observable with an empty payload, but still representing the state of the request: statusCode, + * errorMessage, timeCompleted, etc + */ + deleteAsync?(objectId: string, copyVirtualMetadata?: string[]): Observable>; + + /** + * Delete an existing object on the server in async way + * @param href The self link of the object to be removed + * @param copyVirtualMetadata (optional parameter) the identifiers of the relationship types for which the virtual + * metadata should be saved as real metadata + * @return A RemoteData observable with an empty payload, but still representing the state of the request: statusCode, + * errorMessage, timeCompleted, etc + * Only emits once all request related to the DSO has been invalidated. + */ + deleteByHrefAsync?(href: string, copyVirtualMetadata?: string[]): Promise>; } export class DeleteDataImpl extends IdentifiableDataService implements DeleteData { @@ -84,4 +105,30 @@ export class DeleteDataImpl extends IdentifiableDataS return this.rdbService.buildFromRequestUUIDAndAwait(requestId, () => this.invalidateByHref(href)); } + + deleteAsync(objectId: string, copyVirtualMetadata?: string[]): Observable> { + return this.getIDHrefObs(objectId).pipe( + switchMap((href: string) => this.deleteByHrefAsync(href, copyVirtualMetadata)), + ); + } + + deleteByHrefAsync(href: string, copyVirtualMetadata?: string[]): Promise> { + const requestId = this.requestService.generateRequestId(); + + if (copyVirtualMetadata) { + copyVirtualMetadata.forEach((id) => + href += (href.includes('?') ? '&' : '?') + + 'copyVirtualMetadata=' + + id, + ); + } + + const request = new DeleteRequest(requestId, href); + if (hasValue(this.responseMsToLive)) { + request.responseMsToLive = this.responseMsToLive; + } + this.requestService.send(request); + + return this.rdbService.buildFromRequestUUIDAsync(requestId, () => this.invalidateByHref(href)); + } } diff --git a/src/app/core/openaire/reciter-suggestions/suggestions/quality-assurance-suggestion-data.service.ts b/src/app/core/openaire/reciter-suggestions/suggestions/quality-assurance-suggestion-data.service.ts index 05373b74173..bbc518a3094 100644 --- a/src/app/core/openaire/reciter-suggestions/suggestions/quality-assurance-suggestion-data.service.ts +++ b/src/app/core/openaire/reciter-suggestions/suggestions/quality-assurance-suggestion-data.service.ts @@ -72,6 +72,11 @@ export class QualityAssuranceSuggestionDataService extends IdentifiableDataServi return this.deleteData.delete(suggestionId); } + public deleteSuggestionAsync(suggestionId: string): Observable> { + return this.deleteData.deleteAsync(suggestionId); + } + + /** * Return a Suggestion for a given user id * diff --git a/src/app/openaire/reciter-suggestions/suggestions.service.ts b/src/app/openaire/reciter-suggestions/suggestions.service.ts index fc979cd918d..76023b37dd8 100644 --- a/src/app/openaire/reciter-suggestions/suggestions.service.ts +++ b/src/app/openaire/reciter-suggestions/suggestions.service.ts @@ -1,7 +1,7 @@ import { Injectable } from '@angular/core'; import { forkJoin, Observable, of } from 'rxjs'; -import { catchError, map, mergeMap, take } from 'rxjs/operators'; +import { catchError, map, mergeMap, take, tap } from 'rxjs/operators'; import { SortDirection, SortOptions } from '../../core/cache/models/sort-options.model'; import { FindListOptions } from '../../core/data/find-list-options.model'; @@ -166,6 +166,19 @@ export class SuggestionsService { ); } + public deleteReviewedSuggestionAsync(suggestionId: string): Observable> { + return this.suggestionsDataService.deleteSuggestionAsync(suggestionId).pipe( + tap((response: RemoteData) => { + if (response.isSuccess) { + return response; + } else { + throw new Error('Can\'t delete Suggestion from the Search Target REST service'); + } + }), + take(1) + ); + } + /** * Retrieve suggestion targets for the given user * @@ -218,6 +231,12 @@ export class SuggestionsService { ); } + public notMineAsync(suggestionId): Observable> { + return this.deleteReviewedSuggestionAsync(suggestionId).pipe( + catchError((error) => of(null)) + ); + } + /** * Perform a bulk approve and import operation. * @param workspaceitemService injected dependency @@ -243,7 +262,7 @@ export class SuggestionsService { * @param suggestions the array containing the suggestions */ public notMineMultiple(suggestions: OpenaireSuggestion[]): Observable { - return forkJoin(suggestions.map((suggestion: OpenaireSuggestion) => this.notMine(suggestion.id))) + return forkJoin(suggestions.map((suggestion: OpenaireSuggestion) => this.notMineAsync(suggestion.id))) .pipe(map((results: RemoteData[]) => { return { success: results.filter((result) => result != null).length, diff --git a/src/app/suggestions-page/suggestions-page.component.ts b/src/app/suggestions-page/suggestions-page.component.ts index cde3a33d005..577b5c1c0b0 100644 --- a/src/app/suggestions-page/suggestions-page.component.ts +++ b/src/app/suggestions-page/suggestions-page.component.ts @@ -179,6 +179,21 @@ export class SuggestionsPageComponent implements OnInit { * Used to delete all selected suggestions. */ notMineAllSelected() { + // forkJoin(Object.values(this.selectedSuggestions).map(async (suggestion: OpenaireSuggestion) => { + // const response = await lastValueFrom(this.suggestionsDataService.deleteSuggestion(suggestion.id)); + // if (response.isSuccess) { + // return response; + // } else { + // throw new Error('Can\'t delete Suggestion from the Search Target REST service'); + // } + // })) + // .pipe(map((results: RemoteData[]) => { + // return { + // success: results.filter((result) => result != null).length, + // fails: results.filter((result) => result == null).length + // }; + // }), take(1)).pipe( + this.isBulkOperationPending = true; this.suggestionService.notMineMultiple(Object.values(this.selectedSuggestions)).pipe( tap((results: SuggestionBulkResult) => { From e9ac2f53fe8edd78b1986af0a6beb4d7d7593df8 Mon Sep 17 00:00:00 2001 From: "aliaksei.bykau" Date: Wed, 30 Aug 2023 15:25:06 +0200 Subject: [PATCH 02/17] [DSC-1209] comment deleted --- .../suggestions-page.component.ts | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/src/app/suggestions-page/suggestions-page.component.ts b/src/app/suggestions-page/suggestions-page.component.ts index 577b5c1c0b0..cde3a33d005 100644 --- a/src/app/suggestions-page/suggestions-page.component.ts +++ b/src/app/suggestions-page/suggestions-page.component.ts @@ -179,21 +179,6 @@ export class SuggestionsPageComponent implements OnInit { * Used to delete all selected suggestions. */ notMineAllSelected() { - // forkJoin(Object.values(this.selectedSuggestions).map(async (suggestion: OpenaireSuggestion) => { - // const response = await lastValueFrom(this.suggestionsDataService.deleteSuggestion(suggestion.id)); - // if (response.isSuccess) { - // return response; - // } else { - // throw new Error('Can\'t delete Suggestion from the Search Target REST service'); - // } - // })) - // .pipe(map((results: RemoteData[]) => { - // return { - // success: results.filter((result) => result != null).length, - // fails: results.filter((result) => result == null).length - // }; - // }), take(1)).pipe( - this.isBulkOperationPending = true; this.suggestionService.notMineMultiple(Object.values(this.selectedSuggestions)).pipe( tap((results: SuggestionBulkResult) => { From 75ebea5d04ff8c3bab1b540dafe4f075d11c6a48 Mon Sep 17 00:00:00 2001 From: Alisa Ismailati Date: Tue, 29 Aug 2023 11:46:10 +0200 Subject: [PATCH 03/17] [DSC-1224][CST-11640] Added download button --- .../metadata-registry/metadata-registry.component.html | 10 ++++++++++ src/assets/i18n/en.json5 | 3 ++- src/assets/i18n/it.json5 | 5 ++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/app/admin/admin-registries/metadata-registry/metadata-registry.component.html b/src/app/admin/admin-registries/metadata-registry/metadata-registry.component.html index 771f18ba4b5..3078a10eaa3 100644 --- a/src/app/admin/admin-registries/metadata-registry/metadata-registry.component.html +++ b/src/app/admin/admin-registries/metadata-registry/metadata-registry.component.html @@ -23,6 +23,11 @@