package th.co.ais.ssbsrfc.config; import th.co.ais.ssbsrfc.instance.CheckRequest; import th.co.ais.ssbsrfc.instance.EC02Instance; import th.co.ais.ssbsrfc.utils.Log; import ec02.af.abstracts.AbstractAF; import ec02.af.data.EquinoxRawData; import ec02.utils.AppLog; public class StateConfig { //define project name public static final String PROJECT_NAME = "LBCF"; public static String PROJECT_STAT_NAME = PROJECT_NAME; public static final boolean isMultiFlow = false; //define main state public static final String STATE_IDLE = "IDLE"; public static final String STATE_ACTIVE = "ACTIVE"; public static final String STATE_E11_TIMEOUT = "E11_TIMEOUT"; //define sub state public static final String SSTATE_UNKNOWN = "UNKNOWN"; public static final String SSTATE_REJECT = "REJECT"; public static final String SSTATE_ABORT = "ABORT"; public static final String SSTATE_BEGIN = "BEGIN"; public static final String SSTATE_END = "END"; public static final String SSTATE_W_A = "W_A"; public static final String SSTATE_W_CHARGEREQUEST = "W_CHARGEREQUEST"; public static final String SSTATE_W_CHARGEREPORT = "W_CHARGEREPORT"; public static final String SSTATE_W_ADJUSTMENT_CHARGEREQUEST = "W_ADJUSTMENTRESPONSE_CHARGEREQUEST"; public static final String SSTATE_W_ADJUSTMENT_CHARGEREPORT = "W_ADJUSTMENTRESPONSE_CHARGEREPORT"; //define event public static final String Incoming_Unknown ="Incoming_Unknown"; public static final String Incoming_REJECT ="Incoming_REJECT"; public static final String Incoming_ABORT ="Incoming_ABORT"; public static final String Incoming_A_Request = "Incoming_A_Request"; public static final String Incoming_ChargeRequest_Request = "Incoming_ChargeRequest_Request"; public static final String Incoming_ChargeReport_Request = "Incoming_ChargeReport_Request"; public static final String Incoming_Adjustment_ChargeRequest_Response = "Incoming_Adjustment_ChargeRequest_Response"; public static final String Incoming_Adjustment_ChargeReport_Response = "Incoming_Adjustment_ChargeReport_Response"; //define LASE (Log, Alarm, Stat, Error) public static final String LASE_Unknown = "Unknown Command"; public static final String LASE_Reject = "Unknown Reject"; public static final String LASE_Abort = "Unknown Abort"; // define frist state of each flow public static final String[] arrFirstStateFlow = { SSTATE_W_CHARGEREQUEST,SSTATE_W_CHARGEREPORT, }; // SSTATE_UNKNOWN //define sub state list and messages that relate to public static State subStateList[] = { new State(SSTATE_REJECT, Incoming_REJECT, LASE_Reject), new State(SSTATE_ABORT, Incoming_ABORT, LASE_Abort), new State(SSTATE_END, Incoming_Unknown, LASE_Unknown), new State(SSTATE_W_CHARGEREQUEST, Incoming_ChargeRequest_Request, "Test A", "Test A", Constant.TYPE_REQUEST, Constant.FLOW_TEST_A), new State(SSTATE_W_CHARGEREPORT, Incoming_ChargeReport_Request, "Test A", "Test A", Constant.TYPE_REQUEST, Constant.FLOW_TEST_A), new State(SSTATE_W_ADJUSTMENT_CHARGEREQUEST, Incoming_Adjustment_ChargeRequest_Response, "Test A", "Test A", Constant.TYPE_REQUEST, Constant.FLOW_TEST_A), new State(SSTATE_W_ADJUSTMENT_CHARGEREPORT, Incoming_Adjustment_ChargeReport_Response, "Test A", "Test A", Constant.TYPE_REQUEST, Constant.FLOW_TEST_A), // new State(SSTATE_W_A, Incoming_A_Request, "Test A", "Test A", Constant.TYPE_RESPONSE), new State(SSTATE_END, Incoming_Unknown,"Unknown_Command"), }; //define event type message filter public static final EventFilter[] eventFilter = { // Flow 0 new EventFilter(Incoming_ChargeRequest_Request, "request", "text/plain", null, null), new EventFilter(Incoming_ChargeReport_Request, "request", "text/plain", null, null), new EventFilter(Incoming_Adjustment_ChargeRequest_Response, "request", "text/plain", null, null), new EventFilter(Incoming_Adjustment_ChargeReport_Response, "request", "text/plain", null, null), }; public static String getSubStateFromEventType(String eventType) { String subState=""; try { // find sub state to handler event type for(int i=0; i < subStateList.length; i++) { State state = subStateList[i]; String ssName = state.name; String ssEventType = state.eventType; // if we found matching relation if(eventType.equals(ssEventType)) { subState = ssName; break; } } } catch (Exception e) { AppLog.e("ERROR: getSubStateFromEventType!! eventType:" + eventType + "desc: " + e); } return subState; } public static String getEventTypeFromSubState(String subState) { String eventType = ""; try { // find sub state to handler event type for(int i=0; i < subStateList.length; i++) { State state = subStateList[i]; String sstate = state.name; String ssEventType = state.eventType; // if we found matching relation if(sstate.equals(subState)) { eventType = ssEventType; break; } } } catch (Exception e) { AppLog.e("ERROR: getEventTypeFromSubState!! subState:" + subState + "desc: " + e); } return eventType; } public static String getCommandFromEventType(String eventType) { String command=""; try { // find sub state to handler event type for(int i=0; i < subStateList.length; i++) { State state = subStateList[i]; String ssCommand = state.nameReq; String ssEventType = state.eventType; // if we found matching relation if(eventType.equals(ssEventType)) { command = ssCommand; break; } } } catch (Exception e) { AppLog.e("ERROR: getSubStateFromEventType!! eventType:" + eventType + "desc: " + e); } return command; } public static void changeCommandFromEventType(String eventType, String command) { try { // find sub state to handler event type for(int i=0; i < subStateList.length; i++) { State state = subStateList[i]; String ssEventType = state.eventType; // if we found matching relation if(eventType.equals(ssEventType)) { subStateList[i].setLASEName(command); break; } } } catch (Exception e) { AppLog.e("ERROR: changeCommangFromEventType!! eventType:" + eventType + " new command:" + command + " desc: " + e); } } public static int getFlowFromEventType(String eventType) { int flow = -1; try { // find sub state to handler event type for(int i=0; i < subStateList.length; i++) { State state = subStateList[i]; String ssEventType = state.eventType; int ssFlow = state.flow; // if we found matching relation if(eventType.equals(ssEventType)) { flow = ssFlow; break; } } } catch (Exception e) { AppLog.e("ERROR: getFlowFromEventType!! eventType:" + eventType + "desc: " + e); } return flow; } public static String getCommandFromState(String subState) { String command=""; try { // find sub state to handler event type for(int i=0; i < subStateList.length; i++) { State state = subStateList[i]; String ssCommand = state.nameReq; String ssState = state.name; // if we found matching relation if(subState.equals(ssState)) { command = ssCommand; break; } } } catch (Exception e) { AppLog.e("ERROR: getSubStateFromEventType!! eventType:" + subState + "desc: " + e); } return command; } public static String getCommandFromStateAndType(String subState, int type) { String command=""; try { // find sub state to handler event type for(int i=0; i < subStateList.length; i++) { State state = subStateList[i]; String ssCmdReq= state.nameReq; String ssCmdRes= state.nameRes; String ssState = state.name; // if we found matching relation if(subState.equals(ssState)) { if (type == Constant.TYPE_REQUEST) { command = ssCmdReq; } else if (type == Constant.TYPE_RESPONSE) { command = ssCmdRes; } break; } } } catch (Exception e) { AppLog.e("ERROR: getSubStateFromEventType!! eventType:" + subState + "desc: " + e); } return command; } public static int getSubStateIndex(String currentState) { int idx=-1; // find sub state to handler event type for(int i=0; i < subStateList.length; i++) { State state = subStateList[i]; String ssName = state.name; // if we found matching relation if(currentState.equals(ssName)) { idx = i; } } return idx; } public static boolean isFirstState(String state) { boolean first = false; for (String _state : arrFirstStateFlow) { if (_state.contains(state)) { first = true; break; } } return first; } public static void setNextSubState(EC02Instance ec02Instance) { // get current state String currentState = ec02Instance.getAFInstance().getCurrentState(); String nextState = StateConfig.getNextSubState(currentState); ec02Instance.getAFInstance().setCurrentState(nextState); // end } public static String getNextSubState(String currentState) { if(currentState.equals(SSTATE_END)) { return SSTATE_END; } int idx = getSubStateIndex(currentState); if(idx != -1) { idx++; State state = subStateList[idx]; String ssName = state.name; return ssName; } else //if not found { return SSTATE_UNKNOWN; } } public static String getEventTypeFromInvoke(String invokeMsg) { String eventType = null; Invoke invoke = new Invoke(invokeMsg); eventType = invoke.getEventType(); return eventType; } public static boolean isValidateEventType(String eventType) { boolean isValidate = false; // find sub state to handler event type for(int i=0; i < subStateList.length; i++) { State state = subStateList[i]; String ssEventType = state.eventType; // if we found matching relation if(ssEventType.equals(eventType)) { isValidate = true; } } return isValidate; } public static String getEventTypeFromEquinoxRawData(EC02Instance ec02Instance, EquinoxRawData rawData) { String eventType = null; // 1.1.1. Extract type, ctype, method, invoke, ret attributes. String type = rawData.getRawDataAttribute("type"); String ctype = rawData.getRawDataAttribute("ctype"); String method = rawData.getRawDataAttribute("method"); String invoke = rawData.getInvoke(); String cmd = ""; /*String ret = rawData.getRawDataAttribute("ret"); // 1.1.2. If ret in (1, 2, 3, 4) Then if (ret.equals("2")) { return StateConfig.Incoming_REJECT; } else if (ret.equals("3")) { return StateConfig.Incoming_ABORT; }*/ // if (type.equals("response")) { // ArrayList listTimeout = ec02Instance.getAFInstance().getListTimeout(); // boolean isBool = false; // for (Timeout timeout : listTimeout) { // if (timeout.getName().equals(invoke)) { // isBool = true; // } // } // if (!isBool) { // return StateConfig.Incoming_Unknown; // } // } // 1.1.3. Try to get event type from invoke if(invoke != null && invoke.length() >0) { // 1.1.4. If valid event type Then String event = getEventTypeFromInvoke(invoke); if(event != null && isValidateEventType(event)) { // 1.1.4.1. Set event type = return event; } } // 1.1.6. Get event type from type, ctype, method, cmd int maxCount = 0; for(int i=0; i < eventFilter.length; i++) { EventFilter ef = eventFilter[i]; boolean bMatch = false; int count = 0; //use for count matched in each parameter // try matching 1 by 1 // check type if(ef.type != null) { if(type.equals(ef.type)) { bMatch = true; count++; } else bMatch = false; } // check ctype if(ef.ctype != null) { if(ctype.equals(ef.ctype)) { bMatch = true; count++; } else bMatch = false; } // check method if(ef.method != null) { if(method.equals(ef.method)) { bMatch = true; count++; } else bMatch = false; } // check cmd if(ef.cmd != null) { if(cmd.equals(ef.cmd)) { bMatch = true; count++; } else bMatch = false; } //check and set maxCount for use to select event type if(bMatch && count > maxCount) { maxCount = count; //set return event type to this matched eventType = ef.eventType; } if (eventType.equals(StateConfig.Incoming_ChargeRequest_Request)) { //String page = rawData.getRawDataMessage(); String page = rawData.getRawDataAttribute("val"); CheckRequest checkRequest = new CheckRequest(); checkRequest.setDn(page); String [] dnList = checkRequest.getDn().split("&", -1); page = dnList[0].substring("page=".length()); if (page.equals("chargeRequest")) { eventType = StateConfig.Incoming_ChargeRequest_Request; } else if (page.equals("chargeReport")) { eventType = StateConfig.Incoming_ChargeReport_Request; } } } return eventType; } public static String getLASEName(String currentSubState, int sendOrReceive, int responseOrRequest, int missingOrInvalidOrTARE, String errMsg) { String name = StateConfig.getLASEName(currentSubState, sendOrReceive, responseOrRequest, missingOrInvalidOrTARE, errMsg, null); return name; } public static String getLASEName(String currentSubState, int sendOrReceive, int responseOrRequest, int missingOrInvalidOrTARE, String errMsg, String command, int flow) { switch (flow) { default: StateConfig.PROJECT_STAT_NAME = StateConfig.PROJECT_NAME; break; } String name = StateConfig.getLASEName(currentSubState, sendOrReceive, responseOrRequest, missingOrInvalidOrTARE, errMsg, command); return name; } public static String getLASEName(String currentSubState, int sendOrReceive, int responseOrRequest, int missingOrInvalidOrTARE, String errMsg, String command) { // AppLog.d("## [mSSB-SRFC] [Send|Received] [Bad] [Response|Request] [Timeout|Abort|Reject|Error] [errMsg]"); // AppLog.d("## getLASEName :" + currentSubState + "/" + sendOrReceive + "/" + responseOrRequest + "/" + missingOrInvalidOrTARE + "/" + errMsg); String stateName = null; // int idx = StateConfig.getSubStateIndex(currentSubState); // State state = StateConfig.subStateList[idx]; String LASEName = StateConfig.getCommandFromStateAndType(currentSubState, responseOrRequest); /* * [mSSB-SRFC] [Send|Received] [Bad] [Response|Request] [Timeout|Abort|Reject|Error] */ String sr = ""; switch (sendOrReceive) { case Constant.TYPE_SEND: sr = Constant.SEND; break; case Constant.TYPE_RECEIVE: sr = Constant.RECEIVE; break; } String rr = ""; switch (responseOrRequest) { case Constant.TYPE_RESPONSE: rr = Constant.RESPONSE + " "; break; case Constant.TYPE_REQUEST: rr = Constant.REQUEST + " "; break; } //Timeout, Abort, Reject, Error String tare = ""; String bad = ""; String cmd = ""; switch (missingOrInvalidOrTARE) { case Constant.TYPE_MISSING: bad = Constant.BAD + " "; break; case Constant.TYPE_INVALID: bad = Constant.BAD + " "; break; case Constant.TYPE_DUPLICATE: bad = Constant.DUPLICATE + " "; break; case Constant.TYPE_TIMEOUT: tare = Constant.TIMEOUT; break; case Constant.TYPE_ABORT: tare = Constant.ABORT; break; case Constant.TYPE_REJECT: tare = Constant.REJECT; break; case Constant.TYPE_ERROR: case Constant.TYPE_UNKNOWN_ERROR: tare = Constant.ERROR; break; } if (command != null) { cmd = command; } else { if (missingOrInvalidOrTARE == Constant.TYPE_REJECT_APPLICATION) { cmd = "Unknown"; rr = Constant.REQUEST + " "; } else { cmd = LASEName; } } stateName = StateConfig.PROJECT_STAT_NAME + " " + sr + " " + bad + cmd + " " + rr + tare; stateName = stateName.trim(); return stateName; } public static String getTimeout(AbstractAF abstractAF, String event) { String timeout = StateConfig.getTimeout(abstractAF, event, null); return timeout; } public static String getTimeout(AbstractAF abstractAF, String event, String command) { String time = "10"; String configName = "Default-timeout"; try { if (event.equals(StateConfig.Incoming_Unknown)) { configName = "Wait-Get-File-Timeout"; } else { configName = "Default-timeout"; } time = abstractAF.getUtils().getHmWarmConfig().get(configName).get(0); AppLog.d("## SET TIMEOUT: " + configName + " " + time + " sec"); } catch (Exception e) { if (Log.debug) { AppLog.d("## CHECKCONFIG EC02 READDING..."); AppLog.d("## EXCEPTION : " + e.getMessage()); AppLog.d("## DATA EVENTTYPE OR INVOKE:" + event + " COMMAND:" + command); } } return time; } }