mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
[CST-5337] Refactoring in order to comply with new data service
This commit is contained in:
@@ -87,7 +87,8 @@ describe('QualityAssuranceEventRestService', () => {
|
||||
buildList: cold('(a)', {
|
||||
a: paginatedListRD
|
||||
}),
|
||||
buildFromRequestUUID: jasmine.createSpy('buildFromRequestUUID')
|
||||
buildFromRequestUUID: jasmine.createSpy('buildFromRequestUUID'),
|
||||
buildFromRequestUUIDAndAwait: jasmine.createSpy('buildFromRequestUUIDAndAwait')
|
||||
});
|
||||
|
||||
objectCache = {} as ObjectCacheService;
|
||||
@@ -105,17 +106,16 @@ describe('QualityAssuranceEventRestService', () => {
|
||||
objectCache,
|
||||
halService,
|
||||
notificationsService,
|
||||
http,
|
||||
comparator
|
||||
);
|
||||
|
||||
serviceASAny = service;
|
||||
|
||||
spyOn(serviceASAny.dataService, 'searchBy').and.callThrough();
|
||||
spyOn(serviceASAny.dataService, 'findById').and.callThrough();
|
||||
spyOn(serviceASAny.dataService, 'patch').and.callThrough();
|
||||
spyOn(serviceASAny.dataService, 'postOnRelated').and.callThrough();
|
||||
spyOn(serviceASAny.dataService, 'deleteOnRelated').and.callThrough();
|
||||
spyOn(serviceASAny.searchData, 'searchBy').and.callThrough();
|
||||
spyOn(serviceASAny, 'findById').and.callThrough();
|
||||
spyOn(serviceASAny.patchData, 'patch').and.callThrough();
|
||||
spyOn(serviceASAny, 'postOnRelated').and.callThrough();
|
||||
spyOn(serviceASAny, 'deleteOnRelated').and.callThrough();
|
||||
});
|
||||
|
||||
describe('getEventsByTopic', () => {
|
||||
@@ -125,7 +125,7 @@ describe('QualityAssuranceEventRestService', () => {
|
||||
serviceASAny.rdbService.buildFromRequestUUID.and.returnValue(observableOf(qaEventObjectRD));
|
||||
});
|
||||
|
||||
it('should proxy the call to dataservice.searchBy', () => {
|
||||
it('should proxy the call to searchData.searchBy', () => {
|
||||
const options: FindListOptions = {
|
||||
searchParams: [
|
||||
{
|
||||
@@ -135,7 +135,7 @@ describe('QualityAssuranceEventRestService', () => {
|
||||
]
|
||||
};
|
||||
service.getEventsByTopic(topic);
|
||||
expect(serviceASAny.dataService.searchBy).toHaveBeenCalledWith('findByTopic', options, true, true);
|
||||
expect(serviceASAny.searchData.searchBy).toHaveBeenCalledWith('findByTopic', options, true, true);
|
||||
});
|
||||
|
||||
it('should return a RemoteData<PaginatedList<QualityAssuranceEventObject>> for the object with the given Topic', () => {
|
||||
@@ -154,15 +154,15 @@ describe('QualityAssuranceEventRestService', () => {
|
||||
serviceASAny.rdbService.buildFromRequestUUID.and.returnValue(observableOf(qaEventObjectRD));
|
||||
});
|
||||
|
||||
it('should proxy the call to dataservice.findById', () => {
|
||||
it('should call findById', () => {
|
||||
service.getEvent(qualityAssuranceEventObjectMissingPid.id).subscribe(
|
||||
(res) => {
|
||||
expect(serviceASAny.dataService.findById).toHaveBeenCalledWith(qualityAssuranceEventObjectMissingPid.id, true, true);
|
||||
expect(serviceASAny.findById).toHaveBeenCalledWith(qualityAssuranceEventObjectMissingPid.id, true, true);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should return a RemoteData<QualityAssuranceEventObject> for the object with the given URL', () => {
|
||||
it('should return a RemoteData for the object with the given URL', () => {
|
||||
const result = service.getEvent(qualityAssuranceEventObjectMissingPid.id);
|
||||
const expected = cold('(a)', {
|
||||
a: qaEventObjectRD
|
||||
@@ -176,12 +176,13 @@ describe('QualityAssuranceEventRestService', () => {
|
||||
serviceASAny.requestService.getByHref.and.returnValue(observableOf(responseCacheEntry));
|
||||
serviceASAny.requestService.getByUUID.and.returnValue(observableOf(responseCacheEntry));
|
||||
serviceASAny.rdbService.buildFromRequestUUID.and.returnValue(observableOf(qaEventObjectRD));
|
||||
serviceASAny.rdbService.buildFromRequestUUIDAndAwait.and.returnValue(observableOf(qaEventObjectRD));
|
||||
});
|
||||
|
||||
it('should proxy the call to dataservice.patch', () => {
|
||||
it('should proxy the call to patchData.patch', () => {
|
||||
service.patchEvent(status, qualityAssuranceEventObjectMissingPid).subscribe(
|
||||
(res) => {
|
||||
expect(serviceASAny.dataService.patch).toHaveBeenCalledWith(qualityAssuranceEventObjectMissingPid, operation);
|
||||
expect(serviceASAny.patchData.patch).toHaveBeenCalledWith(qualityAssuranceEventObjectMissingPid, operation);
|
||||
}
|
||||
);
|
||||
});
|
||||
@@ -202,10 +203,10 @@ describe('QualityAssuranceEventRestService', () => {
|
||||
serviceASAny.rdbService.buildFromRequestUUID.and.returnValue(observableOf(qaEventObjectMissingProjectRD));
|
||||
});
|
||||
|
||||
it('should proxy the call to dataservice.postOnRelated', () => {
|
||||
it('should call postOnRelated', () => {
|
||||
service.boundProject(qualityAssuranceEventObjectMissingProjectFound.id, requestUUID).subscribe(
|
||||
(res) => {
|
||||
expect(serviceASAny.dataService.postOnRelated).toHaveBeenCalledWith(qualityAssuranceEventObjectMissingProjectFound.id, requestUUID);
|
||||
expect(serviceASAny.postOnRelated).toHaveBeenCalledWith(qualityAssuranceEventObjectMissingProjectFound.id, requestUUID);
|
||||
}
|
||||
);
|
||||
});
|
||||
@@ -226,10 +227,10 @@ describe('QualityAssuranceEventRestService', () => {
|
||||
serviceASAny.rdbService.buildFromRequestUUID.and.returnValue(observableOf(createSuccessfulRemoteDataObject({})));
|
||||
});
|
||||
|
||||
it('should proxy the call to dataservice.deleteOnRelated', () => {
|
||||
it('should call deleteOnRelated', () => {
|
||||
service.removeProject(qualityAssuranceEventObjectMissingProjectFound.id).subscribe(
|
||||
(res) => {
|
||||
expect(serviceASAny.dataService.deleteOnRelated).toHaveBeenCalledWith(qualityAssuranceEventObjectMissingProjectFound.id);
|
||||
expect(serviceASAny.deleteOnRelated).toHaveBeenCalledWith(qualityAssuranceEventObjectMissingProjectFound.id);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
@@ -1,73 +1,42 @@
|
||||
/* eslint-disable max-classes-per-file */
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Store } from '@ngrx/store';
|
||||
|
||||
import { Observable } from 'rxjs';
|
||||
import { find, take } from 'rxjs/operators';
|
||||
import { ReplaceOperation } from 'fast-json-patch';
|
||||
|
||||
import { HALEndpointService } from '../../../shared/hal-endpoint.service';
|
||||
import { NotificationsService } from '../../../../shared/notifications/notifications.service';
|
||||
import { RemoteDataBuildService } from '../../../cache/builders/remote-data-build.service';
|
||||
import { RestResponse } from '../../../cache/response.models';
|
||||
import { ObjectCacheService } from '../../../cache/object-cache.service';
|
||||
import { dataService } from '../../../cache/builders/build-decorators';
|
||||
import { dataService } from '../../../data/base/data-service.decorator';
|
||||
import { RequestService } from '../../../data/request.service';
|
||||
import { ChangeAnalyzer } from '../../../data/change-analyzer';
|
||||
import { DefaultChangeAnalyzer } from '../../../data/default-change-analyzer.service';
|
||||
import { RemoteData } from '../../../data/remote-data';
|
||||
import { QualityAssuranceEventObject } from '../models/quality-assurance-event.model';
|
||||
import { QUALITY_ASSURANCE_EVENT_OBJECT } from '../models/quality-assurance-event-object.resource-type';
|
||||
import { FollowLinkConfig } from '../../../../shared/utils/follow-link-config.model';
|
||||
import { PaginatedList } from '../../../data/paginated-list.model';
|
||||
import { ReplaceOperation } from 'fast-json-patch';
|
||||
import { NoContent } from '../../../shared/NoContent.model';
|
||||
import {CoreState} from '../../../core-state.model';
|
||||
import { FindListOptions } from '../../../data/find-list-options.model';
|
||||
|
||||
|
||||
/**
|
||||
* A private DataService implementation to delegate specific methods to.
|
||||
*/
|
||||
class DataServiceImpl extends DataService<QualityAssuranceEventObject> {
|
||||
/**
|
||||
* The REST endpoint.
|
||||
*/
|
||||
protected linkPath = 'qualityassuranceevents';
|
||||
|
||||
/**
|
||||
* Initialize service variables
|
||||
* @param {RequestService} requestService
|
||||
* @param {RemoteDataBuildService} rdbService
|
||||
* @param {Store<CoreState>} store
|
||||
* @param {ObjectCacheService} objectCache
|
||||
* @param {HALEndpointService} halService
|
||||
* @param {NotificationsService} notificationsService
|
||||
* @param {HttpClient} http
|
||||
* @param {ChangeAnalyzer<QualityAssuranceEventObject>} comparator
|
||||
*/
|
||||
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: ChangeAnalyzer<QualityAssuranceEventObject>) {
|
||||
super();
|
||||
}
|
||||
}
|
||||
import { IdentifiableDataService } from '../../../data/base/identifiable-data.service';
|
||||
import { CreateData, CreateDataImpl } from '../../../data/base/create-data';
|
||||
import { PatchData, PatchDataImpl } from '../../../data/base/patch-data';
|
||||
import { DeleteData, DeleteDataImpl } from '../../../data/base/delete-data';
|
||||
import { SearchData, SearchDataImpl } from '../../../data/base/search-data';
|
||||
import { DefaultChangeAnalyzer } from '../../../data/default-change-analyzer.service';
|
||||
import { hasValue } from '../../../../shared/empty.util';
|
||||
import { DeleteByIDRequest, PostRequest } from '../../../data/request.models';
|
||||
|
||||
/**
|
||||
* The service handling all Quality Assurance topic REST requests.
|
||||
*/
|
||||
@Injectable()
|
||||
@dataService(QUALITY_ASSURANCE_EVENT_OBJECT)
|
||||
export class QualityAssuranceEventRestService {
|
||||
/**
|
||||
* A private DataService implementation to delegate specific methods to.
|
||||
*/
|
||||
private dataService: DataServiceImpl;
|
||||
export class QualityAssuranceEventRestService extends IdentifiableDataService<QualityAssuranceEventObject> {
|
||||
|
||||
private createData: CreateData<QualityAssuranceEventObject>;
|
||||
private searchData: SearchData<QualityAssuranceEventObject>;
|
||||
private patchData: PatchData<QualityAssuranceEventObject>;
|
||||
private deleteData: DeleteData<QualityAssuranceEventObject>;
|
||||
|
||||
/**
|
||||
* Initialize service variables
|
||||
@@ -76,7 +45,6 @@ export class QualityAssuranceEventRestService {
|
||||
* @param {ObjectCacheService} objectCache
|
||||
* @param {HALEndpointService} halService
|
||||
* @param {NotificationsService} notificationsService
|
||||
* @param {HttpClient} http
|
||||
* @param {DefaultChangeAnalyzer<QualityAssuranceEventObject>} comparator
|
||||
*/
|
||||
constructor(
|
||||
@@ -85,9 +53,13 @@ export class QualityAssuranceEventRestService {
|
||||
protected objectCache: ObjectCacheService,
|
||||
protected halService: HALEndpointService,
|
||||
protected notificationsService: NotificationsService,
|
||||
protected http: HttpClient,
|
||||
protected comparator: DefaultChangeAnalyzer<QualityAssuranceEventObject>) {
|
||||
this.dataService = new DataServiceImpl(requestService, rdbService, null, objectCache, halService, notificationsService, http, comparator);
|
||||
protected comparator: DefaultChangeAnalyzer<QualityAssuranceEventObject>
|
||||
) {
|
||||
super('qualityassuranceevents', requestService, rdbService, objectCache, halService);
|
||||
this.createData = new CreateDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, notificationsService, this.responseMsToLive);
|
||||
this.deleteData = new DeleteDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, notificationsService, this.responseMsToLive, this.constructIdEndpoint);
|
||||
this.patchData = new PatchDataImpl<QualityAssuranceEventObject>(this.linkPath, requestService, rdbService, objectCache, halService, comparator, this.responseMsToLive, this.constructIdEndpoint);
|
||||
this.searchData = new SearchDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, this.responseMsToLive);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -109,14 +81,14 @@ export class QualityAssuranceEventRestService {
|
||||
fieldValue: topic
|
||||
}
|
||||
];
|
||||
return this.dataService.searchBy('findByTopic', options, true, true, ...linksToFollow);
|
||||
return this.searchData.searchBy('findByTopic', options, true, true, ...linksToFollow);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear findByTopic requests from cache
|
||||
*/
|
||||
public clearFindByTopicRequests() {
|
||||
this.requestService.removeByHrefSubstring('findByTopic');
|
||||
this.requestService.setStaleByHrefSubstring('findByTopic');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -130,7 +102,7 @@ export class QualityAssuranceEventRestService {
|
||||
* The Quality Assurance event.
|
||||
*/
|
||||
public getEvent(id: string, ...linksToFollow: FollowLinkConfig<QualityAssuranceEventObject>[]): Observable<RemoteData<QualityAssuranceEventObject>> {
|
||||
return this.dataService.findById(id, true, true, ...linksToFollow);
|
||||
return this.findById(id, true, true, ...linksToFollow);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -153,7 +125,7 @@ export class QualityAssuranceEventRestService {
|
||||
value: status
|
||||
}
|
||||
];
|
||||
return this.dataService.patch(dso, operation);
|
||||
return this.patchData.patch(dso, operation);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -167,7 +139,7 @@ export class QualityAssuranceEventRestService {
|
||||
* The REST response.
|
||||
*/
|
||||
public boundProject(itemId: string, projectId: string): Observable<RemoteData<QualityAssuranceEventObject>> {
|
||||
return this.dataService.postOnRelated(itemId, projectId);
|
||||
return this.postOnRelated(itemId, projectId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -179,6 +151,53 @@ export class QualityAssuranceEventRestService {
|
||||
* The REST response.
|
||||
*/
|
||||
public removeProject(itemId: string): Observable<RemoteData<NoContent>> {
|
||||
return this.dataService.deleteOnRelated(itemId);
|
||||
return this.deleteOnRelated(itemId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a delete operation on an endpoint related item. Ex.: endpoint/<itemId>/related
|
||||
* @param objectId The item id
|
||||
* @return the RestResponse as an Observable
|
||||
*/
|
||||
private deleteOnRelated(objectId: string): Observable<RemoteData<NoContent>> {
|
||||
const requestId = this.requestService.generateRequestId();
|
||||
|
||||
const hrefObs = this.getIDHrefObs(objectId);
|
||||
|
||||
hrefObs.pipe(
|
||||
find((href: string) => hasValue(href)),
|
||||
).subscribe((href: string) => {
|
||||
const request = new DeleteByIDRequest(requestId, href + '/related', objectId);
|
||||
if (hasValue(this.responseMsToLive)) {
|
||||
request.responseMsToLive = this.responseMsToLive;
|
||||
}
|
||||
this.requestService.send(request);
|
||||
});
|
||||
|
||||
return this.rdbService.buildFromRequestUUID<QualityAssuranceEventObject>(requestId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a post on an endpoint related item with ID. Ex.: endpoint/<itemId>/related?item=<relatedItemId>
|
||||
* @param objectId The item id
|
||||
* @param relatedItemId The related item Id
|
||||
* @param body The optional POST body
|
||||
* @return the RestResponse as an Observable
|
||||
*/
|
||||
private postOnRelated(objectId: string, relatedItemId: string, body?: any) {
|
||||
const requestId = this.requestService.generateRequestId();
|
||||
const hrefObs = this.getIDHrefObs(objectId);
|
||||
|
||||
hrefObs.pipe(
|
||||
take(1)
|
||||
).subscribe((href: string) => {
|
||||
const request = new PostRequest(requestId, href + '/related?item=' + relatedItemId, body);
|
||||
if (hasValue(this.responseMsToLive)) {
|
||||
request.responseMsToLive = this.responseMsToLive;
|
||||
}
|
||||
this.requestService.send(request);
|
||||
});
|
||||
|
||||
return this.rdbService.buildFromRequestUUID<QualityAssuranceEventObject>(requestId);
|
||||
}
|
||||
}
|
||||
|
@@ -77,20 +77,18 @@ describe('QualityAssuranceSourceRestService', () => {
|
||||
rdbService,
|
||||
objectCache,
|
||||
halService,
|
||||
notificationsService,
|
||||
http,
|
||||
comparator
|
||||
notificationsService
|
||||
);
|
||||
|
||||
spyOn((service as any).dataService, 'findAllByHref').and.callThrough();
|
||||
spyOn((service as any).dataService, 'findByHref').and.callThrough();
|
||||
spyOn((service as any), 'findListByHref').and.callThrough();
|
||||
spyOn((service as any), 'findByHref').and.callThrough();
|
||||
});
|
||||
|
||||
describe('getSources', () => {
|
||||
it('should proxy the call to dataservice.findAllByHref', (done) => {
|
||||
it('should call findListByHref', (done) => {
|
||||
service.getSources().subscribe(
|
||||
(res) => {
|
||||
expect((service as any).dataService.findAllByHref).toHaveBeenCalledWith(endpointURL, {}, true, true);
|
||||
expect((service as any).findListByHref).toHaveBeenCalledWith(endpointURL, {}, true, true);
|
||||
}
|
||||
);
|
||||
done();
|
||||
@@ -106,10 +104,10 @@ describe('QualityAssuranceSourceRestService', () => {
|
||||
});
|
||||
|
||||
describe('getSource', () => {
|
||||
it('should proxy the call to dataservice.findByHref', (done) => {
|
||||
it('should call findByHref', (done) => {
|
||||
service.getSource(qualityAssuranceSourceObjectMorePid.id).subscribe(
|
||||
(res) => {
|
||||
expect((service as any).dataService.findByHref).toHaveBeenCalledWith(endpointURL + '/' + qualityAssuranceSourceObjectMorePid.id, true, true);
|
||||
expect((service as any).findByHref).toHaveBeenCalledWith(endpointURL + '/' + qualityAssuranceSourceObjectMorePid.id, true, true);
|
||||
}
|
||||
);
|
||||
done();
|
||||
|
@@ -1,7 +1,5 @@
|
||||
/* eslint-disable max-classes-per-file */
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Store } from '@ngrx/store';
|
||||
|
||||
import { Observable } from 'rxjs';
|
||||
import { mergeMap, take } from 'rxjs/operators';
|
||||
@@ -10,62 +8,22 @@ import { HALEndpointService } from '../../../shared/hal-endpoint.service';
|
||||
import { NotificationsService } from '../../../../shared/notifications/notifications.service';
|
||||
import { RemoteDataBuildService } from '../../../cache/builders/remote-data-build.service';
|
||||
import { ObjectCacheService } from '../../../cache/object-cache.service';
|
||||
import { dataService } from '../../../cache/builders/build-decorators';
|
||||
import { dataService } from '../../../data/base/data-service.decorator';
|
||||
import { RequestService } from '../../../data/request.service';
|
||||
import { DataService } from '../../../data/data.service';
|
||||
import { ChangeAnalyzer } from '../../../data/change-analyzer';
|
||||
import { DefaultChangeAnalyzer } from '../../../data/default-change-analyzer.service';
|
||||
import { RemoteData } from '../../../data/remote-data';
|
||||
import { QualityAssuranceSourceObject } from '../models/quality-assurance-source.model';
|
||||
import { QUALITY_ASSURANCE_SOURCE_OBJECT } from '../models/quality-assurance-source-object.resource-type';
|
||||
import { FollowLinkConfig } from '../../../../shared/utils/follow-link-config.model';
|
||||
import { PaginatedList } from '../../../data/paginated-list.model';
|
||||
import {CoreState} from '../../../core-state.model';
|
||||
import { FindListOptions } from '../../../data/find-list-options.model';
|
||||
|
||||
/**
|
||||
* A private DataService implementation to delegate specific methods to.
|
||||
*/
|
||||
class DataServiceImpl extends DataService<QualityAssuranceSourceObject> {
|
||||
/**
|
||||
* The REST endpoint.
|
||||
*/
|
||||
protected linkPath = 'qualityassurancesources';
|
||||
|
||||
/**
|
||||
* Initialize service variables
|
||||
* @param {RequestService} requestService
|
||||
* @param {RemoteDataBuildService} rdbService
|
||||
* @param {Store<CoreState>} store
|
||||
* @param {ObjectCacheService} objectCache
|
||||
* @param {HALEndpointService} halService
|
||||
* @param {NotificationsService} notificationsService
|
||||
* @param {HttpClient} http
|
||||
* @param {ChangeAnalyzer<QualityAssuranceSourceObject>} comparator
|
||||
*/
|
||||
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: ChangeAnalyzer<QualityAssuranceSourceObject>) {
|
||||
super();
|
||||
}
|
||||
}
|
||||
import { IdentifiableDataService } from '../../../data/base/identifiable-data.service';
|
||||
|
||||
/**
|
||||
* The service handling all Quality Assurance source REST requests.
|
||||
*/
|
||||
@Injectable()
|
||||
@dataService(QUALITY_ASSURANCE_SOURCE_OBJECT)
|
||||
export class QualityAssuranceSourceRestService {
|
||||
/**
|
||||
* A private DataService implementation to delegate specific methods to.
|
||||
*/
|
||||
private dataService: DataServiceImpl;
|
||||
export class QualityAssuranceSourceRestService extends IdentifiableDataService<QualityAssuranceSourceObject> {
|
||||
|
||||
/**
|
||||
* Initialize service variables
|
||||
@@ -74,18 +32,15 @@ export class QualityAssuranceSourceRestService {
|
||||
* @param {ObjectCacheService} objectCache
|
||||
* @param {HALEndpointService} halService
|
||||
* @param {NotificationsService} notificationsService
|
||||
* @param {HttpClient} http
|
||||
* @param {DefaultChangeAnalyzer<QualityAssuranceSourceObject>} comparator
|
||||
*/
|
||||
constructor(
|
||||
protected requestService: RequestService,
|
||||
protected rdbService: RemoteDataBuildService,
|
||||
protected objectCache: ObjectCacheService,
|
||||
protected halService: HALEndpointService,
|
||||
protected notificationsService: NotificationsService,
|
||||
protected http: HttpClient,
|
||||
protected comparator: DefaultChangeAnalyzer<QualityAssuranceSourceObject>) {
|
||||
this.dataService = new DataServiceImpl(requestService, rdbService, null, objectCache, halService, notificationsService, http, comparator);
|
||||
protected notificationsService: NotificationsService
|
||||
) {
|
||||
super('qualityassurancesources', requestService, rdbService, objectCache, halService);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -99,9 +54,9 @@ export class QualityAssuranceSourceRestService {
|
||||
* The list of Quality Assurance source.
|
||||
*/
|
||||
public getSources(options: FindListOptions = {}, ...linksToFollow: FollowLinkConfig<QualityAssuranceSourceObject>[]): Observable<RemoteData<PaginatedList<QualityAssuranceSourceObject>>> {
|
||||
return this.dataService.getBrowseEndpoint(options, 'qualityassurancesources').pipe(
|
||||
return this.getBrowseEndpoint(options).pipe(
|
||||
take(1),
|
||||
mergeMap((href: string) => this.dataService.findAllByHref(href, options, true, true, ...linksToFollow)),
|
||||
mergeMap((href: string) => this.findListByHref(href, options, true, true, ...linksToFollow)),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -124,9 +79,9 @@ export class QualityAssuranceSourceRestService {
|
||||
*/
|
||||
public getSource(id: string, ...linksToFollow: FollowLinkConfig<QualityAssuranceSourceObject>[]): Observable<RemoteData<QualityAssuranceSourceObject>> {
|
||||
const options = {};
|
||||
return this.dataService.getBrowseEndpoint(options, 'qualityassurancesources').pipe(
|
||||
return this.getBrowseEndpoint(options, 'qualityassurancesources').pipe(
|
||||
take(1),
|
||||
mergeMap((href: string) => this.dataService.findByHref(href + '/' + id, true, true, ...linksToFollow))
|
||||
mergeMap((href: string) => this.findByHref(href + '/' + id, true, true, ...linksToFollow))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -77,20 +77,18 @@ describe('QualityAssuranceTopicRestService', () => {
|
||||
rdbService,
|
||||
objectCache,
|
||||
halService,
|
||||
notificationsService,
|
||||
http,
|
||||
comparator
|
||||
notificationsService
|
||||
);
|
||||
|
||||
spyOn((service as any).dataService, 'findAllByHref').and.callThrough();
|
||||
spyOn((service as any).dataService, 'findByHref').and.callThrough();
|
||||
spyOn((service as any), 'findListByHref').and.callThrough();
|
||||
spyOn((service as any), 'findByHref').and.callThrough();
|
||||
});
|
||||
|
||||
describe('getTopics', () => {
|
||||
it('should proxy the call to dataservice.findAllByHref', (done) => {
|
||||
it('should call findListByHref', (done) => {
|
||||
service.getTopics().subscribe(
|
||||
(res) => {
|
||||
expect((service as any).dataService.findAllByHref).toHaveBeenCalledWith(endpointURL, {}, true, true);
|
||||
expect((service as any).findListByHref).toHaveBeenCalledWith(endpointURL, {}, true, true);
|
||||
}
|
||||
);
|
||||
done();
|
||||
@@ -106,10 +104,10 @@ describe('QualityAssuranceTopicRestService', () => {
|
||||
});
|
||||
|
||||
describe('getTopic', () => {
|
||||
it('should proxy the call to dataservice.findByHref', (done) => {
|
||||
it('should call findByHref', (done) => {
|
||||
service.getTopic(qualityAssuranceTopicObjectMorePid.id).subscribe(
|
||||
(res) => {
|
||||
expect((service as any).dataService.findByHref).toHaveBeenCalledWith(endpointURL + '/' + qualityAssuranceTopicObjectMorePid.id, true, true);
|
||||
expect((service as any).findByHref).toHaveBeenCalledWith(endpointURL + '/' + qualityAssuranceTopicObjectMorePid.id, true, true);
|
||||
}
|
||||
);
|
||||
done();
|
||||
|
@@ -1,7 +1,4 @@
|
||||
/* eslint-disable max-classes-per-file */
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Store } from '@ngrx/store';
|
||||
|
||||
import { Observable } from 'rxjs';
|
||||
import { mergeMap, take } from 'rxjs/operators';
|
||||
@@ -10,62 +7,22 @@ import { HALEndpointService } from '../../../shared/hal-endpoint.service';
|
||||
import { NotificationsService } from '../../../../shared/notifications/notifications.service';
|
||||
import { RemoteDataBuildService } from '../../../cache/builders/remote-data-build.service';
|
||||
import { ObjectCacheService } from '../../../cache/object-cache.service';
|
||||
import { dataService } from '../../../cache/builders/build-decorators';
|
||||
import { RequestService } from '../../../data/request.service';
|
||||
import { DataService } from '../../../data/data.service';
|
||||
import { ChangeAnalyzer } from '../../../data/change-analyzer';
|
||||
import { DefaultChangeAnalyzer } from '../../../data/default-change-analyzer.service';
|
||||
import { RemoteData } from '../../../data/remote-data';
|
||||
import { QualityAssuranceTopicObject } from '../models/quality-assurance-topic.model';
|
||||
import { QUALITY_ASSURANCE_TOPIC_OBJECT } from '../models/quality-assurance-topic-object.resource-type';
|
||||
import { FollowLinkConfig } from '../../../../shared/utils/follow-link-config.model';
|
||||
import { PaginatedList } from '../../../data/paginated-list.model';
|
||||
import {CoreState} from '../../../core-state.model';
|
||||
import { FindListOptions } from '../../../data/find-list-options.model';
|
||||
|
||||
/**
|
||||
* A private DataService implementation to delegate specific methods to.
|
||||
*/
|
||||
class DataServiceImpl extends DataService<QualityAssuranceTopicObject> {
|
||||
/**
|
||||
* The REST endpoint.
|
||||
*/
|
||||
protected linkPath = 'qualityassurancetopics';
|
||||
|
||||
/**
|
||||
* Initialize service variables
|
||||
* @param {RequestService} requestService
|
||||
* @param {RemoteDataBuildService} rdbService
|
||||
* @param {Store<CoreState>} store
|
||||
* @param {ObjectCacheService} objectCache
|
||||
* @param {HALEndpointService} halService
|
||||
* @param {NotificationsService} notificationsService
|
||||
* @param {HttpClient} http
|
||||
* @param {ChangeAnalyzer<QualityAssuranceTopicObject>} comparator
|
||||
*/
|
||||
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: ChangeAnalyzer<QualityAssuranceTopicObject>) {
|
||||
super();
|
||||
}
|
||||
}
|
||||
import { IdentifiableDataService } from '../../../data/base/identifiable-data.service';
|
||||
import { dataService } from '../../../data/base/data-service.decorator';
|
||||
import { QUALITY_ASSURANCE_TOPIC_OBJECT } from '../models/quality-assurance-topic-object.resource-type';
|
||||
|
||||
/**
|
||||
* The service handling all Quality Assurance topic REST requests.
|
||||
*/
|
||||
@Injectable()
|
||||
@dataService(QUALITY_ASSURANCE_TOPIC_OBJECT)
|
||||
export class QualityAssuranceTopicRestService {
|
||||
/**
|
||||
* A private DataService implementation to delegate specific methods to.
|
||||
*/
|
||||
private dataService: DataServiceImpl;
|
||||
export class QualityAssuranceTopicRestService extends IdentifiableDataService<QualityAssuranceTopicObject> {
|
||||
|
||||
/**
|
||||
* Initialize service variables
|
||||
@@ -74,18 +31,15 @@ export class QualityAssuranceTopicRestService {
|
||||
* @param {ObjectCacheService} objectCache
|
||||
* @param {HALEndpointService} halService
|
||||
* @param {NotificationsService} notificationsService
|
||||
* @param {HttpClient} http
|
||||
* @param {DefaultChangeAnalyzer<QualityAssuranceTopicObject>} comparator
|
||||
*/
|
||||
constructor(
|
||||
protected requestService: RequestService,
|
||||
protected rdbService: RemoteDataBuildService,
|
||||
protected objectCache: ObjectCacheService,
|
||||
protected halService: HALEndpointService,
|
||||
protected notificationsService: NotificationsService,
|
||||
protected http: HttpClient,
|
||||
protected comparator: DefaultChangeAnalyzer<QualityAssuranceTopicObject>) {
|
||||
this.dataService = new DataServiceImpl(requestService, rdbService, null, objectCache, halService, notificationsService, http, comparator);
|
||||
protected notificationsService: NotificationsService
|
||||
) {
|
||||
super('qualityassurancetopics', requestService, rdbService, objectCache, halService);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -99,9 +53,9 @@ export class QualityAssuranceTopicRestService {
|
||||
* The list of Quality Assurance topics.
|
||||
*/
|
||||
public getTopics(options: FindListOptions = {}, ...linksToFollow: FollowLinkConfig<QualityAssuranceTopicObject>[]): Observable<RemoteData<PaginatedList<QualityAssuranceTopicObject>>> {
|
||||
return this.dataService.getBrowseEndpoint(options, 'qualityassurancetopics').pipe(
|
||||
return this.getBrowseEndpoint(options).pipe(
|
||||
take(1),
|
||||
mergeMap((href: string) => this.dataService.findAllByHref(href, options, true, true, ...linksToFollow)),
|
||||
mergeMap((href: string) => this.findListByHref(href, options, true, true, ...linksToFollow)),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -124,9 +78,9 @@ export class QualityAssuranceTopicRestService {
|
||||
*/
|
||||
public getTopic(id: string, ...linksToFollow: FollowLinkConfig<QualityAssuranceTopicObject>[]): Observable<RemoteData<QualityAssuranceTopicObject>> {
|
||||
const options = {};
|
||||
return this.dataService.getBrowseEndpoint(options, 'qualityassurancetopics').pipe(
|
||||
return this.getBrowseEndpoint(options).pipe(
|
||||
take(1),
|
||||
mergeMap((href: string) => this.dataService.findByHref(href + '/' + id, true, true, ...linksToFollow))
|
||||
mergeMap((href: string) => this.findByHref(href + '/' + id, true, true, ...linksToFollow))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user