Skip to content

Commit

Permalink
Merge pull request DSpace#3014 from atmire/w2p-113904_AddSupportForNu…
Browse files Browse the repository at this point in the history
…llUsers

Handle Null Users Gracefully in Process Overview Page
  • Loading branch information
tdonohue authored May 8, 2024
2 parents 2aa0f95 + 2d5d4a0 commit b406e71
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 14 deletions.
24 changes: 23 additions & 1 deletion src/app/process-page/form/process-form.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,5 +177,27 @@ export class ProcessFormComponent implements OnInit {
};
void this.router.navigate([getProcessListRoute()], extras);
}
}

updateScript($event: Script) {
this.selectedScript = $event;
this.parameters = undefined;
}

get generatedProcessName() {
const paramsString = this.parameters?.map((p: ProcessParameter) => {
const value = this.parseValue(p.value);
return isEmpty(value) ? p.name : `${p.name} ${value}`;
}).join(' ') || '';
return isEmpty(paramsString) ? this.selectedScript.name : `${this.selectedScript.name} ${paramsString}`;
}

private parseValue(value: any) {
if (typeof value === 'boolean') {
return undefined;
}
if (value instanceof File) {
return value.name;
}
return value?.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import {
NgbCollapse,
NgbModal,
} from '@ng-bootstrap/ng-bootstrap';
import { TranslateModule } from '@ngx-translate/core';
import {
TranslateModule,
TranslateService,
} from '@ngx-translate/core';
import { BehaviorSubject } from 'rxjs';
import { take } from 'rxjs/operators';

Expand Down Expand Up @@ -50,6 +53,8 @@ describe('ProcessOverviewTableComponent', () => {
let processes: Process[];
let ePerson: EPerson;

let translateServiceSpy: jasmine.SpyObj<TranslateService>;

function init() {
processes = [
Object.assign(new Process(), {
Expand All @@ -58,23 +63,28 @@ describe('ProcessOverviewTableComponent', () => {
startTime: '2020-03-19 00:30:00',
endTime: '2020-03-19 23:30:00',
processStatus: ProcessStatus.COMPLETED,
userId: 'testid',
}),
Object.assign(new Process(), {
processId: 2,
scriptName: 'script-b',
startTime: '2020-03-20 00:30:00',
endTime: '2020-03-20 23:30:00',
processStatus: ProcessStatus.FAILED,
userId: 'testid',
}),
Object.assign(new Process(), {
processId: 3,
scriptName: 'script-c',
startTime: '2020-03-21 00:30:00',
endTime: '2020-03-21 23:30:00',
processStatus: ProcessStatus.RUNNING,
userId: 'testid',
}),
];
ePerson = Object.assign(new EPerson(), {
id: 'testid',
uuid: 'testid',
metadata: {
'eperson.firstname': [
{
Expand Down Expand Up @@ -133,6 +143,8 @@ describe('ProcessOverviewTableComponent', () => {
beforeEach(waitForAsync(() => {
init();

translateServiceSpy = jasmine.createSpyObj('TranslateService', ['get']);

void TestBed.configureTestingModule({
declarations: [NgbCollapse],
imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([]), VarDirective, ProcessOverviewTableComponent],
Expand Down Expand Up @@ -217,4 +229,43 @@ describe('ProcessOverviewTableComponent', () => {
});

});

describe('getEPersonName function', () => {
it('should return unknown user when id is null', (done: DoneFn) => {
const id = null;
const expectedTranslation = 'process.overview.unknown.user';

translateServiceSpy.get(expectedTranslation);

component.getEPersonName(id).subscribe((result: string) => {
expect(result).toBe(expectedTranslation);
done();
});
expect(translateServiceSpy.get).toHaveBeenCalledWith('process.overview.unknown.user');
});

it('should return unknown user when id is invalid', (done: DoneFn) => {
const id = '';
const expectedTranslation = 'process.overview.unknown.user';

translateServiceSpy.get(expectedTranslation);

component.getEPersonName(id).subscribe((result: string) => {
expect(result).toBe(expectedTranslation);
done();
});
expect(translateServiceSpy.get).toHaveBeenCalledWith('process.overview.unknown.user');
});

it('should return EPerson name when id is correct', (done: DoneFn) => {
const id = 'testid';
const expectedName = 'John Doe';

component.getEPersonName(id).subscribe((result: string) => {
expect(result).toEqual(expectedName);
done();
});
expect(translateServiceSpy.get).not.toHaveBeenCalled();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ import {
RouterLink,
} from '@angular/router';
import { NgbCollapseModule } from '@ng-bootstrap/ng-bootstrap';
import { TranslateModule } from '@ngx-translate/core';
import {
TranslateModule,
TranslateService,
} from '@ngx-translate/core';
import {
BehaviorSubject,
from as observableFrom,
Expand Down Expand Up @@ -46,9 +49,12 @@ import { RouteService } from '../../../core/services/route.service';
import { redirectOn4xx } from '../../../core/shared/authorized.operators';
import {
getAllCompletedRemoteData,
getFirstSucceededRemoteDataPayload,
getFirstCompletedRemoteData,
} from '../../../core/shared/operators';
import { hasValue } from '../../../shared/empty.util';
import {
hasValue,
isNotEmpty,
} from '../../../shared/empty.util';
import { ThemedLoadingComponent } from '../../../shared/loading/themed-loading.component';
import { PaginationComponent } from '../../../shared/pagination/pagination.component';
import { PaginationComponentOptions } from '../../../shared/pagination/pagination-component-options.model';
Expand Down Expand Up @@ -153,12 +159,13 @@ export class ProcessOverviewTableComponent implements OnInit, OnDestroy {

constructor(protected processOverviewService: ProcessOverviewService,
protected processBulkDeleteService: ProcessBulkDeleteService,
protected ePersonDataService: EPersonDataService,
protected dsoNameService: DSONameService,
public ePersonDataService: EPersonDataService,
public dsoNameService: DSONameService,
protected paginationService: PaginationService,
protected routeService: RouteService,
protected router: Router,
protected auth: AuthService,
private translateService: TranslateService,
@Inject(PLATFORM_ID) protected platformId: object,
) {
}
Expand All @@ -176,7 +183,7 @@ export class ProcessOverviewTableComponent implements OnInit, OnDestroy {
// Creates an ID from the first 2 characters of the process status.
// Should two process status values ever start with the same substring,
// increase the number of characters until the ids are distinct.
this.paginationId = this.processStatus.toLowerCase().substring(0,2);
this.paginationId = this.processStatus.toLowerCase().substring(0, 2);

const defaultPaginationOptions = Object.assign(new PaginationComponentOptions(), {
id: this.paginationId,
Expand Down Expand Up @@ -218,7 +225,7 @@ export class ProcessOverviewTableComponent implements OnInit, OnDestroy {
// Map RemoteData<PaginatedList<Process>> to RemoteData<PaginatedList<ProcessOverviewTableEntry>>
switchMap((processesRD: RemoteData<PaginatedList<Process>>) => {
// Create observable emitting all processes one by one
return observableFrom(processesRD.payload.page).pipe(
return observableFrom(processesRD.payload.page).pipe(
// Map every Process to ProcessOverviewTableEntry
mergeMap((process: Process) => {
return this.getEPersonName(process.userId).pipe(
Expand All @@ -243,7 +250,6 @@ export class ProcessOverviewTableComponent implements OnInit, OnDestroy {
}),
);
}),

).subscribe((next: RemoteData<PaginatedList<ProcessOverviewTableEntry>>) => {
this.processesRD$.next(next);
}));
Expand All @@ -267,10 +273,20 @@ export class ProcessOverviewTableComponent implements OnInit, OnDestroy {
* @param id ID of the EPerson
*/
getEPersonName(id: string): Observable<string> {
return this.ePersonDataService.findById(id).pipe(
getFirstSucceededRemoteDataPayload(),
map((eperson: EPerson) => this.dsoNameService.getName(eperson)),
);
if (isNotEmpty(id)) {
return this.ePersonDataService.findById(id).pipe(
getFirstCompletedRemoteData(),
switchMap((rd: RemoteData<EPerson>) => {
if (rd.hasSucceeded) {
return [this.dsoNameService.getName(rd.payload)];
} else {
return this.translateService.get('process.overview.unknown.user');
}
}),
);
} else {
return this.translateService.get('process.overview.unknown.user');
}
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/en.json5
Original file line number Diff line number Diff line change
Expand Up @@ -3846,6 +3846,8 @@

"process.overview.delete.header": "Delete processes",

"process.overview.unknown.user": "Unknown",

"process.bulk.delete.error.head": "Error on deleteing process",

"process.bulk.delete.error.body": "The process with ID {{processId}} could not be deleted. The remaining processes will continue being deleted. ",
Expand Down

0 comments on commit b406e71

Please sign in to comment.