/
TsoResponseService.ts
100 lines (92 loc) · 3.99 KB
/
TsoResponseService.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
/*
* 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 { ImperativeError } from "@zowe/imperative";
import { IZosmfTsoResponse } from "./doc/zosmf/IZosmfTsoResponse";
import { IStartStopResponse } from "./doc/IStartStopResponse";
import { TsoValidator } from "./TsoValidator";
import { IStartStopResponses } from "./doc/IStartStopResponses";
import { ICollectedResponses } from "./doc/ICollectedResponses";
import { IZosmfPingResponse } from "./doc/zosmf/IZosmfPingResponse";
import { IPingResponse } from "./doc/IPingResponse";
/**
* Filter responses from z/OSMF
* @export
* @class TsoResponseService
*/
export class TsoResponseService {
/**
* Populates start and stop commands response with z/OSMF response details
* @param {IZosmfTsoResponse} zosmfResponse - z/OSMF response object, @see {IZosmfTsoResponse}
* @returns {IStartStopResponse} populated object with type of IStartStopResponse, @see {IStartStopResponse}
* @memberof TsoResponseService
*/
public static populateStartAndStop(zosmfResponse: IZosmfTsoResponse): IStartStopResponse {
TsoValidator.validateStartZosmfResponse(zosmfResponse);
const startResponse: IStartStopResponse = {
success: false,
zosmfTsoResponse: zosmfResponse,
servletKey: zosmfResponse.servletKey
};
if (zosmfResponse.servletKey != null) {
startResponse.success = true;
} else if (zosmfResponse.msgData) {
startResponse.failureResponse = new ImperativeError({
msg: zosmfResponse.msgData[0].messageText
});
}
return startResponse;
}
/**
* Populates start and stop commands response with z/OSMF response details
* @param {IZosmfTsoResponse} zosmfResponse - z/OSMF response object, @see {IZosmfTsoResponse}
* @param {ICollectedResponses} collectedResponses - collected z/OSMF responses object, @see {ICollectedResponses}
* @returns {IStartStopResponse} populated object with type of IStartStopResponse, @see {IStartStopResponse}
* @memberof TsoResponseService
*/
public static populateStartAndStopCollectAll(zosmfResponse: IZosmfTsoResponse, collectedResponses?: ICollectedResponses): IStartStopResponses {
TsoValidator.validateStartZosmfResponse(zosmfResponse);
const startResponse: IStartStopResponses = {
success: false,
zosmfTsoResponse: zosmfResponse,
servletKey: zosmfResponse.servletKey,
collectedResponses: collectedResponses?.tsos ?? null,
messages: collectedResponses?.messages ?? ""
};
if (zosmfResponse.servletKey != null) {
startResponse.success = true;
} else if (zosmfResponse.msgData) {
startResponse.failureResponse = new ImperativeError({
msg: zosmfResponse.msgData[0].messageText
});
}
return startResponse;
}
/**
* Populates ping command response with z/OSMF response details
* @param {IZosmfPingResponse} zosmfResponse - z/OSMF response object, @see {IZosmfPingResponse}
* @returns {PingResponse} populated object with type of IPingResponse
* @memberof TsoResponseService
*/
public static populatePing(zosmfResponse: IZosmfPingResponse): IPingResponse {
TsoValidator.validatePingZosmfResponse(zosmfResponse);
const PingResponse: IPingResponse = {
success: false,
zosmfPingResponse: null,
servletKey: null
};
if (zosmfResponse.servletKey != null) {
PingResponse.success = true;
PingResponse.zosmfPingResponse = zosmfResponse;
PingResponse.servletKey = zosmfResponse.servletKey;
}
return PingResponse;
}
}