Global.java
8.84 KB
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
package th.co.ais.ssbsrfc.utils;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.UUID;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.XML;
import th.co.ais.ssbsrfc.config.Constant;
import th.co.ais.ssbsrfc.config.StateConfig;
import th.co.ais.ssbsrfc.instance.AFInstance;
import th.co.ais.ssbsrfc.instance.EC02Instance;
import th.co.ais.ssbsrfc.instance.FMInstance;
import th.co.ais.ssbsrfc.message.EC02Builder;
import ais.mmt.sand.comlog.bean.DataBean;
import ais.mmt.sand.comlog.bean.DataBean.TYPE;
import com.google.gson.Gson;
import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;
import ec02.af.abstracts.AbstractAF;
import ec02.utils.AppLog;
public class Global
{
private static AbstractAF abstractAF = null;
private static EC02Builder ec02Builder = null;
private static boolean isOpenRawData = true;
private static String outputTimeStamp = null;
public static String inputTimeStamp = null;
public static String detailNameLog = null;
public static String summaryNameLog = null;
public static boolean isUDR = false;
public static boolean isDetail = true;
public static boolean isDetailRawData = true;
public static boolean isDetailData = true;
public static boolean isDetailStat = true;
public static boolean isDetailScenario = true;
public static boolean isDetailCurrentState = true;
public static boolean isDetailNextState = true;
public static boolean isSummary = false;
public static boolean isStat = true;
public static boolean isErrorLog = false;
public static int detailLog = 0;
public static String tmpDialogueId = null;
public static int minDialogueId = 0;
public static int maxDialogueId = 99;
public static int flow = 0;
public static HashMap<String, String> mapNode = new HashMap<String, String>();
public static HashMap<Integer, String> mapFlow = new HashMap<Integer, String>();
public static boolean isDebugModeForQA = false;
public static boolean isWriteSummary = false;
public static boolean isOutputTimeStamp = true;
public static boolean isRejectByApplication = false;
public static long currentInputDateTime;
public static boolean isOpenRawData() {
return isOpenRawData;
}
public static void getConfigEC02(AbstractAF abstractAF, EC02Instance ec02Instance)
{
Global.setNode();
Global.setFlow();
Global.flow = ec02Instance.getAFInstance().getFlow();
Global.abstractAF = abstractAF;
}
public static String getNodeFromEventType(String eventType) {
String node = mapNode.get(eventType);
// AppLog.d("## node:" + node + ":eventtype:" + eventType);
return node;
}
public static void setNode()
{
mapNode.put(StateConfig.Incoming_A_Request, Constant.nodeE01);
}
public static String getFlowName(int flow) {
String flowName = mapFlow.get(flow);
if(flowName == null) {
flowName = mapFlow.get(Constant.FLOW_Unexpected_Event_Handling);
}
return flowName;
}
public static void setFlow() {
//flow #1
mapFlow.put(Constant.FLOW_TEST_A, "TEST A");
}
public static void setOpenRawData(boolean isOpenRawData) {
Global.isOpenRawData = isOpenRawData;
}
public static void checkActiveLog(EC02Instance ec02Instance, String value)
{
String[] tempLog =null;
tempLog = value.split("\\|");
//"DETAIL|STAT|UDR"
for (int i = 0; i < tempLog.length; i++) {
if (tempLog[i].equalsIgnoreCase("DETAIL")) {
isDetail = true;
} else if (tempLog[i].equalsIgnoreCase("STAT")) {
isStat = true;
} else if (tempLog[i].equalsIgnoreCase("UDR")) {
isUDR = true;
} else if (tempLog[i].equalsIgnoreCase("SUMMARY")) {
isSummary = true;
} else if (tempLog[i].equalsIgnoreCase("ERROR")) {
isErrorLog = true;
}
}
}
public static FMInstance getInvokeForManageFlow(EC02Instance ec02Instance)
{
int flow = ec02Instance.getAFInstance().getFlow();
String date = ec02Instance.getAFInstance().getStartFlowTimeStamp();
return new FMInstance(flow, date);
}
public static void setRejectByApplication(boolean isRejectByApplication) {
Global.isRejectByApplication = isRejectByApplication;
// write summary
if (isRejectByApplication) {
Global.isWriteSummary = isRejectByApplication;
}
}
public static String getDetailLogRawData(String rawData) {
if (rawData != null) {
// rawData = StringEscapeUtils.escapeHtml(rawData);
// rawData = StringEscapeUtils.unescapeJava(rawData);
}
return rawData;
}
public static void setDetailLog(String value)
{
if (value.equals("0")) {
Global.detailLog = Constant.DETAILLOG.CLOSE.get();
} else if (value.equals("1")) {
Global.detailLog = Constant.DETAILLOG.OPENERROR.get();
} else if (value.equals("2")) {
Global.detailLog = Constant.DETAILLOG.OPEN.get();
}
}
public static String unescapePrintString(String value)
{
return value;
}
public static String getUnique()
{
return UUID.randomUUID().toString().replace("-", "");
}
public static DataBean.TYPE getDetailLogType(String strType) {
TYPE retType = null;
if(strType.toLowerCase().equals("request")) {
retType = TYPE.REQ;
} else {
retType = TYPE.RES;
}
return retType;
}
public static String encodeInstance(AFInstance instance) {
String encodeString = "";
try {
// check remove Timeout
int cout = instance.getListTimeout().size();
if (cout == 0) {
instance.setListTimeout(null);
}
Gson gson = new Gson();
String str = gson.toJson(instance);
byte[] bytes = str.getBytes();
byte[] zipBytes = Zip.compressBytes(bytes);
encodeString = Base64.encode(zipBytes);
}
catch (Exception e) {
AppLog.e("Encode fail!! " + e);
}
return encodeString;
}
public static AFInstance decodeInstance(String instance) {
AFInstance afInstance = null;
try {
byte[] simpleString = Base64.decode(instance);
byte[] unZipString = Zip.extractBytes(simpleString);
Gson gson = new Gson();
afInstance = gson.fromJson(new String(unZipString), AFInstance.class);
} catch (Exception e) {
AppLog.e("Decode fail!! " + e);
}
return afInstance;
}
public static String getOutputTimeStamp() {
return outputTimeStamp;
}
public static void setOutputTimeStamp(String outputTimeStamp) {
Global.outputTimeStamp = outputTimeStamp;
}
public static String getEC02WarmConfig(String key)
{
String value = null;
try {
value = Global.abstractAF.getUtils().getHmWarmConfig().get(key).get(0).trim();
AppLog.d("## GETCONFIG EC02 READDING(" + key + ") VALUE:" + value);
} catch (Exception e) {
AppLog.e("## CHECKCONFIG EC02 EXCEPTION(" + key + ") READ ERROR");
}
return value;
}
public static EC02Builder getEc02Builder() {
return ec02Builder;
}
public static void setEc02Builder(EC02Builder ec02Builder) {
Global.ec02Builder = ec02Builder;
}
public static String replaceSoapToXml(String value)
{
try {
JSONObject json = new JSONObject(value);
value = XML.toString(json);
AppLog.d("## CONVERT MESSAGE JSON TO XML :" + value);
} catch (JSONException e) { }
return value.replaceAll("(?s)<(\\w+):Envelope[^<>]*>.*?<\\1:Body>\\s*(.*?)\\s*</\\1:Body>\\s*</\\1:Envelope>", "$2").replaceAll(" xmlns(:\\w+)?=\"(.*)\"", "").replaceAll("\\<\\?xml(.+?)\\?\\>", "");
}
// LOG ETC
public static long convertTocurrentTimeMillis(String strDate)
{
DateFormat formatter = new SimpleDateFormat("yyyyMMdd HH:mm:ss.S");
long value = 0;
try {
Date date = formatter.parse(strDate);
Calendar cal = Calendar.getInstance();
cal.setTime(date);
value = cal.getTimeInMillis();
} catch (ParseException e) {
e.printStackTrace();
}
return value;
}
public static String getTimeStampLog (long currentDateTime)
{
Date date = new Date(currentDateTime);
SimpleDateFormat ft = new SimpleDateFormat ("yyyyMMdd HH:mm:ss.S");
// display time and date using toString()
String timestamp = ft.format(date);
return timestamp;
}
public static long diffTimeStampLog(String first, String last) throws ParseException
{
DateFormat formatter = new SimpleDateFormat("yyyyMMdd HH:mm:ss.S");
Date dateFist = formatter.parse(first);
Date dateLast = formatter.parse(last);
Calendar strF_Cal = Calendar.getInstance();
Calendar strL_Cal = Calendar.getInstance();
strF_Cal.setTime(dateFist);
strL_Cal.setTime(dateLast);
long lastLong = strL_Cal.getTimeInMillis();
long firstLong = strF_Cal.getTimeInMillis();
long diff = lastLong - firstLong;
return diff;
}
public static String datePartnerTimestamp(String value)
{
String partner = "";
try {
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
DateFormat newFttr = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss.S");
Date date = formatter.parse(value);
partner = newFttr.format(date);
} catch (ParseException e) { }
return partner;
}
public static String getXmlTemplateKey(String keyType, String id) {
return keyType + "[id='"+id+"']";
}
}