mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
85262: Get submission object instead of sending empty patch + revert empty patch code
This commit is contained in:
@@ -40,15 +40,13 @@ export abstract class JsonPatchOperationsService<ResponseDefinitionDomain, Patch
|
||||
* The resource type value
|
||||
* @param resourceId
|
||||
* The resource id value
|
||||
* @param allowEmptyRequest
|
||||
* Allow an empty list of operations in the request's body
|
||||
* @return Observable<ResponseDefinitionDomain>
|
||||
* observable of response
|
||||
*/
|
||||
protected submitJsonPatchOperations(hrefObs: Observable<string>, resourceType: string, resourceId?: string, allowEmptyRequest = false): Observable<ResponseDefinitionDomain> {
|
||||
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) => allowEmptyRequest || isNotEmpty(request.body))(hrefObs.pipe(
|
||||
const [patchRequest$, emptyRequest$] = partition((request: PatchRequestDefinition) => isNotEmpty(request.body))(hrefObs.pipe(
|
||||
mergeMap((endpointURL: string) => {
|
||||
return this.store.select(jsonPatchOperationsByResourceType(resourceType)).pipe(
|
||||
take(1),
|
||||
@@ -81,11 +79,11 @@ export abstract class JsonPatchOperationsService<ResponseDefinitionDomain, Patch
|
||||
|
||||
return observableMerge(
|
||||
emptyRequest$.pipe(
|
||||
filter((request: PatchRequestDefinition) => !allowEmptyRequest && isEmpty(request.body)),
|
||||
filter((request: PatchRequestDefinition) => isEmpty(request.body)),
|
||||
tap(() => startTransactionTime = null),
|
||||
map(() => null)),
|
||||
patchRequest$.pipe(
|
||||
filter((request: PatchRequestDefinition) => allowEmptyRequest || isNotEmpty(request.body)),
|
||||
filter((request: PatchRequestDefinition) => isNotEmpty(request.body)),
|
||||
tap(() => this.store.dispatch(new StartTransactionPatchOperationsAction(resourceType, resourceId, startTransactionTime))),
|
||||
tap((request: PatchRequestDefinition) => this.requestService.send(request)),
|
||||
mergeMap(() => {
|
||||
@@ -143,18 +141,16 @@ export abstract class JsonPatchOperationsService<ResponseDefinitionDomain, Patch
|
||||
* The scope id
|
||||
* @param resourceType
|
||||
* The resource type value
|
||||
* @param allowEmptyRequest
|
||||
* Allow an empty list of operations in the request's body
|
||||
* @return Observable<ResponseDefinitionDomain>
|
||||
* observable of response
|
||||
*/
|
||||
public jsonPatchByResourceType(linkPath: string, scopeId: string, resourceType: string, allowEmptyRequest = false): Observable<ResponseDefinitionDomain> {
|
||||
public jsonPatchByResourceType(linkPath: string, scopeId: string, resourceType: string): Observable<ResponseDefinitionDomain> {
|
||||
const href$ = this.halService.getEndpoint(linkPath).pipe(
|
||||
filter((href: string) => isNotEmpty(href)),
|
||||
distinctUntilChanged(),
|
||||
map((endpointURL: string) => this.getEndpointByIDHref(endpointURL, scopeId)));
|
||||
|
||||
return this.submitJsonPatchOperations(href$, resourceType, undefined, allowEmptyRequest);
|
||||
return this.submitJsonPatchOperations(href$, resourceType);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -54,6 +54,8 @@ import { Item } from '../../core/shared/item.model';
|
||||
import { WorkspaceitemDataService } from '../../core/submission/workspaceitem-data.service';
|
||||
import { WorkflowItemDataService } from '../../core/submission/workflowitem-data.service';
|
||||
import { HALEndpointService } from '../../core/shared/hal-endpoint.service';
|
||||
import { SubmissionObjectDataService } from '../../core/submission/submission-object-data.service';
|
||||
import { mockSubmissionObjectDataService } from '../../shared/testing/submission-oject-data-service.mock';
|
||||
|
||||
describe('SubmissionObjectEffects test suite', () => {
|
||||
let submissionObjectEffects: SubmissionObjectEffects;
|
||||
@@ -63,6 +65,7 @@ describe('SubmissionObjectEffects test suite', () => {
|
||||
let notificationsServiceStub;
|
||||
let submissionServiceStub;
|
||||
let submissionJsonPatchOperationsServiceStub;
|
||||
let submissionObjectDataServiceStub;
|
||||
const collectionId: string = mockSubmissionCollectionId;
|
||||
const submissionId: string = mockSubmissionId;
|
||||
const submissionDefinitionResponse: any = mockSubmissionDefinitionResponse;
|
||||
@@ -75,6 +78,9 @@ describe('SubmissionObjectEffects test suite', () => {
|
||||
notificationsServiceStub = new NotificationsServiceStub();
|
||||
submissionServiceStub = new SubmissionServiceStub();
|
||||
submissionJsonPatchOperationsServiceStub = new SubmissionJsonPatchOperationsServiceStub();
|
||||
submissionObjectDataServiceStub = mockSubmissionObjectDataService;
|
||||
|
||||
submissionServiceStub.hasUnsavedModification.and.returnValue(observableOf(true));
|
||||
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
@@ -99,6 +105,7 @@ describe('SubmissionObjectEffects test suite', () => {
|
||||
{ provide: WorkflowItemDataService, useValue: {} },
|
||||
{ provide: WorkflowItemDataService, useValue: {} },
|
||||
{ provide: HALEndpointService, useValue: {} },
|
||||
{ provide: SubmissionObjectDataService, useValue: submissionObjectDataServiceStub },
|
||||
],
|
||||
});
|
||||
|
||||
|
@@ -196,13 +196,21 @@ export class SubmissionObjectEffects {
|
||||
*/
|
||||
@Effect() saveAndDeposit$ = this.actions$.pipe(
|
||||
ofType(SubmissionObjectActionTypes.SAVE_AND_DEPOSIT_SUBMISSION),
|
||||
withLatestFrom(this.store$),
|
||||
switchMap(([action, currentState]: [SaveAndDepositSubmissionAction, any]) => {
|
||||
return this.operationsService.jsonPatchByResourceType(
|
||||
withLatestFrom(this.submissionService.hasUnsavedModification()),
|
||||
switchMap(([action, hasUnsavedModification]: [SaveAndDepositSubmissionAction, boolean]) => {
|
||||
let response$: Observable<SubmissionObject[]>;
|
||||
if (hasUnsavedModification) {
|
||||
response$ = this.operationsService.jsonPatchByResourceType(
|
||||
this.submissionService.getSubmissionObjectLinkName(),
|
||||
action.payload.submissionId,
|
||||
'sections',
|
||||
true).pipe(
|
||||
'sections') as Observable<SubmissionObject[]>;
|
||||
} else {
|
||||
response$ = this.submissionObjectService.findById(action.payload.submissionId).pipe(
|
||||
getFirstSucceededRemoteDataPayload(),
|
||||
map((submissionObject: SubmissionObject) => [submissionObject])
|
||||
);
|
||||
}
|
||||
return response$.pipe(
|
||||
map((response: SubmissionObject[]) => {
|
||||
if (this.canDeposit(response)) {
|
||||
return new DepositSubmissionAction(action.payload.submissionId);
|
||||
|
Reference in New Issue
Block a user