Blame view

src/th/co/ais/ssbsrfc/control/mainAF.java 3.97 KB
1048b156   Suraputt Suntimitr   Template
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
package th.co.ais.ssbsrfc.control;

import java.util.ArrayList;

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.utils.Global;
import ec02.af.abstracts.AbstractAF;
import ec02.af.data.ECDialogue;
import ec02.af.data.EquinoxProperties;
import ec02.af.data.EquinoxRawData;
import ec02.af.exception.ActionProcessException;
import ec02.af.exception.ComposeInstanceException;
import ec02.af.exception.ConstructRawDataException;
import ec02.af.exception.ExtractInstanceException;
import ec02.af.exception.ExtractRawDataException;
import ec02.interfaces.IEC02;
import ec02.utils.AppLog;

public class mainAF extends AbstractAF implements IEC02 {

	@Override
	public ECDialogue actionProcess(EquinoxProperties eqxProp,
			ArrayList<EquinoxRawData> eqxRawDataList, Object instance)
			throws ActionProcessException {
		AppLog.d("[CURRENT STATE] : " + eqxProp.getState());
		EC02Instance ec02Ins = (EC02Instance) instance;
		ec02Ins.setEquinoxProperties(eqxProp);
		ec02Ins.setAbstractAF((AbstractAF) this);
		ec02Ins.getAFInstance().setStartFlowTimeStampForEmpty();
		
		String currentState = eqxProp.getState();				
		
		StateManager sm = new StateManager(currentState);
		String eqxState = sm.doAction((AbstractAF) this, ec02Ins, eqxRawDataList);
		EquinoxProperties newEqxProp = new EquinoxProperties();
		newEqxProp.setState(eqxState);
		// TODO must be have function to calculate timeout
		newEqxProp.setTimeout(ec02Ins.getTimeout());
		ECDialogue ecDialogue = new ECDialogue(newEqxProp, ec02Ins);
		return ecDialogue;
	}

	@Override
	public boolean verifyAFConfiguration(String arg0) {
		// TODO Auto-generated method stub
		return true;
	}

	/*
	 * 5.4 ComposeInstance Module
	 */
	@Override
	public String composeInstance(Object instance) throws ComposeInstanceException {
		// 1. Read instance into variable
		EC02Instance ec02Instance = (EC02Instance) instance;
		AFInstance afInstance = ec02Instance.getAFInstance();
		String encodeString = "";
		// 2. try to encode instanceData bean object into string format
		try {
			encodeString = Global.encodeInstance(afInstance);
		}
		catch (Exception e) {
			e.printStackTrace();
		}
		// 3. return instanceData in string format
		return encodeString;
	}

	/*
	 * 5.3 ConstructRawData Module
	 */
	@Override
	public ArrayList<EquinoxRawData> constructRawData(Object instance)
			throws ConstructRawDataException {
		// 1. Read instance into variable
		EC02Instance ins = (EC02Instance) instance;
		ArrayList<EquinoxRawData> list = ins.getEqxRawDataList();
		// 2. Return equinox raw data
		return list;
	}

	/*
	 * 5.1 ExtractInstance Module
	 */
	@Override
	public Object extractInstance(String instance) throws ExtractInstanceException {
		
		EC02Instance ec02Instance = new EC02Instance();
		AFInstance afInstance = null;
		
		// 1. Check instance data from equinox is null or not
		if ((instance == null) || instance.isEmpty()) {
			// 1.1. If instance data is null, create new instanceData bean object
			afInstance = new AFInstance();
		} 
		else {
			// 1.2. If instance data is not null, try to decode instance to instanceData bean object
			try {
				afInstance = Global.decodeInstance(instance);
			}
			catch (Exception e) {
				e.printStackTrace();
			}
		}
		ec02Instance.setAFInstance(afInstance);
		// 2. return instanceData bean object
		return (Object) ec02Instance;
	}

	/*
	 * 5.2 ExtractRawData Module
	 */
	@Override
	public void extractRawData(Object instanceData, ArrayList<EquinoxRawData> rawDatas)
			throws ExtractRawDataException {
		EC02Instance ec02Instance = (EC02Instance) instanceData;
		// 1. Loop RawData
		for (EquinoxRawData r : rawDatas) {
			// 1.1.	Get event type from equinox raw data
			String eventType = StateConfig.getEventTypeFromEquinoxRawData(ec02Instance, r);
			// 1.1.7. Set raw event type = event type
			r.setRawEventType(eventType);
			ec02Instance.getAFInstance().listTimeoutRemove(r.getInvoke());
			AppLog.d("[eventType] : " + eventType);
		}
	}
}