Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
Signed-off-by: enam-khan <[email protected]>
  • Loading branch information
enamkhan committed Feb 14, 2025
1 parent 6e32281 commit a5251ac
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ describe("Test suite for CICSRegionsContainer", () => {

await sut.loadRegionsInCICSGroup(CICSTreeMock as any as CICSTree);

expect(getResourceMock).toHaveBeenCalledWith(sut.getParent().getParent().getSession(), testData);
expect(getResourceMock).toHaveBeenCalledWith(sut.getParent().getParent().getSession(), testData,
{ failOnNoData: false, useCICSCmciRestError: true });
expect(sut.label).toBe("Regions (cics) [1/1]");
expect(sut.collapsibleState).toBe(2);
});
Expand All @@ -103,7 +104,7 @@ describe("Test suite for CICSRegionsContainer", () => {

it("Should load all regions of plex", async () => {
await sut.loadRegionsInPlex();

expect(getRegionInfoInPlexMock).toHaveBeenCalledTimes(1);
expect(sut.label).toBe("Regions [2/2]");
expect(sut.collapsibleState).toBe(2);
Expand Down
4 changes: 2 additions & 2 deletions packages/vsce/src/commands/closeLocalFileCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { CICSTree } from "../trees/CICSTree";
import { CICSLocalFileTreeItem } from "../trees/treeItems/CICSLocalFileTreeItem";
import { findSelectedNodes, splitCmciErrorMessage } from "../utils/commandUtils";
import { ICommandParams } from "./ICommandParams";
import { runGetResource } from "../utils/resourceUtils";
import { runPutResource } from "../utils/resourceUtils";
import constants from "../utils/constants";

export function getCloseLocalFileCommand(tree: CICSTree, treeview: TreeView<any>) {
Expand Down Expand Up @@ -122,7 +122,7 @@ async function closeLocalFile(
parms: ICommandParams,
busyDecision: string
): Promise<ICMCIApiResponse> {
return runGetResource({
return runPutResource({
session: session,
resourceName: CicsCmciConstants.CICS_CMCI_LOCAL_FILE,
cicsPlex: parms.cicsPlex,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { findSelectedNodes } from "../../utils/commandUtils";
import { ICommandParams } from "../ICommandParams";
import { CICSLocalFileTreeItem } from "../../trees/treeItems/CICSLocalFileTreeItem";
import constants from "../../utils/constants";
import { runGetResource } from "../../utils/resourceUtils";
import { runPutResource } from "../../utils/resourceUtils";

export function getDisableLocalFileCommand(tree: CICSTree, treeview: TreeView<any>) {
return commands.registerCommand("cics-extension-for-zowe.disableLocalFile", async (clickedNode) => {
Expand Down Expand Up @@ -111,7 +111,7 @@ function disableLocalFile(
parms: ICommandParams,
busyDecision: string
): Promise<ICMCIApiResponse> {
return runGetResource({
return runPutResource({
session: session,
resourceName: CicsCmciConstants.CICS_CMCI_LOCAL_FILE,
cicsPlex: parms.cicsPlex,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { findSelectedNodes } from "../../utils/commandUtils";
import { CICSProgramTreeItem } from "../../trees/treeItems/CICSProgramTreeItem";
import { ICommandParams } from "../ICommandParams";
import constants from "../../utils/constants";
import { runGetResource } from "../../utils/resourceUtils";
import { runPutResource } from "../../utils/resourceUtils";

/**
* Performs disable on selected CICSProgram nodes.
Expand Down Expand Up @@ -103,7 +103,7 @@ export function getDisableProgramCommand(tree: CICSTree, treeview: TreeView<any>
}

function disableProgram(session: imperative.AbstractSession, parms: ICommandParams): Promise<ICMCIApiResponse> {
return runGetResource({
return runPutResource({
session: session,
resourceName: CicsCmciConstants.CICS_PROGRAM_RESOURCE,
cicsPlex: parms.cicsPlex,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { findSelectedNodes, splitCmciErrorMessage } from "../../utils/commandUti
import { CICSTransactionTreeItem } from "../../trees/treeItems/CICSTransactionTreeItem";
import { ICommandParams } from "../ICommandParams";
import constants from "../../utils/constants";
import { runGetResource } from "../../utils/resourceUtils";
import { runPutResource } from "../../utils/resourceUtils";

export function getDisableTransactionCommand(tree: CICSTree, treeview: TreeView<any>) {
return commands.registerCommand("cics-extension-for-zowe.disableTransaction", async (clickedNode) => {
Expand Down Expand Up @@ -110,7 +110,7 @@ function disableTransaction(
session: imperative.AbstractSession,
parms: ICommandParams
): Promise<ICMCIApiResponse> {
return runGetResource({
return runPutResource({
session: session,
resourceName: CicsCmciConstants.CICS_LOCAL_TRANSACTION,
cicsPlex: parms.cicsPlex,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { CICSTree } from "../../trees/CICSTree";
import { CICSLocalFileTreeItem } from "../../trees/treeItems/CICSLocalFileTreeItem";
import { findSelectedNodes } from "../../utils/commandUtils";
import { ICommandParams } from "../ICommandParams";
import { runGetResource } from "../../utils/resourceUtils";
import { runPutResource } from "../../utils/resourceUtils";
import constants from "../../utils/constants";

export function getEnableLocalFileCommand(tree: CICSTree, treeview: TreeView<any>) {
Expand Down Expand Up @@ -97,7 +97,7 @@ export function getEnableLocalFileCommand(tree: CICSTree, treeview: TreeView<any
}

function enableLocalFile(session: imperative.AbstractSession, parms: ICommandParams): Promise<ICMCIApiResponse> {
return runGetResource({
return runPutResource({
session: session,
resourceName: CicsCmciConstants.CICS_CMCI_LOCAL_FILE,
cicsPlex: parms.cicsPlex,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { CICSTree } from "../../trees/CICSTree";
import { CICSProgramTreeItem } from "../../trees/treeItems/CICSProgramTreeItem";
import { findSelectedNodes } from "../../utils/commandUtils";
import { ICommandParams } from "../ICommandParams";
import { runGetResource } from "../../utils/resourceUtils";
import { runPutResource } from "../../utils/resourceUtils";
import constants from "../../utils/constants";

/**
Expand Down Expand Up @@ -101,7 +101,7 @@ export function getEnableProgramCommand(tree: CICSTree, treeview: TreeView<any>)
}

function enableProgram(session: imperative.AbstractSession, parms: ICommandParams): Promise<ICMCIApiResponse> {
return runGetResource({
return runPutResource({
session: session,
resourceName: CicsCmciConstants.CICS_PROGRAM_RESOURCE,
cicsPlex: parms.cicsPlex,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { CICSTree } from "../../trees/CICSTree";
import { findSelectedNodes } from "../../utils/commandUtils";
import { CICSTransactionTreeItem } from "../../trees/treeItems/CICSTransactionTreeItem";
import { ICommandParams } from "../ICommandParams";
import { runGetResource } from "../../utils/resourceUtils";
import { runPutResource } from "../../utils/resourceUtils";
import constants from "../../utils/constants";

export function getEnableTransactionCommand(tree: CICSTree, treeview: TreeView<any>) {
Expand Down Expand Up @@ -97,7 +97,7 @@ export function getEnableTransactionCommand(tree: CICSTree, treeview: TreeView<a
}

function enableTransaction(session: imperative.AbstractSession, parms: ICommandParams): Promise<ICMCIApiResponse> {
return runGetResource({
return runPutResource({
session: session,
resourceName: CicsCmciConstants.CICS_LOCAL_TRANSACTION,
cicsPlex: parms.cicsPlex,
Expand Down
6 changes: 3 additions & 3 deletions packages/vsce/src/commands/openLocalFileCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*
*/

import { CicsCmciConstants, ICMCIApiResponse } from "@zowe/cics-for-zowe-sdk";
import { CicsCmciConstants, ICMCIApiResponse, ICMCIRequestOptions } from "@zowe/cics-for-zowe-sdk";

Check notice

Code scanning / CodeQL

Unused variable, import, function or class Note

Unused import ICMCIRequestOptions.
import { imperative } from "@zowe/zowe-explorer-api";
import { commands, ProgressLocation, TreeView, window } from "vscode";
import { CICSCombinedLocalFileTree } from "../trees/CICSCombinedTrees/CICSCombinedLocalFileTree";
Expand All @@ -19,7 +19,7 @@ import { CICSTree } from "../trees/CICSTree";
import { CICSLocalFileTreeItem } from "../trees/treeItems/CICSLocalFileTreeItem";
import { findSelectedNodes, splitCmciErrorMessage } from "../utils/commandUtils";
import { ICommandParams } from "./ICommandParams";
import { runGetResource } from "../utils/resourceUtils";
import { runPutResource } from "../utils/resourceUtils";
import constants from "../utils/constants";

export function getOpenLocalFileCommand(tree: CICSTree, treeview: TreeView<any>) {
Expand Down Expand Up @@ -105,7 +105,7 @@ export function getOpenLocalFileCommand(tree: CICSTree, treeview: TreeView<any>)
}

function openLocalFile(session: imperative.AbstractSession, parms: ICommandParams): Promise<ICMCIApiResponse> {
return runGetResource({
return runPutResource({
session: session,
resourceName: CicsCmciConstants.CICS_PROGRAM_RESOURCE,
cicsPlex: parms.cicsPlex,
Expand Down
4 changes: 2 additions & 2 deletions packages/vsce/src/commands/phaseInCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { CICSRegionTree } from "../trees/CICSRegionTree";
import { CICSTree } from "../trees/CICSTree";
import { CICSProgramTreeItem } from "../trees/treeItems/CICSProgramTreeItem";
import { findSelectedNodes, splitCmciErrorMessage } from "../utils/commandUtils";
import { runGetResource } from "../utils/resourceUtils";
import { runPutResource } from "../utils/resourceUtils";
import constants from "../utils/constants";

/**
Expand Down Expand Up @@ -111,7 +111,7 @@ export function getPhaseInCommand(tree: CICSTree, treeview: TreeView<any>) {
}

async function performPhaseIn(session: imperative.AbstractSession, parms: { cicsPlex: string | null; regionName: string; name: string; }) {
return runGetResource({
return runPutResource({
session: session,
resourceName: CicsCmciConstants.CICS_PROGRAM_RESOURCE,
cicsPlex: parms.cicsPlex,
Expand Down
4 changes: 2 additions & 2 deletions packages/vsce/src/commands/purgeTaskCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { CICSTree } from "../trees/CICSTree";
import { findSelectedNodes, splitCmciErrorMessage } from "../utils/commandUtils";
import { CICSTaskTreeItem } from "../trees/treeItems/CICSTaskTreeItem";
import { ICommandParams } from "./ICommandParams";
import { runGetResource } from "../utils/resourceUtils";
import { runPutResource } from "../utils/resourceUtils";
import constants from "../utils/constants";

/**
Expand Down Expand Up @@ -134,7 +134,7 @@ function purgeTask(
parms: ICommandParams,
purgeType: string
): Promise<ICMCIApiResponse> {
return runGetResource({
return runPutResource({
session: session,
resourceName: CicsCmciConstants.CICS_CMCI_TASK,
cicsPlex: parms.cicsPlex,
Expand Down
46 changes: 39 additions & 7 deletions packages/vsce/src/utils/resourceUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@
*/

import {
CicsCmciRestClient,
getResource,
IResourceQueryParams
ICMCIRequestOptions,
IGetResourceUriOptions,
IResourceQueryParams,
Utils
} from "@zowe/cics-for-zowe-sdk";

Check notice

Code scanning / CodeQL

Unused variable, import, function or class Note

Unused import ICMCIRequestOptions.
import { Session } from "@zowe/imperative";
import { imperative } from "@zowe/zowe-explorer-api";
import constants from "./constants";
import { getErrorCode } from "./errorUtils";

Expand All @@ -24,21 +27,19 @@ export async function runGetResource({ session, resourceName, regionName, cicsPl
regionName?: string,
cicsPlex?: string,
params?: { criteria?: string, parameter?: string; queryParams?: IResourceQueryParams; };
}, requestBody?: {}) {
}) {
let count = 0;
while (count <= 1) {
try {
const response = await getResource(session, {
name: resourceName,
...regionName && { regionName: regionName},
...cicsPlex && { cicsPlex: regionName },
...cicsPlex && { cicsPlex: cicsPlex },
...params?.criteria && { criteria: params.criteria },
...params?.parameter && { parameter: params.parameter },
...params?.queryParams && { queryParams: params.queryParams },
},
{ ...requestBody,
...{ failOnNoData: false, useCICSCmciRestError: true }
});
{ failOnNoData: false, useCICSCmciRestError: true });
return response;
} catch (error){
count++;
Expand All @@ -50,4 +51,35 @@ export async function runGetResource({ session, resourceName, regionName, cicsPl
throw error;
}
}
}

export async function runPutResource({ session, resourceName, regionName, cicsPlex, params }: {

Check failure on line 56 in packages/vsce/src/utils/resourceUtils.ts

View workflow job for this annotation

GitHub Actions / lint

Async function 'runPutResource' has no 'await' expression
session: Session,
resourceName: string,
regionName?: string,
cicsPlex?: string,
params?: { criteria?: string, parameter?: string; queryParams?: IResourceQueryParams; };
}, requestBody: any) {
let count = 0;
while (count <= 1) {
try {
const options: IGetResourceUriOptions = {
"cicsPlex": cicsPlex,
"regionName": regionName,
...params
};

const cmciResource = Utils.getResourceUri(resourceName, options);

return CicsCmciRestClient.putExpectParsedXml(session, cmciResource, [], requestBody);
} catch (error){
count++;
if (count <= 1 &&
getErrorCode(error) === constants.HTTP_ERROR_UNAUTHORIZED && session.ISession.tokenValue) {
session.ISession.tokenValue = null;
continue;
}
throw error;
}
}
}

0 comments on commit a5251ac

Please sign in to comment.