Skip to content

Commit

Permalink
Merge pull request #1200 from atmire/w2p-79219_update-metadata-import…
Browse files Browse the repository at this point in the history
…-export-script-params

Update metadata import export script params
  • Loading branch information
tdonohue authored May 24, 2021
2 parents fab5674 + f0fb8c1 commit 8daf52e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ import { By } from '@angular/platform-browser';
import { Router } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';
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 { EPerson } from '../../core/eperson/models/eperson.model';
import { ProcessParameter } from '../../process-page/processes/process-parameter.model';
import { NotificationsService } from '../../shared/notifications/notifications.service';
import { NotificationsServiceStub } from '../../shared/testing/notifications-service.stub';
Expand All @@ -22,12 +19,9 @@ describe('MetadataImportPageComponent', () => {
let comp: MetadataImportPageComponent;
let fixture: ComponentFixture<MetadataImportPageComponent>;

let user;

let notificationService: NotificationsServiceStub;
let scriptService: any;
let router;
let authService;
let locationStub;

function init() {
Expand All @@ -37,13 +31,6 @@ describe('MetadataImportPageComponent', () => {
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', {
navigateByUrl: jasmine.createSpy('navigateByUrl')
});
Expand All @@ -65,7 +52,6 @@ describe('MetadataImportPageComponent', () => {
{ provide: NotificationsService, useValue: notificationService },
{ provide: ScriptDataService, useValue: scriptService },
{ provide: Router, useValue: router },
{ provide: AuthService, useValue: authService },
{ provide: Location, useValue: locationStub },
],
schemas: [NO_ERRORS_SCHEMA]
Expand Down Expand Up @@ -107,9 +93,8 @@ describe('MetadataImportPageComponent', () => {
proceed.click();
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[] = [
Object.assign(new ProcessParameter(), { name: '-e', value: user.email }),
Object.assign(new ProcessParameter(), { name: '-f', value: 'filename.txt' }),
];
expect(scriptService.invoke).toHaveBeenCalledWith(METADATA_IMPORT_SCRIPT_NAME, parameterValues, [fileMock]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,14 @@ import { getProcessDetailRoute } from '../../process-page/process-page-routing.p
/**
* Component that represents a metadata import page for administrators
*/
export class MetadataImportPageComponent implements OnInit {
export class MetadataImportPageComponent {

/**
* The current value of the file
*/
fileObject: File;

/**
* The authenticated user's email
*/
private currentUserEmail$: Observable<string>;

public constructor(protected authService: AuthService,
private location: Location,
public constructor(private location: Location,
protected translate: TranslateService,
protected notificationsService: NotificationsService,
private scriptDataService: ScriptDataService,
Expand All @@ -51,15 +45,6 @@ export class MetadataImportPageComponent implements OnInit {
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
*/
Expand All @@ -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() {
if (this.fileObject == null) {
this.notificationsService.error(this.translate.get('admin.metadata-import.page.error.addFile'));
} else {
this.currentUserEmail$.pipe(
switchMap((email: string) => {
if (isNotEmpty(email)) {
const parameterValues: ProcessParameter[] = [
Object.assign(new ProcessParameter(), { name: '-e', value: email }),
Object.assign(new ProcessParameter(), { name: '-f', value: this.fileObject.name }),
];
return this.scriptDataService.invoke(METADATA_IMPORT_SCRIPT_NAME, parameterValues, [this.fileObject]);
}
}),
const parameterValues: ProcessParameter[] = [
Object.assign(new ProcessParameter(), { name: '-f', value: this.fileObject.name }),
];

this.scriptDataService.invoke(METADATA_IMPORT_SCRIPT_NAME, parameterValues, [this.fileObject]).pipe(
getFirstCompletedRemoteData(),
).subscribe((rd: RemoteData<Process>) => {
if (rd.hasSucceeded) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,14 @@ describe('ExportMetadataSelectorComponent', () => {

const mockItem = Object.assign(new Item(), {
id: 'fake-id',
uuid: 'fake-id',
handle: 'fake/handle',
lastModified: '2018'
});

const mockCollection: Collection = Object.assign(new Collection(), {
id: 'test-collection-1-1',
uuid: 'test-collection-1-1',
name: 'test-collection-1',
metadata: {
'dc.identifier.uri': [
Expand All @@ -70,6 +72,7 @@ describe('ExportMetadataSelectorComponent', () => {

const mockCommunity = Object.assign(new Community(), {
id: 'test-uuid',
uuid: 'test-uuid',
metadata: {
'dc.identifier.uri': [
{
Expand Down Expand Up @@ -157,10 +160,9 @@ describe('ExportMetadataSelectorComponent', () => {
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[] = [
Object.assign(new ProcessParameter(), { name: '-i', value: mockCollection.handle }),
Object.assign(new ProcessParameter(), { name: '-f', value: mockCollection.uuid + '.csv' }),
Object.assign(new ProcessParameter(), { name: '-i', value: mockCollection.uuid }),
];
expect(scriptService.invoke).toHaveBeenCalledWith(METADATA_EXPORT_SCRIPT_NAME, parameterValues, []);
});
Expand All @@ -182,10 +184,9 @@ describe('ExportMetadataSelectorComponent', () => {
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[] = [
Object.assign(new ProcessParameter(), { name: '-i', value: mockCommunity.handle }),
Object.assign(new ProcessParameter(), { name: '-f', value: mockCommunity.uuid + '.csv' }),
Object.assign(new ProcessParameter(), { name: '-i', value: mockCommunity.uuid }),
];
expect(scriptService.invoke).toHaveBeenCalledWith(METADATA_EXPORT_SCRIPT_NAME, parameterValues, []);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class ExportMetadataSelectorComponent extends DSOSelectorModalWrapperComp
modalRef.componentInstance.confirmIcon = 'fas fa-file-export';
const resp$ = modalRef.componentInstance.response.pipe(switchMap((confirm: boolean) => {
if (confirm) {
const startScriptSucceeded$ = this.startScriptNotifyAndRedirect(dso, dso.handle);
const startScriptSucceeded$ = this.startScriptNotifyAndRedirect(dso);
return startScriptSucceeded$.pipe(
switchMap((r: boolean) => {
return observableOf(r);
Expand All @@ -78,12 +78,10 @@ export class ExportMetadataSelectorComponent extends DSOSelectorModalWrapperComp
* Start export-metadata script of dso & navigate to process if successful
* Otherwise show error message
* @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[] = [
Object.assign(new ProcessParameter(), { name: '-i', value: handle }),
Object.assign(new ProcessParameter(), { name: '-f', value: dso.uuid + '.csv' }),
Object.assign(new ProcessParameter(), { name: '-i', value: dso.uuid }),
];
return this.scriptDataService.invoke(METADATA_EXPORT_SCRIPT_NAME, parameterValues, [])
.pipe(
Expand Down

0 comments on commit 8daf52e

Please sign in to comment.