import { AbstractSession , ImperativeExpect , Logger , Headers } from "@zowe/imperative" ; import { posix } from "path" ; import { ZosmfRestClient , IHeaderContent , ZosmfHeaders } from "@zowe/core-for-zowe-sdk" ; import { ZosFilesConstants } from "../../constants/ZosFiles.constants" ; import { ZosFilesMessages } from "../../constants/ZosFiles.messages" ; import { IZosFilesResponse } from "../../doc/IZosFilesResponse" ; import { IDataSet } from "../../doc/IDataSet" ; import { IZosFilesOptions } from "../../doc/IZosFilesOptions" ; /**
 * Class to handle renaming data sets
 */ export class Rename { param { AbstractSession } session param { string } beforeDataSetName param { string } fterDataSetName returns { Promise < IZosFilesResponse > } public static async dataSet ( session , beforeDataSetName , afterDataSetName , options ? ) { ImperativeExpect . toBeDefinedAndNonBlank ( beforeDataSetName , "beforeDataSetName" ) ; ImperativeExpect . toBeDefinedAndNonBlank ( afterDataSetName , "afterDataSetName" ) ; return this . rename ( session , afterDataSetName . trim ( ) , { dataSetName : beforeDataSetName . trim ( ) } , options ) ; } param { AbstractSession } session param { string } dataSetName param { string } beforeMemberName param { string } afterMemberName returns { Promise < IZosFilesResponse > } public static async dataSetMember ( session , dataSetName , beforeMemberName , afterMemberName , options ? ) { ImperativeExpect . toBeDefinedAndNonBlank ( dataSetName , "dataSetName" ) ; ImperativeExpect . toBeDefinedAndNonBlank ( beforeMemberName , "beforeMemberName" ) ; ImperativeExpect . toBeDefinedAndNonBlank ( afterMemberName , "afterMemberName" ) ; return this . rename ( session , `${ dataSetName . trim ( ) }(${ afterMemberName . trim ( ) })` , { dataSetName : dataSetName . trim ( ) , memberName : beforeMemberName . trim ( ) } , options ) ; } param { AbstractSession } session param { string } afterDataSetName param { IDataSet } beforeDataSet private static async rename ( session , afterDataSetName , { dataSetName : beforeDataSetName , memberName : beforeMemberName } , options ? ) { const endpoint = posix . join ( ZosFilesConstants . RESOURCE , ZosFilesConstants . RES_DS_FILES , afterDataSetName ) ; Logger . getAppLogger ( ) . debug ( `Endpoint: ${ endpoint }` ) ; const payload = { "request" : "rename" , "from-dataset" : { dsn : beforeDataSetName , member : beforeMemberName } } ; const reqHeaders = [ Headers . APPLICATION_JSON , { [ Headers . CONTENT_LENGTH ] : JSON . stringify ( payload ) . length . toString ( ) } , ZosmfHeaders . ACCEPT_ENCODING ] ; if ( options && options . responseTimeout != null ) { reqHeaders . push ( { [ ZosmfHeaders . X_IBM_RESPONSE_TIMEOUT ] : options . responseTimeout . toString ( ) } ) ; } try { await ZosmfRestClient . putExpectString ( session , endpoint , reqHeaders , payload ) ; return { success : true , commandResponse : ZosFilesMessages . dataSetRenamedSuccessfully . message } ; } catch ( err ) { Logger . getAppLogger ( ) . error ( err ) ; throw err ; } } }