import { AbstractSession , Headers } from "@zowe/imperative" ; import { ZosmfRestClient , nozOSMFVersion } from "@zowe/core-for-zowe-sdk" ; import { WorkflowConstants , noWorkflowKey } from "./WorkflowConstants" ; import { WorkflowValidator } from "./WorkflowValidator" ; import { IWorkflowInfo } from "./doc/IWorkflowInfo" ; import { IStepSummary } from "./doc/IStepSummary" ; import { IStepInfo } from "./doc/IStepInfo" ; export class PropertiesWorkflow { param { AbstractSession } session param { string } workflowfKey param { string } zOSMFVersion param { boolean } steps param { boolean } variables returns { Promise < IWorkflowInfo > } memberof public static async getWorkflowProperties ( session , workflowKey , zOSMFVersion = WorkflowConstants . ZOSMF_VERSION , steps ? , variables ? ) { WorkflowValidator . validateSession ( session ) ; WorkflowValidator . validateNotEmptyString ( zOSMFVersion , nozOSMFVersion . message ) ; WorkflowValidator . validateNotEmptyString ( workflowKey , noWorkflowKey . message ) ; const wfKey = workflowKey ; let resourcesQuery = `${ WorkflowConstants . RESOURCE }/${ zOSMFVersion }/` ; resourcesQuery += `${ WorkflowConstants . WORKFLOW_RESOURCE }/${ wfKey }` ; if ( steps && variables ) { resourcesQuery += `?${ WorkflowConstants . returnData }=${ WorkflowConstants . steps },${ WorkflowConstants . variables }` ; } else if ( steps ) { resourcesQuery += `?${ WorkflowConstants . returnData }=${ WorkflowConstants . steps }` ; } else if ( variables ) { resourcesQuery += `?${ WorkflowConstants . returnData }=${ WorkflowConstants . variables }` ; } return ZosmfRestClient . getExpectJSON < IWorkflowInfo > ( session , resourcesQuery , [ Headers . APPLICATION_JSON ] ) ; } protected static param { IStepInfo [ ] } steps returns { Promise < IStepSummary [ ] > } memberof public static async processStepSummaries ( steps ) { let stepSummaries = [ ] ; for ( const step of steps ) { let miscValue = "N/A" ; if ( step . submitAs && step . submitAs . match ( /.*JCL/ ) ) { if ( step . jobInfo && step . jobInfo . jobstatus ) { miscValue = step . jobInfo . jobstatus . jobid ; } } else if ( step . template ) { miscValue = "TSO" ; } else if ( step . isRestStep ) { miscValue = `HTTP ${ step . actualStatusCode }` ; } const stepSummary = { stepNumber : step . stepNumber , name : step . name , state : step . state , misc : miscValue , autoEnable : step . autoEnable , description : step . description , isRestStep : step . isRestStep , optional : step . optional , runAsUser : step . runAsUser , title : step . title , userDefined : step . userDefined } ; stepSummaries . push ( stepSummary ) ; if ( step . steps ) { const subSteps = await PropertiesWorkflow . processStepSummaries ( step . steps ) ; stepSummaries = stepSummaries . concat ( subSteps ) ; } } return stepSummaries ; } }