import { AbstractSession , Headers } from "@zowe/imperative" ; import { ZosmfRestClient } from "@zowe/core-for-zowe-sdk" ; import { isNullOrUndefined } from "util" ; import { TsoValidator } from "./TsoValidator" ; import { noDataInput , noServletKeyInput , TsoConstants } from "./TsoConstants" ; import { ISendTsoParms } from "./doc/input/ISendTsoParms" ; import { IZosmfTsoResponse } from "./doc/zosmf/IZosmfTsoResponse" ; import { ICollectedResponses } from "./doc/ICollectedResponses" ; import { ISendResponse } from "./doc/ISendResponse" ; class export class SendTso { param { AbstractSession } session param { string } servletKey param { string } data returns { Promise < ISendResponse > } see { ISendResponse } memberof public static async sendDataToTSOCollect ( session , servletKey , data ) { const putResponse = await SendTso . sendDataToTSOCommon ( session , { servletKey , data } ) ; TsoValidator . validateErrorMessageFromZosmf ( putResponse ) ; const responses = await SendTso . getAllResponses ( session , putResponse ) ; return SendTso . createResponse ( responses . tsos , responses . messages ) ; } param { AbstractSession } session param { IStartTsoParms } commandParams see { ISendTsoParms } returns { Promise < IZosmfTsoResponse > } see { IZosmfTsoResponse } memberof public static async sendDataToTSOCommon ( session , commandParams ) { TsoValidator . validateSession ( session ) ; TsoValidator . validateNotEmptyString ( commandParams . servletKey , noServletKeyInput . message ) ; TsoValidator . validateNotEmptyString ( commandParams . data , noDataInput . message ) ; const parameters = "/" + TsoConstants . RES_START_TSO + "/" + commandParams . servletKey + TsoConstants . RES_DONT_READ_REPLY ; const jobObj = { "TSO RESPONSE" : { VERSION : "0100" , DATA : commandParams . data } } ; return ZosmfRestClient . putExpectJSON < IZosmfTsoResponse > ( session , TsoConstants . RESOURCE + parameters , [ Headers . APPLICATION_JSON ] , jobObj ) ; } param { AbstractSession } session param { String } servletKey returns { Promise < IZosmfTsoResponse > } see { IZosmfTsoResponse } memberof public static async getDataFromTSO ( session , servletKey ) { TsoValidator . validateSession ( session ) ; const parameters = "/" + TsoConstants . RES_START_TSO + "/" + servletKey ; return ZosmfRestClient . getExpectJSON < IZosmfTsoResponse > ( session , TsoConstants . RESOURCE + parameters , [ Headers . APPLICATION_JSON ] ) ; } param { AbstractSession } session param { IZosmfTsoResponse } tso returns { Promise < ICollectedResponses > } see { ICollectedResponses } memberof public static async getAllResponses ( session , tso ) { let done = false ; const tsos = [ ] ; tsos . push ( tso ) ; let messages = "" ; while ( ! done ) { if ( ! isNullOrUndefined ( tso . tsoData ) ) { tso . tsoData . forEach ( ( data ) => { if ( data [ TsoConstants . TSO_MESSAGE ] ) { messages += ( data [ TsoConstants . TSO_MESSAGE ] . DATA + "\n" ) ; } else if ( data [ TsoConstants . TSO_PROMPT ] ) { if ( messages !== "" ) { done = true ; } else { } } } ) ; } if ( ! done ) { tso = await SendTso . getDataFromTSO ( session , tso . servletKey ) ; TsoValidator . validateErrorMessageFromZosmf ( tso ) ; } } return { tsos , messages } ; } param { IZosmfTsoResponse [ ] } allResponses param { string } messages returns { ISendResponse } see { ISendResponse } memberof private static createResponse ( allResponses , messages ) { return { success : true , zosmfResponse : allResponses , commandResponse : messages } ; } }