import { ImperativeError , Logger , TextUtils } from "@zowe/imperative" ; import { inspect , isNullOrUndefined } from "util" ; import { IZosmfIssueResponse } from "./doc/zosmf/IZosmfIssueResponse" ; import { IConsoleResponse } from "./doc/IConsoleResponse" ; import { displayError , displayResponse } from "./ConsoleConstants" ; export class export class ConsoleResponseService { static param { IZosmfIssueResponse } zosmfResponse see { IZosmfIssueResponse } param { IConsoleResponse } response see { IConsoleResponse } param { boolean } processResponses return { IConsoleResponse } see { IConsoleResponse } memberof public static populate ( zosmfResponse , response , processResponses ? ) { Logger . getImperativeLogger ( ) . trace ( TextUtils . formatMessage ( displayResponse . message , { data : inspect ( zosmfResponse ) } ) ) ; Logger . getImperativeLogger ( ) . trace ( TextUtils . formatMessage ( displayResponse . message , { data : inspect ( response ) } ) ) ; response . zosmfResponse = response . zosmfResponse . concat ( zosmfResponse ) ; response . success = true ; if ( ! isNullOrUndefined ( zosmfResponse [ "sol-key-detected" ] ) ) { response . keywordDetected = zosmfResponse [ "sol-key-detected" ] ; } if ( ! isNullOrUndefined ( zosmfResponse [ "cmd-response" ] ) && zosmfResponse [ "cmd-response" ] . length > 0 && ( isNullOrUndefined ( processResponses ) || processResponses !== false ) ) { response . commandResponse += zosmfResponse [ "cmd-response" ] . replace ( /\r\n/g , "\n" ) . replace ( /\r/g , "\n" ) ; if ( response . commandResponse . length > 0 && ( response . commandResponse . indexOf ( "\n" ) !== response . commandResponse . length - 1 ) ) { response . commandResponse += "\n" ; } } if ( ! isNullOrUndefined ( zosmfResponse [ "cmd-response-key" ] ) ) { response . lastResponseKey = zosmfResponse [ "cmd-response-key" ] ; } if ( ! isNullOrUndefined ( zosmfResponse [ "cmd-response-url" ] ) ) { response . cmdResponseUrl = zosmfResponse [ "cmd-response-url" ] ; } return response ; } tatic param { ImperativeError } error see { ImperativeError } param { IConsoleResponse } response see { IConsoleResponse } return { IConsoleResponse } see { IConsoleResponse } memberof public static populateError ( error , response ) { Logger . getImperativeLogger ( ) . trace ( TextUtils . formatMessage ( displayError . message , { data : inspect ( error ) } ) ) ; response . failureResponse = error ; response . success = false ; return response ; } static return { IConsoleResponse } memberof public static getEmptyConsoleResponse ( ) { return { success : true , zosmfResponse : [ ] , commandResponse : "" } ; } static param { IConsoleResponse } response return { boolean } memberof public static isLastZosmfResponseEmpty ( response ) { let result = true ; if ( ! isNullOrUndefined ( response ) && response . zosmfResponse . length > 0 ) { const lastResponse = response . zosmfResponse [ response . zosmfResponse . length - 1 ] ; result = isNullOrUndefined ( lastResponse [ "cmd-response" ] ) || lastResponse [ "cmd-response" ] === "" ; } return result ; } }