mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-15 22:13:02 +00:00
[CST-5337] Replace Notifications broker with Quality assurance
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { find, map } from 'rxjs/operators';
|
||||
import { QualityAssuranceSourceRestService } from '../../../core/notifications/qa/source/quality-assurance-source-rest.service';
|
||||
import { SortDirection, SortOptions } from '../../../core/cache/models/sort-options.model';
|
||||
import { RemoteData } from '../../../core/data/remote-data';
|
||||
import { PaginatedList } from '../../../core/data/paginated-list.model';
|
||||
import { QualityAssuranceSourceObject } from '../../../core/notifications/qa/models/quality-assurance-source.model';
|
||||
import {FindListOptions} from '../../../core/data/find-list-options.model';
|
||||
|
||||
/**
|
||||
* The service handling all Quality Assurance source requests to the REST service.
|
||||
*/
|
||||
@Injectable()
|
||||
export class QualityAssuranceSourceService {
|
||||
|
||||
/**
|
||||
* Initialize the service variables.
|
||||
* @param {QualityAssuranceSourceRestService} qualityAssuranceSourceRestService
|
||||
*/
|
||||
constructor(
|
||||
private qualityAssuranceSourceRestService: QualityAssuranceSourceRestService
|
||||
) { }
|
||||
|
||||
/**
|
||||
* Return the list of Quality Assurance source managing pagination and errors.
|
||||
*
|
||||
* @param elementsPerPage
|
||||
* The number of the source per page
|
||||
* @param currentPage
|
||||
* The page number to retrieve
|
||||
* @return Observable<PaginatedList<QualityAssuranceSourceObject>>
|
||||
* The list of Quality Assurance source.
|
||||
*/
|
||||
public getSources(elementsPerPage, currentPage): Observable<PaginatedList<QualityAssuranceSourceObject>> {
|
||||
const sortOptions = new SortOptions('name', SortDirection.ASC);
|
||||
|
||||
const findListOptions: FindListOptions = {
|
||||
elementsPerPage: elementsPerPage,
|
||||
currentPage: currentPage,
|
||||
sort: sortOptions
|
||||
};
|
||||
|
||||
return this.qualityAssuranceSourceRestService.getSources(findListOptions).pipe(
|
||||
find((rd: RemoteData<PaginatedList<QualityAssuranceSourceObject>>) => !rd.isResponsePending),
|
||||
map((rd: RemoteData<PaginatedList<QualityAssuranceSourceObject>>) => {
|
||||
if (rd.hasSucceeded) {
|
||||
return rd.payload;
|
||||
} else {
|
||||
throw new Error('Can\'t retrieve Quality Assurance source from the Broker source REST service');
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user