Skip to content

Commit

Permalink
move getCachedResources to getCache SDK method
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Twydell <[email protected]>
  • Loading branch information
AndrewTwydell committed Dec 18, 2024
1 parent ba2be18 commit 7e3de0a
Showing 1 changed file with 20 additions and 28 deletions.
48 changes: 20 additions & 28 deletions packages/vsce/src/utils/profileManagement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
*
*/

import { getResource, ICMCIApiResponse } from "@zowe/cics-for-zowe-sdk";
import { getCache, getResource, ICMCIApiResponse } from "@zowe/cics-for-zowe-sdk";
import { Session } from "@zowe/imperative";
import { imperative, Types, ZoweVsCodeExtension } from "@zowe/zowe-explorer-api";
import axios, { AxiosRequestConfig } from "axios";
import { window } from "vscode";
import { xml2json } from "xml-js";
import { CICSPlexTree } from "../trees/CICSPlexTree";
Expand Down Expand Up @@ -70,17 +69,6 @@ export class ProfileManagement {
return mProfileInfo;
}

/**
* Makes axios GET request with path and axios config object given
* @param path
* @param config
* @returns
*/
public static async makeRequest(path: string, config: AxiosRequestConfig) {
const response = await axios.get(path, config);
return response;
}

public static cmciResponseXml2Json(data: string) {
return JSON.parse(xml2json(data, { compact: true, spaces: 4 }));
}
Expand Down Expand Up @@ -330,21 +318,25 @@ export class ProfileManagement {

public static async getCachedResources(profile: imperative.IProfileLoaded, cacheToken: string, resourceName: string, start = 1, increment = 800) {
try {
const config: AxiosRequestConfig = {
baseURL: `${profile.profile.protocol}://${profile.profile.host}:${profile.profile.port}/CICSSystemManagement`,
auth: {
username: profile.profile.user,
password: profile.profile.password,
},
};
const allItemsResponse = await ProfileManagement.makeRequest(`/CICSResultCache/${cacheToken}/${start}/${increment}`, config);
if (allItemsResponse.status === 200) {
const jsonFromXml = ProfileManagement.cmciResponseXml2Json(allItemsResponse.data);
if (jsonFromXml.response && jsonFromXml.response.records && jsonFromXml.response.records[resourceName.toLowerCase()]) {
const recordAttributes = jsonFromXml.response.records[resourceName.toLowerCase()];
const recordAttributesArr = toArray(recordAttributes);
const returnedResources = recordAttributesArr.map((item: { _attributes: any; }) => item._attributes);
return returnedResources;
const session = new Session({
protocol: profile.profile.protocol,
hostname: profile.profile.host,
port: profile.profile.port,
type: "basic",
user: profile.profile.user,
password: profile.profile.password,
rejectUnauthorized: profile.profile && 'rejectUnauthorized' in profile.profile ? profile.profile.rejectUnauthorized : true,
});
const allItemsresponse = await getCache(session, {
cacheToken,
startIndex: start,
count: increment,
});

if (allItemsresponse.response.resultsummary.api_response1_alt === "OK") {
if (allItemsresponse.response && allItemsresponse.response.records && allItemsresponse.response.records[resourceName.toLowerCase()]) {
const recordAttributes = allItemsresponse.response.records[resourceName.toLowerCase()];
return toArray(recordAttributes);
}
}
} catch (error) {
Expand Down

0 comments on commit 7e3de0a

Please sign in to comment.