mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-17 15:03:07 +00:00
[CST-9636] Fix argument to send to the process
This commit is contained in:
@@ -14,7 +14,7 @@ import { RouterTestingModule } from '@angular/router/testing';
|
|||||||
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';
|
||||||
|
|
||||||
fdescribe('BulkAccessComponent', () => {
|
describe('BulkAccessComponent', () => {
|
||||||
let component: BulkAccessComponent;
|
let component: BulkAccessComponent;
|
||||||
let fixture: ComponentFixture<BulkAccessComponent>;
|
let fixture: ComponentFixture<BulkAccessComponent>;
|
||||||
let bulkAccessControlService: any;
|
let bulkAccessControlService: any;
|
||||||
|
@@ -1,20 +1,12 @@
|
|||||||
import { Component, OnInit, ViewChild } from '@angular/core';
|
import { Component, OnInit, ViewChild } from '@angular/core';
|
||||||
import { Router } from '@angular/router';
|
|
||||||
|
|
||||||
import { BehaviorSubject, Subscription } from 'rxjs';
|
import { BehaviorSubject, Subscription } from 'rxjs';
|
||||||
import { distinctUntilChanged, map } from 'rxjs/operators';
|
import { distinctUntilChanged, map } from 'rxjs/operators';
|
||||||
import { TranslateService } from '@ngx-translate/core';
|
|
||||||
|
|
||||||
import { BulkAccessSettingsComponent } from './settings/bulk-access-settings.component';
|
import { BulkAccessSettingsComponent } from './settings/bulk-access-settings.component';
|
||||||
import { BulkAccessControlService } from '../../shared/access-control-form-container/bulk-access-control.service';
|
import { BulkAccessControlService } from '../../shared/access-control-form-container/bulk-access-control.service';
|
||||||
import { SelectableListState } from '../../shared/object-list/selectable-list/selectable-list.reducer';
|
import { SelectableListState } from '../../shared/object-list/selectable-list/selectable-list.reducer';
|
||||||
import { SelectableListService } from '../../shared/object-list/selectable-list/selectable-list.service';
|
import { SelectableListService } from '../../shared/object-list/selectable-list/selectable-list.service';
|
||||||
import { getFirstCompletedRemoteData } from '../../core/shared/operators';
|
|
||||||
import { RemoteData } from '../../core/data/remote-data';
|
|
||||||
import { Process } from '../../process-page/processes/process.model';
|
|
||||||
import { isNotEmpty } from '../../shared/empty.util';
|
|
||||||
import { getProcessDetailRoute } from '../../process-page/process-page-routing.paths';
|
|
||||||
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-bulk-access',
|
selector: 'ds-bulk-access',
|
||||||
@@ -45,10 +37,7 @@ export class BulkAccessComponent implements OnInit {
|
|||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private bulkAccessControlService: BulkAccessControlService,
|
private bulkAccessControlService: BulkAccessControlService,
|
||||||
private notificationsService: NotificationsService,
|
private selectableListService: SelectableListService
|
||||||
private router: Router,
|
|
||||||
private selectableListService: SelectableListService,
|
|
||||||
private translationService: TranslateService
|
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,24 +80,7 @@ export class BulkAccessComponent implements OnInit {
|
|||||||
this.bulkAccessControlService.executeScript(
|
this.bulkAccessControlService.executeScript(
|
||||||
this.objectsSelected$.value || [],
|
this.objectsSelected$.value || [],
|
||||||
file
|
file
|
||||||
).pipe(
|
).subscribe();
|
||||||
getFirstCompletedRemoteData(),
|
|
||||||
map((rd: RemoteData<Process>) => {
|
|
||||||
if (rd.hasSucceeded) {
|
|
||||||
const title = this.translationService.get('process.new.notification.success.title');
|
|
||||||
const content = this.translationService.get('process.new.notification.success.content');
|
|
||||||
this.notificationsService.success(title, content);
|
|
||||||
if (isNotEmpty(rd.payload)) {
|
|
||||||
this.router.navigateByUrl(getProcessDetailRoute(rd.payload.processId));
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
const title = this.translationService.get('process.new.notification.error.title');
|
|
||||||
const content = this.translationService.get('process.new.notification.error.content');
|
|
||||||
this.notificationsService.error(title, content);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
})).subscribe();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -1,20 +1,57 @@
|
|||||||
import { TestBed } from '@angular/core/testing';
|
import { TestBed } from '@angular/core/testing';
|
||||||
import { BulkAccessControlService, BulkAccessPayload } from './bulk-access-control.service';
|
import { RouterTestingModule } from '@angular/router/testing';
|
||||||
|
import { TranslateModule } from '@ngx-translate/core';
|
||||||
|
|
||||||
|
import { BulkAccessControlService } from './bulk-access-control.service';
|
||||||
import { ScriptDataService } from '../../core/data/processes/script-data.service';
|
import { ScriptDataService } from '../../core/data/processes/script-data.service';
|
||||||
import { ProcessParameter } from '../../process-page/processes/process-parameter.model';
|
import { ProcessParameter } from '../../process-page/processes/process-parameter.model';
|
||||||
|
import { NotificationsService } from '../notifications/notifications.service';
|
||||||
|
import { NotificationsServiceStub } from '../testing/notifications-service.stub';
|
||||||
|
import { createSuccessfulRemoteDataObject$ } from '../remote-data.utils';
|
||||||
|
import { Process } from '../../process-page/processes/process.model';
|
||||||
|
|
||||||
describe('BulkAccessControlService', () => {
|
describe('BulkAccessControlService', () => {
|
||||||
let service: BulkAccessControlService;
|
let service: BulkAccessControlService;
|
||||||
let scriptServiceSpy: jasmine.SpyObj<ScriptDataService>;
|
let scriptServiceSpy: jasmine.SpyObj<ScriptDataService>;
|
||||||
|
|
||||||
|
const mockPayload: any = {
|
||||||
|
'bitstream': [],
|
||||||
|
'item': [
|
||||||
|
{
|
||||||
|
'name': 'embargo',
|
||||||
|
'startDate': {
|
||||||
|
'year': 2026,
|
||||||
|
'month': 5,
|
||||||
|
'day': 31
|
||||||
|
},
|
||||||
|
'endDate': null
|
||||||
|
}
|
||||||
|
],
|
||||||
|
'state': {
|
||||||
|
'item': {
|
||||||
|
'toggleStatus': true,
|
||||||
|
'accessMode': 'replace'
|
||||||
|
},
|
||||||
|
'bitstream': {
|
||||||
|
'toggleStatus': false,
|
||||||
|
'accessMode': '',
|
||||||
|
'changesLimit': '',
|
||||||
|
'selectedBitstreams': []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
const spy = jasmine.createSpyObj('ScriptDataService', ['invoke']);
|
const spy = jasmine.createSpyObj('ScriptDataService', ['invoke']);
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
|
imports: [
|
||||||
|
RouterTestingModule,
|
||||||
|
TranslateModule.forRoot()
|
||||||
|
],
|
||||||
providers: [
|
providers: [
|
||||||
BulkAccessControlService,
|
BulkAccessControlService,
|
||||||
{ provide: ScriptDataService, useValue: spy }
|
{ provide: ScriptDataService, useValue: spy },
|
||||||
|
{ provide: NotificationsService, useValue: NotificationsServiceStub },
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
service = TestBed.inject(BulkAccessControlService);
|
service = TestBed.inject(BulkAccessControlService);
|
||||||
@@ -27,7 +64,7 @@ describe('BulkAccessControlService', () => {
|
|||||||
|
|
||||||
describe('createPayloadFile', () => {
|
describe('createPayloadFile', () => {
|
||||||
it('should create a file and return the URL and file object', () => {
|
it('should create a file and return the URL and file object', () => {
|
||||||
const payload: BulkAccessPayload = { state: null, bitstreamAccess: null, itemAccess: null };
|
const payload = mockPayload;
|
||||||
const result = service.createPayloadFile(payload);
|
const result = service.createPayloadFile(payload);
|
||||||
|
|
||||||
expect(result.url).toBeTruthy();
|
expect(result.url).toBeTruthy();
|
||||||
@@ -39,10 +76,13 @@ describe('BulkAccessControlService', () => {
|
|||||||
it('should invoke the script service with the correct parameters', () => {
|
it('should invoke the script service with the correct parameters', () => {
|
||||||
const uuids = ['123', '456'];
|
const uuids = ['123', '456'];
|
||||||
const file = new File(['test'], 'data.json', { type: 'application/json' });
|
const file = new File(['test'], 'data.json', { type: 'application/json' });
|
||||||
const expectedParams: ProcessParameter[] = [{ name: 'uuid', value: '123,456' }];
|
const expectedParams: ProcessParameter[] = [
|
||||||
|
{ name: '-u', value: '123,456' },
|
||||||
|
{ name: '-f', value: 'data.json' }
|
||||||
|
];
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
scriptServiceSpy.invoke.and.returnValue(Promise.resolve({}));
|
scriptServiceSpy.invoke.and.returnValue(createSuccessfulRemoteDataObject$(new Process()));
|
||||||
|
|
||||||
const result = service.executeScript(uuids, file);
|
const result = service.executeScript(uuids, file);
|
||||||
|
|
||||||
|
@@ -1,8 +1,19 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
|
import { Router } from '@angular/router';
|
||||||
|
|
||||||
|
import { Observable } from 'rxjs';
|
||||||
|
import { map } from 'rxjs/operators';
|
||||||
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
|
|
||||||
import { ScriptDataService } from '../../core/data/processes/script-data.service';
|
import { ScriptDataService } from '../../core/data/processes/script-data.service';
|
||||||
import { ProcessParameter } from '../../process-page/processes/process-parameter.model';
|
import { ProcessParameter } from '../../process-page/processes/process-parameter.model';
|
||||||
import { AccessControlFormState } from './access-control-form-container.component';
|
import { AccessControlFormState } from './access-control-form-container.component';
|
||||||
|
import { getFirstCompletedRemoteData } from '../../core/shared/operators';
|
||||||
|
import { RemoteData } from '../../core/data/remote-data';
|
||||||
|
import { Process } from '../../process-page/processes/process.model';
|
||||||
|
import { isNotEmpty } from '../empty.util';
|
||||||
|
import { getProcessDetailRoute } from '../../process-page/process-page-routing.paths';
|
||||||
|
import { NotificationsService } from '../notifications/notifications.service';
|
||||||
|
|
||||||
export interface BulkAccessPayload {
|
export interface BulkAccessPayload {
|
||||||
state: AccessControlFormState;
|
state: AccessControlFormState;
|
||||||
@@ -12,7 +23,14 @@ export interface BulkAccessPayload {
|
|||||||
|
|
||||||
@Injectable({ providedIn: 'root' })
|
@Injectable({ providedIn: 'root' })
|
||||||
export class BulkAccessControlService {
|
export class BulkAccessControlService {
|
||||||
constructor(private scriptService: ScriptDataService) {}
|
constructor(
|
||||||
|
private notificationsService: NotificationsService,
|
||||||
|
private router: Router,
|
||||||
|
private scriptService: ScriptDataService,
|
||||||
|
private translationService: TranslateService
|
||||||
|
) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
createPayloadFile(payload: BulkAccessPayload) {
|
createPayloadFile(payload: BulkAccessPayload) {
|
||||||
const content = convertToBulkAccessControlFileModel(payload);
|
const content = convertToBulkAccessControlFileModel(payload);
|
||||||
@@ -26,19 +44,37 @@ export class BulkAccessControlService {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const url = URL.createObjectURL(file);
|
const url = URL.createObjectURL(file);
|
||||||
window.open(url, '_blank'); // remove this later
|
|
||||||
|
|
||||||
return { url, file };
|
return { url, file };
|
||||||
}
|
}
|
||||||
|
|
||||||
executeScript(uuids: string[], file: File) {
|
executeScript(uuids: string[], file: File): Observable<boolean> {
|
||||||
console.log('execute', { uuids, file });
|
console.log('execute', { uuids, file });
|
||||||
|
|
||||||
const params: ProcessParameter[] = [
|
const params: ProcessParameter[] = [
|
||||||
{ name: 'uuid', value: uuids.join(',') },
|
{ name: '-u', value: uuids.join(',') },
|
||||||
|
{ name: '-f', value: file.name }
|
||||||
];
|
];
|
||||||
|
|
||||||
return this.scriptService.invoke('bulk-access-control', params, [file]);
|
return this.scriptService.invoke('bulk-access-control', params, [file]).pipe(
|
||||||
|
getFirstCompletedRemoteData(),
|
||||||
|
map((rd: RemoteData<Process>) => {
|
||||||
|
if (rd.hasSucceeded) {
|
||||||
|
const title = this.translationService.get('process.new.notification.success.title');
|
||||||
|
const content = this.translationService.get('process.new.notification.success.content');
|
||||||
|
this.notificationsService.success(title, content);
|
||||||
|
if (isNotEmpty(rd.payload)) {
|
||||||
|
this.router.navigateByUrl(getProcessDetailRoute(rd.payload.processId));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
const title = this.translationService.get('process.new.notification.error.title');
|
||||||
|
const content = this.translationService.get('process.new.notification.error.content');
|
||||||
|
this.notificationsService.error(title, content);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user