import { AbstractSession , Headers } from "@zowe/imperative" ; import { isNullOrUndefined } from "util" ; import { ZosmfRestClient } from "@zowe/core-for-zowe-sdk" ; import { SendTso } from "./SendTso" ; import { IStartStopResponses } from "./doc/IStartStopResponses" ; import { IStartTsoParms } from "./doc/input/IStartTsoParms" ; import { IZosmfTsoResponse } from "./doc/zosmf/IZosmfTsoResponse" ; import { TsoValidator } from "./TsoValidator" ; import { noAccountNumber , TsoConstants } from "./TsoConstants" ; import { TsoResponseService } from "./TsoResponseService" ; export class export class StartTso { static param { AbstractSession } session param { IStartTsoParms } commandParms see { IStartTsoParms } returns { Promise < IZosmfTsoResponse > } see { IZosmfTsoResponse } memberOf public static startCommon ( session , commandParms ) { TsoValidator . validateSession ( session ) ; TsoValidator . validateStartParams ( commandParms ) ; const startResources = this . getResourcesQuery ( commandParms ) ; return ZosmfRestClient . postExpectJSON < IZosmfTsoResponse > ( session , startResources , [ Headers . APPLICATION_JSON ] ) ; } static param { AbstractSession } session param { string } accountNumber param { IStartTsoParms } parms see { IStartTsoParms } returns { Promise < IStartStopResponses > } see { IStartStopResponses } memberOf public static async start ( session , accountNumber , parms ? ) { TsoValidator . validateSession ( session ) ; TsoValidator . validateNotEmptyString ( accountNumber , noAccountNumber . message ) ; let customParms ; if ( isNullOrUndefined ( parms ) ) { customParms = this . setDefaultAddressSpaceParams ( { } , encodeURIComponent ( accountNumber ) ) ; } else { customParms = this . setDefaultAddressSpaceParams ( parms , encodeURIComponent ( accountNumber ) ) ; } const zosmfResponse = await this . startCommon ( session , customParms ) ; let collectedResponses = null ; if ( ! isNullOrUndefined ( zosmfResponse . servletKey ) ) { collectedResponses = await SendTso . getAllResponses ( session , zosmfResponse ) ; } return TsoResponseService . populateStartAndStopCollectAll ( zosmfResponse , collectedResponses ) ; } static param { IStartTsoParms } parms see { IStartTsoParms } param { string } accountNumber returns { IStartTsoParms } memberOf public static setDefaultAddressSpaceParams ( parms , accountNumber ) { const proc = isNullOrUndefined ( parms . logonProcedure ) ? TsoConstants . DEFAULT_PROC : parms . logonProcedure ; const chset = isNullOrUndefined ( parms . characterSet ) ? TsoConstants . DEFAULT_CHSET : parms . characterSet ; const cpage = isNullOrUndefined ( parms . codePage ) ? TsoConstants . DEFAULT_CPAGE : parms . codePage ; const rowNum = isNullOrUndefined ( parms . rows ) ? TsoConstants . DEFAULT_ROWS : parms . rows ; const cols = isNullOrUndefined ( parms . columns ) ? TsoConstants . DEFAULT_COLS : parms . columns ; const rSize = isNullOrUndefined ( parms . regionSize ) ? TsoConstants . DEFAULT_RSIZE : parms . regionSize ; const parameters = { logonProcedure : proc , characterSet : chset , codePage : cpage , rows : rowNum , columns : cols , regionSize : rSize , account : accountNumber } ; return parameters ; } param { IStartTsoParms } parms see { IStartTsoParms } returns { string } memberOf public static getResourcesQuery ( parms ) { let query = `${ TsoConstants . RESOURCE + "/" + TsoConstants . RES_START_TSO }?` ; query += `${ TsoConstants . PARM_ACCT }=${ parms . account }&` ; query += `${ TsoConstants . PARM_PROC }=${ parms . logonProcedure }&` ; query += `${ TsoConstants . PARM_CHSET }=${ parms . characterSet }&` ; query += `${ TsoConstants . PARM_CPAGE }=${ parms . codePage }&` ; query += `${ TsoConstants . PARM_ROWS }=${ parms . rows }&` ; query += `${ TsoConstants . PARM_COLS }=${ parms . columns }&` ; query += `${ TsoConstants . PARM_RSIZE }=${ parms . regionSize }` ; return query ; } }