Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
84 changed files
with
2,892 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/app/core/data/process-files-response-parsing.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { ResponseParsingService } from './parsing.service'; | ||
import { RestRequest } from './request.models'; | ||
import { GenericSuccessResponse, RestResponse } from '../cache/response.models'; | ||
import { DSpaceRESTV2Response } from '../dspace-rest-v2/dspace-rest-v2-response.model'; | ||
import { isEmpty, isNotEmpty } from '../../shared/empty.util'; | ||
import { PaginatedList } from './paginated-list'; | ||
import { PageInfo } from '../shared/page-info.model'; | ||
import { Injectable } from '@angular/core'; | ||
import { DSpaceSerializer } from '../dspace-rest-v2/dspace.serializer'; | ||
import { Bitstream } from '../shared/bitstream.model'; | ||
|
||
@Injectable() | ||
/** | ||
* A ResponseParsingService used to parse DSpaceRESTV2Response coming from the REST API to a GenericSuccessResponse | ||
* containing a PaginatedList of a process's output files | ||
*/ | ||
export class ProcessFilesResponseParsingService implements ResponseParsingService { | ||
parse(request: RestRequest, data: DSpaceRESTV2Response): RestResponse { | ||
const payload = data.payload; | ||
|
||
let page; | ||
if (isNotEmpty(payload._embedded) && isNotEmpty(Object.keys(payload._embedded))) { | ||
const bitstreams = new DSpaceSerializer(Bitstream).deserializeArray(payload._embedded[Object.keys(payload._embedded)[0]]); | ||
|
||
if (isNotEmpty(bitstreams)) { | ||
page = new PaginatedList(Object.assign(new PageInfo(), { | ||
elementsPerPage: bitstreams.length, | ||
totalElements: bitstreams.length, | ||
totalPages: 1, | ||
currentPage: 1 | ||
}), bitstreams); | ||
} | ||
} | ||
|
||
if (isEmpty(page)) { | ||
page = new PaginatedList(new PageInfo(), []); | ||
} | ||
|
||
return new GenericSuccessResponse(page, data.statusCode, data.statusText); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { DataService } from '../data.service'; | ||
import { RequestService } from '../request.service'; | ||
import { RemoteDataBuildService } from '../../cache/builders/remote-data-build.service'; | ||
import { Store } from '@ngrx/store'; | ||
import { CoreState } from '../../core.reducers'; | ||
import { ObjectCacheService } from '../../cache/object-cache.service'; | ||
import { HALEndpointService } from '../../shared/hal-endpoint.service'; | ||
import { NotificationsService } from '../../../shared/notifications/notifications.service'; | ||
import { HttpClient } from '@angular/common/http'; | ||
import { DefaultChangeAnalyzer } from '../default-change-analyzer.service'; | ||
import { Process } from '../../../process-page/processes/process.model'; | ||
import { dataService } from '../../cache/builders/build-decorators'; | ||
import { PROCESS } from '../../../process-page/processes/process.resource-type'; | ||
import { Observable } from 'rxjs/internal/Observable'; | ||
import { map, switchMap } from 'rxjs/operators'; | ||
import { ProcessFilesRequest, RestRequest } from '../request.models'; | ||
import { configureRequest, filterSuccessfulResponses } from '../../shared/operators'; | ||
import { GenericSuccessResponse } from '../../cache/response.models'; | ||
import { PaginatedList } from '../paginated-list'; | ||
import { Bitstream } from '../../shared/bitstream.model'; | ||
import { RemoteData } from '../remote-data'; | ||
|
||
@Injectable() | ||
@dataService(PROCESS) | ||
export class ProcessDataService extends DataService<Process> { | ||
protected linkPath = 'processes'; | ||
|
||
constructor( | ||
protected requestService: RequestService, | ||
protected rdbService: RemoteDataBuildService, | ||
protected store: Store<CoreState>, | ||
protected objectCache: ObjectCacheService, | ||
protected halService: HALEndpointService, | ||
protected notificationsService: NotificationsService, | ||
protected http: HttpClient, | ||
protected comparator: DefaultChangeAnalyzer<Process>) { | ||
super(); | ||
} | ||
|
||
/** | ||
* Get the endpoint for a process his files | ||
* @param processId The ID of the process | ||
*/ | ||
getFilesEndpoint(processId: string): Observable<string> { | ||
return this.getBrowseEndpoint().pipe( | ||
switchMap((href) => this.halService.getEndpoint('files', `${href}/${processId}`)) | ||
); | ||
} | ||
|
||
/** | ||
* Get a process his output files | ||
* @param processId The ID of the process | ||
*/ | ||
getFiles(processId: string): Observable<RemoteData<PaginatedList<Bitstream>>> { | ||
const request$ = this.getFilesEndpoint(processId).pipe( | ||
map((href) => new ProcessFilesRequest(this.requestService.generateRequestId(), href)), | ||
configureRequest(this.requestService) | ||
); | ||
const requestEntry$ = request$.pipe( | ||
switchMap((request: RestRequest) => this.requestService.getByHref(request.href)) | ||
); | ||
const payload$ = requestEntry$.pipe( | ||
filterSuccessfulResponses(), | ||
map((response: GenericSuccessResponse<PaginatedList<Bitstream>>) => response.payload) | ||
); | ||
|
||
return this.rdbService.toRemoteDataObservable(requestEntry$, payload$); | ||
} | ||
} |
Oops, something went wrong.