mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
Refactored to use process log bitstream
This commit is contained in:
@@ -7,7 +7,6 @@ import { EffectsModule } from '@ngrx/effects';
|
|||||||
|
|
||||||
import { Action, StoreConfig, StoreModule } from '@ngrx/store';
|
import { Action, StoreConfig, StoreModule } from '@ngrx/store';
|
||||||
import { MyDSpaceGuard } from '../+my-dspace-page/my-dspace.guard';
|
import { MyDSpaceGuard } from '../+my-dspace-page/my-dspace.guard';
|
||||||
import { ProcessOutput } from '../process-page/processes/process-output.model';
|
|
||||||
|
|
||||||
import { isNotEmpty } from '../shared/empty.util';
|
import { isNotEmpty } from '../shared/empty.util';
|
||||||
import { FormBuilderService } from '../shared/form/builder/form-builder.service';
|
import { FormBuilderService } from '../shared/form/builder/form-builder.service';
|
||||||
@@ -72,7 +71,6 @@ import { LookupRelationService } from './data/lookup-relation.service';
|
|||||||
import { MappedCollectionsReponseParsingService } from './data/mapped-collections-reponse-parsing.service';
|
import { MappedCollectionsReponseParsingService } from './data/mapped-collections-reponse-parsing.service';
|
||||||
import { MyDSpaceResponseParsingService } from './data/mydspace-response-parsing.service';
|
import { MyDSpaceResponseParsingService } from './data/mydspace-response-parsing.service';
|
||||||
import { ObjectUpdatesService } from './data/object-updates/object-updates.service';
|
import { ObjectUpdatesService } from './data/object-updates/object-updates.service';
|
||||||
import { ProcessOutputDataService } from './data/process-output-data.service';
|
|
||||||
import { RelationshipTypeService } from './data/relationship-type.service';
|
import { RelationshipTypeService } from './data/relationship-type.service';
|
||||||
import { RelationshipService } from './data/relationship.service';
|
import { RelationshipService } from './data/relationship.service';
|
||||||
import { ResourcePolicyService } from './resource-policy/resource-policy.service';
|
import { ResourcePolicyService } from './resource-policy/resource-policy.service';
|
||||||
@@ -291,7 +289,6 @@ const PROVIDERS = [
|
|||||||
ItemTypeDataService,
|
ItemTypeDataService,
|
||||||
WorkflowActionDataService,
|
WorkflowActionDataService,
|
||||||
ProcessDataService,
|
ProcessDataService,
|
||||||
ProcessOutputDataService,
|
|
||||||
ScriptDataService,
|
ScriptDataService,
|
||||||
ProcessFilesResponseParsingService,
|
ProcessFilesResponseParsingService,
|
||||||
FeatureDataService,
|
FeatureDataService,
|
||||||
@@ -365,7 +362,6 @@ export const models =
|
|||||||
ExternalSourceEntry,
|
ExternalSourceEntry,
|
||||||
Script,
|
Script,
|
||||||
Process,
|
Process,
|
||||||
ProcessOutput,
|
|
||||||
Version,
|
Version,
|
||||||
VersionHistory,
|
VersionHistory,
|
||||||
WorkflowAction,
|
WorkflowAction,
|
||||||
|
@@ -1,72 +0,0 @@
|
|||||||
import { HttpClient } from '@angular/common/http';
|
|
||||||
import { Injectable } from '@angular/core';
|
|
||||||
import { Store } from '@ngrx/store';
|
|
||||||
import { Observable } from 'rxjs';
|
|
||||||
import { ProcessOutput } from '../../process-page/processes/process-output.model';
|
|
||||||
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
|
||||||
import { FollowLinkConfig } from '../../shared/utils/follow-link-config.model';
|
|
||||||
import { dataService } from '../cache/builders/build-decorators';
|
|
||||||
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
|
|
||||||
import { ObjectCacheService } from '../cache/object-cache.service';
|
|
||||||
import { CoreState } from '../core.reducers';
|
|
||||||
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
|
||||||
import { PROCESS_OUTPUT_TYPE } from '../shared/process-output.resource-type';
|
|
||||||
import { DataService } from './data.service';
|
|
||||||
import { DefaultChangeAnalyzer } from './default-change-analyzer.service';
|
|
||||||
import { RemoteData } from './remote-data';
|
|
||||||
import { RequestService } from './request.service';
|
|
||||||
|
|
||||||
/* tslint:disable:max-classes-per-file */
|
|
||||||
/**
|
|
||||||
* A private DataService implementation to delegate specific methods to.
|
|
||||||
*/
|
|
||||||
class DataServiceImpl extends DataService<ProcessOutput> {
|
|
||||||
protected linkPath = 'processes';
|
|
||||||
|
|
||||||
constructor(
|
|
||||||
protected requestService: RequestService,
|
|
||||||
protected rdbService: RemoteDataBuildService,
|
|
||||||
protected store: Store<CoreState>,
|
|
||||||
protected objectCache: ObjectCacheService,
|
|
||||||
protected halService: HALEndpointService,
|
|
||||||
protected notificationsService: NotificationsService,
|
|
||||||
protected http: HttpClient,
|
|
||||||
protected comparator: DefaultChangeAnalyzer<ProcessOutput>) {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A service to retrieve output from processes from the REST API.
|
|
||||||
*/
|
|
||||||
@Injectable()
|
|
||||||
@dataService(PROCESS_OUTPUT_TYPE)
|
|
||||||
export class ProcessOutputDataService {
|
|
||||||
/**
|
|
||||||
* A private DataService instance to delegate specific methods to.
|
|
||||||
*/
|
|
||||||
private dataService: DataServiceImpl;
|
|
||||||
|
|
||||||
constructor(
|
|
||||||
protected requestService: RequestService,
|
|
||||||
protected rdbService: RemoteDataBuildService,
|
|
||||||
protected store: Store<CoreState>,
|
|
||||||
protected objectCache: ObjectCacheService,
|
|
||||||
protected halService: HALEndpointService,
|
|
||||||
protected notificationsService: NotificationsService,
|
|
||||||
protected http: HttpClient,
|
|
||||||
protected comparator: DefaultChangeAnalyzer<ProcessOutput>) {
|
|
||||||
this.dataService = new DataServiceImpl(requestService, rdbService, null, objectCache, halService, notificationsService, http, comparator);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns an observable of {@link RemoteData} of a {@link ProcessOutput}, based on an href, with a list of {@link FollowLinkConfig},
|
|
||||||
* to automatically resolve {@link HALLink}s of the {@link ProcessOutput}
|
|
||||||
* @param href The url of {@link ProcessOutput} we want to retrieve
|
|
||||||
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which {@link HALLink}s should be automatically resolved
|
|
||||||
*/
|
|
||||||
findByHref(href: string, ...linksToFollow: Array<FollowLinkConfig<ProcessOutput>>): Observable<RemoteData<ProcessOutput>> {
|
|
||||||
return this.dataService.findByHref(href, ...linksToFollow);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* tslint:enable:max-classes-per-file */
|
|
@@ -17,7 +17,7 @@
|
|||||||
<ds-process-detail-field *ngIf="files && files?.length > 0" id="process-files" [title]="'process.detail.output-files'">
|
<ds-process-detail-field *ngIf="files && files?.length > 0" id="process-files" [title]="'process.detail.output-files'">
|
||||||
<ds-file-download-link *ngFor="let file of files; let last=last;" [href]="file?._links?.content?.href" [download]="getFileName(file)">
|
<ds-file-download-link *ngFor="let file of files; let last=last;" [href]="file?._links?.content?.href" [download]="getFileName(file)">
|
||||||
<span>{{getFileName(file)}}</span>
|
<span>{{getFileName(file)}}</span>
|
||||||
<span>({{(file?.sizeBytes) | dsFileSize }})</span>
|
<span>({{(file?.sizeBytes) | dsFileSize }})</span>
|
||||||
</ds-file-download-link>
|
</ds-file-download-link>
|
||||||
</ds-process-detail-field>
|
</ds-process-detail-field>
|
||||||
</div>
|
</div>
|
||||||
@@ -34,14 +34,15 @@
|
|||||||
<div>{{ process.processStatus }}</div>
|
<div>{{ process.processStatus }}</div>
|
||||||
</ds-process-detail-field>
|
</ds-process-detail-field>
|
||||||
|
|
||||||
<ds-process-detail-field id="process-output" [title]="'process.detail.output'">
|
<ds-process-detail-field *ngIf="isProcessFinished(process)" id="process-output" [title]="'process.detail.output'">
|
||||||
<button *ngIf="!showOutputLogs" id="showOutputButton" class="btn btn-light" (click)="showProcessOutputLogs()">
|
<button *ngIf="!showOutputLogs && process?._links?.output?.href != undefined" id="showOutputButton" class="btn btn-light" (click)="showProcessOutputLogs()">
|
||||||
{{ 'process.detail.logs.button' | translate }}
|
{{ 'process.detail.logs.button' | translate }}
|
||||||
</button>
|
</button>
|
||||||
<ds-loading *ngIf="retrievingOutputLogs$ | async" class="ds-loading" message="{{ 'process.detail.logs.loading' | translate }}"></ds-loading>
|
<ds-loading *ngIf="retrievingOutputLogs$ | async" class="ds-loading" message="{{ 'process.detail.logs.loading' | translate }}"></ds-loading>
|
||||||
<pre class="font-weight-bold text-secondary bg-light p-3"
|
<pre class="font-weight-bold text-secondary bg-light p-3"
|
||||||
*ngIf="showOutputLogs && (outputLogs$ | async)?.length > 0">{{ (outputLogs$ | async)?.join('\n') }}</pre>
|
*ngIf="showOutputLogs && (outputLogs$ | async)?.length > 0">{{ (outputLogs$ | async) }}</pre>
|
||||||
<p id="no-output-logs-message" *ngIf="showOutputLogs && !(outputLogs$ | async) || (outputLogs$ | async)?.length == 0">
|
<p id="no-output-logs-message" *ngIf="(!(retrievingOutputLogs$ | async) && showOutputLogs)
|
||||||
|
&& !(outputLogs$ | async) || (outputLogs$ | async)?.length == 0 || !process._links.output">
|
||||||
{{ 'process.detail.logs.none' | translate }}
|
{{ 'process.detail.logs.none' | translate }}
|
||||||
</p>
|
</p>
|
||||||
</ds-process-detail-field>
|
</ds-process-detail-field>
|
||||||
|
@@ -1,11 +1,22 @@
|
|||||||
import { ProcessOutputDataService } from '../../core/data/process-output-data.service';
|
import { HttpClient } from '@angular/common/http';
|
||||||
import { ProcessOutput } from '../processes/process-output.model';
|
import { AuthService } from '../../core/auth/auth.service';
|
||||||
|
import { BitstreamDataService } from '../../core/data/bitstream-data.service';
|
||||||
|
import { AuthServiceMock } from '../../shared/mocks/auth.service.mock';
|
||||||
import { ProcessDetailComponent } from './process-detail.component';
|
import { ProcessDetailComponent } from './process-detail.component';
|
||||||
import { async, ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
|
import {
|
||||||
|
async,
|
||||||
|
ComponentFixture,
|
||||||
|
discardPeriodicTasks,
|
||||||
|
fakeAsync,
|
||||||
|
flush,
|
||||||
|
flushMicrotasks,
|
||||||
|
TestBed,
|
||||||
|
tick
|
||||||
|
} from '@angular/core/testing';
|
||||||
import { VarDirective } from '../../shared/utils/var.directive';
|
import { VarDirective } from '../../shared/utils/var.directive';
|
||||||
import { TranslateModule } from '@ngx-translate/core';
|
import { TranslateModule } from '@ngx-translate/core';
|
||||||
import { RouterTestingModule } from '@angular/router/testing';
|
import { RouterTestingModule } from '@angular/router/testing';
|
||||||
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
|
||||||
import { ProcessDetailFieldComponent } from './process-detail-field/process-detail-field.component';
|
import { ProcessDetailFieldComponent } from './process-detail-field/process-detail-field.component';
|
||||||
import { Process } from '../processes/process.model';
|
import { Process } from '../processes/process.model';
|
||||||
import { ActivatedRoute } from '@angular/router';
|
import { ActivatedRoute } from '@angular/router';
|
||||||
@@ -23,8 +34,9 @@ describe('ProcessDetailComponent', () => {
|
|||||||
let fixture: ComponentFixture<ProcessDetailComponent>;
|
let fixture: ComponentFixture<ProcessDetailComponent>;
|
||||||
|
|
||||||
let processService: ProcessDataService;
|
let processService: ProcessDataService;
|
||||||
let processOutputService: ProcessOutputDataService;
|
|
||||||
let nameService: DSONameService;
|
let nameService: DSONameService;
|
||||||
|
let bitstreamDataService: BitstreamDataService;
|
||||||
|
let httpClient: HttpClient;
|
||||||
|
|
||||||
let process: Process;
|
let process: Process;
|
||||||
let fileName: string;
|
let fileName: string;
|
||||||
@@ -33,13 +45,11 @@ describe('ProcessDetailComponent', () => {
|
|||||||
let processOutput;
|
let processOutput;
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
processOutput = Object.assign(new ProcessOutput(), {
|
processOutput = 'Process Started'
|
||||||
logs: ['Process started', 'Process completed']
|
|
||||||
}
|
|
||||||
);
|
|
||||||
process = Object.assign(new Process(), {
|
process = Object.assign(new Process(), {
|
||||||
processId: 1,
|
processId: 1,
|
||||||
scriptName: 'script-name',
|
scriptName: 'script-name',
|
||||||
|
processStatus: 'COMPLETED',
|
||||||
parameters: [
|
parameters: [
|
||||||
{
|
{
|
||||||
name: '-f',
|
name: '-f',
|
||||||
@@ -76,15 +86,24 @@ describe('ProcessDetailComponent', () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
|
const logBitstream = Object.assign(new Bitstream(), {
|
||||||
|
id: 'output.log',
|
||||||
|
_links: {
|
||||||
|
content: { href: 'log-selflink' }
|
||||||
|
}
|
||||||
|
});
|
||||||
processService = jasmine.createSpyObj('processService', {
|
processService = jasmine.createSpyObj('processService', {
|
||||||
getFiles: createSuccessfulRemoteDataObject$(createPaginatedList(files))
|
getFiles: createSuccessfulRemoteDataObject$(createPaginatedList(files))
|
||||||
});
|
});
|
||||||
processOutputService = jasmine.createSpyObj('processOutputService', {
|
bitstreamDataService = jasmine.createSpyObj('bitstreamDataService', {
|
||||||
findByHref: createSuccessfulRemoteDataObject$(processOutput)
|
findByHref: createSuccessfulRemoteDataObject$(logBitstream)
|
||||||
});
|
});
|
||||||
nameService = jasmine.createSpyObj('nameService', {
|
nameService = jasmine.createSpyObj('nameService', {
|
||||||
getName: fileName
|
getName: fileName
|
||||||
});
|
});
|
||||||
|
httpClient = jasmine.createSpyObj('httpClient', {
|
||||||
|
get: observableOf(processOutput)
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
beforeEach(async(() => {
|
beforeEach(async(() => {
|
||||||
@@ -98,10 +117,12 @@ describe('ProcessDetailComponent', () => {
|
|||||||
useValue: { data: observableOf({ process: createSuccessfulRemoteDataObject(process) }) }
|
useValue: { data: observableOf({ process: createSuccessfulRemoteDataObject(process) }) }
|
||||||
},
|
},
|
||||||
{ provide: ProcessDataService, useValue: processService },
|
{ provide: ProcessDataService, useValue: processService },
|
||||||
{ provide: ProcessOutputDataService, useValue: processOutputService },
|
{ provide: BitstreamDataService, useValue: bitstreamDataService },
|
||||||
{ provide: DSONameService, useValue: nameService }
|
{ provide: DSONameService, useValue: nameService },
|
||||||
|
{ provide: AuthService, useValue: new AuthServiceMock() },
|
||||||
|
{ provide: HttpClient, useValue: httpClient },
|
||||||
],
|
],
|
||||||
schemas: [NO_ERRORS_SCHEMA]
|
schemas: [CUSTOM_ELEMENTS_SCHEMA]
|
||||||
}).compileComponents();
|
}).compileComponents();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@@ -109,6 +130,14 @@ describe('ProcessDetailComponent', () => {
|
|||||||
fixture = TestBed.createComponent(ProcessDetailComponent);
|
fixture = TestBed.createComponent(ProcessDetailComponent);
|
||||||
component = fixture.componentInstance;
|
component = fixture.componentInstance;
|
||||||
});
|
});
|
||||||
|
afterEach(fakeAsync(() => {
|
||||||
|
TestBed.resetTestingModule();
|
||||||
|
fixture.destroy();
|
||||||
|
flush();
|
||||||
|
flushMicrotasks();
|
||||||
|
discardPeriodicTasks();
|
||||||
|
component = null;
|
||||||
|
}));
|
||||||
|
|
||||||
it('should display the script\'s name', () => {
|
it('should display the script\'s name', () => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
@@ -134,6 +163,7 @@ describe('ProcessDetailComponent', () => {
|
|||||||
beforeEach(fakeAsync(() => {
|
beforeEach(fakeAsync(() => {
|
||||||
spyOn(component, 'showProcessOutputLogs').and.callThrough();
|
spyOn(component, 'showProcessOutputLogs').and.callThrough();
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
const showOutputButton = fixture.debugElement.query(By.css('#showOutputButton'));
|
const showOutputButton = fixture.debugElement.query(By.css('#showOutputButton'));
|
||||||
showOutputButton.triggerEventHandler('click', {
|
showOutputButton.triggerEventHandler('click', {
|
||||||
preventDefault: () => {/**/
|
preventDefault: () => {/**/
|
||||||
@@ -147,20 +177,16 @@ describe('ProcessDetailComponent', () => {
|
|||||||
it('should display the process\'s output logs', () => {
|
it('should display the process\'s output logs', () => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
const outputProcess = fixture.debugElement.query(By.css('#process-output pre'));
|
const outputProcess = fixture.debugElement.query(By.css('#process-output pre'));
|
||||||
expect(outputProcess.nativeElement.textContent).toContain('Process started');
|
expect(outputProcess.nativeElement.textContent).toContain(processOutput);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('if press show output logs and process has no output logs (yet)', () => {
|
describe('if press show output logs and process has no output logs', () => {
|
||||||
beforeEach(fakeAsync(() => {
|
beforeEach(fakeAsync(() => {
|
||||||
jasmine.getEnv().allowRespy(true);
|
jasmine.getEnv().allowRespy(true);
|
||||||
const emptyProcessOutput = Object.assign(new ProcessOutput(), {
|
spyOn(httpClient, 'get').and.returnValue(observableOf(null));
|
||||||
logs: []
|
|
||||||
});
|
|
||||||
spyOn(processOutputService, 'findByHref').and.returnValue(createSuccessfulRemoteDataObject$(emptyProcessOutput));
|
|
||||||
fixture = TestBed.createComponent(ProcessDetailComponent);
|
fixture = TestBed.createComponent(ProcessDetailComponent);
|
||||||
component = fixture.componentInstance;
|
component = fixture.componentInstance;
|
||||||
fixture.detectChanges();
|
|
||||||
spyOn(component, 'showProcessOutputLogs').and.callThrough();
|
spyOn(component, 'showProcessOutputLogs').and.callThrough();
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
const showOutputButton = fixture.debugElement.query(By.css('#showOutputButton'));
|
const showOutputButton = fixture.debugElement.query(By.css('#showOutputButton'));
|
||||||
|
@@ -1,19 +1,23 @@
|
|||||||
|
import { HttpClient } from '@angular/common/http';
|
||||||
import { Component, NgZone, OnInit } from '@angular/core';
|
import { Component, NgZone, OnInit } from '@angular/core';
|
||||||
import { ActivatedRoute, Router } from '@angular/router';
|
import { ActivatedRoute, Router } from '@angular/router';
|
||||||
import { BehaviorSubject } from 'rxjs/internal/BehaviorSubject';
|
import { BehaviorSubject } from 'rxjs/internal/BehaviorSubject';
|
||||||
import { Observable } from 'rxjs/internal/Observable';
|
import { Observable } from 'rxjs/internal/Observable';
|
||||||
import { ProcessOutputDataService } from '../../core/data/process-output-data.service';
|
import { finalize, map, mergeMap, switchMap, take, tap } from 'rxjs/operators';
|
||||||
import { RemoteData } from '../../core/data/remote-data';
|
import { AuthService } from '../../core/auth/auth.service';
|
||||||
import { DSpaceObject } from '../../core/shared/dspace-object.model';
|
|
||||||
import { ProcessOutput } from '../processes/process-output.model';
|
|
||||||
import { Process } from '../processes/process.model';
|
|
||||||
import { finalize, map, switchMap, take } from 'rxjs/operators';
|
|
||||||
import { getFirstSucceededRemoteDataPayload, redirectOn404Or401 } from '../../core/shared/operators';
|
|
||||||
import { AlertType } from '../../shared/alert/aletr-type';
|
|
||||||
import { ProcessDataService } from '../../core/data/processes/process-data.service';
|
|
||||||
import { PaginatedList } from '../../core/data/paginated-list';
|
|
||||||
import { Bitstream } from '../../core/shared/bitstream.model';
|
|
||||||
import { DSONameService } from '../../core/breadcrumbs/dso-name.service';
|
import { DSONameService } from '../../core/breadcrumbs/dso-name.service';
|
||||||
|
import { BitstreamDataService } from '../../core/data/bitstream-data.service';
|
||||||
|
import { PaginatedList } from '../../core/data/paginated-list';
|
||||||
|
import { ProcessDataService } from '../../core/data/processes/process-data.service';
|
||||||
|
import { RemoteData } from '../../core/data/remote-data';
|
||||||
|
import { Bitstream } from '../../core/shared/bitstream.model';
|
||||||
|
import { DSpaceObject } from '../../core/shared/dspace-object.model';
|
||||||
|
import { getFirstSucceededRemoteDataPayload, redirectOn404Or401 } from '../../core/shared/operators';
|
||||||
|
import { URLCombiner } from '../../core/url-combiner/url-combiner';
|
||||||
|
import { AlertType } from '../../shared/alert/aletr-type';
|
||||||
|
import { hasValue } from '../../shared/empty.util';
|
||||||
|
import { ProcessStatus } from '../processes/process-status.model';
|
||||||
|
import { Process } from '../processes/process.model';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-process-detail',
|
selector: 'ds-process-detail',
|
||||||
@@ -40,26 +44,33 @@ export class ProcessDetailComponent implements OnInit {
|
|||||||
*/
|
*/
|
||||||
filesRD$: Observable<RemoteData<PaginatedList<Bitstream>>>;
|
filesRD$: Observable<RemoteData<PaginatedList<Bitstream>>>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* File link that contain the output logs with auth token
|
||||||
|
*/
|
||||||
|
outputLogFileUrl$: Observable<string>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Process's Output logs
|
* The Process's Output logs
|
||||||
*/
|
*/
|
||||||
outputLogs$: Observable<string[]>;
|
outputLogs$: Observable<string>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Boolean on whether or not to show the output logs
|
* Boolean on whether or not to show the output logs
|
||||||
*/
|
*/
|
||||||
showOutputLogs = false;
|
showOutputLogs;
|
||||||
/**
|
/**
|
||||||
* When it's retrieving the output logs from backend, to show loading component
|
* When it's retrieving the output logs from backend, to show loading component
|
||||||
*/
|
*/
|
||||||
retrievingOutputLogs$ = new BehaviorSubject<boolean>(false);
|
retrievingOutputLogs$: BehaviorSubject<boolean>;
|
||||||
|
|
||||||
constructor(protected route: ActivatedRoute,
|
constructor(protected route: ActivatedRoute,
|
||||||
protected router: Router,
|
protected router: Router,
|
||||||
protected processService: ProcessDataService,
|
protected processService: ProcessDataService,
|
||||||
protected processOutputService: ProcessOutputDataService,
|
protected bitstreamDataService: BitstreamDataService,
|
||||||
protected nameService: DSONameService,
|
protected nameService: DSONameService,
|
||||||
private zone: NgZone) {
|
private zone: NgZone,
|
||||||
|
protected authService: AuthService,
|
||||||
|
protected http: HttpClient) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -67,8 +78,12 @@ export class ProcessDetailComponent implements OnInit {
|
|||||||
* Display a 404 if the process doesn't exist
|
* Display a 404 if the process doesn't exist
|
||||||
*/
|
*/
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
|
this.showOutputLogs = false;
|
||||||
|
this.retrievingOutputLogs$ = new BehaviorSubject<boolean>(false);
|
||||||
this.processRD$ = this.route.data.pipe(
|
this.processRD$ = this.route.data.pipe(
|
||||||
map((data) => data.process as RemoteData<Process>),
|
map((data) => {
|
||||||
|
return data.process as RemoteData<Process>
|
||||||
|
}),
|
||||||
redirectOn404Or401(this.router)
|
redirectOn404Or401(this.router)
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -93,20 +108,58 @@ export class ProcessDetailComponent implements OnInit {
|
|||||||
showProcessOutputLogs() {
|
showProcessOutputLogs() {
|
||||||
this.retrievingOutputLogs$.next(true);
|
this.retrievingOutputLogs$.next(true);
|
||||||
this.zone.runOutsideAngular(() => {
|
this.zone.runOutsideAngular(() => {
|
||||||
const processOutputRD$: Observable<RemoteData<ProcessOutput>> = this.processRD$.pipe(
|
const processOutputRD$: Observable<RemoteData<Bitstream>> = this.processRD$.pipe(
|
||||||
getFirstSucceededRemoteDataPayload(),
|
getFirstSucceededRemoteDataPayload(),
|
||||||
switchMap((process: Process) => this.processOutputService.findByHref(process._links.output.href))
|
switchMap((process: Process) => {
|
||||||
|
return this.bitstreamDataService.findByHref(process._links.output.href);
|
||||||
|
})
|
||||||
);
|
);
|
||||||
this.outputLogs$ = processOutputRD$.pipe(
|
this.outputLogFileUrl$ = processOutputRD$.pipe(
|
||||||
getFirstSucceededRemoteDataPayload(),
|
tap((processOutputFileRD: RemoteData<Bitstream>) => {
|
||||||
map((processOutput: ProcessOutput) => {
|
if (processOutputFileRD.statusCode === 204) {
|
||||||
this.showOutputLogs = true;
|
this.zone.run(() => this.retrievingOutputLogs$.next(false));
|
||||||
return processOutput.logs;
|
this.showOutputLogs = true;
|
||||||
|
}
|
||||||
}),
|
}),
|
||||||
finalize(() => this.zone.run(() => this.retrievingOutputLogs$.next(false))),
|
getFirstSucceededRemoteDataPayload(),
|
||||||
|
mergeMap((processOutput: Bitstream) => {
|
||||||
|
const url = processOutput._links.content.href;
|
||||||
|
return this.authService.getShortlivedToken().pipe(take(1),
|
||||||
|
map((token: string) => {
|
||||||
|
return hasValue(token) ? new URLCombiner(url, `?authentication-token=${token}`).toString() : url;
|
||||||
|
}));
|
||||||
|
})
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
this.outputLogs$ = this.outputLogFileUrl$.pipe(take(1),
|
||||||
|
mergeMap((url: string) => {
|
||||||
|
return this.getTextFile(url);
|
||||||
|
}),
|
||||||
|
finalize(() => this.zone.run(() => this.retrievingOutputLogs$.next(false))),
|
||||||
|
);
|
||||||
this.outputLogs$.pipe(take(1)).subscribe();
|
this.outputLogs$.pipe(take(1)).subscribe();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getTextFile(filename: string): Observable<string> {
|
||||||
|
// The Observable returned by get() is of type Observable<string>
|
||||||
|
// because a text response was specified.
|
||||||
|
// There's no need to pass a <string> type parameter to get().
|
||||||
|
return this.http.get(filename, { responseType: 'text' })
|
||||||
|
.pipe(
|
||||||
|
finalize(() => {
|
||||||
|
this.showOutputLogs = true;
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether or not the given process has Completed or Failed status
|
||||||
|
* @param process Process to check if completed or failed
|
||||||
|
*/
|
||||||
|
isProcessFinished(process: Process): boolean {
|
||||||
|
return (hasValue(process) && hasValue(process.processStatus) &&
|
||||||
|
(process.processStatus.toString() === ProcessStatus[ProcessStatus.COMPLETED].toString()
|
||||||
|
|| process.processStatus.toString() === ProcessStatus[ProcessStatus.FAILED].toString()));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,36 +0,0 @@
|
|||||||
import { PROCESS_OUTPUT_TYPE } from '../../core/shared/process-output.resource-type';
|
|
||||||
import { CacheableObject } from '../../core/cache/object-cache.reducer';
|
|
||||||
import { HALLink } from '../../core/shared/hal-link.model';
|
|
||||||
import { autoserialize, deserialize } from 'cerialize';
|
|
||||||
import { excludeFromEquals } from '../../core/utilities/equals.decorators';
|
|
||||||
import { ResourceType } from '../../core/shared/resource-type';
|
|
||||||
import { typedObject } from '../../core/cache/builders/build-decorators';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Object representing a process output object
|
|
||||||
*/
|
|
||||||
@typedObject
|
|
||||||
export class ProcessOutput implements CacheableObject {
|
|
||||||
static type = PROCESS_OUTPUT_TYPE;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The object type
|
|
||||||
*/
|
|
||||||
@excludeFromEquals
|
|
||||||
@autoserialize
|
|
||||||
type: ResourceType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The output strings for this ProcessOutput
|
|
||||||
*/
|
|
||||||
@autoserialize
|
|
||||||
logs: string[];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The {@link HALLink}s for this ProcessOutput
|
|
||||||
*/
|
|
||||||
@deserialize
|
|
||||||
_links: {
|
|
||||||
self: HALLink,
|
|
||||||
};
|
|
||||||
}
|
|
@@ -1,5 +1,5 @@
|
|||||||
|
import { Bitstream } from '../../core/shared/bitstream.model';
|
||||||
import { PROCESS_OUTPUT_TYPE } from '../../core/shared/process-output.resource-type';
|
import { PROCESS_OUTPUT_TYPE } from '../../core/shared/process-output.resource-type';
|
||||||
import { ProcessOutput } from './process-output.model';
|
|
||||||
import { ProcessStatus } from './process-status.model';
|
import { ProcessStatus } from './process-status.model';
|
||||||
import { ProcessParameter } from './process-parameter.model';
|
import { ProcessParameter } from './process-parameter.model';
|
||||||
import { CacheableObject } from '../../core/cache/object-cache.reducer';
|
import { CacheableObject } from '../../core/cache/object-cache.reducer';
|
||||||
@@ -93,5 +93,5 @@ export class Process implements CacheableObject {
|
|||||||
* Will be undefined unless the output {@link HALLink} has been resolved.
|
* Will be undefined unless the output {@link HALLink} has been resolved.
|
||||||
*/
|
*/
|
||||||
@link(PROCESS_OUTPUT_TYPE)
|
@link(PROCESS_OUTPUT_TYPE)
|
||||||
output?: Observable<RemoteData<ProcessOutput>>;
|
output?: Observable<RemoteData<Bitstream>>;
|
||||||
}
|
}
|
||||||
|
@@ -1,4 +1,6 @@
|
|||||||
/* tslint:disable:no-empty */
|
/* tslint:disable:no-empty */
|
||||||
|
import { Observable, of as observableOf } from 'rxjs';
|
||||||
|
|
||||||
export class AuthServiceMock {
|
export class AuthServiceMock {
|
||||||
public checksAuthenticationToken() {
|
public checksAuthenticationToken() {
|
||||||
return
|
return
|
||||||
@@ -6,4 +8,8 @@ export class AuthServiceMock {
|
|||||||
public buildAuthHeader() {
|
public buildAuthHeader() {
|
||||||
return 'auth-header';
|
return 'auth-header';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getShortlivedToken(): Observable<string> {
|
||||||
|
return observableOf('token');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -2270,7 +2270,7 @@
|
|||||||
|
|
||||||
"process.detail.logs.loading": "Retrieving",
|
"process.detail.logs.loading": "Retrieving",
|
||||||
|
|
||||||
"process.detail.logs.none": "This process has no output yet",
|
"process.detail.logs.none": "This process has no output",
|
||||||
|
|
||||||
"process.detail.output-files" : "Output Files",
|
"process.detail.output-files" : "Output Files",
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user