1 | import { ResponseParser } from "./responseparser";
|
2 | import { ResponseTemplateManager } from "./responsetemplatemanager";
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | export class ResponseTemplate {
|
8 | |
9 |
|
10 |
|
11 | protected raw: string;
|
12 | |
13 |
|
14 |
|
15 | protected hash: any;
|
16 |
|
17 | |
18 |
|
19 |
|
20 |
|
21 | public constructor(raw: string) {
|
22 | if (!raw) {
|
23 | raw = ResponseTemplateManager.getInstance().getTemplate("empty").getPlain();
|
24 | }
|
25 | this.raw = raw;
|
26 | this.hash = ResponseParser.parse(raw);
|
27 | if (
|
28 | !Object.prototype.hasOwnProperty.call(this.hash, "CODE") ||
|
29 | !Object.prototype.hasOwnProperty.call(this.hash, "DESCRIPTION")
|
30 | ) {
|
31 | this.raw = ResponseTemplateManager.getInstance().getTemplate("invalid").getPlain();
|
32 | this.hash = ResponseParser.parse(this.raw);
|
33 | }
|
34 | }
|
35 |
|
36 | |
37 |
|
38 |
|
39 |
|
40 | public getCode(): number {
|
41 | return parseInt(this.hash.CODE, 10);
|
42 | }
|
43 |
|
44 | |
45 |
|
46 |
|
47 |
|
48 | public getDescription(): string {
|
49 | return this.hash.DESCRIPTION;
|
50 | }
|
51 |
|
52 | |
53 |
|
54 |
|
55 |
|
56 | public getPlain(): string {
|
57 | return this.raw;
|
58 | }
|
59 |
|
60 | |
61 |
|
62 |
|
63 |
|
64 | public getQueuetime(): number {
|
65 | if (Object.prototype.hasOwnProperty.call(this.hash, "QUEUETIME")) {
|
66 | return parseFloat(this.hash.QUEUETIME);
|
67 | }
|
68 | return 0.00;
|
69 | }
|
70 |
|
71 | |
72 |
|
73 |
|
74 |
|
75 | public getHash(): any {
|
76 | return this.hash;
|
77 | }
|
78 |
|
79 | |
80 |
|
81 |
|
82 |
|
83 | public getRuntime(): number {
|
84 | if (Object.prototype.hasOwnProperty.call(this.hash, "RUNTIME")) {
|
85 | return parseFloat(this.hash.RUNTIME);
|
86 | }
|
87 | return 0.00;
|
88 | }
|
89 |
|
90 | |
91 |
|
92 |
|
93 |
|
94 |
|
95 | public isError(): boolean {
|
96 | return this.hash.CODE.charAt(0) === "5";
|
97 | }
|
98 |
|
99 | |
100 |
|
101 |
|
102 |
|
103 |
|
104 | public isSuccess(): boolean {
|
105 | return this.hash.CODE.charAt(0) === "2";
|
106 | }
|
107 |
|
108 | |
109 |
|
110 |
|
111 |
|
112 |
|
113 | public isTmpError(): boolean {
|
114 | return this.hash.CODE.charAt(0) === "4";
|
115 | }
|
116 |
|
117 | |
118 |
|
119 |
|
120 |
|
121 | public isPending(): boolean {
|
122 | return (Object.prototype.hasOwnProperty.call(this.hash, "PENDING") ? this.hash.PENDING === "1" : false);
|
123 | }
|
124 | }
|