1
0

[CST-5337] Refactoring in order to comply with new data service

This commit is contained in:
Giuseppe Digilio
2022-11-09 19:05:20 +01:00
parent 3a70b880cb
commit 5efe3296c6
6 changed files with 146 additions and 221 deletions

View File

@@ -20,8 +20,8 @@ import {
qualityAssuranceEventObjectMissingProjectFound
} from '../../../../shared/mocks/notifications.mock';
import { ReplaceOperation } from 'fast-json-patch';
import {RequestEntry} from '../../../data/request-entry.model';
import {FindListOptions} from '../../../data/find-list-options.model';
import { RequestEntry } from '../../../data/request-entry.model';
import { FindListOptions } from '../../../data/find-list-options.model';
describe('QualityAssuranceEventRestService', () => {
let scheduler: TestScheduler;
@@ -43,7 +43,7 @@ describe('QualityAssuranceEventRestService', () => {
const topic = 'ENRICH!MORE!PID';
const pageInfo = new PageInfo();
const array = [ qualityAssuranceEventObjectMissingPid, qualityAssuranceEventObjectMissingPid2 ];
const array = [qualityAssuranceEventObjectMissingPid, qualityAssuranceEventObjectMissingPid2];
const paginatedList = buildPaginatedList(pageInfo, array);
const qaEventObjectRD = createSuccessfulRemoteDataObject(qualityAssuranceEventObjectMissingPid);
const qaEventObjectMissingProjectRD = createSuccessfulRemoteDataObject(qualityAssuranceEventObjectMissingProjectFound);
@@ -87,12 +87,13 @@ describe('QualityAssuranceEventRestService', () => {
buildList: cold('(a)', {
a: paginatedListRD
}),
buildFromRequestUUID: jasmine.createSpy('buildFromRequestUUID')
buildFromRequestUUID: jasmine.createSpy('buildFromRequestUUID'),
buildFromRequestUUIDAndAwait: jasmine.createSpy('buildFromRequestUUIDAndAwait')
});
objectCache = {} as ObjectCacheService;
halService = jasmine.createSpyObj('halService', {
getEndpoint: cold('a|', { a: endpointURL })
getEndpoint: cold('a|', { a: endpointURL })
});
notificationsService = {} as NotificationsService;
@@ -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,13 +135,13 @@ 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', () => {
const result = service.getEventsByTopic(topic);
const expected = cold('(a)', {
a: paginatedListRD
a: paginatedListRD
});
expect(result).toBeObservable(expected);
});
@@ -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);
}
);
});

View File

@@ -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 { FindListOptions } from '../../../data/find-list-options.model';
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);
}
}

View File

@@ -17,8 +17,8 @@ import {
qualityAssuranceSourceObjectMoreAbstract,
qualityAssuranceSourceObjectMorePid
} from '../../../../shared/mocks/notifications.mock';
import {RequestEntry} from '../../../data/request-entry.model';
import {QualityAssuranceSourceRestService} from './quality-assurance-source-rest.service';
import { RequestEntry } from '../../../data/request-entry.model';
import { QualityAssuranceSourceRestService } from './quality-assurance-source-rest.service';
describe('QualityAssuranceSourceRestService', () => {
let scheduler: TestScheduler;
@@ -36,7 +36,7 @@ describe('QualityAssuranceSourceRestService', () => {
const requestUUID = '8b3c913a-5a4b-438b-9181-be1a5b4a1c8a';
const pageInfo = new PageInfo();
const array = [ qualityAssuranceSourceObjectMorePid, qualityAssuranceSourceObjectMoreAbstract ];
const array = [qualityAssuranceSourceObjectMorePid, qualityAssuranceSourceObjectMoreAbstract];
const paginatedList = buildPaginatedList(pageInfo, array);
const qaSourceObjectRD = createSuccessfulRemoteDataObject(qualityAssuranceSourceObjectMorePid);
const paginatedListRD = createSuccessfulRemoteDataObject(paginatedList);
@@ -65,7 +65,7 @@ describe('QualityAssuranceSourceRestService', () => {
objectCache = {} as ObjectCacheService;
halService = jasmine.createSpyObj('halService', {
getEndpoint: cold('a|', { a: endpointURL })
getEndpoint: cold('a|', { a: endpointURL })
});
notificationsService = {} as NotificationsService;
@@ -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();

View File

@@ -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 { FindListOptions } from '../../../data/find-list-options.model';
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))
);
}
}

View File

@@ -18,7 +18,7 @@ import {
qualityAssuranceTopicObjectMoreAbstract,
qualityAssuranceTopicObjectMorePid
} from '../../../../shared/mocks/notifications.mock';
import {RequestEntry} from '../../../data/request-entry.model';
import { RequestEntry } from '../../../data/request-entry.model';
describe('QualityAssuranceTopicRestService', () => {
let scheduler: TestScheduler;
@@ -36,7 +36,7 @@ describe('QualityAssuranceTopicRestService', () => {
const requestUUID = '8b3c913a-5a4b-438b-9181-be1a5b4a1c8a';
const pageInfo = new PageInfo();
const array = [ qualityAssuranceTopicObjectMorePid, qualityAssuranceTopicObjectMoreAbstract ];
const array = [qualityAssuranceTopicObjectMorePid, qualityAssuranceTopicObjectMoreAbstract];
const paginatedList = buildPaginatedList(pageInfo, array);
const qaTopicObjectRD = createSuccessfulRemoteDataObject(qualityAssuranceTopicObjectMorePid);
const paginatedListRD = createSuccessfulRemoteDataObject(paginatedList);
@@ -65,7 +65,7 @@ describe('QualityAssuranceTopicRestService', () => {
objectCache = {} as ObjectCacheService;
halService = jasmine.createSpyObj('halService', {
getEndpoint: cold('a|', { a: endpointURL })
getEndpoint: cold('a|', { a: endpointURL })
});
notificationsService = {} as NotificationsService;
@@ -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();

View File

@@ -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 { FindListOptions } from '../../../data/find-list-options.model';
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))
);
}
}