diff --git a/packages/sdk/__tests__/__unit__/common/Common.getResourceUri.unit.test.ts b/packages/sdk/__tests__/__unit__/utils/Utils.unit.test.ts similarity index 68% rename from packages/sdk/__tests__/__unit__/common/Common.getResourceUri.unit.test.ts rename to packages/sdk/__tests__/__unit__/utils/Utils.unit.test.ts index 2a49dbb8..56d26200 100644 --- a/packages/sdk/__tests__/__unit__/common/Common.getResourceUri.unit.test.ts +++ b/packages/sdk/__tests__/__unit__/utils/Utils.unit.test.ts @@ -9,13 +9,13 @@ * */ -import { getResourceUri } from "../../../src/methods/common"; +import { Utils } from "../../../src/utils"; +import { IGetResourceUriOptions } from "../../../src"; -describe("getResourceUri", () => { +describe("Utils - getResourceUri", () => { let error: any; let response: any; - let endPoint: string; describe("validation", () => { beforeEach(() => { @@ -25,7 +25,7 @@ describe("getResourceUri", () => { it("should throw error if resourceName is empty", async () => { try { - response = getResourceUri("", "", ""); + response = Utils.getResourceUri(""); } catch (err) { error = err; } @@ -37,7 +37,7 @@ describe("getResourceUri", () => { it("should throw error if resourceName is undefined", async () => { try { - response = getResourceUri("", "", undefined); + response = Utils.getResourceUri(undefined); } catch (err) { error = err; } @@ -49,7 +49,7 @@ describe("getResourceUri", () => { it("should throw error if resourceName is null", async () => { try { - response = getResourceUri("", "", null); + response = Utils.getResourceUri(null); } catch (err) { error = err; } @@ -69,19 +69,25 @@ describe("getResourceUri", () => { it("should be able to get a resource uri with only the resource name specified", async () => { try { - response = getResourceUri("", "", "resource1"); + response = Utils.getResourceUri("resource1"); } catch (err) { error = err; } expect(response).toBeDefined(); expect(error).toBeUndefined(); - expect(response).toEqual("/CICSSystemManagement/resource1//"); + expect(response).toEqual("/CICSSystemManagement/resource1/"); }); it("should be able to get a resource uri with the cicsplex and resource name specified", async () => { try { - response = getResourceUri("cicsplex1", "", "resource1"); + + const options: IGetResourceUriOptions = { + "cicsPlex": "cicsplex1", + "regionName": "" + }; + + response = Utils.getResourceUri("resource1", options); } catch (err) { error = err; } @@ -93,7 +99,12 @@ describe("getResourceUri", () => { it("should be able to get a resource uri with the region and resource names specified", async () => { try { - response = getResourceUri("", "region1", "resource1"); + const options: IGetResourceUriOptions = { + "cicsPlex": "", + "regionName": "region1" + }; + + response = Utils.getResourceUri("resource1", options); } catch (err) { error = err; } @@ -105,7 +116,12 @@ describe("getResourceUri", () => { it("should be able to get a resource uri with the plex, region and resource names specified", async () => { try { - response = getResourceUri("cicsplex1", "region1", "resource1"); + const options: IGetResourceUriOptions = { + "cicsPlex": "cicsplex1", + "regionName": "region1" + }; + + response = Utils.getResourceUri("resource1", options); } catch (err) { error = err; } @@ -117,7 +133,13 @@ describe("getResourceUri", () => { it("should be able to get a resource uri with the criteria is unspecified", async () => { try { - response = getResourceUri("cicsplex1", "region1", "resource1", ""); + const options: IGetResourceUriOptions = { + "cicsPlex": "cicsplex1", + "regionName": "region1", + "criteria": "" + }; + + response = Utils.getResourceUri("resource1", options); } catch (err) { error = err; } @@ -129,7 +151,13 @@ describe("getResourceUri", () => { it("should be able to get a resource uri with the criteria is specified", async () => { try { - response = getResourceUri("cicsplex1", "region1", "resource1", "NAME=test"); + const options: IGetResourceUriOptions = { + "cicsPlex": "cicsplex1", + "regionName": "region1", + "criteria": "NAME=test" + }; + + response = Utils.getResourceUri("resource1", options); } catch (err) { error = err; } @@ -141,7 +169,14 @@ describe("getResourceUri", () => { it("should be able to get a resource uri with the parameter is unspecified", async () => { try { - response = getResourceUri("cicsplex1", "region1", "resource1", "", ""); + const options: IGetResourceUriOptions = { + "cicsPlex": "cicsplex1", + "regionName": "region1", + "criteria": "", + "parameter": "" + }; + + response = Utils.getResourceUri("resource1", options); } catch (err) { error = err; } @@ -153,7 +188,14 @@ describe("getResourceUri", () => { it("should be able to get a resource uri with the parameter is specified", async () => { try { - response = getResourceUri("cicsplex1", "region1", "resource1", "", "PARAM=test"); + const options: IGetResourceUriOptions = { + "cicsPlex": "cicsplex1", + "regionName": "region1", + "criteria": "", + "parameter": "PARAM=test" + }; + + response = Utils.getResourceUri("resource1", options); } catch (err) { error = err; } @@ -165,7 +207,14 @@ describe("getResourceUri", () => { it("should be able to get a resource uri when both criteria and parameter are specified", async () => { try { - response = getResourceUri("cicsplex1", "region1", "resource1", "NAME=test1", "PARAM=test2"); + const options: IGetResourceUriOptions = { + "cicsPlex": "cicsplex1", + "regionName": "region1", + "criteria": "NAME=test1", + "parameter": "PARAM=test2" + }; + + response = Utils.getResourceUri("resource1", options); } catch (err) { error = err; } diff --git a/packages/sdk/src/doc/IGetResourceUriOptions.ts b/packages/sdk/src/doc/IGetResourceUriOptions.ts new file mode 100644 index 00000000..c4d9c4ad --- /dev/null +++ b/packages/sdk/src/doc/IGetResourceUriOptions.ts @@ -0,0 +1,42 @@ +/** + * 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. + * + */ + +export interface IGetResourceUriOptions { + + /** + * CICS Plex of the program + */ + cicsPlex?: string; + + /** + * The name of the CICS region of the program + */ + regionName?: string; + + /** + * Criteria by which to filter the records + * + * Examples: + * "TRANID=TRAN" + * "PROGRAM=PRG*" + * "NAME=C* AND PROGRAM=D*" + */ + criteria?: string; + + /** + * Parameter by which to refine the records + * + * Example: + * "CSDGROUP(GRP1)" + * "CSDGROUP(D*)" + */ + parameter?: string; +} diff --git a/packages/sdk/src/doc/index.ts b/packages/sdk/src/doc/index.ts index 084dcaa8..c418516a 100644 --- a/packages/sdk/src/doc/index.ts +++ b/packages/sdk/src/doc/index.ts @@ -17,3 +17,4 @@ export * from "./IResourceParms"; export * from "./ITransactionParms"; export * from "./IURIMapParms"; export * from "./IWebServiceParms"; +export * from "./IGetResourceUriOptions"; diff --git a/packages/sdk/src/methods/add-to-list/AddToList.ts b/packages/sdk/src/methods/add-to-list/AddToList.ts index 3d97bed3..fb711c80 100644 --- a/packages/sdk/src/methods/add-to-list/AddToList.ts +++ b/packages/sdk/src/methods/add-to-list/AddToList.ts @@ -12,8 +12,8 @@ import { AbstractSession, ImperativeExpect, Logger } from "@zowe/imperative"; import { CicsCmciRestClient } from "../../rest"; import { CicsCmciConstants } from "../../constants"; -import { getResourceUri } from "../common"; -import { ICMCIApiResponse, ICSDGroupParms } from "../../doc"; +import { Utils } from "../../utils"; +import { ICMCIApiResponse, ICSDGroupParms, IGetResourceUriOptions } from "../../doc"; /** * Add a new CSD Group resource to a CSD List in CICS through CMCI REST API @@ -32,8 +32,13 @@ export function addCSDGroupToList(session: AbstractSession, parms: ICSDGroupParm Logger.getAppLogger().debug("Attempting to add a CSD Group to a CSD List with the following parameters:\n%s", JSON.stringify(parms)); - const cmciResource = getResourceUri(parms.cicsPlex, parms.regionName, - CicsCmciConstants.CICS_CSDGROUP, "NAME=='" + parms.name + "'"); + const options: IGetResourceUriOptions = { + "cicsPlex": parms.cicsPlex, + "regionName": parms.regionName, + "criteria": `NAME=='${parms.name}'` + }; + + const cmciResource = Utils.getResourceUri(CicsCmciConstants.CICS_CSDGROUP, options); const requestBody: any = { request: { diff --git a/packages/sdk/src/methods/common/Common.ts b/packages/sdk/src/methods/common/Common.ts deleted file mode 100644 index e940e3d4..00000000 --- a/packages/sdk/src/methods/common/Common.ts +++ /dev/null @@ -1,49 +0,0 @@ -/** - * 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. - * - */ - -import { ImperativeExpect } from "@zowe/imperative"; -import { CicsCmciConstants } from "../../constants"; - -/** - * Get uri for requesting a resources in CICS through CMCI REST API - * @param {string} cicsPlexName - CICSplex name - * @param {string} regionName - CICS region name - * @param {string} resourceName - CMCI resource name - * @param {string} criteria - criteria string - * @param {string} parameter - parameter string - * @returns {string} return a string containing the resource uri - */ -export function getResourceUri(cicsPlexName: string, regionName: string, resourceName: string, criteria?: string, parameter?: string) { - ImperativeExpect.toBeDefinedAndNonBlank(resourceName, "CICS Resource name", "CICS resource name is required"); - - let delimiter = "?"; // initial delimiter - - const cicsPlex = cicsPlexName == null ? "" : cicsPlexName + CicsCmciConstants.SEPERATOR; - const region = regionName == null ? "" : regionName; - - let cmciResource = CicsCmciConstants.SEPERATOR + CicsCmciConstants.CICS_SYSTEM_MANAGEMENT + - CicsCmciConstants.SEPERATOR + resourceName + CicsCmciConstants.SEPERATOR + - cicsPlex + region; - - if (criteria != null && criteria.length > 0) { - let addParentheses = criteria.charAt(0) !== '('; - - cmciResource = cmciResource + delimiter + "CRITERIA=" + (addParentheses ? "(": "") + encodeURIComponent(criteria) + (addParentheses ? ")": "") ; - delimiter = "&"; - } - - if (parameter != null && parameter.length > 0) { - cmciResource = cmciResource + delimiter + "PARAMETER=" + encodeURIComponent(parameter); - } - - return cmciResource; -} - diff --git a/packages/sdk/src/methods/define/Define.ts b/packages/sdk/src/methods/define/Define.ts index 966fb63c..86da4786 100644 --- a/packages/sdk/src/methods/define/Define.ts +++ b/packages/sdk/src/methods/define/Define.ts @@ -12,8 +12,8 @@ import { AbstractSession, ImperativeExpect, Logger } from "@zowe/imperative"; import { CicsCmciRestClient } from "../../rest"; import { CicsCmciConstants } from "../../constants"; -import { ICMCIApiResponse, IProgramParms, ITransactionParms, IURIMapParms, IWebServiceParms } from "../../doc"; -import { getResourceUri } from "../common"; +import { ICMCIApiResponse, IProgramParms, ITransactionParms, IURIMapParms, IWebServiceParms, IGetResourceUriOptions } from "../../doc"; +import { Utils } from "../../utils"; /** * Define a new program resource to CICS through CMCI REST API @@ -50,8 +50,12 @@ export function defineProgram(session: AbstractSession, parms: IProgramParms): P } }; - const cmciResource = getResourceUri(parms.cicsPlex, parms.regionName, - CicsCmciConstants.CICS_DEFINITION_PROGRAM); + const options: IGetResourceUriOptions = { + "cicsPlex": parms.cicsPlex, + "regionName": parms.regionName + }; + + const cmciResource = Utils.getResourceUri(CicsCmciConstants.CICS_DEFINITION_PROGRAM, options); return CicsCmciRestClient.postExpectParsedXml(session, cmciResource, [], requestBody) as any; } @@ -93,8 +97,12 @@ export function defineTransaction(session: AbstractSession, parms: ITransactionP } }; - const cmciResource = getResourceUri(parms.cicsPlex, parms.regionName, - CicsCmciConstants.CICS_DEFINITION_TRANSACTION); + const options: IGetResourceUriOptions = { + "cicsPlex": parms.cicsPlex, + "regionName": parms.regionName + }; + + const cmciResource = Utils.getResourceUri(CicsCmciConstants.CICS_DEFINITION_TRANSACTION, options); return CicsCmciRestClient.postExpectParsedXml(session, cmciResource, [], requestBody) as any; } @@ -122,8 +130,12 @@ export function defineUrimapServer(session: AbstractSession, parms: IURIMapParms const requestBody: any = buildUrimapRequestBody(parms, "server"); requestBody.request.create.attributes.$.program = parms.programName; - const cmciResource = getResourceUri(parms.cicsPlex, parms.regionName, - CicsCmciConstants.CICS_DEFINITION_URIMAP); + const options: IGetResourceUriOptions = { + "cicsPlex": parms.cicsPlex, + "regionName": parms.regionName + }; + + const cmciResource = Utils.getResourceUri(CicsCmciConstants.CICS_DEFINITION_URIMAP, options); return CicsCmciRestClient.postExpectParsedXml(session, cmciResource, [], requestBody) as any; } @@ -147,8 +159,12 @@ export function defineUrimapClient(session: AbstractSession, parms: IURIMapParms Logger.getAppLogger().debug("Attempting to define a client URIMap with the following parameters:\n%s", JSON.stringify(parms)); const requestBody: any = buildUrimapRequestBody(parms, "client"); - const cmciResource = getResourceUri(parms.cicsPlex, parms.regionName, - CicsCmciConstants.CICS_DEFINITION_URIMAP); + const options: IGetResourceUriOptions = { + "cicsPlex": parms.cicsPlex, + "regionName": parms.regionName + }; + + const cmciResource = Utils.getResourceUri(CicsCmciConstants.CICS_DEFINITION_URIMAP, options); return CicsCmciRestClient.postExpectParsedXml(session, cmciResource, [], requestBody) as any; } @@ -175,8 +191,12 @@ export function defineUrimapPipeline(session: AbstractSession, parms: IURIMapPar const requestBody: any = buildUrimapRequestBody(parms, "pipeline"); requestBody.request.create.attributes.$.pipeline = parms.pipelineName; - const cmciResource = getResourceUri(parms.cicsPlex, parms.regionName, - CicsCmciConstants.CICS_DEFINITION_URIMAP); + const options: IGetResourceUriOptions = { + "cicsPlex": parms.cicsPlex, + "regionName": parms.regionName + }; + + const cmciResource = Utils.getResourceUri(CicsCmciConstants.CICS_DEFINITION_URIMAP, options); return CicsCmciRestClient.postExpectParsedXml(session, cmciResource, [], requestBody) as any; } @@ -300,8 +320,12 @@ export function defineWebservice(session: AbstractSession, parms: IWebServicePar } }; - const cmciResource = getResourceUri(parms.cicsPlex, parms.regionName, - CicsCmciConstants.CICS_DEFINITION_WEBSERVICE); + const options: IGetResourceUriOptions = { + "cicsPlex": parms.cicsPlex, + "regionName": parms.regionName + }; + + const cmciResource = Utils.getResourceUri(CicsCmciConstants.CICS_DEFINITION_WEBSERVICE, options); return CicsCmciRestClient.postExpectParsedXml(session, cmciResource, [], requestBody) as any; } diff --git a/packages/sdk/src/methods/delete/Delete.ts b/packages/sdk/src/methods/delete/Delete.ts index ee13b92d..1addff6b 100644 --- a/packages/sdk/src/methods/delete/Delete.ts +++ b/packages/sdk/src/methods/delete/Delete.ts @@ -12,8 +12,8 @@ import { AbstractSession, ImperativeExpect, Logger } from "@zowe/imperative"; import { CicsCmciRestClient } from "../../rest"; import { CicsCmciConstants } from "../../constants"; -import { getResourceUri } from "../common"; -import { ICMCIApiResponse, IProgramParms, ITransactionParms, IURIMapParms, IWebServiceParms } from "../../doc"; +import { Utils } from "../../utils"; +import { ICMCIApiResponse, IProgramParms, ITransactionParms, IURIMapParms, IWebServiceParms, IGetResourceUriOptions } from "../../doc"; /** * Delete a program installed in CICS through CMCI REST API @@ -32,10 +32,14 @@ export async function deleteProgram(session: AbstractSession, parms: IProgramPar Logger.getAppLogger().debug("Attempting to delete a program with the following parameters:\n%s", JSON.stringify(parms)); - const cmciResource = getResourceUri(parms.cicsPlex, parms.regionName, - CicsCmciConstants.CICS_DEFINITION_PROGRAM, - `NAME=${parms.name}`, - `CSDGROUP(${parms.csdGroup})`); + const options: IGetResourceUriOptions = { + "cicsPlex": parms.cicsPlex, + "regionName": parms.regionName, + "criteria": `NAME=${parms.name}`, + "parameter": `CSDGROUP(${parms.csdGroup})` + }; + + const cmciResource = Utils.getResourceUri(CicsCmciConstants.CICS_DEFINITION_PROGRAM, options); return CicsCmciRestClient.deleteExpectParsedXml(session, cmciResource, []); } @@ -57,10 +61,14 @@ export async function deleteTransaction(session: AbstractSession, parms: ITransa Logger.getAppLogger().debug("Attempting to delete a transaction with the following parameters:\n%s", JSON.stringify(parms)); - const cmciResource = getResourceUri(parms.cicsPlex, parms.regionName, - CicsCmciConstants.CICS_DEFINITION_TRANSACTION, - `NAME=${parms.name}`, - `CSDGROUP(${parms.csdGroup})`); + const options: IGetResourceUriOptions = { + "cicsPlex": parms.cicsPlex, + "regionName": parms.regionName, + "criteria": `NAME=${parms.name}`, + "parameter": `CSDGROUP(${parms.csdGroup})` + }; + + const cmciResource = Utils.getResourceUri(CicsCmciConstants.CICS_DEFINITION_TRANSACTION, options); return CicsCmciRestClient.deleteExpectParsedXml(session, cmciResource, []); } @@ -83,10 +91,14 @@ export async function deleteUrimap(session: AbstractSession, parms: IURIMapParms Logger.getAppLogger().debug("Attempting to delete a URIMap with the following parameters:\n%s", JSON.stringify(parms)); - const cmciResource = getResourceUri(parms.cicsPlex, parms.regionName, - CicsCmciConstants.CICS_DEFINITION_URIMAP, - `NAME=${parms.name}`, - `CSDGROUP(${parms.csdGroup})`); + const options: IGetResourceUriOptions = { + "cicsPlex": parms.cicsPlex, + "regionName": parms.regionName, + "criteria": `NAME=${parms.name}`, + "parameter": `CSDGROUP(${parms.csdGroup})` + }; + + const cmciResource = Utils.getResourceUri(CicsCmciConstants.CICS_DEFINITION_URIMAP, options); return CicsCmciRestClient.deleteExpectParsedXml(session, cmciResource, []); } @@ -109,10 +121,14 @@ export async function deleteWebservice(session: AbstractSession, parms: IWebServ Logger.getAppLogger().debug("Attempting to delete a web service with the following parameters:\n%s", JSON.stringify(parms)); - const cmciResource = getResourceUri(parms.cicsPlex, parms.regionName, - CicsCmciConstants.CICS_DEFINITION_WEBSERVICE, - `NAME=${parms.name}`, - `CSDGROUP(${parms.csdGroup})`); + const options: IGetResourceUriOptions = { + "cicsPlex": parms.cicsPlex, + "regionName": parms.regionName, + "criteria": `NAME=${parms.name}`, + "parameter": `CSDGROUP(${parms.csdGroup})` + }; + + const cmciResource = Utils.getResourceUri(CicsCmciConstants.CICS_DEFINITION_WEBSERVICE, options); return CicsCmciRestClient.deleteExpectParsedXml(session, cmciResource, []); } diff --git a/packages/sdk/src/methods/disable/Disable.ts b/packages/sdk/src/methods/disable/Disable.ts index c925d612..498f5d0f 100644 --- a/packages/sdk/src/methods/disable/Disable.ts +++ b/packages/sdk/src/methods/disable/Disable.ts @@ -12,8 +12,8 @@ import { AbstractSession, ImperativeExpect, Logger } from "@zowe/imperative"; import { CicsCmciRestClient } from "../../rest"; import { CicsCmciConstants } from "../../constants"; -import { getResourceUri } from "../common"; -import { ICMCIApiResponse, IURIMapParms } from "../../doc"; +import { Utils } from "../../utils"; +import { ICMCIApiResponse, IURIMapParms, IGetResourceUriOptions } from "../../doc"; /** * Disable a URIMap installed in CICS through CMCI REST API @@ -33,9 +33,13 @@ export async function disableUrimap(session: AbstractSession, parms: IURIMapParm Logger.getAppLogger().debug("Attempting to disable a URIMap with the following parameters:\n%s", JSON.stringify(parms)); - const cmciResource = getResourceUri(parms.cicsPlex, parms.regionName, - CicsCmciConstants.CICS_URIMAP, - `NAME=${parms.name}`); + const options: IGetResourceUriOptions = { + "cicsPlex": parms.cicsPlex, + "regionName": parms.regionName, + "criteria": `NAME=${parms.name}` + }; + + const cmciResource = Utils.getResourceUri(CicsCmciConstants.CICS_URIMAP, options); const requestBody: any = { request: { diff --git a/packages/sdk/src/methods/discard/Discard.ts b/packages/sdk/src/methods/discard/Discard.ts index bc8b80a8..91da9c42 100644 --- a/packages/sdk/src/methods/discard/Discard.ts +++ b/packages/sdk/src/methods/discard/Discard.ts @@ -12,8 +12,8 @@ import { AbstractSession, ImperativeExpect, Logger } from "@zowe/imperative"; import { CicsCmciRestClient } from "../../rest"; import { CicsCmciConstants } from "../../constants"; -import { getResourceUri } from "../common"; -import { ICMCIApiResponse, IProgramParms, ITransactionParms, IURIMapParms } from "../../doc"; +import { Utils } from "../../utils"; +import { ICMCIApiResponse, IProgramParms, ITransactionParms, IURIMapParms, IGetResourceUriOptions } from "../../doc"; /** * Discard a program installed in CICS through CMCI REST API @@ -31,9 +31,13 @@ export async function discardProgram(session: AbstractSession, parms: IProgramPa Logger.getAppLogger().debug("Attempting to discard a program with the following parameters:\n%s", JSON.stringify(parms)); - const cmciResource = getResourceUri(parms.cicsPlex, parms.regionName, - CicsCmciConstants.CICS_PROGRAM_RESOURCE, - `PROGRAM=${parms.name}`); + const options: IGetResourceUriOptions = { + "cicsPlex": parms.cicsPlex, + "regionName": parms.regionName, + "criteria": `PROGRAM=${parms.name}` + }; + + const cmciResource = Utils.getResourceUri(CicsCmciConstants.CICS_PROGRAM_RESOURCE, options); return CicsCmciRestClient.deleteExpectParsedXml(session, cmciResource, []); } @@ -54,9 +58,13 @@ export async function discardTransaction(session: AbstractSession, parms: ITrans Logger.getAppLogger().debug("Attempting to discard a transaction with the following parameters:\n%s", JSON.stringify(parms)); - const cmciResource = getResourceUri(parms.cicsPlex, parms.regionName, - CicsCmciConstants.CICS_LOCAL_TRANSACTION, - `(TRANID=${parms.name})`); + const options: IGetResourceUriOptions = { + "cicsPlex": parms.cicsPlex, + "regionName": parms.regionName, + "criteria": `(TRANID=${parms.name})` + }; + + const cmciResource = Utils.getResourceUri(CicsCmciConstants.CICS_LOCAL_TRANSACTION, options); return CicsCmciRestClient.deleteExpectParsedXml(session, cmciResource, []); } @@ -67,9 +75,13 @@ export async function discardUrimap(session: AbstractSession, parms: IURIMapParm Logger.getAppLogger().debug("Attempting to discard a URIMap with the following parameters:\n%s", JSON.stringify(parms)); - const cmciResource = getResourceUri(parms.cicsPlex, parms.regionName, - CicsCmciConstants.CICS_URIMAP, - `(NAME=${parms.name})`); + const options: IGetResourceUriOptions = { + "cicsPlex": parms.cicsPlex, + "regionName": parms.regionName, + "criteria": `(NAME=${parms.name})` + }; + + const cmciResource = Utils.getResourceUri(CicsCmciConstants.CICS_URIMAP, options); return CicsCmciRestClient.deleteExpectParsedXml(session, cmciResource, []); } diff --git a/packages/sdk/src/methods/enable/Enable.ts b/packages/sdk/src/methods/enable/Enable.ts index 7d34305a..8d8459ed 100644 --- a/packages/sdk/src/methods/enable/Enable.ts +++ b/packages/sdk/src/methods/enable/Enable.ts @@ -12,8 +12,8 @@ import { AbstractSession, ImperativeExpect, Logger } from "@zowe/imperative"; import { CicsCmciRestClient } from "../../rest"; import { CicsCmciConstants } from "../../constants"; -import { getResourceUri } from "../common"; -import { ICMCIApiResponse, IURIMapParms } from "../../doc"; +import { Utils } from "../../utils"; +import { ICMCIApiResponse, IURIMapParms, IGetResourceUriOptions } from "../../doc"; /** * Enable a URIMap installed in CICS through CMCI REST API @@ -33,9 +33,13 @@ export async function enableUrimap(session: AbstractSession, parms: IURIMapParms Logger.getAppLogger().debug("Attempting to enable a URIMap with the following parameters:\n%s", JSON.stringify(parms)); - const cmciResource = getResourceUri(parms.cicsPlex, parms.regionName, - CicsCmciConstants.CICS_URIMAP, - `NAME=${parms.name}`); + const options: IGetResourceUriOptions = { + "cicsPlex": parms.cicsPlex, + "regionName": parms.regionName, + "criteria": `NAME=${parms.name}` + }; + + const cmciResource = Utils.getResourceUri(CicsCmciConstants.CICS_URIMAP, options); const requestBody: any = { request: { diff --git a/packages/sdk/src/methods/get/Get.ts b/packages/sdk/src/methods/get/Get.ts index 94a2369e..fb60be42 100644 --- a/packages/sdk/src/methods/get/Get.ts +++ b/packages/sdk/src/methods/get/Get.ts @@ -11,8 +11,8 @@ import { AbstractSession, ImperativeExpect, Logger } from "@zowe/imperative"; import { CicsCmciRestClient } from "../../rest"; -import { ICMCIApiResponse, IResourceParms } from "../../doc"; -import { getResourceUri } from "../common"; +import { ICMCIApiResponse, IResourceParms, IGetResourceUriOptions } from "../../doc"; +import { Utils } from "../../utils"; /** * Get resources on in CICS through CMCI REST API @@ -29,7 +29,14 @@ export async function getResource(session: AbstractSession, parms: IResourceParm Logger.getAppLogger().debug("Attempting to get resource(s) with the following parameters:\n%s", JSON.stringify(parms)); - const cmciResource = getResourceUri(parms.cicsPlex, parms.regionName, parms.name, parms.criteria, parms.parameter); + const options: IGetResourceUriOptions = { + "cicsPlex": parms.cicsPlex, + "regionName": parms.regionName, + "criteria": parms.criteria, + "parameter": parms.parameter + }; + + const cmciResource = Utils.getResourceUri(parms.name, options); return CicsCmciRestClient.getExpectParsedXml(session, cmciResource, []); } diff --git a/packages/sdk/src/methods/install/Install.ts b/packages/sdk/src/methods/install/Install.ts index 0d1414ac..ed1b1d87 100644 --- a/packages/sdk/src/methods/install/Install.ts +++ b/packages/sdk/src/methods/install/Install.ts @@ -12,8 +12,8 @@ import { AbstractSession, ImperativeExpect, Logger } from "@zowe/imperative"; import { CicsCmciRestClient } from "../../rest"; import { CicsCmciConstants } from "../../constants"; -import { getResourceUri } from "../common"; -import { ICMCIApiResponse, IProgramParms, IURIMapParms } from "../../doc"; +import { Utils } from "../../utils"; +import { ICMCIApiResponse, IProgramParms, IURIMapParms, IGetResourceUriOptions } from "../../doc"; /** * Install a program definition to CICS through CMCI REST API @@ -42,10 +42,14 @@ export function installProgram(session: AbstractSession, parms: IProgramParms): } }; - const cmciResource = getResourceUri(parms.cicsPlex, parms.regionName, - CicsCmciConstants.CICS_DEFINITION_PROGRAM, - `NAME=${parms.name}`, - `CSDGROUP(${parms.csdGroup})`); + const options: IGetResourceUriOptions = { + "cicsPlex": parms.cicsPlex, + "regionName": parms.regionName, + "criteria": `NAME=${parms.name}`, + "parameter": `CSDGROUP(${parms.csdGroup})` + }; + + const cmciResource = Utils.getResourceUri(CicsCmciConstants.CICS_DEFINITION_PROGRAM, options); return CicsCmciRestClient.putExpectParsedXml(session, cmciResource, [], requestBody) as any; } @@ -77,10 +81,14 @@ export function installTransaction(session: AbstractSession, parms: IProgramParm } }; - const cmciResource = getResourceUri(parms.cicsPlex, parms.regionName, - CicsCmciConstants.CICS_DEFINITION_TRANSACTION, - `NAME=${parms.name}`, - `CSDGROUP(${parms.csdGroup})`); + const options: IGetResourceUriOptions = { + "cicsPlex": parms.cicsPlex, + "regionName": parms.regionName, + "criteria": `NAME=${parms.name}`, + "parameter": `CSDGROUP(${parms.csdGroup})` + }; + + const cmciResource = Utils.getResourceUri(CicsCmciConstants.CICS_DEFINITION_TRANSACTION, options); return CicsCmciRestClient.putExpectParsedXml(session, cmciResource, [], requestBody) as any; @@ -105,10 +113,14 @@ export function installUrimap(session: AbstractSession, parms: IURIMapParms): Pr Logger.getAppLogger().debug("Attempting to install a URIMap with the following parameters:\n%s", JSON.stringify(parms)); - const cmciResource = getResourceUri(parms.cicsPlex, parms.regionName, - CicsCmciConstants.CICS_DEFINITION_URIMAP, - `NAME=${parms.name}`, - `CSDGROUP(${parms.csdGroup})`); + const options: IGetResourceUriOptions = { + "cicsPlex": parms.cicsPlex, + "regionName": parms.regionName, + "criteria": `NAME=${parms.name}`, + "parameter": `CSDGROUP(${parms.csdGroup})` + }; + + const cmciResource = Utils.getResourceUri(CicsCmciConstants.CICS_DEFINITION_URIMAP, options); const requestBody: any = { request: { diff --git a/packages/sdk/src/methods/remove-from-list/RemoveFromList.ts b/packages/sdk/src/methods/remove-from-list/RemoveFromList.ts index 5554f1fd..a0c50acd 100644 --- a/packages/sdk/src/methods/remove-from-list/RemoveFromList.ts +++ b/packages/sdk/src/methods/remove-from-list/RemoveFromList.ts @@ -12,8 +12,8 @@ import { AbstractSession, ImperativeExpect, Logger } from "@zowe/imperative"; import { CicsCmciRestClient } from "../../rest"; import { CicsCmciConstants } from "../../constants"; -import { getResourceUri } from "../common"; -import { ICMCIApiResponse, ICSDGroupParms } from "../../doc"; +import { Utils } from "../../utils"; +import { ICMCIApiResponse, ICSDGroupParms, IGetResourceUriOptions } from "../../doc"; /** * Remove a CSD Group resource from a CSD List in CICS through CMCI REST API @@ -32,9 +32,13 @@ export function removeCSDGroupFromList(session: AbstractSession, parms: ICSDGrou Logger.getAppLogger().debug("Attempting to remove a CSD Group from a CSD List with the following parameters:\n%s", JSON.stringify(parms)); - const cmciResource = getResourceUri(parms.cicsPlex, parms.regionName, - CicsCmciConstants.CICS_CSDGROUP_IN_LIST, - `(CSDLIST=='${parms.csdList}') AND (CSDGROUP=='${parms.name}')`); + const options: IGetResourceUriOptions = { + "cicsPlex": parms.cicsPlex, + "regionName": parms.regionName, + "criteria": `(CSDLIST=='${parms.csdList}') AND (CSDGROUP=='${parms.name}')` + }; + + const cmciResource = Utils.getResourceUri(CicsCmciConstants.CICS_CSDGROUP_IN_LIST, options); return CicsCmciRestClient.deleteExpectParsedXml(session, cmciResource, []) as any; } diff --git a/packages/sdk/src/methods/set/Set.ts b/packages/sdk/src/methods/set/Set.ts index ec11f5af..dff16dd5 100644 --- a/packages/sdk/src/methods/set/Set.ts +++ b/packages/sdk/src/methods/set/Set.ts @@ -12,8 +12,8 @@ import { AbstractSession, ImperativeExpect, Logger } from "@zowe/imperative"; import { CicsCmciRestClient } from "../../rest"; import { CicsCmciConstants } from "../../constants"; -import { getResourceUri } from "../common"; -import { ICMCIApiResponse, IProgramParms } from "../../doc"; +import { Utils } from "../../utils"; +import { ICMCIApiResponse, IProgramParms, IGetResourceUriOptions } from "../../doc"; /** * Refresh a program definition on CICS through CMCI REST API @@ -40,9 +40,13 @@ export function programNewcopy(session: AbstractSession, parms: IProgramParms): } }; - const cmciResource = getResourceUri(parms.cicsPlex, parms.regionName, - CicsCmciConstants.CICS_PROGRAM_RESOURCE, - `PROGRAM=${parms.name}`); + const options: IGetResourceUriOptions = { + "cicsPlex": parms.cicsPlex, + "regionName": parms.regionName, + "criteria": `PROGRAM=${parms.name}` + }; + + const cmciResource = Utils.getResourceUri(CicsCmciConstants.CICS_PROGRAM_RESOURCE, options); return CicsCmciRestClient.putExpectParsedXml(session, cmciResource, [], requestBody) as any; } diff --git a/packages/sdk/src/utils/Utils.ts b/packages/sdk/src/utils/Utils.ts new file mode 100644 index 00000000..df05dc14 --- /dev/null +++ b/packages/sdk/src/utils/Utils.ts @@ -0,0 +1,56 @@ +/** + * 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. + * + */ + +import { ImperativeExpect } from "@zowe/imperative"; +import { CicsCmciConstants } from "../constants"; +import { IGetResourceUriOptions } from "../doc"; + +/** + * Class for providing static utility methods + * @export + * @class Utils + */ +export class Utils { + + /** + * Get uri for requesting a resources in CICS through CMCI REST API + * @param {string} resourceName - CMCI resource name + * @param {IGetResourceUriOptions} options - CMCI resource options + */ + public static getResourceUri(resourceName: string, options?: IGetResourceUriOptions) : string { + ImperativeExpect.toBeDefinedAndNonBlank(resourceName, "CICS Resource name", "CICS resource name is required"); + + let delimiter = "?"; // initial delimiter + + const cicsPlex = (options && options.cicsPlex) == null ? "" : options.cicsPlex + CicsCmciConstants.SEPERATOR; + const region = (options && options.regionName) == null ? "" : options.regionName; + + let cmciResource = CicsCmciConstants.SEPERATOR + CicsCmciConstants.CICS_SYSTEM_MANAGEMENT + + CicsCmciConstants.SEPERATOR + resourceName + CicsCmciConstants.SEPERATOR + + cicsPlex + region; + + if (options != null) { + if (options.criteria != null && options.criteria.length > 0) { + const addParentheses = options.criteria.charAt(0) !== '('; + + cmciResource = cmciResource + delimiter + "CRITERIA=" + (addParentheses ? "(": "") + + encodeURIComponent(options.criteria) + (addParentheses ? ")": "") ; + delimiter = "&"; + } + + if (options.parameter != null && options.parameter.length > 0) { + cmciResource = cmciResource + delimiter + "PARAMETER=" + encodeURIComponent(options.parameter); + } + } + + return cmciResource; + } +} diff --git a/packages/sdk/src/methods/common/index.ts b/packages/sdk/src/utils/index.ts similarity index 92% rename from packages/sdk/src/methods/common/index.ts rename to packages/sdk/src/utils/index.ts index b09d1150..ff161f3e 100644 --- a/packages/sdk/src/methods/common/index.ts +++ b/packages/sdk/src/utils/index.ts @@ -9,4 +9,4 @@ * */ -export * from "./Common"; +export * from "./Utils";