diff --git a/openbis_ng_ui/src/js/services/openbis/api.js b/openbis_ng_ui/src/js/services/openbis/api.js index 921597a32616e3a848cf7f738f77a47fc9952771..d269fc65341de5fadbacc81910de5435dbb5d163 100644 --- a/openbis_ng_ui/src/js/services/openbis/api.js +++ b/openbis_ng_ui/src/js/services/openbis/api.js @@ -1,4 +1,5 @@ import autoBind from 'auto-bind' +import dto from '@src/js/services/openbis/dto.js' class Facade { constructor() { @@ -178,6 +179,10 @@ class Facade { return this.promise(this.v3.getVocabularies(ids, fo)) } + getOperationExecutions(ids, fo) { + return this.promise(this.v3.getOperationExecutions(ids, fo)) + } + updateSampleTypes(updates) { return this.promise(this.v3.updateSampleTypes(updates)) } @@ -230,8 +235,40 @@ class Facade { return this.promise(this.v3.evaluatePlugin(options)) } - executeService(id, options) { - return this.promise(this.v3.executeCustomASService(id, options)) + async executeService(id, options) { + const scheduleResult = await this.executeOperations( + [new dto.ExecuteCustomASServiceOperation(id, options)], + new dto.AsynchronousOperationExecutionOptions() + ) + + const executionId = scheduleResult.executionId + const executionFetchOptions = new dto.OperationExecutionFetchOptions() + executionFetchOptions.withDetails().withResults() + executionFetchOptions.withDetails().withError() + + for (;;) { + const executions = await this.getOperationExecutions( + [executionId], + executionFetchOptions + ) + + const execution = executions[executionId] + + if (!execution) { + throw Error('Execution id: ' + executionId + ' not found.') + } else if (execution.details.error !== null) { + throw Error(execution.details.error.message) + } else if ( + execution.details.results !== null && + execution.details.results.length > 0 + ) { + return execution.details.results[0].result + } else { + await new Promise(resolve => { + setTimeout(resolve, 1000) + }) + } + } } executeQuery(id, options) { diff --git a/openbis_ng_ui/src/js/services/openbis/dto.js b/openbis_ng_ui/src/js/services/openbis/dto.js index b481f6dec2e0994b3d395101121b9a857cc41435..2145a63bc702a7a072f80c1f040529f7c4847cec 100644 --- a/openbis_ng_ui/src/js/services/openbis/dto.js +++ b/openbis_ng_ui/src/js/services/openbis/dto.js @@ -54,6 +54,8 @@ const CLASS_FULL_NAMES = [ 'as/dto/material/update/MaterialTypeUpdate', 'as/dto/material/update/UpdateMaterialTypesOperation', 'as/dto/operation/SynchronousOperationExecutionOptions', + 'as/dto/operation/AsynchronousOperationExecutionOptions', + 'as/dto/operation/fetchoptions/OperationExecutionFetchOptions', 'as/dto/pat/create/CreatePersonalAccessTokensOperation', 'as/dto/pat/create/PersonalAccessTokenCreation', 'as/dto/pat/delete/DeletePersonalAccessTokensOperation', @@ -146,6 +148,7 @@ const CLASS_FULL_NAMES = [ 'as/dto/sample/update/SampleTypeUpdate', 'as/dto/sample/update/UpdateSampleTypesOperation', 'as/dto/service/CustomASServiceExecutionOptions', + 'as/dto/service/execute/ExecuteCustomASServiceOperation', 'as/dto/service/id/CustomASServiceCode', 'as/dto/space/Space', 'as/dto/space/fetchoptions/SpaceFetchOptions',