mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-14 13:33:03 +00:00
Merge pull request #1200 from atmire/w2p-79219_update-metadata-import-export-script-params
Update metadata import export script params
This commit is contained in:
@@ -6,10 +6,7 @@ import { By } from '@angular/platform-browser';
|
|||||||
import { Router } from '@angular/router';
|
import { Router } from '@angular/router';
|
||||||
import { RouterTestingModule } from '@angular/router/testing';
|
import { RouterTestingModule } from '@angular/router/testing';
|
||||||
import { TranslateModule } from '@ngx-translate/core';
|
import { TranslateModule } from '@ngx-translate/core';
|
||||||
import { of as observableOf } from 'rxjs';
|
|
||||||
import { AuthService } from '../../core/auth/auth.service';
|
|
||||||
import { METADATA_IMPORT_SCRIPT_NAME, ScriptDataService } from '../../core/data/processes/script-data.service';
|
import { METADATA_IMPORT_SCRIPT_NAME, ScriptDataService } from '../../core/data/processes/script-data.service';
|
||||||
import { EPerson } from '../../core/eperson/models/eperson.model';
|
|
||||||
import { ProcessParameter } from '../../process-page/processes/process-parameter.model';
|
import { ProcessParameter } from '../../process-page/processes/process-parameter.model';
|
||||||
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||||
import { NotificationsServiceStub } from '../../shared/testing/notifications-service.stub';
|
import { NotificationsServiceStub } from '../../shared/testing/notifications-service.stub';
|
||||||
@@ -22,12 +19,9 @@ describe('MetadataImportPageComponent', () => {
|
|||||||
let comp: MetadataImportPageComponent;
|
let comp: MetadataImportPageComponent;
|
||||||
let fixture: ComponentFixture<MetadataImportPageComponent>;
|
let fixture: ComponentFixture<MetadataImportPageComponent>;
|
||||||
|
|
||||||
let user;
|
|
||||||
|
|
||||||
let notificationService: NotificationsServiceStub;
|
let notificationService: NotificationsServiceStub;
|
||||||
let scriptService: any;
|
let scriptService: any;
|
||||||
let router;
|
let router;
|
||||||
let authService;
|
|
||||||
let locationStub;
|
let locationStub;
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
@@ -37,13 +31,6 @@ describe('MetadataImportPageComponent', () => {
|
|||||||
invoke: createSuccessfulRemoteDataObject$({ processId: '45' })
|
invoke: createSuccessfulRemoteDataObject$({ processId: '45' })
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
user = Object.assign(new EPerson(), {
|
|
||||||
id: 'userId',
|
|
||||||
email: 'user@test.com'
|
|
||||||
});
|
|
||||||
authService = jasmine.createSpyObj('authService', {
|
|
||||||
getAuthenticatedUserFromStore: observableOf(user)
|
|
||||||
});
|
|
||||||
router = jasmine.createSpyObj('router', {
|
router = jasmine.createSpyObj('router', {
|
||||||
navigateByUrl: jasmine.createSpy('navigateByUrl')
|
navigateByUrl: jasmine.createSpy('navigateByUrl')
|
||||||
});
|
});
|
||||||
@@ -65,7 +52,6 @@ describe('MetadataImportPageComponent', () => {
|
|||||||
{ provide: NotificationsService, useValue: notificationService },
|
{ provide: NotificationsService, useValue: notificationService },
|
||||||
{ provide: ScriptDataService, useValue: scriptService },
|
{ provide: ScriptDataService, useValue: scriptService },
|
||||||
{ provide: Router, useValue: router },
|
{ provide: Router, useValue: router },
|
||||||
{ provide: AuthService, useValue: authService },
|
|
||||||
{ provide: Location, useValue: locationStub },
|
{ provide: Location, useValue: locationStub },
|
||||||
],
|
],
|
||||||
schemas: [NO_ERRORS_SCHEMA]
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
@@ -107,9 +93,8 @@ describe('MetadataImportPageComponent', () => {
|
|||||||
proceed.click();
|
proceed.click();
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
}));
|
}));
|
||||||
it('metadata-import script is invoked with its -e currentUserEmail, -f fileName and the mockFile', () => {
|
it('metadata-import script is invoked with -f fileName and the mockFile', () => {
|
||||||
const parameterValues: ProcessParameter[] = [
|
const parameterValues: ProcessParameter[] = [
|
||||||
Object.assign(new ProcessParameter(), { name: '-e', value: user.email }),
|
|
||||||
Object.assign(new ProcessParameter(), { name: '-f', value: 'filename.txt' }),
|
Object.assign(new ProcessParameter(), { name: '-f', value: 'filename.txt' }),
|
||||||
];
|
];
|
||||||
expect(scriptService.invoke).toHaveBeenCalledWith(METADATA_IMPORT_SCRIPT_NAME, parameterValues, [fileMock]);
|
expect(scriptService.invoke).toHaveBeenCalledWith(METADATA_IMPORT_SCRIPT_NAME, parameterValues, [fileMock]);
|
||||||
|
@@ -23,20 +23,14 @@ import { getProcessDetailRoute } from '../../process-page/process-page-routing.p
|
|||||||
/**
|
/**
|
||||||
* Component that represents a metadata import page for administrators
|
* Component that represents a metadata import page for administrators
|
||||||
*/
|
*/
|
||||||
export class MetadataImportPageComponent implements OnInit {
|
export class MetadataImportPageComponent {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The current value of the file
|
* The current value of the file
|
||||||
*/
|
*/
|
||||||
fileObject: File;
|
fileObject: File;
|
||||||
|
|
||||||
/**
|
public constructor(private location: Location,
|
||||||
* The authenticated user's email
|
|
||||||
*/
|
|
||||||
private currentUserEmail$: Observable<string>;
|
|
||||||
|
|
||||||
public constructor(protected authService: AuthService,
|
|
||||||
private location: Location,
|
|
||||||
protected translate: TranslateService,
|
protected translate: TranslateService,
|
||||||
protected notificationsService: NotificationsService,
|
protected notificationsService: NotificationsService,
|
||||||
private scriptDataService: ScriptDataService,
|
private scriptDataService: ScriptDataService,
|
||||||
@@ -51,15 +45,6 @@ export class MetadataImportPageComponent implements OnInit {
|
|||||||
this.fileObject = file;
|
this.fileObject = file;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Method provided by Angular. Invoked after the constructor.
|
|
||||||
*/
|
|
||||||
ngOnInit() {
|
|
||||||
this.currentUserEmail$ = this.authService.getAuthenticatedUserFromStore().pipe(
|
|
||||||
map((user: EPerson) => user.email)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When return button is pressed go to previous location
|
* When return button is pressed go to previous location
|
||||||
*/
|
*/
|
||||||
@@ -68,22 +53,17 @@ export class MetadataImportPageComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts import-metadata script with -e currentUserEmail -f fileName (and the selected file)
|
* Starts import-metadata script with -f fileName (and the selected file)
|
||||||
*/
|
*/
|
||||||
public importMetadata() {
|
public importMetadata() {
|
||||||
if (this.fileObject == null) {
|
if (this.fileObject == null) {
|
||||||
this.notificationsService.error(this.translate.get('admin.metadata-import.page.error.addFile'));
|
this.notificationsService.error(this.translate.get('admin.metadata-import.page.error.addFile'));
|
||||||
} else {
|
} else {
|
||||||
this.currentUserEmail$.pipe(
|
const parameterValues: ProcessParameter[] = [
|
||||||
switchMap((email: string) => {
|
Object.assign(new ProcessParameter(), { name: '-f', value: this.fileObject.name }),
|
||||||
if (isNotEmpty(email)) {
|
];
|
||||||
const parameterValues: ProcessParameter[] = [
|
|
||||||
Object.assign(new ProcessParameter(), { name: '-e', value: email }),
|
this.scriptDataService.invoke(METADATA_IMPORT_SCRIPT_NAME, parameterValues, [this.fileObject]).pipe(
|
||||||
Object.assign(new ProcessParameter(), { name: '-f', value: this.fileObject.name }),
|
|
||||||
];
|
|
||||||
return this.scriptDataService.invoke(METADATA_IMPORT_SCRIPT_NAME, parameterValues, [this.fileObject]);
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
getFirstCompletedRemoteData(),
|
getFirstCompletedRemoteData(),
|
||||||
).subscribe((rd: RemoteData<Process>) => {
|
).subscribe((rd: RemoteData<Process>) => {
|
||||||
if (rd.hasSucceeded) {
|
if (rd.hasSucceeded) {
|
||||||
|
@@ -51,12 +51,14 @@ describe('ExportMetadataSelectorComponent', () => {
|
|||||||
|
|
||||||
const mockItem = Object.assign(new Item(), {
|
const mockItem = Object.assign(new Item(), {
|
||||||
id: 'fake-id',
|
id: 'fake-id',
|
||||||
|
uuid: 'fake-id',
|
||||||
handle: 'fake/handle',
|
handle: 'fake/handle',
|
||||||
lastModified: '2018'
|
lastModified: '2018'
|
||||||
});
|
});
|
||||||
|
|
||||||
const mockCollection: Collection = Object.assign(new Collection(), {
|
const mockCollection: Collection = Object.assign(new Collection(), {
|
||||||
id: 'test-collection-1-1',
|
id: 'test-collection-1-1',
|
||||||
|
uuid: 'test-collection-1-1',
|
||||||
name: 'test-collection-1',
|
name: 'test-collection-1',
|
||||||
metadata: {
|
metadata: {
|
||||||
'dc.identifier.uri': [
|
'dc.identifier.uri': [
|
||||||
@@ -70,6 +72,7 @@ describe('ExportMetadataSelectorComponent', () => {
|
|||||||
|
|
||||||
const mockCommunity = Object.assign(new Community(), {
|
const mockCommunity = Object.assign(new Community(), {
|
||||||
id: 'test-uuid',
|
id: 'test-uuid',
|
||||||
|
uuid: 'test-uuid',
|
||||||
metadata: {
|
metadata: {
|
||||||
'dc.identifier.uri': [
|
'dc.identifier.uri': [
|
||||||
{
|
{
|
||||||
@@ -157,10 +160,9 @@ describe('ExportMetadataSelectorComponent', () => {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('metadata-export script is invoked with its -i handle and -f uuid.csv', () => {
|
it('should invoke the metadata-export script with option -i uuid', () => {
|
||||||
const parameterValues: ProcessParameter[] = [
|
const parameterValues: ProcessParameter[] = [
|
||||||
Object.assign(new ProcessParameter(), { name: '-i', value: mockCollection.handle }),
|
Object.assign(new ProcessParameter(), { name: '-i', value: mockCollection.uuid }),
|
||||||
Object.assign(new ProcessParameter(), { name: '-f', value: mockCollection.uuid + '.csv' }),
|
|
||||||
];
|
];
|
||||||
expect(scriptService.invoke).toHaveBeenCalledWith(METADATA_EXPORT_SCRIPT_NAME, parameterValues, []);
|
expect(scriptService.invoke).toHaveBeenCalledWith(METADATA_EXPORT_SCRIPT_NAME, parameterValues, []);
|
||||||
});
|
});
|
||||||
@@ -182,10 +184,9 @@ describe('ExportMetadataSelectorComponent', () => {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('metadata-export script is invoked with its -i handle and -f uuid.csv', () => {
|
it('should invoke the metadata-export script with option -i uuid', () => {
|
||||||
const parameterValues: ProcessParameter[] = [
|
const parameterValues: ProcessParameter[] = [
|
||||||
Object.assign(new ProcessParameter(), { name: '-i', value: mockCommunity.handle }),
|
Object.assign(new ProcessParameter(), { name: '-i', value: mockCommunity.uuid }),
|
||||||
Object.assign(new ProcessParameter(), { name: '-f', value: mockCommunity.uuid + '.csv' }),
|
|
||||||
];
|
];
|
||||||
expect(scriptService.invoke).toHaveBeenCalledWith(METADATA_EXPORT_SCRIPT_NAME, parameterValues, []);
|
expect(scriptService.invoke).toHaveBeenCalledWith(METADATA_EXPORT_SCRIPT_NAME, parameterValues, []);
|
||||||
});
|
});
|
||||||
|
@@ -56,7 +56,7 @@ export class ExportMetadataSelectorComponent extends DSOSelectorModalWrapperComp
|
|||||||
modalRef.componentInstance.confirmIcon = 'fas fa-file-export';
|
modalRef.componentInstance.confirmIcon = 'fas fa-file-export';
|
||||||
const resp$ = modalRef.componentInstance.response.pipe(switchMap((confirm: boolean) => {
|
const resp$ = modalRef.componentInstance.response.pipe(switchMap((confirm: boolean) => {
|
||||||
if (confirm) {
|
if (confirm) {
|
||||||
const startScriptSucceeded$ = this.startScriptNotifyAndRedirect(dso, dso.handle);
|
const startScriptSucceeded$ = this.startScriptNotifyAndRedirect(dso);
|
||||||
return startScriptSucceeded$.pipe(
|
return startScriptSucceeded$.pipe(
|
||||||
switchMap((r: boolean) => {
|
switchMap((r: boolean) => {
|
||||||
return observableOf(r);
|
return observableOf(r);
|
||||||
@@ -78,12 +78,10 @@ export class ExportMetadataSelectorComponent extends DSOSelectorModalWrapperComp
|
|||||||
* Start export-metadata script of dso & navigate to process if successful
|
* Start export-metadata script of dso & navigate to process if successful
|
||||||
* Otherwise show error message
|
* Otherwise show error message
|
||||||
* @param dso Dso to export
|
* @param dso Dso to export
|
||||||
* @param handle Dso handle to export
|
|
||||||
*/
|
*/
|
||||||
private startScriptNotifyAndRedirect(dso: DSpaceObject, handle: string): Observable<boolean> {
|
private startScriptNotifyAndRedirect(dso: DSpaceObject): Observable<boolean> {
|
||||||
const parameterValues: ProcessParameter[] = [
|
const parameterValues: ProcessParameter[] = [
|
||||||
Object.assign(new ProcessParameter(), { name: '-i', value: handle }),
|
Object.assign(new ProcessParameter(), { name: '-i', value: dso.uuid }),
|
||||||
Object.assign(new ProcessParameter(), { name: '-f', value: dso.uuid + '.csv' }),
|
|
||||||
];
|
];
|
||||||
return this.scriptDataService.invoke(METADATA_EXPORT_SCRIPT_NAME, parameterValues, [])
|
return this.scriptDataService.invoke(METADATA_EXPORT_SCRIPT_NAME, parameterValues, [])
|
||||||
.pipe(
|
.pipe(
|
||||||
|
Reference in New Issue
Block a user