Commits

Giuseppe Digilio authored 660cf7e4dd3
[DURACOM-234] Remove assertions on isResponsePending in favour of remote data operators
No tags

src/app/core/data/collection-data.service.ts

Modified
21 21 import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
22 22 import { RequestParam } from '../cache/models/request-param.model';
23 23 import { ObjectCacheService } from '../cache/object-cache.service';
24 24 import { DSpaceSerializer } from '../dspace-rest/dspace.serializer';
25 25 import { HttpOptions } from '../dspace-rest/dspace-rest.service';
26 26 import { Collection } from '../shared/collection.model';
27 27 import { Community } from '../shared/community.model';
28 28 import { ContentSource } from '../shared/content-source.model';
29 29 import { HALEndpointService } from '../shared/hal-endpoint.service';
30 30 import { Item } from '../shared/item.model';
31 -import { getFirstCompletedRemoteData } from '../shared/operators';
31 +import {
32 + getAllCompletedRemoteData,
33 + getFirstCompletedRemoteData,
34 +} from '../shared/operators';
32 35 import { BitstreamDataService } from './bitstream-data.service';
33 36 import { ComColDataService } from './comcol-data.service';
34 37 import { CommunityDataService } from './community-data.service';
35 38 import { DSOChangeAnalyzer } from './dso-change-analyzer.service';
36 39 import { FindListOptions } from './find-list-options.model';
37 40 import { PaginatedList } from './paginated-list.model';
38 41 import { RemoteData } from './remote-data';
39 42 import {
40 43 ContentSourceRequest,
41 44 UpdateContentSourceRequest,
77 80 * @return Observable<RemoteData<PaginatedList<Collection>>>
78 81 * collection list
79 82 */
80 83 getAuthorizedCollection(query: string, options: FindListOptions = {}, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<Collection>[]): Observable<RemoteData<PaginatedList<Collection>>> {
81 84 const searchHref = 'findSubmitAuthorized';
82 85 options = Object.assign({}, options, {
83 86 searchParams: [new RequestParam('query', query)],
84 87 });
85 88
86 89 return this.searchBy(searchHref, options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow).pipe(
87 - filter((collections: RemoteData<PaginatedList<Collection>>) => !collections.isResponsePending));
90 + getAllCompletedRemoteData(),
91 + );
88 92 }
89 93
90 94 /**
91 95 * Get all collections the user is authorized to submit to
92 96 *
93 97 * @param query limit the returned collection to those with metadata values matching the query terms.
94 98 * @param entityType The entity type used to limit the returned collection
95 99 * @param options The [[FindListOptions]] object
96 100 * @param reRequestOnStale Whether or not the request should automatically be re-requested after
97 101 * the response becomes stale
107 111 ...linksToFollow: FollowLinkConfig<Collection>[]): Observable<RemoteData<PaginatedList<Collection>>> {
108 112 const searchHref = 'findSubmitAuthorizedByEntityType';
109 113 options = Object.assign({}, options, {
110 114 searchParams: [
111 115 new RequestParam('query', query),
112 116 new RequestParam('entityType', entityType),
113 117 ],
114 118 });
115 119
116 120 return this.searchBy(searchHref, options, true, reRequestOnStale, ...linksToFollow).pipe(
117 - filter((collections: RemoteData<PaginatedList<Collection>>) => !collections.isResponsePending));
121 + getAllCompletedRemoteData(),
122 + );
118 123 }
119 124
120 125 /**
121 126 * Get all collections the user is authorized to submit to, by community
122 127 *
123 128 * @param communityId The community id
124 129 * @param query limit the returned collection to those with metadata values matching the query terms.
125 130 * @param options The [[FindListOptions]] object
126 131 * @param reRequestOnStale Whether or not the request should automatically be re-
127 132 * requested after the response becomes stale
131 136 getAuthorizedCollectionByCommunity(communityId: string, query: string, options: FindListOptions = {}, reRequestOnStale = true): Observable<RemoteData<PaginatedList<Collection>>> {
132 137 const searchHref = 'findSubmitAuthorizedByCommunity';
133 138 options = Object.assign({}, options, {
134 139 searchParams: [
135 140 new RequestParam('uuid', communityId),
136 141 new RequestParam('query', query),
137 142 ],
138 143 });
139 144
140 145 return this.searchBy(searchHref, options, reRequestOnStale).pipe(
141 - filter((collections: RemoteData<PaginatedList<Collection>>) => !collections.isResponsePending));
146 + getAllCompletedRemoteData(),
147 + );
142 148 }
143 149 /**
144 150 * Get all collections the user is authorized to submit to, by community and has the metadata
145 151 *
146 152 * @param communityId The community id
147 153 * @param entityType The entity type used to limit the returned collection
148 154 * @param options The [[FindListOptions]] object
149 155 * @param reRequestOnStale Whether or not the request should automatically be re-requested after
150 156 * the response becomes stale
151 157 * @param linksToFollow The array of [[FollowLinkConfig]]
162 168 const searchParams = [
163 169 new RequestParam('uuid', communityId),
164 170 new RequestParam('entityType', entityType),
165 171 ];
166 172
167 173 options = Object.assign({}, options, {
168 174 searchParams: searchParams,
169 175 });
170 176
171 177 return this.searchBy(searchHref, options, true, reRequestOnStale, ...linksToFollow).pipe(
172 - filter((collections: RemoteData<PaginatedList<Collection>>) => !collections.isResponsePending));
178 + getAllCompletedRemoteData(),
179 + );
173 180 }
174 181
175 182 /**
176 183 * Find whether there is a collection whom user has authorization to submit to
177 184 *
178 185 * @return boolean
179 186 * true if the user has at least one collection to submit to
180 187 */
181 188 hasAuthorizedCollection(): Observable<boolean> {
182 189 const searchHref = 'findSubmitAuthorized';
183 190 const options = new FindListOptions();
184 191 options.elementsPerPage = 1;
185 192
186 193 return this.searchBy(searchHref, options).pipe(
187 - filter((collections: RemoteData<PaginatedList<Collection>>) => !collections.isResponsePending),
188 - take(1),
189 - map((collections: RemoteData<PaginatedList<Collection>>) => collections.payload.totalElements > 0),
194 + getFirstCompletedRemoteData(),
195 + map((collections: RemoteData<PaginatedList<Collection>>) => collections?.payload?.totalElements > 0),
190 196 );
191 197 }
192 198
193 199 /**
194 200 * Get the endpoint for the collection's content harvester
195 201 * @param collectionId
196 202 */
197 203 getHarvesterEndpoint(collectionId: string): Observable<string> {
198 204 return this.halService.getEndpoint(this.linkPath).pipe(
199 205 switchMap((href: string) => this.halService.getEndpoint('harvester', `${href}/${collectionId}`)),

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut