[DURACOM-234] Remove assertions on isResponsePending in favour of remote data operators

This commit is contained in:
Giuseppe Digilio
2024-04-02 18:54:00 +02:00
parent b49d883e0b
commit 660cf7e4dd
3 changed files with 25 additions and 26 deletions

View File

@@ -28,7 +28,10 @@ import { Community } from '../shared/community.model';
import { ContentSource } from '../shared/content-source.model'; import { ContentSource } from '../shared/content-source.model';
import { HALEndpointService } from '../shared/hal-endpoint.service'; import { HALEndpointService } from '../shared/hal-endpoint.service';
import { Item } from '../shared/item.model'; import { Item } from '../shared/item.model';
import { getFirstCompletedRemoteData } from '../shared/operators'; import {
getAllCompletedRemoteData,
getFirstCompletedRemoteData,
} from '../shared/operators';
import { BitstreamDataService } from './bitstream-data.service'; import { BitstreamDataService } from './bitstream-data.service';
import { ComColDataService } from './comcol-data.service'; import { ComColDataService } from './comcol-data.service';
import { CommunityDataService } from './community-data.service'; import { CommunityDataService } from './community-data.service';
@@ -84,7 +87,8 @@ export class CollectionDataService extends ComColDataService<Collection> {
}); });
return this.searchBy(searchHref, options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow).pipe( return this.searchBy(searchHref, options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow).pipe(
filter((collections: RemoteData<PaginatedList<Collection>>) => !collections.isResponsePending)); getAllCompletedRemoteData(),
);
} }
/** /**
@@ -114,7 +118,8 @@ export class CollectionDataService extends ComColDataService<Collection> {
}); });
return this.searchBy(searchHref, options, true, reRequestOnStale, ...linksToFollow).pipe( return this.searchBy(searchHref, options, true, reRequestOnStale, ...linksToFollow).pipe(
filter((collections: RemoteData<PaginatedList<Collection>>) => !collections.isResponsePending)); getAllCompletedRemoteData(),
);
} }
/** /**
@@ -138,7 +143,8 @@ export class CollectionDataService extends ComColDataService<Collection> {
}); });
return this.searchBy(searchHref, options, reRequestOnStale).pipe( return this.searchBy(searchHref, options, reRequestOnStale).pipe(
filter((collections: RemoteData<PaginatedList<Collection>>) => !collections.isResponsePending)); getAllCompletedRemoteData(),
);
} }
/** /**
* Get all collections the user is authorized to submit to, by community and has the metadata * Get all collections the user is authorized to submit to, by community and has the metadata
@@ -169,7 +175,8 @@ export class CollectionDataService extends ComColDataService<Collection> {
}); });
return this.searchBy(searchHref, options, true, reRequestOnStale, ...linksToFollow).pipe( return this.searchBy(searchHref, options, true, reRequestOnStale, ...linksToFollow).pipe(
filter((collections: RemoteData<PaginatedList<Collection>>) => !collections.isResponsePending)); getAllCompletedRemoteData(),
);
} }
/** /**
@@ -184,9 +191,8 @@ export class CollectionDataService extends ComColDataService<Collection> {
options.elementsPerPage = 1; options.elementsPerPage = 1;
return this.searchBy(searchHref, options).pipe( return this.searchBy(searchHref, options).pipe(
filter((collections: RemoteData<PaginatedList<Collection>>) => !collections.isResponsePending), getFirstCompletedRemoteData(),
take(1), map((collections: RemoteData<PaginatedList<Collection>>) => collections?.payload?.totalElements > 0),
map((collections: RemoteData<PaginatedList<Collection>>) => collections.payload.totalElements > 0),
); );
} }

View File

@@ -1,7 +1,6 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { import {
filter,
map, map,
switchMap, switchMap,
take, take,
@@ -14,6 +13,7 @@ import { HALEndpointService } from '../shared/hal-endpoint.service';
import { ItemType } from '../shared/item-relationships/item-type.model'; import { ItemType } from '../shared/item-relationships/item-type.model';
import { RelationshipType } from '../shared/item-relationships/relationship-type.model'; import { RelationshipType } from '../shared/item-relationships/relationship-type.model';
import { import {
getAllCompletedRemoteData,
getFirstSucceededRemoteData, getFirstSucceededRemoteData,
getRemoteDataPayload, getRemoteDataPayload,
} from '../shared/operators'; } from '../shared/operators';
@@ -89,8 +89,7 @@ export class EntityTypeDataService extends BaseDataService<ItemType> implements
getAllAuthorizedRelationshipType(options: FindListOptions = {}): Observable<RemoteData<PaginatedList<ItemType>>> { getAllAuthorizedRelationshipType(options: FindListOptions = {}): Observable<RemoteData<PaginatedList<ItemType>>> {
const searchHref = 'findAllByAuthorizedCollection'; const searchHref = 'findAllByAuthorizedCollection';
return this.searchBy(searchHref, options).pipe( return this.searchBy(searchHref, options).pipe(getAllCompletedRemoteData());
filter((type: RemoteData<PaginatedList<ItemType>>) => !type.isResponsePending));
} }
/** /**
@@ -123,8 +122,7 @@ export class EntityTypeDataService extends BaseDataService<ItemType> implements
getAllAuthorizedRelationshipTypeImport(options: FindListOptions = {}): Observable<RemoteData<PaginatedList<ItemType>>> { getAllAuthorizedRelationshipTypeImport(options: FindListOptions = {}): Observable<RemoteData<PaginatedList<ItemType>>> {
const searchHref = 'findAllByAuthorizedExternalSource'; const searchHref = 'findAllByAuthorizedExternalSource';
return this.searchBy(searchHref, options).pipe( return this.searchBy(searchHref, options).pipe(getAllCompletedRemoteData());
filter((type: RemoteData<PaginatedList<ItemType>>) => !type.isResponsePending));
} }
/** /**
@@ -136,15 +134,8 @@ export class EntityTypeDataService extends BaseDataService<ItemType> implements
currentPage: 1, currentPage: 1,
}; };
return this.getAllAuthorizedRelationshipTypeImport(findListOptions).pipe( return this.getAllAuthorizedRelationshipTypeImport(findListOptions).pipe(
map((result: RemoteData<PaginatedList<ItemType>>) => { take(1),
let output: boolean; map((result: RemoteData<PaginatedList<ItemType>>) => result?.payload?.totalElements > 1),
if (result.payload) {
output = ( result.payload.page.length > 1 );
} else {
output = false;
}
return output;
}),
); );
} }

View File

@@ -7,13 +7,13 @@ import {
Input, Input,
OnInit, OnInit,
} from '@angular/core'; } from '@angular/core';
import { find } from 'rxjs/operators';
import { DSONameService } from '../../../../core/breadcrumbs/dso-name.service'; import { DSONameService } from '../../../../core/breadcrumbs/dso-name.service';
import { RemoteData } from '../../../../core/data/remote-data'; import { RemoteData } from '../../../../core/data/remote-data';
import { GroupDataService } from '../../../../core/eperson/group-data.service'; import { GroupDataService } from '../../../../core/eperson/group-data.service';
import { Group } from '../../../../core/eperson/models/group.model'; import { Group } from '../../../../core/eperson/models/group.model';
import { ResourcePolicy } from '../../../../core/resource-policy/models/resource-policy.model'; import { ResourcePolicy } from '../../../../core/resource-policy/models/resource-policy.model';
import { getFirstCompletedRemoteData } from '../../../../core/shared/operators';
import { isEmpty } from '../../../../shared/empty.util'; import { isEmpty } from '../../../../shared/empty.util';
/** /**
@@ -55,13 +55,15 @@ export class SubmissionSectionUploadAccessConditionsComponent implements OnInit
this.accessConditions.forEach((accessCondition: ResourcePolicy) => { this.accessConditions.forEach((accessCondition: ResourcePolicy) => {
if (isEmpty(accessCondition.name)) { if (isEmpty(accessCondition.name)) {
this.groupService.findByHref(accessCondition._links.group.href).pipe( this.groupService.findByHref(accessCondition._links.group.href).pipe(
find((rd: RemoteData<Group>) => !rd.isResponsePending && rd.hasSucceeded)) getFirstCompletedRemoteData(),
.subscribe((rd: RemoteData<Group>) => { ).subscribe((rd: RemoteData<Group>) => {
if (rd.hasSucceeded) {
const group: Group = rd.payload; const group: Group = rd.payload;
const accessConditionEntry = Object.assign({}, accessCondition); const accessConditionEntry = Object.assign({}, accessCondition);
accessConditionEntry.name = this.dsoNameService.getName(group); accessConditionEntry.name = this.dsoNameService.getName(group);
this.accessConditionsList.push(accessConditionEntry); this.accessConditionsList.push(accessConditionEntry);
}); }
});
} else { } else {
this.accessConditionsList.push(accessCondition); this.accessConditionsList.push(accessCondition);
} }