CST-12174 Ldn services are now retrieved with the remotadata object

This commit is contained in:
Mattia Vianelli
2023-10-11 15:35:28 +02:00
parent 9216073b5b
commit 8de0e76b72
7 changed files with 66 additions and 140 deletions

View File

@@ -24,25 +24,45 @@ import { hasValue } from '../../../shared/empty.util';
import { LdnService } from '../ldn-services-model/ldn-services.model'; import { LdnService } from '../ldn-services-model/ldn-services.model';
import { LdnServiceConstraint } from '../ldn-services-model/ldn-service-constraint.model'; import { LdnServiceConstraint } from '../ldn-services-model/ldn-service-constraint.model';
import { PatchData, PatchDataImpl } from '../../../core/data/base/patch-data';
import { ChangeAnalyzer } from '../../../core/data/change-analyzer';
import { Operation } from 'fast-json-patch';
import { RestRequestMethod } from 'src/app/core/data/rest-request-method';
@Injectable() @Injectable()
@dataService(LDN_SERVICE) @dataService(LDN_SERVICE)
export class LdnServicesService extends IdentifiableDataService<LdnService> implements FindAllData<LdnService>, DeleteData<LdnService> { export class LdnServicesService extends IdentifiableDataService<LdnService> implements FindAllData<LdnService>, DeleteData<LdnService>, PatchData<LdnService> {
private findAllData: FindAllDataImpl<LdnService>; // Corrected the type private findAllData: FindAllDataImpl<LdnService>;
private deleteData: DeleteDataImpl<LdnService>; // Corrected the type private deleteData: DeleteDataImpl<LdnService>;
private patchData: PatchDataImpl<LdnService>;
private comparator: ChangeAnalyzer<LdnService>;
constructor( constructor(
protected requestService: RequestService, protected requestService: RequestService,
protected rdbService: RemoteDataBuildService, protected rdbService: RemoteDataBuildService,
protected objectCache: ObjectCacheService, protected objectCache: ObjectCacheService,
protected halService: HALEndpointService, protected halService: HALEndpointService,
protected notificationsService: NotificationsService, protected notificationsService: NotificationsService,
) { ) {
super('ldnservices', requestService, rdbService, objectCache, halService); super('ldnservices', requestService, rdbService, objectCache, halService);
this.findAllData = new FindAllDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, this.responseMsToLive); this.findAllData = new FindAllDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, this.responseMsToLive);
this.deleteData = new DeleteDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, notificationsService, this.responseMsToLive, this.constructIdEndpoint); this.deleteData = new DeleteDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, notificationsService, this.responseMsToLive, this.constructIdEndpoint);
} this.patchData = new PatchDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, this.comparator, this.responseMsToLive, this.constructIdEndpoint);
}
patch(object: LdnService, operations: Operation[]): Observable<RemoteData<LdnService>> {
throw new Error('Method not implemented.');
}
update(object: LdnService): Observable<RemoteData<LdnService>> {
throw new Error('Method not implemented.');
}
commitUpdates(method?: RestRequestMethod): void {
throw new Error('Method not implemented.');
}
createPatchFromCache(object: LdnService): Observable<Operation[]> {
throw new Error('Method not implemented.');
}
findAll(options?: FindListOptions, useCachedVersionIfAvailable?: boolean, reRequestOnStale?: boolean, ...linksToFollow: FollowLinkConfig<LdnService>[]): Observable<RemoteData<PaginatedList<LdnService>>> { findAll(options?: FindListOptions, useCachedVersionIfAvailable?: boolean, reRequestOnStale?: boolean, ...linksToFollow: FollowLinkConfig<LdnService>[]): Observable<RemoteData<PaginatedList<LdnService>>> {
return this.findAllData.findAll(options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow); return this.findAllData.findAll(options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);

View File

@@ -23,7 +23,7 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr *ngFor="let ldnService of servicesData"> <tr *ngFor="let ldnService of (ldnServicesRD$| async)?.payload?.page">
<td>{{ ldnService.name }}</td> <td>{{ ldnService.name }}</td>
<td>{{ ldnService.description }}</td> <td>{{ ldnService.description }}</td>
<td> <td>

View File

@@ -12,6 +12,7 @@ import { PaginationService } from 'src/app/core/pagination/pagination.service';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { hasValue } from '../../../shared/empty.util'; import { hasValue } from '../../../shared/empty.util';
import { HttpClient } from '@angular/common/http'; import { HttpClient } from '@angular/common/http';
import { getFirstCompletedRemoteData } from "../../../core/shared/operators";
@Component({ @Component({
selector: 'ds-ldn-services-directory', selector: 'ds-ldn-services-directory',
templateUrl: './ldn-services-directory.component.html', templateUrl: './ldn-services-directory.component.html',
@@ -33,8 +34,12 @@ export class LdnServicesOverviewComponent implements OnInit, OnDestroy {
isProcessingSub: Subscription; isProcessingSub: Subscription;
private modalRef: any; private modalRef: any;
constructor( constructor(
protected processLdnService: LdnServicesService, protected processLdnService: LdnServicesService,
private ldnServicesService: LdnServicesService,
protected paginationService: PaginationService, protected paginationService: PaginationService,
protected modalService: NgbModal, protected modalService: NgbModal,
public ldnDirectoryService: LdnDirectoryService, public ldnDirectoryService: LdnDirectoryService,
@@ -44,9 +49,9 @@ export class LdnServicesOverviewComponent implements OnInit, OnDestroy {
} }
ngOnInit(): void { ngOnInit(): void {
/*this.ldnDirectoryService.listLdnServices();*/ this.setLdnServices2();
this.findAllServices();
this.setLdnServices(); this.setLdnServices();
/*this.ldnDirectoryService.listLdnServices();*/
/*this.ldnServicesRD$.subscribe(data => { /*this.ldnServicesRD$.subscribe(data => {
console.log('searchByLdnUrl()', data); console.log('searchByLdnUrl()', data);
});*/ });*/
@@ -62,10 +67,22 @@ export class LdnServicesOverviewComponent implements OnInit, OnDestroy {
} }
setLdnServices() { setLdnServices() {
this.ldnServicesService.findAll().pipe(getFirstCompletedRemoteData()).subscribe((remoteData) => {
if (remoteData.hasSucceeded) {
const ldnservices = remoteData.payload.page;
console.log(ldnservices);
} else {
console.error('Error fetching LDN services:', remoteData.errorMessage);
}
});
}
setLdnServices2() {
this.ldnServicesRD$ = this.paginationService.getFindListOptions(this.pageConfig.id, this.config).pipe( this.ldnServicesRD$ = this.paginationService.getFindListOptions(this.pageConfig.id, this.config).pipe(
switchMap((config) => this.processLdnService.findAll(config, true, false)) switchMap((config) => this.ldnServicesService.findAll(config, true, false))
); );
console.log();
} }
ngOnDestroy(): void { ngOnDestroy(): void {

View File

@@ -6,4 +6,4 @@
*/ */
import { ResourceType } from '../../../core/shared/resource-type'; import { ResourceType } from '../../../core/shared/resource-type';
export const LDN_SERVICE = new ResourceType('ldnservices'); export const LDN_SERVICE = new ResourceType('ldnservice');

View File

@@ -26,6 +26,9 @@ export class LdnService extends CacheableObject {
@autoserialize @autoserialize
url: string; url: string;
@autoserialize
enabled: boolean;
@autoserialize @autoserialize
ldnUrl: string; ldnUrl: string;

View File

@@ -1,117 +0,0 @@
import { Injectable } from '@angular/core';
import { BehaviorSubject, count, from } from 'rxjs';
import { LdnServicesService } from '../ldn-services-data/ldn-services-data.service';
import { NotificationsService } from '../../../shared/notifications/notifications.service';
import { TranslateService } from '@ngx-translate/core';
import { isNotEmpty } from '../../../shared/empty.util';
import { concatMap, filter, tap } from 'rxjs/operators';
import { getFirstCompletedRemoteData } from '../../../core/shared/operators';
import { RemoteData } from '../../../core/data/remote-data';
import { LdnService } from '../ldn-services-model/ldn-services.model';
@Injectable({
providedIn: 'root'
})
/**
* Service to facilitate removing ldn services in bulk.
*/
export class LdnServicesBulkDeleteService {
/**
* Array to track the services to be deleted
*/
ldnServicesToDelete: string[] = [];
/**
* Behavior subject to track whether the delete is processing
* @protected
*/
protected isProcessingBehaviorSubject: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
constructor(
protected processLdnService: LdnServicesService,
protected notificationsService: NotificationsService,
protected translateService: TranslateService
) {
}
/**
* Add or remove a process id to/from the list
* If the id is already present it will be removed, otherwise it will be added.
*
* @param notifyServiceName - The process id to add or remove
*/
toggleDelete(notifyServiceName: string) {
if (this.isToBeDeleted(notifyServiceName)) {
this.ldnServicesToDelete.splice(this.ldnServicesToDelete.indexOf(notifyServiceName), 1);
} else {
this.ldnServicesToDelete.push(notifyServiceName);
}
}
/**
* Checks if the provided service id is present in the to be deleted list
* @param notifyServiceName
*/
isToBeDeleted(notifyServiceName: string) {
return this.ldnServicesToDelete.includes(notifyServiceName);
}
/**
* Clear the list of services to be deleted
*/
clearAllServices() {
this.ldnServicesToDelete.splice(0);
}
/**
* Get the amount of processes selected for deletion
*/
getAmountOfSelectedServices() {
return this.ldnServicesToDelete.length;
}
/**
* Returns a behavior subject to indicate whether the bulk delete is processing
*/
isProcessing$() {
return this.isProcessingBehaviorSubject;
}
/**
* Returns whether there currently are values selected for deletion
*/
hasSelected(): boolean {
return isNotEmpty(this.ldnServicesToDelete);
}
/**
* Delete all selected processes one by one
* When the deletion for a process fails, an error notification will be shown with the process id,
* but it will continue deleting the other processes.
* At the end it will show a notification stating the amount of successful deletes
* The successfully deleted processes will be removed from the list of selected values, the failed ones will be retained.
*/
deleteSelectedLdnServices() {
this.isProcessingBehaviorSubject.next(true);
from([...this.ldnServicesToDelete]).pipe(
concatMap((notifyServiceName) => {
return this.processLdnService.delete(notifyServiceName).pipe(
getFirstCompletedRemoteData(),
tap((rd: RemoteData<LdnService>) => {
if (rd.hasFailed) {
this.notificationsService.error(this.translateService.get('process.bulk.delete.error.head'), this.translateService.get('process.bulk.delete.error.body', {processId: notifyServiceName}));
} else {
this.toggleDelete(notifyServiceName);
}
})
);
}),
filter((rd: RemoteData<LdnService>) => rd.hasSucceeded),
count(),
).subscribe((value) => {
this.notificationsService.success(this.translateService.get('process.bulk.delete.success', {count: value}));
this.isProcessingBehaviorSubject.next(false);
});
}
}

View File

@@ -188,6 +188,7 @@ import { BulkAccessConditionOptions } from './config/models/bulk-access-conditio
import { SuggestionTarget } from './suggestion-notifications/reciter-suggestions/models/suggestion-target.model'; import { SuggestionTarget } from './suggestion-notifications/reciter-suggestions/models/suggestion-target.model';
import { SuggestionSource } from './suggestion-notifications/reciter-suggestions/models/suggestion-source.model'; import { SuggestionSource } from './suggestion-notifications/reciter-suggestions/models/suggestion-source.model';
import { LdnServicesService } from '../admin/admin-ldn-services/ldn-services-data/ldn-services-data.service'; import { LdnServicesService } from '../admin/admin-ldn-services/ldn-services-data/ldn-services-data.service';
import { LdnService } from '../admin/admin-ldn-services/ldn-services-model/ldn-services.model';
/** /**
* When not in production, endpoint responses can be mocked for testing purposes * When not in production, endpoint responses can be mocked for testing purposes
@@ -392,7 +393,9 @@ export const models =
ItemRequest, ItemRequest,
BulkAccessConditionOptions, BulkAccessConditionOptions,
SuggestionTarget, SuggestionTarget,
SuggestionSource SuggestionSource,
LdnService
]; ];
@NgModule({ @NgModule({