mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
Fixes after merge with master
This commit is contained in:
@@ -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);
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@@ -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<ObjectCacheState>({});
|
||||
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);
|
||||
});
|
||||
|
||||
|
@@ -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<ObjectCacheState>({});
|
||||
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);
|
||||
});
|
||||
|
||||
|
@@ -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 {
|
||||
|
@@ -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();
|
||||
|
@@ -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';
|
||||
|
@@ -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()
|
||||
});
|
||||
|
||||
|
@@ -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;
|
||||
|
@@ -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<T extends CacheableObject>(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 {
|
||||
|
@@ -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';
|
||||
|
@@ -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<TNormalized extends NormalizedObject, TDomain> extends DataService<TNormalized, TDomain> {
|
||||
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<TNormalized extends NormalizedObject, TDomain extends CacheableObject> extends DataService<TNormalized, TDomain> {
|
||||
|
||||
public getBrowseEndpoint(options: FindAllOptions): Observable<string> {
|
||||
return this.halService.getEndpoint(this.linkPath);
|
||||
|
@@ -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<NormalizedGroup, Group>
|
||||
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<CoreState>,
|
||||
@@ -57,4 +63,5 @@ export class GroupEpersonService extends EpersonService<NormalizedGroup, Group>
|
||||
map((groups: RemoteData<PaginatedList<Group>>) => groups.payload.totalElements > 0)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -12,6 +12,9 @@ export class NormalizedGroup extends NormalizedDSpaceObject implements Cacheable
|
||||
@autoserialize
|
||||
public handle: string;
|
||||
|
||||
@autoserialize
|
||||
public name: string;
|
||||
|
||||
@autoserialize
|
||||
public permanent: boolean;
|
||||
}
|
||||
|
@@ -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',
|
||||
|
@@ -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;
|
||||
|
@@ -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<SubmitDataResponseDefinitionObject, SubmissionPatchRequest> {
|
||||
protected linkPath = '';
|
||||
protected patchRequestConstructor = SubmissionPatchRequest;
|
||||
|
||||
constructor(
|
||||
protected responseCache: ResponseCacheService,
|
||||
protected requestService: RequestService,
|
||||
protected store: Store<CoreState>,
|
||||
protected halService: HALEndpointService) {
|
||||
@@ -41,7 +40,6 @@ class TestService extends JsonPatchOperationsService<SubmitDataResponseDefinitio
|
||||
describe('JsonPatchOperationsService test suite', () => {
|
||||
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);
|
||||
|
@@ -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<ResponseDefinitionDomain, PatchRequestDefinition extends PatchRequest> {
|
||||
protected abstract responseCache: ResponseCacheService;
|
||||
|
||||
protected abstract requestService: RequestService;
|
||||
protected abstract store: Store<CoreState>;
|
||||
protected abstract linkPath: string;
|
||||
protected abstract halService: HALEndpointService;
|
||||
protected abstract patchRequestConstructor: any;
|
||||
|
||||
protected submitData(request: RestRequest): Observable<ResponseDefinitionDomain> {
|
||||
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<ResponseDefinitionDomain, Patch
|
||||
* observable of response
|
||||
*/
|
||||
protected submitJsonPatchOperations(hrefObs: Observable<string>, resourceType: string, resourceId?: string): Observable<ResponseDefinitionDomain> {
|
||||
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<ResponseDefinitionDomain, Patch
|
||||
})
|
||||
}
|
||||
}
|
||||
return this.getRequestInstance(this.requestService.generateRequestId(), endpointURL, body);
|
||||
return this.getRequestInstance(requestId, endpointURL, body);
|
||||
}));
|
||||
})));
|
||||
|
||||
@@ -96,12 +84,12 @@ export abstract class JsonPatchOperationsService<ResponseDefinitionDomain, Patch
|
||||
patchRequest$.pipe(
|
||||
filter((request: PatchRequestDefinition) => 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(
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -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));
|
||||
});
|
||||
|
@@ -48,7 +48,7 @@ export abstract class SubmissionObject extends DSpaceObject implements Cacheable
|
||||
/**
|
||||
* The submission config definition
|
||||
*/
|
||||
submissionDefinition: SubmissionDefinitionsModel;
|
||||
submissionDefinition: Observable<RemoteData<SubmissionDefinitionsModel>> | SubmissionDefinitionsModel;
|
||||
|
||||
/**
|
||||
* The workspaceitem submitter
|
||||
|
@@ -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<CoreState>;
|
||||
const halEndpointService = {} as HALEndpointService;
|
||||
|
||||
function initTestService() {
|
||||
return new SubmissionJsonPatchOperationsService(
|
||||
responseCache,
|
||||
requestService,
|
||||
store,
|
||||
halEndpointService
|
||||
|
@@ -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<CoreState>,
|
||||
protected halService: HALEndpointService) {
|
||||
|
@@ -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';
|
||||
|
@@ -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<NormalizedWorkflowItem, Workflowitem> {
|
||||
@@ -19,12 +21,15 @@ export class WorkflowitemDataService extends DataService<NormalizedWorkflowItem,
|
||||
protected forceBypassCache = true;
|
||||
|
||||
constructor(
|
||||
protected responseCache: ResponseCacheService,
|
||||
protected comparator: DSOChangeAnalyzer,
|
||||
protected dataBuildService: NormalizedObjectBuildService,
|
||||
protected halService: HALEndpointService,
|
||||
protected http: HttpClient,
|
||||
protected notificationsService: NotificationsService,
|
||||
protected requestService: RequestService,
|
||||
protected rdbService: RemoteDataBuildService,
|
||||
protected store: Store<CoreState>,
|
||||
protected bs: BrowseService,
|
||||
protected halService: HALEndpointService) {
|
||||
protected objectCache: ObjectCacheService,
|
||||
protected store: Store<CoreState>) {
|
||||
super();
|
||||
}
|
||||
|
||||
|
@@ -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<NormalizedWorkspaceItem, Workspaceitem> {
|
||||
@@ -19,12 +21,15 @@ export class WorkspaceitemDataService extends DataService<NormalizedWorkspaceIte
|
||||
protected forceBypassCache = true;
|
||||
|
||||
constructor(
|
||||
protected responseCache: ResponseCacheService,
|
||||
protected comparator: DSOChangeAnalyzer,
|
||||
protected dataBuildService: NormalizedObjectBuildService,
|
||||
protected halService: HALEndpointService,
|
||||
protected http: HttpClient,
|
||||
protected notificationsService: NotificationsService,
|
||||
protected requestService: RequestService,
|
||||
protected rdbService: RemoteDataBuildService,
|
||||
protected store: Store<CoreState>,
|
||||
protected bs: BrowseService,
|
||||
protected halService: HALEndpointService) {
|
||||
protected objectCache: ObjectCacheService,
|
||||
protected store: Store<CoreState>) {
|
||||
super();
|
||||
}
|
||||
|
||||
|
@@ -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();
|
||||
|
@@ -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<CoreState>;
|
||||
protected halService: HALEndpointService;
|
||||
|
@@ -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,
|
||||
|
@@ -77,7 +77,6 @@ describe('UploadSectionFileViewComponent test suite', () => {
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
console.log(comp.metadata);
|
||||
expect(comp.metadata.length).toBe(2);
|
||||
|
||||
});
|
||||
|
@@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -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<SubmitDataResponseDefinitionObject> {
|
||||
const responses = this.responseCache.get(request.href).pipe(map((entry: ResponseCacheEntry) => entry.response));
|
||||
protected fetchRequest(requestId: string): Observable<SubmitDataResponseDefinitionObject> {
|
||||
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<SubmitDataResponseDefinitionObject> {
|
||||
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<SubmitDataResponseDefinitionObject> {
|
||||
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<any> {
|
||||
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<SubmitDataResponseDefinitionObject> {
|
||||
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<SubmitDataResponseDefinitionObject> {
|
||||
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());
|
||||
}
|
||||
|
||||
|
@@ -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()
|
||||
|
@@ -27,4 +27,4 @@ export interface AutoSyncConfig {
|
||||
* The max number of requests in the buffer before a sync to the server
|
||||
*/
|
||||
maxBufferSize: number;
|
||||
};
|
||||
}
|
||||
|
@@ -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"
|
||||
|
||||
|
Reference in New Issue
Block a user