@zowe/zos-workflows-for-zowe-sdk
Version:
Zowe SDK to interact with the z/OS workflows APIs
100 lines • 5.4 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.ListWorkflows = void 0;
const core_for_zowe_sdk_1 = require("@zowe/core-for-zowe-sdk");
const WorkflowValidator_1 = require("./WorkflowValidator");
const imperative_1 = require("@zowe/imperative");
const WorkflowConstants_1 = require("./WorkflowConstants");
/**
* Get list of workflows from registry.
* @export
* @class ListWorkflows
*/
class ListWorkflows {
/**
* This operation returns list of workflows.
* Parameters are optional,request can include one or more parameters to filter the results.
* @param {AbstractSession} session - z/OSMF connection info
* @param {IGetWorkflowsOptions} options - Options to filter the request
* @returns {string} z/OSMF response object
* @memberof ListWorkflows
*/
static getWorkflows(session_1) {
return __awaiter(this, arguments, void 0, function* (session, options = {}) {
WorkflowValidator_1.WorkflowValidator.validateSession(session);
options = Object.assign(Object.assign({}, options), {
// zOSMFVersion by design was only checking for undefined. To prevent a breaking change we have to do the same ??
// Added another "system" test for this
zOSMFVersion: options.zOSMFVersion !== undefined ? options.zOSMFVersion : WorkflowConstants_1.WorkflowConstants.ZOSMF_VERSION, workflowName: options.workflowName ? encodeURIComponent(options.workflowName) : null });
WorkflowValidator_1.WorkflowValidator.validateNotEmptyString(options.zOSMFVersion, core_for_zowe_sdk_1.nozOSMFVersion.message);
const resourcesQuery = ListWorkflows.getResourceQuery(options);
return core_for_zowe_sdk_1.ZosmfRestClient.getExpectJSON(session, resourcesQuery);
});
}
/**
* This operation Builds URI path from provided parameters.
* @param {IGetWorkflowsOptions} params - The array with URI path with filters for listing filtered workflows.
* @returns {string} URI path for the REST call.
* @memberof ListWorkflows
*/
static getResourceQuery(params) {
let query = `${WorkflowConstants_1.WorkflowConstants.RESOURCE}/${params.zOSMFVersion}/${WorkflowConstants_1.WorkflowConstants.WORKFLOW_RESOURCE}`;
let sign = "?";
for (const key in params) {
if (key === "zOSMFVersion")
continue;
if (params[key]) {
// Validate if parameter value does not contains ? or &
WorkflowValidator_1.WorkflowValidator.validateParameter(params[key], WorkflowConstants_1.wrongString.message);
query += sign + `${key}=${params[key]}`;
sign = "&";
}
}
return query;
}
/**
* This operation is used to return a worflow-key by given workflow name.
* @param {AbstractSession} session - z/OSMF connection info
* @param {string} workflowName - workflow name by which to list workflows
* @param {string} zOSMFVersion - identifies the version of the provisioning service.
* @returns {Promise<string> | null} - Promise with string containing wf key, or null if none was found
* @throws {ImperativeError}
* @memberof ListWorkflows
*/
static getWfKey(session_1, workflowName_1) {
return __awaiter(this, arguments, void 0, function* (session, workflowName, zOSMFVersion = WorkflowConstants_1.WorkflowConstants.ZOSMF_VERSION) {
WorkflowValidator_1.WorkflowValidator.validateSession(session);
WorkflowValidator_1.WorkflowValidator.validateNotEmptyString(zOSMFVersion, core_for_zowe_sdk_1.nozOSMFVersion.message);
WorkflowValidator_1.WorkflowValidator.validateNotEmptyString(workflowName, WorkflowConstants_1.noWorkflowName.message);
const result = yield this.getWorkflows(session, { workflowName });
// Check if there was more than one workflows found
if (result.workflows.length > 1) {
throw new imperative_1.ImperativeError({
msg: `More than one workflows found with name ` + workflowName
});
}
return result.workflows.length !== 0 ? result.workflows[0].workflowKey : null;
});
}
}
exports.ListWorkflows = ListWorkflows;
//# sourceMappingURL=ListWorkflows.js.map