import { ZosmfRestClient , nozOSMFVersion } from "@zowe/core-for-zowe-sdk" ; import { WorkflowValidator } from "./WorkflowValidator" ; import { AbstractSession , ImperativeError } from "@zowe/imperative" ; import { WorkflowConstants , wrongString , noWorkflowName } from "./WorkflowConstants" ; import { IActiveWorkflows } from "./doc/IActiveWorkflows" ; import { IGetWorkflowsOptions } from "./doc/IGetWorkflowsOptions" ; export class export class ListWorkflows { param { AbstractSession } session param { string } zOSMFVersion param { string } workflowName param { string } category param { string } system param { string } owner param { string } vendor param { string } statusName returns { string } memberof deprecated public static async listWorkflows ( session , zOSMFVersion = WorkflowConstants . ZOSMF_VERSION , workflowName ? , category ? , system ? , owner ? , vendor ? , statusName ? ) { return this . getWorkflows ( session , { zOSMFVersion , workflowName , category , system , owner , vendor , statusName } ) ; } param { AbstractSession } session param { IGetWorkflowsOptions } options returns { string } memberof public static async getWorkflows ( session , options = { } ) { WorkflowValidator . validateSession ( session ) ; options = { ... options , zOSMFVersion : options . zOSMFVersion !== undefined ? options . zOSMFVersion : WorkflowConstants . ZOSMF_VERSION , workflowName : options . workflowName ? encodeURIComponent ( options . workflowName ) : null } ; WorkflowValidator . validateNotEmptyString ( options . zOSMFVersion , nozOSMFVersion . message ) ; const resourcesQuery = ListWorkflows . getResourceQuery ( options ) ; return ZosmfRestClient . getExpectJSON ( session , resourcesQuery ) ; } param { string } zOSMFVersion param { string } params returns { string } memberof deprecated public static getResourcesQuery ( zOSMFVersion , params ) { let query = `${ WorkflowConstants . RESOURCE }/${ zOSMFVersion }/${ WorkflowConstants . WORKFLOW_RESOURCE }` ; let sign = "?" ; params . forEach ( ( element ) => { if ( element . value ) { WorkflowValidator . validateParameter ( element . value , wrongString . message ) ; query += sign + `${ element . key }=${ element . value }` ; sign = "&" ; } } ) ; return query ; } param { IGetWorkflowsOptions } params returns { string } memberof public static getResourceQuery ( params ) { let query = `${ WorkflowConstants . RESOURCE }/${ params . zOSMFVersion }/${ WorkflowConstants . WORKFLOW_RESOURCE }` ; let sign = "?" ; for ( const key in params ) { if ( key === "zOSMFVersion" ) continue ; if ( params [ key ] ) { WorkflowValidator . validateParameter ( params [ key ] , wrongString . message ) ; query += sign + `${ key }=${ params [ key ] }` ; sign = "&" ; } } return query ; } param { AbstractSession } session param { string } workflowName param { string } zOSMFVersion returns { Promise < string > | null } throws memberof public static async getWfKey ( session , workflowName , zOSMFVersion = WorkflowConstants . ZOSMF_VERSION ) { WorkflowValidator . validateSession ( session ) ; WorkflowValidator . validateNotEmptyString ( zOSMFVersion , nozOSMFVersion . message ) ; WorkflowValidator . validateNotEmptyString ( workflowName , noWorkflowName . message ) ; const result = await this . getWorkflows ( session , { workflowName } ) ; if ( result . workflows . length > 1 ) { throw new ImperativeError ( { msg : `More than one workflows found with name ` + workflowName } ) ; } return result . workflows . length !== 0 ? result . workflows [ 0 ] . workflowKey : null ; } }