[CST-6876] Fix issue with invalid request done when the claimed/pool task changed its status due to a performed action

This commit is contained in:
Giuseppe Digilio
2022-09-29 15:05:18 +02:00
parent 750c6032bd
commit 7f30e92782
6 changed files with 93 additions and 57 deletions

View File

@@ -1,9 +1,18 @@
<ng-container *ngVar="(workflowitemRD$ | async)?.payload as workflowitem"> <ds-themed-item-list-preview *ngIf="workflowitem$.value"
<ds-themed-item-list-preview *ngIf="workflowitem" [item]="(workflowitem$.value?.item | async)?.payload"
[item]="(workflowitem?.item | async)?.payload" [object]="object"
[object]="object" [showSubmitter]="showSubmitter"
[showSubmitter]="showSubmitter" [status]="status"></ds-themed-item-list-preview>
[status]="status"></ds-themed-item-list-preview>
<ds-claimed-task-actions *ngIf="workflowitem" [object]="dso" (processCompleted)="reloadedObject.emit($event.reloadedObject)"></ds-claimed-task-actions> <div class="row">
</ng-container> <div [ngClass]="showThumbnails ? 'offset-3 offset-md-2 pl-3' : ''">
<ds-claimed-task-actions *ngIf="workflowitem$.value"
[object]="dso"
(processCompleted)="reloadedObject.emit($event.reloadedObject)"></ds-claimed-task-actions>
</div>
</div>

View File

