import { AbstractSession , Headers } from "@zowe/imperative" ; import { ZosmfRestClient } from "@zowe/core-for-zowe-sdk" ; import { isNullOrUndefined } from "util" ; import { IZosmfIssueParms } from "./doc/zosmf/IZosmfIssueParms" ; import { ConsoleValidator } from "./ConsoleValidator" ; import { IZosmfIssueResponse } from "./doc/zosmf/IZosmfIssueResponse" ; import { ConsoleConstants } from "./ConsoleConstants" ; import { IIssueParms } from "./doc/IIssueParms" ; import { ConsoleResponseService } from "./ConsoleResponseService" ; import { IConsoleResponse } from "./doc/IConsoleResponse" ; import { ICollectParms } from "./doc/ICollectParms" ; import { CollectCommand } from "./CollectCommand" ; export class export class IssueCommand { static param { AbstractSession } session param { string } consoleName param { IZosmfIssueParms } commandParms see { IZosmfIssueParms } return { Promise < IZosmfIssueResponse > } see { IZosmfIssueResponse } memberof public static issueCommon ( session , consoleName , commandParms ) { ConsoleValidator . validateCommonParms ( session , consoleName , commandParms ) ; return ZosmfRestClient . putExpectJSON < IZosmfIssueResponse > ( session , IssueCommand . getResource ( consoleName ) , [ Headers . APPLICATION_JSON ] , commandParms ) ; } static param { AbstractSession } session param { IZosmfIssueParms } commandParms see { IZosmfIssueParms } return { Promise < IZosmfIssueResponse > } see { IZosmfIssueResponse } memberof public static issueDefConsoleCommon ( session , commandParms ) { return IssueCommand . issueCommon ( session , ConsoleConstants . RES_DEF_CN , commandParms ) ; } static param { AbstractSession } session param { IIssueParms } parms see { IIssueParms } return { Promise < IConsoleResponse > } see { IConsoleResponse } memberof public static async issue ( session , parms ) { ConsoleValidator . validateIssueParms ( session , parms ) ; const consoleName = isNullOrUndefined ( parms . consoleName ) ? ConsoleConstants . RES_DEF_CN : parms . consoleName ; const commandParms = IssueCommand . buildZosmfConsoleApiParameters ( parms ) ; let response = ConsoleResponseService . getEmptyConsoleResponse ( ) ; const resp = await IssueCommand . issueCommon ( session , consoleName , commandParms ) ; response = ConsoleResponseService . populate ( resp , response , parms . processResponses ) ; return response ; } static param { AbstractSession } session param { string } theCommand return { Promise < IConsoleResponse > } see { IConsoleResponse } memberof public static async issueSimple ( session , theCommand ) { ConsoleValidator . validateIssueSimpleParms ( session , theCommand ) ; const parms = { command : theCommand , processResponses : true } ; return IssueCommand . issue ( session , parms ) ; } static param { AbstractSession } session param { IIssueParms } issueParms see { IIssueParms } param { ICollectParms } collectParms see { ICollectParms } return { Promise < IConsoleResponse > } see { IConsoleResponse } memberof public static async issueAndCollect ( session , issueParms , collectParms ) { ConsoleValidator . validateCollectParm ( collectParms ) ; let response = await IssueCommand . issue ( session , issueParms ) ; if ( response . lastResponseKey && ! response . keywordDetected ) { collectParms . commandResponseKey = response . lastResponseKey ; response = await CollectCommand . collect ( session , collectParms , response ) ; } return response ; } static param { string } consoleName return { string } memberof public static getResource ( consoleName ) { return ConsoleConstants . RESOURCE + "/" + consoleName ; } static param { IIssueParms } parms return { IZosmfIssueParms } see { ZosmfConsoleApiParameters } memberof public static buildZosmfConsoleApiParameters ( parms ) { ConsoleValidator . validateIssueParm ( parms ) ; const zosmfParms = { cmd : parms . command } ; if ( ! isNullOrUndefined ( parms . solicitedKeyword ) ) { zosmfParms [ "sol-key" ] = parms . solicitedKeyword ; } if ( ! isNullOrUndefined ( parms . sysplexSystem ) ) { zosmfParms . system = parms . sysplexSystem ; } if ( ! isNullOrUndefined ( parms . async ) ) { zosmfParms . async = parms . async ; } return zosmfParms ; } }