-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcloseLocalFileCommand.ts
146 lines (140 loc) · 5.78 KB
/
closeLocalFileCommand.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/**
* 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 { CicsCmciConstants, ICMCIApiResponse } from "@zowe/cics-for-zowe-sdk";
import { imperative } from "@zowe/zowe-explorer-api";
import { commands, ProgressLocation, TreeView, window } from "vscode";
import { CICSCombinedLocalFileTree } from "../trees/CICSCombinedTrees/CICSCombinedLocalFileTree";
import { CICSRegionsContainer } from "../trees/CICSRegionsContainer";
import { CICSRegionTree } from "../trees/CICSRegionTree";
import { CICSTree } from "../trees/CICSTree";
import { CICSLocalFileTreeItem } from "../trees/treeItems/CICSLocalFileTreeItem";
import { findSelectedNodes, splitCmciErrorMessage } from "../utils/commandUtils";
import { ICommandParams } from "./ICommandParams";
import { runPutResource } from "../utils/resourceUtils";
import constants from "../utils/constants";
export function getCloseLocalFileCommand(tree: CICSTree, treeview: TreeView<any>) {
return commands.registerCommand("cics-extension-for-zowe.closeLocalFile", async (clickedNode) => {
const allSelectedNodes = findSelectedNodes(treeview, CICSLocalFileTreeItem, clickedNode);
if (!allSelectedNodes || !allSelectedNodes.length) {
window.showErrorMessage("No CICS local file selected");
return;
}
const parentRegions: CICSRegionTree[] = [];
let busyDecision = await window.showInformationMessage(
`Choose one of the following for the file busy condition`,
...["Wait", "No Wait", "Force"]
);
if (busyDecision) {
busyDecision = busyDecision.replace(" ", "").toUpperCase();
window.withProgress(
{
title: "Close",
location: ProgressLocation.Notification,
cancellable: true,
},
async (progress, token) => {
token.onCancellationRequested(() => { });
for (const index in allSelectedNodes) {
progress.report({
message: `Closing ${parseInt(index) + 1} of ${allSelectedNodes.length}`,
increment: (parseInt(index) / allSelectedNodes.length) * constants.PERCENTAGE_MAX,
});
const currentNode = allSelectedNodes[parseInt(index)];
try {
await closeLocalFile(
currentNode.parentRegion.parentSession.session,
{
name: currentNode.localFile.file,
regionName: currentNode.parentRegion.label,
cicsPlex: currentNode.parentRegion.parentPlex ? currentNode.parentRegion.parentPlex.getPlexName() : undefined,
},
busyDecision
);
if (!parentRegions.includes(currentNode.parentRegion)) {
parentRegions.push(currentNode.parentRegion);
}
} catch (error) {
// @ts-ignore
if (error.mMessage) {
// @ts-ignore
const [_resp, resp2, respAlt, eibfnAlt] = splitCmciErrorMessage(error.mMessage);
window.showErrorMessage(
`Perform CLOSE on local file "${allSelectedNodes[parseInt(index)].localFile.file
}" failed: EXEC CICS command (${eibfnAlt}) RESP(${respAlt}) RESP2(${resp2})`
);
} else {
window.showErrorMessage(
`Something went wrong when performing a CLOSE - ${JSON.stringify(error, Object.getOwnPropertyNames(error)).replace(
/(\\n\t|\\n|\\t)/gm,
" "
)}`
);
}
}
}
for (const parentRegion of parentRegions) {
try {
const localFileTree = parentRegion.children.filter((child: any) => child.contextValue.includes("cicstreelocalfile."))[0];
// Only load contents if the tree is expanded
if (localFileTree.collapsibleState === 2) {
await localFileTree.loadContents();
}
// if node is in a plex and the plex contains the region container tree
if (parentRegion.parentPlex && parentRegion.parentPlex.children.some((child) => child instanceof CICSRegionsContainer)) {
const allLocalFileTreeTree = parentRegion.parentPlex.children.filter((child: any) =>
child.contextValue.includes("cicscombinedlocalfiletree.")
)[0] as CICSCombinedLocalFileTree;
if (allLocalFileTreeTree.collapsibleState === 2 && allLocalFileTreeTree.getActiveFilter()) {
await allLocalFileTreeTree.loadContents(tree);
}
}
} catch (error) {
window.showErrorMessage(
`Something went wrong when reloading local files - ${JSON.stringify(error, Object.getOwnPropertyNames(error)).replace(
/(\\n\t|\\n|\\t)/gm,
" "
)}`
);
}
}
tree._onDidChangeTreeData.fire(undefined);
}
);
}
});
}
async function closeLocalFile(
session: imperative.AbstractSession,
parms: ICommandParams,
busyDecision: string
): Promise<ICMCIApiResponse> {
return runPutResource({
session: session,
resourceName: CicsCmciConstants.CICS_CMCI_LOCAL_FILE,
cicsPlex: parms.cicsPlex,
regionName: parms.regionName,
params: {"criteria": `FILE='${parms.name}'`}
}, {
request: {
action: {
$: {
name: "CLOSE",
},
parameter: {
$: {
name: "BUSY",
value: busyDecision,
},
},
},
},
});
}