Refactored to remove forceBypassCache param from requestService and from data service classes.

This commit is contained in:
Michael W Spalti
2019-08-28 17:05:37 -07:00
parent 262b33261e
commit 1b48d3d1f6
26 changed files with 24 additions and 47 deletions

View File

@@ -11,7 +11,6 @@ import { DSpaceObjectDataService } from '../../core/data/dspace-object-data.serv
import { MockRouter } from '../../shared/mocks/mock-router';
import { ChangeDetectorRef, NO_ERRORS_SCHEMA } from '@angular/core';
import { of as observableOf } from 'rxjs/internal/observable/of';
import { RemoteData } from '../../core/data/remote-data';
import { ActivatedRouteStub } from '../../shared/testing/active-router-stub';
import { Community } from '../../core/shared/community.model';
import { Item } from '../../core/shared/item.model';

View File

@@ -82,7 +82,8 @@ export class BrowseByDatePageComponent extends BrowseByMetadataPageComponent {
const date = firstItemRD.payload.firstMetadataValue(metadataField);
if (hasValue(date)) {
const dateObj = new Date(date);
lowerLimit = dateObj.getFullYear();
// TODO: it appears that getFullYear (based on local time) is sometimes unreliable. Switching to UTC.
lowerLimit = dateObj.getUTCFullYear();
}
}
const options = [];

View File

@@ -44,7 +44,7 @@ export class AuthRequestService {
map((endpointURL) => this.getEndpointByMethod(endpointURL, method)),
distinctUntilChanged(),
map((endpointURL: string) => new AuthPostRequest(this.requestService.generateRequestId(), endpointURL, body, options)),
tap((request: PostRequest) => this.requestService.configure(request, true)),
tap((request: PostRequest) => this.requestService.configure(request)),
mergeMap((request: PostRequest) => this.fetchRequest(request)),
distinctUntilChanged());
}
@@ -55,7 +55,7 @@ export class AuthRequestService {
map((endpointURL) => this.getEndpointByMethod(endpointURL, method)),
distinctUntilChanged(),
map((endpointURL: string) => new AuthGetRequest(this.requestService.generateRequestId(), endpointURL, options)),
tap((request: GetRequest) => this.requestService.configure(request, true)),
tap((request: GetRequest) => this.requestService.configure(request)),
mergeMap((request: GetRequest) => this.fetchRequest(request)),
distinctUntilChanged());
}

View File

