@zowe/zos-tso-for-zowe-sdk
Version:
Zowe SDK to interact with TSO on z/OS
114 lines • 6.21 kB
JavaScript
;
/*
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright Contributors to the Zowe Project.
*
*/
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.StartTso = void 0;
const imperative_1 = require("@zowe/imperative");
const core_for_zowe_sdk_1 = require("@zowe/core-for-zowe-sdk");
const SendTso_1 = require("./SendTso");
const TsoValidator_1 = require("./TsoValidator");
const TsoConstants_1 = require("./TsoConstants");
const TsoResponseService_1 = require("./TsoResponseService");
/**
* Start TSO address space and receive servlet key
* @export
* @class StartTso
*/
class StartTso {
/**
* Start TSO address space with provided parameters
* @static
* @param {AbstractSession} session - z/OSMF connection info
* @param {IStartTsoParms} commandParms - object with required parameters, @see {IStartTsoParms}
* @returns {Promise<IZosmfTsoResponse>} z/OSMF response object, @see {IZosmfTsoResponse}
* @memberof StartTso
*/
static startCommon(session, commandParms) {
TsoValidator_1.TsoValidator.validateSession(session);
TsoValidator_1.TsoValidator.validateStartParams(commandParms);
const startResources = this.getResourcesQuery(commandParms);
return core_for_zowe_sdk_1.ZosmfRestClient.postExpectJSON(session, startResources, [imperative_1.Headers.APPLICATION_JSON]);
}
/**
* Start TSO address space with provided parameters.
* @static
* @param {AbstractSession} session - z/OSMF connection info
* @param {string} accountNumber - this key of IStartTsoParms required, because it cannot be default.
* @param {IStartTsoParms} parms - optional object with required parameters, @see {IStartTsoParms}
* @returns {Promise<IStartStopResponses>} command response on resolve, @see {IStartStopResponses}
* @memberof StartTso
*/
static start(session, accountNumber, parms) {
return __awaiter(this, void 0, void 0, function* () {
TsoValidator_1.TsoValidator.validateSession(session);
TsoValidator_1.TsoValidator.validateNotEmptyString(accountNumber, TsoConstants_1.noAccountNumber.message);
let customParms;
if (parms == null) {
customParms = this.setDefaultAddressSpaceParams({}, encodeURIComponent(accountNumber));
}
else {
customParms = this.setDefaultAddressSpaceParams(parms, encodeURIComponent(accountNumber));
}
const zosmfResponse = yield this.startCommon(session, customParms);
return TsoResponseService_1.TsoResponseService.populateStartAndStopCollectAll(zosmfResponse, zosmfResponse.servletKey ?
yield SendTso_1.SendTso.getAllResponses(session, zosmfResponse) : null);
});
}
/**
* Sets required parameters by default if not provided. If some parameters provided
* it uses received and the rest required parameters will be default
* @static
* @param {IStartTsoParms} parms - object with required parameters, @see {IStartTsoParms}
* @param {string} accountNumber - this key of IStartTsoParms required, because it cannot be default.
* @returns {IStartTsoParms} object with provided parameters if not the with default
* @memberof StartTso
*/
static setDefaultAddressSpaceParams(parms, accountNumber) {
var _a, _b, _c, _d, _e, _f;
return {
logonProcedure: (_a = parms.logonProcedure) !== null && _a !== void 0 ? _a : TsoConstants_1.TsoConstants.DEFAULT_PROC,
characterSet: (_b = parms.characterSet) !== null && _b !== void 0 ? _b : TsoConstants_1.TsoConstants.DEFAULT_CHSET,
codePage: (_c = parms.codePage) !== null && _c !== void 0 ? _c : TsoConstants_1.TsoConstants.DEFAULT_CPAGE,
rows: (_d = parms.rows) !== null && _d !== void 0 ? _d : TsoConstants_1.TsoConstants.DEFAULT_ROWS,
columns: (_e = parms.columns) !== null && _e !== void 0 ? _e : TsoConstants_1.TsoConstants.DEFAULT_COLS,
regionSize: (_f = parms.regionSize) !== null && _f !== void 0 ? _f : TsoConstants_1.TsoConstants.DEFAULT_RSIZE,
account: accountNumber
};
}
/**
* Builds a resources query from passed parameters which is needed for z/OSMF api URI.
* @param {IStartTsoParms} parms - object with required parameters, @see {IStartTsoParms}
* @returns {string} URI for z/OSMF REST call
* @memberof StartTso
*/
static getResourcesQuery(parms) {
let query = `${TsoConstants_1.TsoConstants.RESOURCE + "/" + TsoConstants_1.TsoConstants.RES_START_TSO}?`;
query += `${TsoConstants_1.TsoConstants.PARM_ACCT}=${parms.account}&`;
query += `${TsoConstants_1.TsoConstants.PARM_PROC}=${parms.logonProcedure}&`;
query += `${TsoConstants_1.TsoConstants.PARM_CHSET}=${parms.characterSet}&`;
query += `${TsoConstants_1.TsoConstants.PARM_CPAGE}=${parms.codePage}&`;
query += `${TsoConstants_1.TsoConstants.PARM_ROWS}=${parms.rows}&`;
query += `${TsoConstants_1.TsoConstants.PARM_COLS}=${parms.columns}&`;
query += `${TsoConstants_1.TsoConstants.PARM_RSIZE}=${parms.regionSize}`;
return query;
}
}
exports.StartTso = StartTso;
//# sourceMappingURL=StartTso.js.map