[CSTPER-3620] Workflow Actions refresh entire MyDSpace page instead of just WorkflowItem

Task Service implementation.
ReloadableAction abstraction.
This commit is contained in:
Alessandro Martelli
2020-12-18 12:19:09 +01:00
parent e867badcb5
commit e32c86f127
56 changed files with 1489 additions and 287 deletions

View File

@@ -1,21 +1,24 @@
import { HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs';
import { distinctUntilChanged, filter, flatMap, map, tap } from 'rxjs/operators';
import { merge as observableMerge, Observable, of as observableOf } from 'rxjs';
import { distinctUntilChanged, filter, find, flatMap, map, mergeMap, switchMap, tap } from 'rxjs/operators';
import { DataService } from '../data/data.service';
import {
DeleteRequest,
FindListOptions,
PostRequest,
TaskDeleteRequest,
TaskPostRequest
} from '../data/request.models';
import { isNotEmpty } from '../../shared/empty.util';
import { HttpOptions } from '../dspace-rest/dspace-rest.service';
import { hasValue, isNotEmpty } from '../../shared/empty.util';
import { ProcessTaskResponse } from './models/process-task-response';
import { getFirstCompletedRemoteData } from '../shared/operators';
import {getFirstCompletedRemoteData, getResponseFromEntry} from '../shared/operators';
import { ErrorResponse, MessageResponse, RestResponse } from '../cache/response.models';
import { CacheableObject } from '../cache/object-cache.reducer';
import { RemoteData } from '../data/remote-data';
import { FollowLinkConfig } from '../../shared/utils/follow-link-config.model';
import {HttpOptions} from '../dspace-rest/dspace-rest.service';
/**
* An abstract class that provides methods to handle task requests.
@@ -51,7 +54,7 @@ export abstract class TasksService<T extends CacheableObject> extends DataServic
* @param resourceID
* The identifier for the object
*/
protected getEndpointByIDHref(endpoint, resourceID): string {
getEndpointByIDHref(endpoint, resourceID): string {
return isNotEmpty(resourceID) ? `${endpoint}/${resourceID}` : `${endpoint}`;
}
@@ -95,10 +98,7 @@ export abstract class TasksService<T extends CacheableObject> extends DataServic
*/
public deleteById(linkPath: string, scopeId: string, options?: HttpOptions): Observable<ProcessTaskResponse> {
const requestId = this.requestService.generateRequestId();
return this.halService.getEndpoint(linkPath || this.linkPath).pipe(
filter((href: string) => isNotEmpty(href)),
distinctUntilChanged(),
map((endpointURL: string) => this.getEndpointByIDHref(endpointURL, scopeId)),
return this.getEndpointById(scopeId, linkPath).pipe(
map((endpointURL: string) => new TaskDeleteRequest(requestId, endpointURL, null, options)),
tap((request: DeleteRequest) => this.requestService.configure(request)),
flatMap((request: DeleteRequest) => this.fetchRequest(requestId)),
@@ -115,4 +115,33 @@ export abstract class TasksService<T extends CacheableObject> extends DataServic
options.headers = headers;
return options;
}
/**
* Get the endpoint of a task by scopeId.
* @param linkPath
* @param scopeId
*/
public getEndpointById(scopeId: string, linkPath?: string): Observable<string> {
return this.halService.getEndpoint(linkPath || this.linkPath).pipe(
filter((href: string) => isNotEmpty(href)),
distinctUntilChanged(),
map((endpointURL: string) => this.getEndpointByIDHref(endpointURL, scopeId)));
}
/**
* Search a task.
* @param searchMethod
* the search method
* @param options
* the find list options
* @param linksToFollow
* links to follow
*/
public searchTask(searchMethod: string, options: FindListOptions = {}, ...linksToFollow: Array<FollowLinkConfig<T>>): Observable<RemoteData<T>> {
const hrefObs = this.getSearchByHref(searchMethod, options, ...linksToFollow);
return hrefObs.pipe(
find((href: string) => hasValue(href)),
switchMap((href) => this.findByHref(href))
);
}
}