@@ -114,7 +114,7 @@ describe('BrowseService', () => {
scheduler.schedule(() => service.getBrowseDefinitions().subscribe());
scheduler.flush();
expect(requestService.configure).toHaveBeenCalledWith(expected, undefined);
expect(requestService.configure).toHaveBeenCalledWith(expected);
});
it('should call RemoteDataBuildService to create the RemoteData Observable', () => {
@@ -155,7 +155,7 @@ describe('BrowseService', () => {
scheduler.schedule(() => service.getBrowseEntriesFor(new BrowseEntrySearchOptions(browseDefinitions[1].id)).subscribe());
scheduler.flush();
expect(requestService.configure).toHaveBeenCalledWith(expected, undefined);
expect(requestService.configure).toHaveBeenCalledWith(expected);
});
it('should call RemoteDataBuildService to create the RemoteData Observable', () => {
@@ -174,7 +174,7 @@ describe('BrowseService', () => {
scheduler.schedule(() => service.getBrowseItemsFor(mockAuthorName, new BrowseEntrySearchOptions(browseDefinitions[1].id)).subscribe());
scheduler.flush();
expect(requestService.configure).toHaveBeenCalledWith(expected, undefined);
expect(requestService.configure).toHaveBeenCalledWith(expected);
});
it('should call RemoteDataBuildService to create the RemoteData Observable', () => {
@@ -303,7 +303,7 @@ describe('BrowseService', () => {
scheduler.schedule(() => service.getFirstItemFor(browseDefinitions[1].id).subscribe());
scheduler.flush();
expect(requestService.configure).toHaveBeenCalledWith(expected, undefined);
expect(requestService.configure).toHaveBeenCalledWith(expected);
});
it('should call RemoteDataBuildService to create the RemoteData Observable', () => {

View File

@@ -24,7 +24,6 @@ import { SearchParam } from '../cache/models/search-param.model';
@Injectable()
export class CollectionDataService extends ComColDataService<Collection> {
protected linkPath = 'collections';
protected forceBypassCache = false;
constructor(
protected requestService: RequestService,

View File

@@ -28,7 +28,6 @@ class NormalizedTestObject extends NormalizedObject<Item> {
}
class TestService extends ComColDataService<any> {
protected forceBypassCache = false;
constructor(
protected requestService: RequestService,

View File

@@ -24,7 +24,6 @@ export class CommunityDataService extends ComColDataService<Community> {
protected linkPath = 'communities';
protected topLinkPath = 'communities/search/top';
protected cds = this;
protected forceBypassCache = false;
constructor(
protected requestService: RequestService,

View File

@@ -24,7 +24,6 @@ class NormalizedTestObject extends NormalizedObject<Item> {
}
class TestService extends DataService<any> {
protected forceBypassCache = false;
constructor(
protected requestService: RequestService,

View File

@@ -45,7 +45,6 @@ export abstract class DataService<T extends CacheableObject> {
protected abstract store: Store<CoreState>;
protected abstract linkPath: string;
protected abstract halService: HALEndpointService;
protected abstract forceBypassCache = false;
protected abstract objectCache: ObjectCacheService;
protected abstract notificationsService: NotificationsService;
protected abstract http: HttpClient;
@@ -131,7 +130,7 @@ export abstract class DataService<T extends CacheableObject> {
first((href: string) => hasValue(href)))
.subscribe((href: string) => {
const request = new FindAllRequest(this.requestService.generateRequestId(), href, options);
this.requestService.configure(request, this.forceBypassCache);
this.requestService.configure(request);
});
return this.rdbService.buildList<T>(hrefObs) as Observable<RemoteData<PaginatedList<T>>>;
@@ -154,14 +153,14 @@ export abstract class DataService<T extends CacheableObject> {
find((href: string) => hasValue(href)))
.subscribe((href: string) => {
const request = new FindByIDRequest(this.requestService.generateRequestId(), href, id);
this.requestService.configure(request, this.forceBypassCache);
this.requestService.configure(request);
});
return this.rdbService.buildSingle<T>(hrefObs);
}
findByHref(href: string, options?: HttpOptions): Observable<RemoteData<T>> {
this.requestService.configure(new GetRequest(this.requestService.generateRequestId(), href, null, options), this.forceBypassCache);
this.requestService.configure(new GetRequest(this.requestService.generateRequestId(), href, null, options));
return this.rdbService.buildSingle<T>(href);
}
@@ -192,7 +191,7 @@ export abstract class DataService<T extends CacheableObject> {
first((href: string) => hasValue(href)))
.subscribe((href: string) => {
const request = new FindAllRequest(this.requestService.generateRequestId(), href, options);
this.requestService.configure(request, true);
this.requestService.configure(request);
});
return this.rdbService.buildList<T>(hrefObs) as Observable<RemoteData<PaginatedList<T>>>;

View File

@@ -72,7 +72,7 @@ describe('DSpaceObjectDataService', () => {
scheduler.schedule(() => service.findById(testObject.uuid));
scheduler.flush();
expect(requestService.configure).toHaveBeenCalledWith(new FindByIDRequest(requestUUID, requestURL, testObject.uuid), false);
expect(requestService.configure).toHaveBeenCalledWith(new FindByIDRequest(requestUUID, requestURL, testObject.uuid));
});
it('should return a RemoteData<DSpaceObject> for the object with the given ID', () => {

View File

@@ -18,7 +18,6 @@ import { DSOChangeAnalyzer } from './dso-change-analyzer.service';
/* tslint:disable:max-classes-per-file */
class DataServiceImpl extends DataService<DSpaceObject> {
protected linkPath = 'dso';
protected forceBypassCache = false;
constructor(
protected requestService: RequestService,

View File

@@ -27,7 +27,6 @@ import { Collection } from '../shared/collection.model';
@Injectable()
export class ItemDataService extends DataService<Item> {
protected linkPath = 'items';
protected forceBypassCache = false;
constructor(
protected requestService: RequestService,

View File

@@ -19,7 +19,6 @@ import { MetadataSchema } from '../metadata/metadata-schema.model';
/* tslint:disable:max-classes-per-file */
class DataServiceImpl extends DataService<MetadataSchema> {
protected linkPath = 'metadataschemas';
protected forceBypassCache = false;
constructor(
protected requestService: RequestService,

View File

@@ -147,12 +147,12 @@ export class RequestService {
* @param {RestRequest} request The request to send out
* @param {boolean} forceBypassCache When true, a new request is always dispatched
*/
configure<T extends CacheableObject>(request: RestRequest, forceBypassCache: boolean = false): void {
configure<T extends CacheableObject>(request: RestRequest): void {
const isGetRequest = request.method === RestRequestMethod.GET;
if (forceBypassCache) {
this.clearRequestsOnTheirWayToTheStore(request);
}
if (!isGetRequest || (forceBypassCache && !this.isPending(request)) || !this.isCachedOrPending(request)) {
// if (forceBypassCache) {
// this.clearRequestsOnTheirWayToTheStore(request);
// }
if (!isGetRequest || !this.isCachedOrPending(request)) {
this.dispatchRequest(request);
if (isGetRequest) {
this.trackRequestsOnTheirWayToTheStore(request);

View File

@@ -61,7 +61,7 @@ describe('ResourcePolicyService', () => {
scheduler.schedule(() => service.findByHref(requestURL));
scheduler.flush();
expect(requestService.configure).toHaveBeenCalledWith(new GetRequest(requestUUID, requestURL, null), false);
expect(requestService.configure).toHaveBeenCalledWith(new GetRequest(requestUUID, requestURL, null));
});
it('should return a RemoteData<ResourcePolicy> for the object with the given URL', () => {

View File

@@ -22,7 +22,6 @@ import { HttpOptions } from '../dspace-rest-v2/dspace-rest-v2.service';
/* tslint:disable:max-classes-per-file */
class DataServiceImpl extends DataService<ResourcePolicy> {
protected linkPath = 'resourcepolicies';
protected forceBypassCache = false;
constructor(
protected requestService: RequestService,

View File

@@ -27,7 +27,6 @@ import { DSOChangeAnalyzer } from '../data/dso-change-analyzer.service';
export class GroupEpersonService extends EpersonService<Group> {
protected linkPath = 'groups';
protected browseEndpoint = '';
protected forceBypassCache = false;
constructor(
protected comparator: DSOChangeAnalyzer<Group>,

View File

@@ -148,7 +148,7 @@ describe('Core Module - RxJS Operators', () => {
scheduler.schedule(() => source.pipe(configureRequest(requestService)).subscribe());
scheduler.flush();
expect(requestService.configure).toHaveBeenCalledWith(testRequest, undefined);
expect(requestService.configure).toHaveBeenCalledWith(testRequest);
});
});

View File

@@ -52,9 +52,9 @@ export const getResourceLinksFromResponse = () =>
map((response: DSOSuccessResponse) => response.resourceSelfLinks),
);
export const configureRequest = (requestService: RequestService, forceBypassCache?: boolean) =>
export const configureRequest = (requestService: RequestService) =>
(source: Observable<RestRequest>): Observable<RestRequest> =>
source.pipe(tap((request: RestRequest) => requestService.configure(request, forceBypassCache)));
source.pipe(tap((request: RestRequest) => requestService.configure(request)));
export const getRemoteDataPayload = () =>
<T>(source: Observable<RemoteData<T>>): Observable<T> =>

View File

@@ -62,7 +62,7 @@ describe('SubmissionRestService test suite', () => {
scheduler.schedule(() => service.getDataById(resourceEndpoint, resourceScope).subscribe());
scheduler.flush();
expect(requestService.configure).toHaveBeenCalledWith(expected, true);
expect(requestService.configure).toHaveBeenCalledWith(expected);
});
});

View File

@@ -109,7 +109,7 @@ export class SubmissionRestService {
filter((href: string) => isNotEmpty(href)),
distinctUntilChanged(),
map((endpointURL: string) => new SubmissionRequest(requestId, endpointURL)),
tap((request: RestRequest) => this.requestService.configure(request, true)),
tap((request: RestRequest) => this.requestService.configure(request)),
flatMap(() => this.fetchRequest(requestId)),
distinctUntilChanged());
}

View File

@@ -20,7 +20,6 @@ import { DSOChangeAnalyzer } from '../data/dso-change-analyzer.service';
@Injectable()
export class WorkflowItemDataService extends DataService<WorkflowItem> {
protected linkPath = 'workflowitems';
protected forceBypassCache = true;
constructor(
protected comparator: DSOChangeAnalyzer<WorkflowItem>,

View File

@@ -20,7 +20,6 @@ import { WorkspaceItem } from './models/workspaceitem.model';
@Injectable()
export class WorkspaceitemDataService extends DataService<WorkspaceItem> {
protected linkPath = 'workspaceitems';
protected forceBypassCache = true;
constructor(
protected comparator: DSOChangeAnalyzer<WorkspaceItem>,

View File

@@ -27,11 +27,6 @@ export class ClaimedTaskDataService extends TasksService<ClaimedTask> {
*/
protected linkPath = 'claimedtasks';
/**
* When true, a new request is always dispatched
*/
protected forceBypassCache = true;
/**
* Initialize instance variables
*

View File

@@ -27,11 +27,6 @@ export class PoolTaskDataService extends TasksService<PoolTask> {
*/
protected linkPath = 'pooltasks';
/**
* When true, a new request is always dispatched
*/
protected forceBypassCache = true;
/**
* Initialize instance variables
*

View File

@@ -29,7 +29,6 @@ class TestTask extends TaskObject {
class TestService extends TasksService<TestTask> {
protected linkPath = LINK_NAME;
protected forceBypassCache = true;
constructor(
protected requestService: RequestService,