diff --git a/src/app/+home-page/home-page.component.ts b/src/app/+home-page/home-page.component.ts index 902a0e820d..c58a10883c 100644 --- a/src/app/+home-page/home-page.component.ts +++ b/src/app/+home-page/home-page.component.ts @@ -1,4 +1,5 @@ import { Component } from '@angular/core'; +import { GroupEpersonService } from '../core/eperson/group-eperson.service'; @Component({ selector: 'ds-home-page', @@ -6,4 +7,12 @@ import { Component } from '@angular/core'; templateUrl: './home-page.component.html' }) export class HomePageComponent { + constructor(private s: GroupEpersonService) {} + + ngOnInit() { + this.s.findById('11cc35e5-a11d-4b64-b5b9-0052a5d15509') + .subscribe((r) => { + console.log(r); + }) + } } diff --git a/src/app/core/auth/auth-response-parsing.service.spec.ts b/src/app/core/auth/auth-response-parsing.service.spec.ts index daf59664f2..df43ab9685 100644 --- a/src/app/core/auth/auth-response-parsing.service.spec.ts +++ b/src/app/core/auth/auth-response-parsing.service.spec.ts @@ -1,20 +1,36 @@ -import { AuthStatusResponse } from '../cache/response.models'; +import { async, TestBed } from '@angular/core/testing'; +import { Store, StoreModule } from '@ngrx/store'; + +import { GlobalConfig } from '../../../config/global-config.interface'; +import { AuthStatusResponse } from '../cache/response.models'; import { ObjectCacheService } from '../cache/object-cache.service'; import { AuthStatus } from './models/auth-status.model'; import { AuthResponseParsingService } from './auth-response-parsing.service'; import { AuthGetRequest, AuthPostRequest } from '../data/request.models'; import { MockStore } from '../../shared/testing/mock-store'; -import { ObjectCacheState } from '../cache/object-cache.reducer'; describe('AuthResponseParsingService', () => { let service: AuthResponseParsingService; - const EnvConfig = { cache: { msToLive: 1000 } } as any; - const store = new MockStore({}); - const objectCacheService = new ObjectCacheService(store as any); + const EnvConfig: GlobalConfig = { cache: { msToLive: 1000 } } as any; + let store: any; + let objectCacheService: ObjectCacheService; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + imports: [ + StoreModule.forRoot({}), + ], + providers: [ + { provide: Store, useClass: MockStore } + ] + }).compileComponents(); + })); beforeEach(() => { + store = TestBed.get(Store); + objectCacheService = new ObjectCacheService(store as any); service = new AuthResponseParsingService(EnvConfig, objectCacheService); }); diff --git a/src/app/core/cache/server-sync-buffer.effects.spec.ts b/src/app/core/cache/server-sync-buffer.effects.spec.ts index 0a8d50107e..724a4b1c6b 100644 --- a/src/app/core/cache/server-sync-buffer.effects.spec.ts +++ b/src/app/core/cache/server-sync-buffer.effects.spec.ts @@ -1,20 +1,17 @@ import { TestBed } from '@angular/core/testing'; + import { Observable, of as observableOf } from 'rxjs'; import { provideMockActions } from '@ngrx/effects/testing'; import { cold, hot } from 'jasmine-marbles'; + import { ServerSyncBufferEffects } from './server-sync-buffer.effects'; import { GLOBAL_CONFIG } from '../../../config'; -import { - CommitSSBAction, - EmptySSBAction, - ServerSyncBufferActionTypes -} from './server-sync-buffer.actions'; +import { CommitSSBAction, EmptySSBAction, ServerSyncBufferActionTypes } from './server-sync-buffer.actions'; import { RestRequestMethod } from '../data/rest-request-method'; -import { Store } from '@ngrx/store'; +import { Store, StoreModule } from '@ngrx/store'; import { RequestService } from '../data/request.service'; import { ObjectCacheService } from './object-cache.service'; import { MockStore } from '../../shared/testing/mock-store'; -import { ObjectCacheState } from './object-cache.reducer'; import * as operators from 'rxjs/operators'; import { spyOnOperator } from '../../shared/testing/utils'; import { DSpaceObject } from '../shared/dspace-object.model'; @@ -38,8 +35,10 @@ describe('ServerSyncBufferEffects', () => { let store; beforeEach(() => { - store = new MockStore({}); TestBed.configureTestingModule({ + imports: [ + StoreModule.forRoot({}), + ], providers: [ ServerSyncBufferEffects, provideMockActions(() => actions), @@ -54,11 +53,12 @@ describe('ServerSyncBufferEffects', () => { } } }, - { provide: Store, useValue: store } + { provide: Store, useClass: MockStore } // other providers ], }); + store = TestBed.get(Store); ssbEffects = TestBed.get(ServerSyncBufferEffects); }); diff --git a/src/app/core/config/config.service.ts b/src/app/core/config/config.service.ts index c6c2e2e7d2..340a7a97d6 100644 --- a/src/app/core/config/config.service.ts +++ b/src/app/core/config/config.service.ts @@ -6,7 +6,6 @@ import { ConfigRequest, FindAllOptions, RestRequest } from '../data/request.mode import { hasValue, isNotEmpty } from '../../shared/empty.util'; import { HALEndpointService } from '../shared/hal-endpoint.service'; import { ConfigData } from './config-data'; -import { RequestEntry } from '../data/request.reducer'; import { getResponseFromEntry } from '../shared/operators'; export abstract class ConfigService { diff --git a/src/app/core/config/submission-uploads-config.service.ts b/src/app/core/config/submission-uploads-config.service.ts index 245e1fab68..2e092fa4f3 100644 --- a/src/app/core/config/submission-uploads-config.service.ts +++ b/src/app/core/config/submission-uploads-config.service.ts @@ -1,8 +1,8 @@ import { Injectable } from '@angular/core'; import { ConfigService } from './config.service'; -import { ResponseCacheService } from '../cache/response-cache.service'; import { RequestService } from '../data/request.service'; import { HALEndpointService } from '../shared/hal-endpoint.service'; +import { ObjectCacheService } from '../cache/object-cache.service'; /** * Provides methods to retrieve, from REST server, bitstream access conditions configurations applicable during the submission process. @@ -13,7 +13,7 @@ export class SubmissionUploadsConfigService extends ConfigService { protected browseEndpoint = ''; constructor( - protected responseCache: ResponseCacheService, + protected objectCache: ObjectCacheService, protected requestService: RequestService, protected halService: HALEndpointService) { super(); diff --git a/src/app/core/data/data.service.ts b/src/app/core/data/data.service.ts index 617e4a95dc..945c881bba 100644 --- a/src/app/core/data/data.service.ts +++ b/src/app/core/data/data.service.ts @@ -1,4 +1,3 @@ -import { distinctUntilChanged, filter, first, map } from 'rxjs/operators'; import { Observable } from 'rxjs'; import { distinctUntilChanged, @@ -10,10 +9,8 @@ import { switchMap, take } from 'rxjs/operators'; -import { Observable } from 'rxjs'; import { Store } from '@ngrx/store'; -import { hasValue, isNotEmpty } from '../../shared/empty.util'; import { hasValue, isNotEmpty, isNotEmptyOperator } from '../../shared/empty.util'; import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service'; import { CoreState } from '../core.reducers'; diff --git a/src/app/core/data/request.reducer.spec.ts b/src/app/core/data/request.reducer.spec.ts index 57fbb01ce1..4a04ec5ae2 100644 --- a/src/app/core/data/request.reducer.spec.ts +++ b/src/app/core/data/request.reducer.spec.ts @@ -9,7 +9,7 @@ import { import { GetRequest } from './request.models'; import { RestResponse } from '../cache/response.models'; -const response = new RestResponse(true, 'OK'); +const response = new RestResponse(true, 200, 'OK'); class NullAction extends RequestCompleteAction { type = null; payload = null; @@ -89,8 +89,8 @@ describe('requestReducer', () => { expect(newState[id1].requestPending).toEqual(state[id1].requestPending); expect(newState[id1].responsePending).toEqual(false); expect(newState[id1].completed).toEqual(true); - expect(newState[id1].response.isSuccessful).toEqual(response.isSuccessful) - expect(newState[id1].response.statusCode).toEqual(response.statusCode) + expect(newState[id1].response.isSuccessful).toEqual(response.isSuccessful); + expect(newState[id1].response.statusCode).toEqual(response.statusCode); expect(newState[id1].response.timeAdded).toBeTruthy() }); diff --git a/src/app/core/data/request.service.spec.ts b/src/app/core/data/request.service.spec.ts index c19543289e..54190e628c 100644 --- a/src/app/core/data/request.service.spec.ts +++ b/src/app/core/data/request.service.spec.ts @@ -289,14 +289,6 @@ describe('RequestService', () => { }); }); - describe('when forceBypassCache is true', () => { - it('should call clearRequestsOnTheirWayToTheStore method', () => { - spyOn(serviceAsAny, 'clearRequestsOnTheirWayToTheStore'); - service.configure(testPostRequest, true); - expect(serviceAsAny.clearRequestsOnTheirWayToTheStore).toHaveBeenCalledWith(testPostRequest.href); - }); - }); - }); describe('isCachedOrPending', () => { @@ -467,37 +459,6 @@ describe('RequestService', () => { }); }); - describe('clearRequestsOnTheirWayToTheStore', () => { - let request: GetRequest; - - beforeEach(() => { - request = testPatchRequest; - }); - - describe('when there is no request entry', () => { - it('should remove response from cache', () => { - spyOn(service, 'getByHref').and.returnValue(observableOf(undefined)); - - serviceAsAny.clearRequestsOnTheirWayToTheStore(request.href); - - expect(responseCache.remove).toHaveBeenCalledWith(request.href); - }); - }); - - describe('when there is a request entry and is not pending', () => { - it('should remove response from cache and stop tracking the request', () => { - spyOn(service, 'getByHref').and.returnValue(observableOf({responsePending: false})); - - serviceAsAny.clearRequestsOnTheirWayToTheStore(request.href); - - expect(responseCache.remove).toHaveBeenCalledWith(request.href); - expect(serviceAsAny.requestsOnTheirWayToTheStore.includes(request.href)).toBeFalsy(); - - }); - }); - - }); - describe('isReusable', () => { describe('when the given UUID is has no value', () => { let reusable; diff --git a/src/app/core/data/request.service.ts b/src/app/core/data/request.service.ts index 81580be89b..1ba38f4486 100644 --- a/src/app/core/data/request.service.ts +++ b/src/app/core/data/request.service.ts @@ -1,8 +1,7 @@ -import { merge as observableMerge, Observable, of as observableOf, race as observableRace } from 'rxjs'; -import { filter, map, mergeMap, switchMap, take } from 'rxjs/operators'; import { Injectable } from '@angular/core'; -import { remove } from 'lodash'; +import { merge as observableMerge, Observable, of as observableOf, race as observableRace } from 'rxjs'; +import { filter, map, mergeMap, switchMap, take } from 'rxjs/operators'; import { MemoizedSelector, select, Store } from '@ngrx/store'; import { hasNoValue, hasValue } from '../../shared/empty.util'; @@ -15,7 +14,6 @@ import { pathSelector } from '../shared/selectors'; import { UUIDService } from '../shared/uuid.service'; import { RequestConfigureAction, RequestExecuteAction } from './request.actions'; import { GetRequest, RestRequest } from './request.models'; - import { RequestEntry } from './request.reducer'; import { CommitSSBAction } from '../cache/server-sync-buffer.actions'; import { RestRequestMethod } from './rest-request-method'; @@ -70,6 +68,7 @@ export class RequestService { this.store.pipe( select(this.originalUUIDFromUUIDSelector(uuid)), mergeMap((originalUUID) => { + console.log(originalUUID); return this.store.pipe(select(this.entryFromUUIDSelector(originalUUID))) }, )) @@ -83,19 +82,6 @@ export class RequestService { ); } - private clearRequestsOnTheirWayToTheStore(href) { - this.getByHref(href).pipe( - take(1) - ).subscribe((re: RequestEntry) => { - if (!hasValue(re)) { - this.responseCache.remove(href); - } else if (!re.responsePending) { - this.responseCache.remove(href); - remove(this.requestsOnTheirWayToTheStore, (item) => item === href); - } - }); - } - /** * Configure a certain request * Used to make sure a request is in the cache @@ -105,12 +91,9 @@ export class RequestService { // TODO to review "forceBypassCache" param when https://github.com/DSpace/dspace-angular/issues/217 will be fixed configure(request: RestRequest, forceBypassCache: boolean = false): void { const isGetRequest = request.method === RestRequestMethod.GET; - if (forceBypassCache) { - this.clearRequestsOnTheirWayToTheStore(request.href); - } - if (!isGetRequest || !this.isCachedOrPending(request) || (forceBypassCache && !this.isPending(request))) { + if (!isGetRequest || !this.isCachedOrPending(request) || forceBypassCache) { this.dispatchRequest(request); - if (isGetRequest) { + if (isGetRequest && !forceBypassCache) { this.trackRequestsOnTheirWayToTheStore(request); } } else { diff --git a/src/app/core/eperson/eperson-response-parsing.service.ts b/src/app/core/eperson/eperson-response-parsing.service.ts index 4af9da71a7..56429340da 100644 --- a/src/app/core/eperson/eperson-response-parsing.service.ts +++ b/src/app/core/eperson/eperson-response-parsing.service.ts @@ -3,7 +3,7 @@ import { Inject, Injectable } from '@angular/core'; import { RestRequest } from '../data/request.models'; import { ResponseParsingService } from '../data/parsing.service'; import { DSpaceRESTV2Response } from '../dspace-rest-v2/dspace-rest-v2-response.model'; -import { EpersonSuccessResponse, ErrorResponse, RestResponse } from '../cache/response-cache.models'; +import { EpersonSuccessResponse, ErrorResponse, RestResponse } from '../cache/response.models'; import { isNotEmpty } from '../../shared/empty.util'; import { BaseResponseParsingService } from '../data/base-response-parsing.service'; import { GLOBAL_CONFIG } from '../../../config'; diff --git a/src/app/core/eperson/eperson.service.ts b/src/app/core/eperson/eperson.service.ts index 777dc397ae..6aff82421d 100644 --- a/src/app/core/eperson/eperson.service.ts +++ b/src/app/core/eperson/eperson.service.ts @@ -1,21 +1,13 @@ import { Observable } from 'rxjs'; -import { RequestService } from '../data/request.service'; -import { ResponseCacheService } from '../cache/response-cache.service'; -import { EpersonRequest, FindAllOptions } from '../data/request.models'; -import { HALEndpointService } from '../shared/hal-endpoint.service'; +import { FindAllOptions } from '../data/request.models'; import { NormalizedObject } from '../cache/models/normalized-object.model'; import { DataService } from '../data/data.service'; +import { CacheableObject } from '../cache/object-cache.reducer'; /** * An abstract class that provides methods to make HTTP request to eperson endpoint. */ -export abstract class EpersonService extends DataService { - protected request: EpersonRequest; - protected abstract responseCache: ResponseCacheService; - protected abstract requestService: RequestService; - protected abstract linkPath: string; - protected abstract browseEndpoint: string; - protected abstract halService: HALEndpointService; +export abstract class EpersonService extends DataService { public getBrowseEndpoint(options: FindAllOptions): Observable { return this.halService.getEndpoint(this.linkPath); diff --git a/src/app/core/eperson/group-eperson.service.ts b/src/app/core/eperson/group-eperson.service.ts index f26ef7d8b7..0e12c55139 100644 --- a/src/app/core/eperson/group-eperson.service.ts +++ b/src/app/core/eperson/group-eperson.service.ts @@ -1,11 +1,11 @@ import { Injectable } from '@angular/core'; +import { HttpClient } from '@angular/common/http'; import { Store } from '@ngrx/store'; import { Observable } from 'rxjs'; import { filter, map, take } from 'rxjs/operators'; import { EpersonService } from './eperson.service'; -import { ResponseCacheService } from '../cache/response-cache.service'; import { RequestService } from '../data/request.service'; import { FindAllOptions } from '../data/request.models'; import { HALEndpointService } from '../shared/hal-endpoint.service'; @@ -17,6 +17,9 @@ import { ObjectCacheService } from '../cache/object-cache.service'; import { SearchParam } from '../cache/models/search-param.model'; import { RemoteData } from '../data/remote-data'; import { PaginatedList } from '../data/paginated-list'; +import { NotificationsService } from '../../shared/notifications/notifications.service'; +import { NormalizedObjectBuildService } from '../cache/builders/normalized-object-build.service'; +import { DSOChangeAnalyzer } from '../data/dso-change-analyzer.service'; /** * Provides methods to retrieve eperson group resources. @@ -28,7 +31,10 @@ export class GroupEpersonService extends EpersonService protected forceBypassCache = false; constructor( - protected responseCache: ResponseCacheService, + protected comparator: DSOChangeAnalyzer, + protected dataBuildService: NormalizedObjectBuildService, + protected http: HttpClient, + protected notificationsService: NotificationsService, protected requestService: RequestService, protected rdbService: RemoteDataBuildService, protected store: Store, @@ -57,4 +63,5 @@ export class GroupEpersonService extends EpersonService map((groups: RemoteData>) => groups.payload.totalElements > 0) ); } + } diff --git a/src/app/core/eperson/models/normalized-group.model.ts b/src/app/core/eperson/models/normalized-group.model.ts index be5995d9c5..3189adbc8f 100644 --- a/src/app/core/eperson/models/normalized-group.model.ts +++ b/src/app/core/eperson/models/normalized-group.model.ts @@ -12,6 +12,9 @@ export class NormalizedGroup extends NormalizedDSpaceObject implements Cacheable @autoserialize public handle: string; + @autoserialize + public name: string; + @autoserialize public permanent: boolean; } diff --git a/src/app/core/integration/integration-response-parsing.service.spec.ts b/src/app/core/integration/integration-response-parsing.service.spec.ts index 9f24aef9b2..4187606265 100644 --- a/src/app/core/integration/integration-response-parsing.service.spec.ts +++ b/src/app/core/integration/integration-response-parsing.service.spec.ts @@ -35,35 +35,35 @@ describe('IntegrationResponseParsingService', () => { function initVars() { pageInfo = Object.assign(new PageInfo(), { elementsPerPage: 5, totalElements: 5, totalPages: 1, currentPage: 1, self: 'https://rest.api/integration/authorities/type/entries'}); definitions = new PaginatedList(pageInfo,[ - Object.assign({}, new AuthorityValue(), { + Object.assign(new AuthorityValue(), { type: 'authority', display: 'One', id: 'One', otherInformation: undefined, value: 'One' }), - Object.assign({}, new AuthorityValue(), { + Object.assign(new AuthorityValue(), { type: 'authority', display: 'Two', id: 'Two', otherInformation: undefined, value: 'Two' }), - Object.assign({}, new AuthorityValue(), { + Object.assign(new AuthorityValue(), { type: 'authority', display: 'Three', id: 'Three', otherInformation: undefined, value: 'Three' }), - Object.assign({}, new AuthorityValue(), { + Object.assign(new AuthorityValue(), { type: 'authority', display: 'Four', id: 'Four', otherInformation: undefined, value: 'Four' }), - Object.assign({}, new AuthorityValue(), { + Object.assign(new AuthorityValue(), { type: 'authority', display: 'Five', id: 'Five', diff --git a/src/app/core/integration/integration.service.ts b/src/app/core/integration/integration.service.ts index 22028e1427..5826f4646d 100644 --- a/src/app/core/integration/integration.service.ts +++ b/src/app/core/integration/integration.service.ts @@ -2,16 +2,12 @@ import { Observable, of as observableOf, throwError as observableThrowError } fr import { distinctUntilChanged, filter, map, mergeMap, tap } from 'rxjs/operators'; import { RequestService } from '../data/request.service'; import { IntegrationSuccessResponse } from '../cache/response.models'; -import { ResponseCacheService } from '../cache/response-cache.service'; -import { IntegrationSuccessResponse, RestResponse } from '../cache/response-cache.models'; import { GetRequest, IntegrationRequest } from '../data/request.models'; import { hasValue, isNotEmpty } from '../../shared/empty.util'; import { HALEndpointService } from '../shared/hal-endpoint.service'; import { IntegrationData } from './integration-data'; import { IntegrationSearchOptions } from './models/integration-options.model'; -import { RequestEntry } from '../data/request.reducer'; import { getResponseFromEntry } from '../shared/operators'; -import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service'; export abstract class IntegrationService { protected request: IntegrationRequest; diff --git a/src/app/core/json-patch/json-patch-operations.service.spec.ts b/src/app/core/json-patch/json-patch-operations.service.spec.ts index a06f1ec5e4..67751ee9a9 100644 --- a/src/app/core/json-patch/json-patch-operations.service.spec.ts +++ b/src/app/core/json-patch/json-patch-operations.service.spec.ts @@ -1,12 +1,11 @@ import { async, TestBed } from '@angular/core/testing'; -import { cold, getTestScheduler } from 'jasmine-marbles'; +import { getTestScheduler } from 'jasmine-marbles'; import { TestScheduler } from 'rxjs/testing'; import { of as observableOf } from 'rxjs'; import { Store, StoreModule } from '@ngrx/store'; import { getMockRequestService } from '../../shared/mocks/mock-request.service'; -import { ResponseCacheService } from '../cache/response-cache.service'; import { RequestService } from '../data/request.service'; import { SubmissionPatchRequest } from '../data/request.models'; import { HALEndpointServiceStub } from '../../shared/testing/hal-endpoint-service-stub'; @@ -23,13 +22,13 @@ import { StartTransactionPatchOperationsAction } from './json-patch-operations.actions'; import { MockStore } from '../../shared/testing/mock-store'; +import { RequestEntry } from '../data/request.reducer'; class TestService extends JsonPatchOperationsService { protected linkPath = ''; protected patchRequestConstructor = SubmissionPatchRequest; constructor( - protected responseCache: ResponseCacheService, protected requestService: RequestService, protected store: Store, protected halService: HALEndpointService) { @@ -41,7 +40,6 @@ class TestService extends JsonPatchOperationsService { let scheduler: TestScheduler; let service: TestService; - let responseCache: ResponseCacheService; let requestService: RequestService; let rdbService: RemoteDataBuildService; let halService: any; @@ -84,18 +82,14 @@ describe('JsonPatchOperationsService test suite', () => { value: ['test'] }]; - function initMockResponseCacheService(isSuccessful: boolean): ResponseCacheService { - return jasmine.createSpyObj('responseCache', { - get: cold('c-', { - c: {response: {isSuccessful}, - timeAdded: timestampResponse} - }) - }); - } + const getRequestEntry$ = (successful: boolean) => { + return observableOf({ + response: { isSuccessful: successful, timeAdded: timestampResponse } as any + } as RequestEntry) + }; function initTestService(): TestService { return new TestService( - responseCache, requestService, store, halService @@ -116,8 +110,7 @@ describe('JsonPatchOperationsService test suite', () => { beforeEach(() => { store = TestBed.get(Store); - responseCache = initMockResponseCacheService(true); - requestService = getMockRequestService(); + requestService = getMockRequestService(getRequestEntry$(true)); rdbService = getMockRemoteDataBuildService(); scheduler = getTestScheduler(); halService = new HALEndpointServiceStub(resourceEndpointURL); @@ -146,7 +139,7 @@ describe('JsonPatchOperationsService test suite', () => { scheduler.schedule(() => service.jsonPatchByResourceType(resourceEndpoint, resourceScope, testJsonPatchResourceType).subscribe()); scheduler.flush(); - expect(requestService.configure).toHaveBeenCalledWith(expected, true); + expect(requestService.configure).toHaveBeenCalledWith(expected); }); it('should dispatch a new StartTransactionPatchOperationsAction', () => { @@ -170,8 +163,7 @@ describe('JsonPatchOperationsService test suite', () => { describe('when request is not successful', () => { beforeEach(() => { store = TestBed.get(Store); - responseCache = initMockResponseCacheService(false); - requestService = getMockRequestService(); + requestService = getMockRequestService(getRequestEntry$(false)); rdbService = getMockRemoteDataBuildService(); scheduler = getTestScheduler(); halService = new HALEndpointServiceStub(resourceEndpointURL); @@ -208,7 +200,7 @@ describe('JsonPatchOperationsService test suite', () => { scheduler.schedule(() => service.jsonPatchByResourceID(resourceEndpoint, resourceScope, testJsonPatchResourceType, testJsonPatchResourceId).subscribe()); scheduler.flush(); - expect(requestService.configure).toHaveBeenCalledWith(expected, true); + expect(requestService.configure).toHaveBeenCalledWith(expected); }); it('should dispatch a new StartTransactionPatchOperationsAction', () => { @@ -232,8 +224,7 @@ describe('JsonPatchOperationsService test suite', () => { describe('when request is not successful', () => { beforeEach(() => { store = TestBed.get(Store); - responseCache = initMockResponseCacheService(false); - requestService = getMockRequestService(); + requestService = getMockRequestService(getRequestEntry$(false)); rdbService = getMockRemoteDataBuildService(); scheduler = getTestScheduler(); halService = new HALEndpointServiceStub(resourceEndpointURL); diff --git a/src/app/core/json-patch/json-patch-operations.service.ts b/src/app/core/json-patch/json-patch-operations.service.ts index a6b3ddc7e1..7ca59e8b39 100644 --- a/src/app/core/json-patch/json-patch-operations.service.ts +++ b/src/app/core/json-patch/json-patch-operations.service.ts @@ -1,12 +1,10 @@ -import { merge as observableMerge, Observable, of as observableOf, throwError as observableThrowError } from 'rxjs'; -import { distinctUntilChanged, filter, flatMap, map, mergeMap, partition, take, tap } from 'rxjs/operators'; +import { merge as observableMerge, Observable, of as observableOf } from 'rxjs'; +import { distinctUntilChanged, filter, find, flatMap, map, partition, take, tap } from 'rxjs/operators'; import { Store } from '@ngrx/store'; import { hasValue, isEmpty, isNotEmpty, isNotUndefined, isUndefined } from '../../shared/empty.util'; -import { ErrorResponse, PostPatchSuccessResponse, RestResponse } from '../cache/response-cache.models'; -import { ResponseCacheEntry } from '../cache/response-cache.reducer'; -import { ResponseCacheService } from '../cache/response-cache.service'; -import { PatchRequest, RestRequest } from '../data/request.models'; +import { ErrorResponse, PostPatchSuccessResponse, RestResponse } from '../cache/response.models'; +import { PatchRequest } from '../data/request.models'; import { RequestService } from '../data/request.service'; import { HALEndpointService } from '../shared/hal-endpoint.service'; import { CoreState } from '../core.reducers'; @@ -18,31 +16,20 @@ import { StartTransactionPatchOperationsAction } from './json-patch-operations.actions'; import { JsonPatchOperationModel } from './json-patch.model'; +import { getResponseFromEntry } from '../shared/operators'; +import { ObjectCacheEntry } from '../cache/object-cache.reducer'; /** * An abstract class that provides methods to make JSON Patch requests. */ export abstract class JsonPatchOperationsService { - protected abstract responseCache: ResponseCacheService; + protected abstract requestService: RequestService; protected abstract store: Store; protected abstract linkPath: string; protected abstract halService: HALEndpointService; protected abstract patchRequestConstructor: any; - protected submitData(request: RestRequest): Observable { - const responses = this.responseCache.get(request.href).pipe(map((entry: ResponseCacheEntry) => entry.response)); - const errorResponses = responses.pipe( - filter((response) => !response.isSuccessful), - mergeMap(() => observableThrowError(new Error(`Couldn't send data to server`))) - ); - const successResponses = responses.pipe( - filter((response: PostPatchSuccessResponse) => isNotEmpty(response)), - map((response: PostPatchSuccessResponse) => response.dataDefinition) - ); - return observableMerge(errorResponses, successResponses); - } - /** * Submit a new JSON Patch request with all operations stored in the state that are ready to be dispatched * @@ -56,6 +43,7 @@ export abstract class JsonPatchOperationsService, resourceType: string, resourceId?: string): Observable { + const requestId = this.requestService.generateRequestId(); let startTransactionTime = null; const [patchRequest$, emptyRequest$] = partition((request: PatchRequestDefinition) => isNotEmpty(request.body))(hrefObs.pipe( flatMap((endpointURL: string) => { @@ -84,7 +72,7 @@ export abstract class JsonPatchOperationsService isNotEmpty(request.body)), tap(() => this.store.dispatch(new StartTransactionPatchOperationsAction(resourceType, resourceId, startTransactionTime))), - tap((request: PatchRequestDefinition) => this.requestService.configure(request, true)), - flatMap((request: PatchRequestDefinition) => { - const [successResponse$, errorResponse$] = partition((response: RestResponse) => response.isSuccessful)(this.responseCache.get(request.href).pipe( - filter((entry: ResponseCacheEntry) => startTransactionTime < entry.timeAdded), - take(1), - map((entry: ResponseCacheEntry) => entry.response) + tap((request: PatchRequestDefinition) => this.requestService.configure(request)), + flatMap(() => { + const [successResponse$, errorResponse$] = partition((response: RestResponse) => response.isSuccessful)(this.requestService.getByUUID(requestId).pipe( + getResponseFromEntry(), + find((entry: ObjectCacheEntry) => startTransactionTime < entry.timeAdded), + map((entry: ObjectCacheEntry) => entry), )); return observableMerge( errorResponse$.pipe( diff --git a/src/app/core/shared/dspace-object.model.ts b/src/app/core/shared/dspace-object.model.ts index 8016f3e425..f61f013064 100644 --- a/src/app/core/shared/dspace-object.model.ts +++ b/src/app/core/shared/dspace-object.model.ts @@ -1,5 +1,5 @@ import { Metadatum } from './metadatum.model' -import { isEmpty, isNotEmpty } from '../../shared/empty.util'; +import { isEmpty, isNotEmpty, isUndefined } from '../../shared/empty.util'; import { CacheableObject } from '../cache/object-cache.reducer'; import { RemoteData } from '../data/remote-data'; import { ResourceType } from './resource-type'; @@ -12,6 +12,8 @@ import { autoserialize } from 'cerialize'; */ export class DSpaceObject implements CacheableObject, ListableObject { + private _name: string; + self: string; /** @@ -35,7 +37,14 @@ export class DSpaceObject implements CacheableObject, ListableObject { * The name for this DSpaceObject */ get name(): string { - return this.findMetadata('dc.title'); + return (isUndefined(this._name)) ? this.findMetadata('dc.title') : this._name; + } + + /** + * The name for this DSpaceObject + */ + set name(name) { + this._name = name; } /** diff --git a/src/app/core/shared/file.service.ts b/src/app/core/shared/file.service.ts index 6dfdb2b647..6d4c997733 100644 --- a/src/app/core/shared/file.service.ts +++ b/src/app/core/shared/file.service.ts @@ -2,7 +2,7 @@ import { Injectable } from '@angular/core'; import { HttpHeaders } from '@angular/common/http'; import { DSpaceRESTv2Service, HttpOptions } from '../dspace-rest-v2/dspace-rest-v2.service'; -import { RestRequestMethod } from '../data/request.models'; +import { RestRequestMethod } from '../data/rest-request-method'; import { saveAs } from 'file-saver'; import { DSpaceRESTV2Response } from '../dspace-rest-v2/dspace-rest-v2-response.model'; @@ -24,7 +24,7 @@ export class FileService { downloadFile(url: string) { const headers = new HttpHeaders(); const options: HttpOptions = Object.create({headers, responseType: 'blob'}); - return this.restService.request(RestRequestMethod.Get, url, null, options) + return this.restService.request(RestRequestMethod.GET, url, null, options) .subscribe((data) => { saveAs(data.payload as Blob, this.getFileNameFromResponseContentDisposition(data)); }); diff --git a/src/app/core/submission/models/submission-object.model.ts b/src/app/core/submission/models/submission-object.model.ts index 3a899e4a07..7e3b74a6a9 100644 --- a/src/app/core/submission/models/submission-object.model.ts +++ b/src/app/core/submission/models/submission-object.model.ts @@ -48,7 +48,7 @@ export abstract class SubmissionObject extends DSpaceObject implements Cacheable /** * The submission config definition */ - submissionDefinition: SubmissionDefinitionsModel; + submissionDefinition: Observable> | SubmissionDefinitionsModel; /** * The workspaceitem submitter diff --git a/src/app/core/submission/submission-json-patch-operations.service.spec.ts b/src/app/core/submission/submission-json-patch-operations.service.spec.ts index d0682720d1..39e6cd42fb 100644 --- a/src/app/core/submission/submission-json-patch-operations.service.spec.ts +++ b/src/app/core/submission/submission-json-patch-operations.service.spec.ts @@ -3,7 +3,6 @@ import { Store } from '@ngrx/store'; import { getTestScheduler } from 'jasmine-marbles'; import { TestScheduler } from 'rxjs/testing'; -import { ResponseCacheService } from '../cache/response-cache.service'; import { CoreState } from '../core.reducers'; import { HALEndpointService } from '../shared/hal-endpoint.service'; import { SubmissionJsonPatchOperationsService } from './submission-json-patch-operations.service'; @@ -14,13 +13,11 @@ describe('SubmissionJsonPatchOperationsService', () => { let scheduler: TestScheduler; let service: SubmissionJsonPatchOperationsService; const requestService = {} as RequestService; - const responseCache = {} as ResponseCacheService; const store = {} as Store; const halEndpointService = {} as HALEndpointService; function initTestService() { return new SubmissionJsonPatchOperationsService( - responseCache, requestService, store, halEndpointService diff --git a/src/app/core/submission/submission-json-patch-operations.service.ts b/src/app/core/submission/submission-json-patch-operations.service.ts index 076c843d69..f9371100d6 100644 --- a/src/app/core/submission/submission-json-patch-operations.service.ts +++ b/src/app/core/submission/submission-json-patch-operations.service.ts @@ -2,7 +2,6 @@ import { Injectable } from '@angular/core'; import { Store } from '@ngrx/store'; -import { ResponseCacheService } from '../cache/response-cache.service'; import { RequestService } from '../data/request.service'; import { HALEndpointService } from '../shared/hal-endpoint.service'; import { JsonPatchOperationsService } from '../json-patch/json-patch-operations.service'; @@ -16,7 +15,6 @@ export class SubmissionJsonPatchOperationsService extends JsonPatchOperationsSer protected patchRequestConstructor = SubmissionPatchRequest; constructor( - protected responseCache: ResponseCacheService, protected requestService: RequestService, protected store: Store, protected halService: HALEndpointService) { diff --git a/src/app/core/submission/submission-response-parsing.service.ts b/src/app/core/submission/submission-response-parsing.service.ts index 5cfd524d62..c9c944d74d 100644 --- a/src/app/core/submission/submission-response-parsing.service.ts +++ b/src/app/core/submission/submission-response-parsing.service.ts @@ -3,7 +3,7 @@ import { Inject, Injectable } from '@angular/core'; import { ResponseParsingService } from '../data/parsing.service'; import { RestRequest } from '../data/request.models'; import { DSpaceRESTV2Response } from '../dspace-rest-v2/dspace-rest-v2-response.model'; -import { ErrorResponse, RestResponse, SubmissionSuccessResponse } from '../cache/response-cache.models'; +import { ErrorResponse, RestResponse, SubmissionSuccessResponse } from '../cache/response.models'; import { isEmpty, isNotEmpty, isNotNull } from '../../shared/empty.util'; import { ConfigObject } from '../config/models/config.model'; import { BaseResponseParsingService } from '../data/base-response-parsing.service'; diff --git a/src/app/core/submission/workflowitem-data.service.ts b/src/app/core/submission/workflowitem-data.service.ts index 0b71812cbf..4468ffdf04 100644 --- a/src/app/core/submission/workflowitem-data.service.ts +++ b/src/app/core/submission/workflowitem-data.service.ts @@ -1,17 +1,19 @@ import { Injectable } from '@angular/core'; +import { HttpClient } from '@angular/common/http'; import { Store } from '@ngrx/store'; -import { BrowseService } from '../browse/browse.service'; import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service'; -import { ResponseCacheService } from '../cache/response-cache.service'; import { CoreState } from '../core.reducers'; - import { DataService } from '../data/data.service'; import { RequestService } from '../data/request.service'; import { NormalizedWorkflowItem } from './models/normalized-workflowitem.model'; import { Workflowitem } from './models/workflowitem.model'; import { HALEndpointService } from '../shared/hal-endpoint.service'; import { FindAllOptions } from '../data/request.models'; +import { NormalizedObjectBuildService } from '../cache/builders/normalized-object-build.service'; +import { NotificationsService } from '../../shared/notifications/notifications.service'; +import { ObjectCacheService } from '../cache/object-cache.service'; +import { DSOChangeAnalyzer } from '../data/dso-change-analyzer.service'; @Injectable() export class WorkflowitemDataService extends DataService { @@ -19,12 +21,15 @@ export class WorkflowitemDataService extends DataService, - protected bs: BrowseService, - protected halService: HALEndpointService) { + protected objectCache: ObjectCacheService, + protected store: Store) { super(); } diff --git a/src/app/core/submission/workspaceitem-data.service.ts b/src/app/core/submission/workspaceitem-data.service.ts index b3685f9775..2edd086fd0 100644 --- a/src/app/core/submission/workspaceitem-data.service.ts +++ b/src/app/core/submission/workspaceitem-data.service.ts @@ -1,17 +1,19 @@ import { Injectable } from '@angular/core'; +import { HttpClient } from '@angular/common/http'; import { Store } from '@ngrx/store'; -import { BrowseService } from '../browse/browse.service'; import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service'; -import { ResponseCacheService } from '../cache/response-cache.service'; import { CoreState } from '../core.reducers'; - import { DataService } from '../data/data.service'; import { RequestService } from '../data/request.service'; import { Workspaceitem } from './models/workspaceitem.model'; import { NormalizedWorkspaceItem } from './models/normalized-workspaceitem.model'; import { HALEndpointService } from '../shared/hal-endpoint.service'; import { FindAllOptions } from '../data/request.models'; +import { NormalizedObjectBuildService } from '../cache/builders/normalized-object-build.service'; +import { NotificationsService } from '../../shared/notifications/notifications.service'; +import { ObjectCacheService } from '../cache/object-cache.service'; +import { DSOChangeAnalyzer } from '../data/dso-change-analyzer.service'; @Injectable() export class WorkspaceitemDataService extends DataService { @@ -19,12 +21,15 @@ export class WorkspaceitemDataService extends DataService, - protected bs: BrowseService, - protected halService: HALEndpointService) { + protected objectCache: ObjectCacheService, + protected store: Store) { super(); } diff --git a/src/app/shared/comcol-forms/delete-comcol-page/delete-comcol-page.component.spec.ts b/src/app/shared/comcol-forms/delete-comcol-page/delete-comcol-page.component.spec.ts index 81ec9c47a0..c1444ec25b 100644 --- a/src/app/shared/comcol-forms/delete-comcol-page/delete-comcol-page.component.spec.ts +++ b/src/app/shared/comcol-forms/delete-comcol-page/delete-comcol-page.component.spec.ts @@ -108,7 +108,6 @@ describe('DeleteComColPageComponent', () => { it('should show an error notification on failure', () => { (dsoDataService.delete as any).and.returnValue(observableOf(false)); - spyOn(notificationsService, 'error'); spyOn(router, 'navigate'); comp.onConfirm(data2); fixture.detectChanges(); @@ -117,7 +116,6 @@ describe('DeleteComColPageComponent', () => { }); it('should show a success notification on success and navigate', () => { - spyOn(notificationsService, 'success'); spyOn(router, 'navigate'); comp.onConfirm(data1); fixture.detectChanges(); diff --git a/src/app/shared/testing/submission-rest-service-stub.ts b/src/app/shared/testing/submission-rest-service-stub.ts index 1ef821f626..53b2341b50 100644 --- a/src/app/shared/testing/submission-rest-service-stub.ts +++ b/src/app/shared/testing/submission-rest-service-stub.ts @@ -1,14 +1,12 @@ import { of as observableOf } from 'rxjs'; import { Store } from '@ngrx/store'; -import { ResponseCacheService } from '../../core/cache/response-cache.service'; import { RequestService } from '../../core/data/request.service'; import { CoreState } from '../../core/core.reducers'; import { HALEndpointService } from '../../core/shared/hal-endpoint.service'; export class SubmissionRestServiceStub { protected linkPath = 'workspaceitems'; - protected responseCache: ResponseCacheService; protected requestService: RequestService; protected store: Store; protected halService: HALEndpointService; diff --git a/src/app/submission/form/submission-form.component.ts b/src/app/submission/form/submission-form.component.ts index 57a6d77a79..deb39fbae2 100644 --- a/src/app/submission/form/submission-form.component.ts +++ b/src/app/submission/form/submission-form.component.ts @@ -104,9 +104,9 @@ export class SubmissionFormComponent implements OnChanges, OnDestroy { onCollectionChange(submissionObject: SubmissionObject) { this.collectionId = (submissionObject.collection as Collection).id; - if (this.definitionId !== submissionObject.submissionDefinition.name) { + if (this.definitionId !== (submissionObject.submissionDefinition as SubmissionDefinitionsModel).name) { this.sections = submissionObject.sections; - this.submissionDefinition = submissionObject.submissionDefinition; + this.submissionDefinition = (submissionObject.submissionDefinition as SubmissionDefinitionsModel); this.definitionId = this.submissionDefinition.name; this.submissionService.resetSubmissionObject( this.collectionId, diff --git a/src/app/submission/sections/upload/file/view/file-view.component.spec.ts b/src/app/submission/sections/upload/file/view/file-view.component.spec.ts index c79c444a3f..5fbc0fadd8 100644 --- a/src/app/submission/sections/upload/file/view/file-view.component.spec.ts +++ b/src/app/submission/sections/upload/file/view/file-view.component.spec.ts @@ -77,7 +77,6 @@ describe('UploadSectionFileViewComponent test suite', () => { fixture.detectChanges(); - console.log(comp.metadata); expect(comp.metadata.length).toBe(2); }); diff --git a/src/app/submission/submission-rest.service.spec.ts b/src/app/submission/submission-rest.service.spec.ts index 0759e7cfba..c5992d7d10 100644 --- a/src/app/submission/submission-rest.service.spec.ts +++ b/src/app/submission/submission-rest.service.spec.ts @@ -1,8 +1,7 @@ import { TestScheduler } from 'rxjs/testing'; -import { cold, getTestScheduler } from 'jasmine-marbles'; +import { getTestScheduler } from 'jasmine-marbles'; import { SubmissionRestService } from './submission-rest.service'; -import { ResponseCacheService } from '../core/cache/response-cache.service'; import { RequestService } from '../core/data/request.service'; import { RemoteDataBuildService } from '../core/cache/builders/remote-data-build.service'; import { getMockRequestService } from '../shared/mocks/mock-request.service'; @@ -19,7 +18,6 @@ import { FormFieldMetadataValueObject } from '../shared/form/builder/models/form describe('SubmissionRestService test suite', () => { let scheduler: TestScheduler; let service: SubmissionRestService; - let responseCache: ResponseCacheService; let requestService: RequestService; let rdbService: RemoteDataBuildService; let halService: any; @@ -31,27 +29,15 @@ describe('SubmissionRestService test suite', () => { const resourceHref = resourceEndpointURL + '/' + resourceEndpoint + '/' + resourceScope; const timestampResponse = 1545994811992; - function initMockResponseCacheService(isSuccessful: boolean): ResponseCacheService { - return jasmine.createSpyObj('responseCache', { - get: cold('c-', { - c: {response: {isSuccessful}, - timeAdded: timestampResponse} - }), - remove: jasmine.createSpy('remove') - }); - } - function initTestService() { return new SubmissionRestService( rdbService, - responseCache, requestService, halService ); } beforeEach(() => { - responseCache = initMockResponseCacheService(true); requestService = getMockRequestService(); rdbService = getMockRemoteDataBuildService(); scheduler = getTestScheduler(); @@ -86,7 +72,7 @@ describe('SubmissionRestService test suite', () => { scheduler.schedule(() => service.postToEndpoint(resourceEndpoint, body, resourceScope).subscribe()); scheduler.flush(); - expect(requestService.configure).toHaveBeenCalledWith(expected, true); + expect(requestService.configure).toHaveBeenCalledWith(expected); }); }); @@ -96,7 +82,7 @@ describe('SubmissionRestService test suite', () => { scheduler.schedule(() => service.patchToEndpoint(resourceEndpoint, body, resourceScope).subscribe()); scheduler.flush(); - expect(requestService.configure).toHaveBeenCalledWith(expected, true); + expect(requestService.configure).toHaveBeenCalledWith(expected); }); }); }); diff --git a/src/app/submission/submission-rest.service.ts b/src/app/submission/submission-rest.service.ts index 83c8e5f594..b5d563549f 100644 --- a/src/app/submission/submission-rest.service.ts +++ b/src/app/submission/submission-rest.service.ts @@ -3,10 +3,7 @@ import { Injectable } from '@angular/core'; import { merge as observableMerge, Observable, throwError as observableThrowError } from 'rxjs'; import { distinctUntilChanged, filter, flatMap, map, mergeMap, tap } from 'rxjs/operators'; -import { ResponseCacheService } from '../core/cache/response-cache.service'; import { RequestService } from '../core/data/request.service'; -import { ResponseCacheEntry } from '../core/cache/response-cache.reducer'; -import { ErrorResponse, RestResponse, SubmissionSuccessResponse } from '../core/cache/response-cache.models'; import { isNotEmpty } from '../shared/empty.util'; import { DeleteRequest, @@ -21,6 +18,8 @@ import { SubmitDataResponseDefinitionObject } from '../core/shared/submit-data-r import { HttpOptions } from '../core/dspace-rest-v2/dspace-rest-v2.service'; import { HALEndpointService } from '../core/shared/hal-endpoint.service'; import { RemoteDataBuildService } from '../core/cache/builders/remote-data-build.service'; +import { ErrorResponse, RestResponse, SubmissionSuccessResponse } from '../core/cache/response.models'; +import { getResponseFromEntry } from '../core/shared/operators'; @Injectable() export class SubmissionRestService { @@ -28,13 +27,14 @@ export class SubmissionRestService { constructor( protected rdbService: RemoteDataBuildService, - protected responseCache: ResponseCacheService, protected requestService: RequestService, protected halService: HALEndpointService) { } - protected submitData(request: RestRequest): Observable { - const responses = this.responseCache.get(request.href).pipe(map((entry: ResponseCacheEntry) => entry.response)); + protected fetchRequest(requestId: string): Observable { + const responses = this.requestService.getByUUID(requestId).pipe( + getResponseFromEntry() + ); const errorResponses = responses.pipe( filter((response: RestResponse) => !response.isSuccessful), mergeMap((error: ErrorResponse) => observableThrowError(error)) @@ -47,67 +47,55 @@ export class SubmissionRestService { return observableMerge(errorResponses, successResponses); } - protected fetchRequest(request: RestRequest): Observable { - const responses = this.responseCache.get(request.href).pipe( - map((entry: ResponseCacheEntry) => entry.response), - tap(() => this.responseCache.remove(request.href))); - const errorResponses = responses.pipe( - filter((response: RestResponse) => !response.isSuccessful), - mergeMap((error: ErrorResponse) => observableThrowError(error)) - ); - const successResponses = responses.pipe( - filter((response: SubmissionSuccessResponse) => response.isSuccessful && isNotEmpty(response)), - map((response: SubmissionSuccessResponse) => response.dataDefinition as any), - distinctUntilChanged() - ); - return observableMerge(errorResponses, successResponses); - } - protected getEndpointByIDHref(endpoint, resourceID): string { return isNotEmpty(resourceID) ? `${endpoint}/${resourceID}` : `${endpoint}`; } public deleteById(scopeId: string, linkName?: string): Observable { + const requestId = this.requestService.generateRequestId(); return this.halService.getEndpoint(linkName || this.linkPath).pipe( filter((href: string) => isNotEmpty(href)), distinctUntilChanged(), map((endpointURL: string) => this.getEndpointByIDHref(endpointURL, scopeId)), - map((endpointURL: string) => new SubmissionDeleteRequest(this.requestService.generateRequestId(), endpointURL)), + map((endpointURL: string) => new SubmissionDeleteRequest(requestId, endpointURL)), tap((request: DeleteRequest) => this.requestService.configure(request)), - flatMap((request: DeleteRequest) => this.submitData(request)), + flatMap((request: DeleteRequest) => this.fetchRequest(requestId)), distinctUntilChanged()); } public getDataById(linkName: string, id: string): Observable { + const requestId = this.requestService.generateRequestId(); return this.halService.getEndpoint(linkName).pipe( map((endpointURL: string) => this.getEndpointByIDHref(endpointURL, id)), filter((href: string) => isNotEmpty(href)), distinctUntilChanged(), - map((endpointURL: string) => new SubmissionRequest(this.requestService.generateRequestId(), endpointURL)), + map((endpointURL: string) => new SubmissionRequest(requestId, endpointURL)), tap((request: RestRequest) => this.requestService.configure(request, true)), - flatMap((request: RestRequest) => this.fetchRequest(request)), + flatMap((request: RestRequest) => this.fetchRequest(requestId)), distinctUntilChanged()); } public postToEndpoint(linkName: string, body: any, scopeId?: string, options?: HttpOptions): Observable { + const requestId = this.requestService.generateRequestId(); return this.halService.getEndpoint(linkName).pipe( filter((href: string) => isNotEmpty(href)), map((endpointURL: string) => this.getEndpointByIDHref(endpointURL, scopeId)), distinctUntilChanged(), - map((endpointURL: string) => new SubmissionPostRequest(this.requestService.generateRequestId(), endpointURL, body, options)), - tap((request: PostRequest) => this.requestService.configure(request, true)), - flatMap((request: PostRequest) => this.submitData(request)), + map((endpointURL: string) => new SubmissionPostRequest(requestId, endpointURL, body, options)), + tap((request: PostRequest) => this.requestService.configure(request)), + flatMap((request: PostRequest) => this.fetchRequest(requestId)), distinctUntilChanged()); } public patchToEndpoint(linkName: string, body: any, scopeId?: string): Observable { + const requestId = this.requestService.generateRequestId(); return this.halService.getEndpoint(linkName).pipe( filter((href: string) => isNotEmpty(href)), map((endpointURL: string) => this.getEndpointByIDHref(endpointURL, scopeId)), distinctUntilChanged(), - map((endpointURL: string) => new SubmissionPatchRequest(this.requestService.generateRequestId(), endpointURL, body)), - tap((request: PostRequest) => this.requestService.configure(request, true)), - flatMap((request: PostRequest) => this.submitData(request)), + map((endpointURL: string) => new SubmissionPatchRequest(requestId, endpointURL, body)), + tap((request: PostRequest) => this.requestService.configure(request)), + flatMap((request: PostRequest) => this.fetchRequest(requestId)), distinctUntilChanged()); } diff --git a/src/app/submission/submission.service.ts b/src/app/submission/submission.service.ts index 53a89547d5..2357d97c6b 100644 --- a/src/app/submission/submission.service.ts +++ b/src/app/submission/submission.service.ts @@ -41,7 +41,7 @@ import { NotificationsService } from '../shared/notifications/notifications.serv import { SubmissionDefinitionsModel } from '../core/config/models/config-submission-definitions.model'; import { WorkspaceitemSectionsObject } from '../core/submission/models/workspaceitem-sections.model'; import { RemoteData } from '../core/data/remote-data'; -import { ErrorResponse } from '../core/cache/response-cache.models'; +import { ErrorResponse } from '../core/cache/response.models'; import { RemoteDataError } from '../core/data/remote-data-error'; @Injectable() diff --git a/src/config/auto-sync-config.interface.ts b/src/config/auto-sync-config.interface.ts index 90e7ebee80..b737314f56 100644 --- a/src/config/auto-sync-config.interface.ts +++ b/src/config/auto-sync-config.interface.ts @@ -27,4 +27,4 @@ export interface AutoSyncConfig { * The max number of requests in the buffer before a sync to the server */ maxBufferSize: number; -}; +} diff --git a/yarn.lock b/yarn.lock index 279d0e8135..dd6298f480 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3500,6 +3500,7 @@ fast-glob@^2.0.2: fast-json-patch@^2.0.7: version "2.0.7" resolved "https://registry.yarnpkg.com/fast-json-patch/-/fast-json-patch-2.0.7.tgz#55864b08b1e50381d2f37fd472bb2e18fe54a733" + integrity sha512-DQeoEyPYxdTtfmB3yDlxkLyKTdbJ6ABfFGcMynDqjvGhPYLto/pZyb/dG2Nyd/n9CArjEWN9ZST++AFmgzgbGw== dependencies: deep-equal "^1.0.1"