@@ -1,5 +1,5 @@
import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core'; import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core';
import { ComponentFixture, fakeAsync, TestBed, tick, waitForAsync } from '@angular/core/testing'; import { ComponentFixture, fakeAsync, flush, TestBed, tick, waitForAsync } from '@angular/core/testing';
import { NoopAnimationsModule } from '@angular/platform-browser/animations'; import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { of as observableOf } from 'rxjs'; import { of as observableOf } from 'rxjs';
@@ -7,7 +7,9 @@ import { of as observableOf } from 'rxjs';
import { Item } from '../../../../core/shared/item.model'; import { Item } from '../../../../core/shared/item.model';
import { ClaimedSearchResultListElementComponent } from './claimed-search-result-list-element.component'; import { ClaimedSearchResultListElementComponent } from './claimed-search-result-list-element.component';
import { ClaimedTask } from '../../../../core/tasks/models/claimed-task-object.model'; import { ClaimedTask } from '../../../../core/tasks/models/claimed-task-object.model';
import { MyDspaceItemStatusType } from '../../../object-collection/shared/mydspace-item-status/my-dspace-item-status-type'; import {
MyDspaceItemStatusType
} from '../../../object-collection/shared/mydspace-item-status/my-dspace-item-status-type';
import { WorkflowItem } from '../../../../core/submission/models/workflowitem.model'; import { WorkflowItem } from '../../../../core/submission/models/workflowitem.model';
import { createSuccessfulRemoteDataObject } from '../../../remote-data.utils'; import { createSuccessfulRemoteDataObject } from '../../../remote-data.utils';
import { ClaimedTaskSearchResult } from '../../../object-collection/shared/claimed-task-search-result.model'; import { ClaimedTaskSearchResult } from '../../../object-collection/shared/claimed-task-search-result.model';
@@ -94,17 +96,15 @@ describe('ClaimedSearchResultListElementComponent', () => {
fixture.detectChanges(); fixture.detectChanges();
}); });
it('should init workflowitem properly', (done) => { it('should init workflowitem properly', fakeAsync(() => {
component.workflowitemRD$.subscribe((workflowitemRD) => { flush();
expect(linkService.resolveLinks).toHaveBeenCalledWith( expect(linkService.resolveLinks).toHaveBeenCalledWith(
component.dso, component.dso,
jasmine.objectContaining({ name: 'workflowitem' }), jasmine.objectContaining({ name: 'workflowitem' }),
jasmine.objectContaining({ name: 'action' }) jasmine.objectContaining({ name: 'action' })
); );
expect(workflowitemRD.payload).toEqual(workflowitem); expect(component.workflowitem$.value).toEqual(workflowitem);
done(); }));
});
});
it('should have properly status', () => { it('should have properly status', () => {
expect(component.status).toEqual(MyDspaceItemStatusType.VALIDATION); expect(component.status).toEqual(MyDspaceItemStatusType.VALIDATION);

View File

@@ -5,16 +5,21 @@ import { listableObjectComponent } from '../../../object-collection/shared/lista
import { ClaimedTaskSearchResult } from '../../../object-collection/shared/claimed-task-search-result.model'; import { ClaimedTaskSearchResult } from '../../../object-collection/shared/claimed-task-search-result.model';
import { LinkService } from '../../../../core/cache/builders/link.service'; import { LinkService } from '../../../../core/cache/builders/link.service';
import { TruncatableService } from '../../../truncatable/truncatable.service'; import { TruncatableService } from '../../../truncatable/truncatable.service';
import { MyDspaceItemStatusType } from '../../../object-collection/shared/mydspace-item-status/my-dspace-item-status-type'; import {
import { Observable } from 'rxjs'; MyDspaceItemStatusType
} from '../../../object-collection/shared/mydspace-item-status/my-dspace-item-status-type';
import { BehaviorSubject, Observable } from 'rxjs';
import { RemoteData } from '../../../../core/data/remote-data'; import { RemoteData } from '../../../../core/data/remote-data';
import { WorkflowItem } from '../../../../core/submission/models/workflowitem.model'; import { WorkflowItem } from '../../../../core/submission/models/workflowitem.model';
import { followLink } from '../../../utils/follow-link-config.model'; import { followLink } from '../../../utils/follow-link-config.model';
import { SearchResultListElementComponent } from '../../search-result-list-element/search-result-list-element.component'; import {
SearchResultListElementComponent
} from '../../search-result-list-element/search-result-list-element.component';
import { ClaimedTask } from '../../../../core/tasks/models/claimed-task-object.model'; import { ClaimedTask } from '../../../../core/tasks/models/claimed-task-object.model';
import { DSONameService } from '../../../../core/breadcrumbs/dso-name.service'; import { DSONameService } from '../../../../core/breadcrumbs/dso-name.service';
import { APP_CONFIG, AppConfig } from '../../../../../config/app-config.interface'; import { APP_CONFIG, AppConfig } from '../../../../../config/app-config.interface';
import { ObjectCacheService } from '../../../../core/cache/object-cache.service'; import { ObjectCacheService } from '../../../../core/cache/object-cache.service';
import { getFirstCompletedRemoteData } from '../../../../core/shared/operators';
@Component({ @Component({
selector: 'ds-claimed-search-result-list-element', selector: 'ds-claimed-search-result-list-element',
@@ -37,7 +42,12 @@ export class ClaimedSearchResultListElementComponent extends SearchResultListEle
/** /**
* The workflowitem object that belonging to the result object * The workflowitem object that belonging to the result object
*/ */
public workflowitemRD$: Observable<RemoteData<WorkflowItem>>; public workflowitem$: BehaviorSubject<WorkflowItem> = new BehaviorSubject<WorkflowItem>(null);
/**
* Display thumbnails if required by configuration
*/
showThumbnails: boolean;
public constructor( public constructor(
protected linkService: LinkService, protected linkService: LinkService,
@@ -57,7 +67,14 @@ export class ClaimedSearchResultListElementComponent extends SearchResultListEle
this.linkService.resolveLinks(this.dso, followLink('workflowitem', {}, this.linkService.resolveLinks(this.dso, followLink('workflowitem', {},
followLink('item'), followLink('submitter') followLink('item'), followLink('submitter')
), followLink('action')); ), followLink('action'));
this.workflowitemRD$ = this.dso.workflowitem as Observable<RemoteData<WorkflowItem>>; (this.dso.workflowitem as Observable<RemoteData<WorkflowItem>>).pipe(
getFirstCompletedRemoteData()
).subscribe((wfiRD: RemoteData<WorkflowItem>) => {
if (wfiRD.hasSucceeded) {
this.workflowitem$.next(wfiRD.payload);
}
});
this.showThumbnails = this.appConfig.browseBy.showThumbnails;
} }
ngOnDestroy() { ngOnDestroy() {

View File

@@ -1,13 +1,12 @@
<ng-container *ngVar="(workflowitemRD$ | async)?.payload as workflowitem"> <ds-themed-item-list-preview *ngIf="workflowitem$.value"
<ds-themed-item-list-preview *ngIf="workflowitem" [item]="(workflowitem$.value?.item | async)?.payload"
[item]="(workflowitem?.item | async)?.payload" [object]="object"
[object]="object" [showSubmitter]="showSubmitter"
[showSubmitter]="showSubmitter" [status]="status"></ds-themed-item-list-preview>
[status]="status"></ds-themed-item-list-preview> <div class="row">
<div class="row"> <div [ngClass]="showThumbnails ? 'offset-3 offset-md-2 pl-3' : ''">
<div [ngClass]="showThumbnails ? 'offset-3 offset-md-2 pl-3' : ''"> <ds-pool-task-actions id="actions" *ngIf="workflowitem$.value"
<ds-pool-task-actions id="actions" *ngIf="workflowitem" [object]="dso" [object]="dso"
(processCompleted)="this.reloadedObject.emit($event.reloadedObject)"></ds-pool-task-actions> (processCompleted)="this.reloadedObject.emit($event.reloadedObject)"></ds-pool-task-actions>
</div>
</div> </div>
</ng-container> </div>

View File

@@ -1,5 +1,5 @@
import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core'; import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core';
import { waitForAsync, ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing'; import { ComponentFixture, fakeAsync, flush, TestBed, tick, waitForAsync } from '@angular/core/testing';
import { NoopAnimationsModule } from '@angular/platform-browser/animations'; import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { of as observableOf } from 'rxjs'; import { of as observableOf } from 'rxjs';
@@ -7,7 +7,9 @@ import { of as observableOf } from 'rxjs';
import { Item } from '../../../../core/shared/item.model'; import { Item } from '../../../../core/shared/item.model';
import { PoolSearchResultListElementComponent } from './pool-search-result-list-element.component'; import { PoolSearchResultListElementComponent } from './pool-search-result-list-element.component';
import { PoolTask } from '../../../../core/tasks/models/pool-task-object.model'; import { PoolTask } from '../../../../core/tasks/models/pool-task-object.model';
import { MyDspaceItemStatusType } from '../../../object-collection/shared/mydspace-item-status/my-dspace-item-status-type'; import {
MyDspaceItemStatusType
} from '../../../object-collection/shared/mydspace-item-status/my-dspace-item-status-type';
import { WorkflowItem } from '../../../../core/submission/models/workflowitem.model'; import { WorkflowItem } from '../../../../core/submission/models/workflowitem.model';
import { createSuccessfulRemoteDataObject } from '../../../remote-data.utils'; import { createSuccessfulRemoteDataObject } from '../../../remote-data.utils';
import { PoolTaskSearchResult } from '../../../object-collection/shared/pool-task-search-result.model'; import { PoolTaskSearchResult } from '../../../object-collection/shared/pool-task-search-result.model';
@@ -72,7 +74,6 @@ const objectCacheServiceMock = jasmine.createSpyObj('ObjectCacheService', {
remove: jasmine.createSpy('remove') remove: jasmine.createSpy('remove')
}); });
describe('PoolSearchResultListElementComponent', () => { describe('PoolSearchResultListElementComponent', () => {
beforeEach(waitForAsync(() => { beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
@@ -101,17 +102,15 @@ describe('PoolSearchResultListElementComponent', () => {
fixture.detectChanges(); fixture.detectChanges();
}); });
it('should init workflowitem properly', (done) => { it('should init workflowitem properly', fakeAsync(() => {
component.workflowitemRD$.subscribe((workflowitemRD) => { flush();
expect(linkService.resolveLinks).toHaveBeenCalledWith( expect(linkService.resolveLinks).toHaveBeenCalledWith(
component.dso, component.dso,
jasmine.objectContaining({ name: 'workflowitem' }), jasmine.objectContaining({ name: 'workflowitem' }),
jasmine.objectContaining({ name: 'action' }) jasmine.objectContaining({ name: 'action' })
); );
expect(workflowitemRD.payload).toEqual(workflowitem); expect(component.workflowitem$.value).toEqual(workflowitem);
done(); }));
});
});
it('should have properly status', () => { it('should have properly status', () => {
expect(component.status).toEqual(MyDspaceItemStatusType.WAITING_CONTROLLER); expect(component.status).toEqual(MyDspaceItemStatusType.WAITING_CONTROLLER);

View File

@@ -1,21 +1,26 @@
import { Component, Inject, OnDestroy, OnInit } from '@angular/core'; import { Component, Inject, OnDestroy, OnInit } from '@angular/core';
import { Observable } from 'rxjs'; import { BehaviorSubject, Observable } from 'rxjs';
import { ViewMode } from '../../../../core/shared/view-mode.model'; import { ViewMode } from '../../../../core/shared/view-mode.model';
import { RemoteData } from '../../../../core/data/remote-data'; import { RemoteData } from '../../../../core/data/remote-data';
import { WorkflowItem } from '../../../../core/submission/models/workflowitem.model'; import { WorkflowItem } from '../../../../core/submission/models/workflowitem.model';
import { PoolTask } from '../../../../core/tasks/models/pool-task-object.model'; import { PoolTask } from '../../../../core/tasks/models/pool-task-object.model';
import { MyDspaceItemStatusType } from '../../../object-collection/shared/mydspace-item-status/my-dspace-item-status-type'; import {
MyDspaceItemStatusType
} from '../../../object-collection/shared/mydspace-item-status/my-dspace-item-status-type';
import { listableObjectComponent } from '../../../object-collection/shared/listable-object/listable-object.decorator'; import { listableObjectComponent } from '../../../object-collection/shared/listable-object/listable-object.decorator';
import { PoolTaskSearchResult } from '../../../object-collection/shared/pool-task-search-result.model'; import { PoolTaskSearchResult } from '../../../object-collection/shared/pool-task-search-result.model';
import { SearchResultListElementComponent } from '../../search-result-list-element/search-result-list-element.component'; import {
SearchResultListElementComponent
} from '../../search-result-list-element/search-result-list-element.component';
import { TruncatableService } from '../../../truncatable/truncatable.service'; import { TruncatableService } from '../../../truncatable/truncatable.service';
import { followLink } from '../../../utils/follow-link-config.model'; import { followLink } from '../../../utils/follow-link-config.model';
import { LinkService } from '../../../../core/cache/builders/link.service'; import { LinkService } from '../../../../core/cache/builders/link.service';
import { DSONameService } from '../../../../core/breadcrumbs/dso-name.service'; import { DSONameService } from '../../../../core/breadcrumbs/dso-name.service';
import { APP_CONFIG, AppConfig } from '../../../../../config/app-config.interface'; import { APP_CONFIG, AppConfig } from '../../../../../config/app-config.interface';
import { ObjectCacheService } from '../../../../core/cache/object-cache.service'; import { ObjectCacheService } from '../../../../core/cache/object-cache.service';
import { getFirstCompletedRemoteData } from '../../../../core/shared/operators';
/** /**
* This component renders pool task object for the search result in the list view. * This component renders pool task object for the search result in the list view.
@@ -42,7 +47,7 @@ export class PoolSearchResultListElementComponent extends SearchResultListElemen
/** /**
* The workflowitem object that belonging to the result object * The workflowitem object that belonging to the result object
*/ */
public workflowitemRD$: Observable<RemoteData<WorkflowItem>>; public workflowitem$: BehaviorSubject<WorkflowItem> = new BehaviorSubject<WorkflowItem>(null);
/** /**
* The index of this list element * The index of this list element
@@ -72,12 +77,19 @@ export class PoolSearchResultListElementComponent extends SearchResultListElemen
this.linkService.resolveLinks(this.dso, followLink('workflowitem', {}, this.linkService.resolveLinks(this.dso, followLink('workflowitem', {},
followLink('item'), followLink('submitter') followLink('item'), followLink('submitter')
), followLink('action')); ), followLink('action'));
this.workflowitemRD$ = this.dso.workflowitem as Observable<RemoteData<WorkflowItem>>; (this.dso.workflowitem as Observable<RemoteData<WorkflowItem>>).pipe(
getFirstCompletedRemoteData()
).subscribe((wfiRD: RemoteData<WorkflowItem>) => {
if (wfiRD.hasSucceeded) {
this.workflowitem$.next(wfiRD.payload);
}
});
this.showThumbnails = this.appConfig.browseBy.showThumbnails; this.showThumbnails = this.appConfig.browseBy.showThumbnails;
} }
ngOnDestroy() { ngOnDestroy() {
// This ensures the object is removed from cache, when action is performed on task // This ensures the object is removed from cache, when action is performed on task
// this.wfiService.invalidateByHref(this.dso._links.workflowitem.href);
this.objectCache.remove(this.dso._links.workflowitem.href); this.objectCache.remove(this.dso._links.workflowitem.href);
} }
} }