package th.co.ais.ssbsrfc.message; import java.util.ArrayList; import th.co.ais.ssbsrfc.config.Constant; import th.co.ais.ssbsrfc.config.Invoke; import th.co.ais.ssbsrfc.config.StateConfig; import th.co.ais.ssbsrfc.instance.EC02Instance; import th.co.ais.ssbsrfc.instance.EQXRawInstance; import th.co.ais.ssbsrfc.instance.Response; import th.co.ais.ssbsrfc.instance.Stat; import th.co.ais.ssbsrfc.interfaces.Atomic; import th.co.ais.ssbsrfc.interfaces.EQXMsg; import th.co.ais.ssbsrfc.utils.EqxStringUtils; import th.co.ais.ssbsrfc.utils.Global; import th.co.ais.ssbsrfc.utils.Log; import ais.mmt.sand.comlog.DetailsLogPrototype; import ais.mmt.sand.comlog.bean.DataBean; import ais.mmt.sand.comlog.bean.DataBean.TYPE; import ais.mmt.sand.comlog.exception.CommonLogException; import ec02.af.abstracts.AbstractAF; import ec02.af.data.EquinoxRawData; import ec02.af.data.KeyObject; import ec02.utils.AppLog; public class EC02Builder { private EC02Instance ec02Ins = null; private AbstractAF abstractAF = null; private EquinoxRawData eqxRawData =null; private EC02MSGBuilder msgBuilder = null; public void setEquinoxRawData(AbstractAF abstractAF, EC02Instance ec02Ins){ this.abstractAF = abstractAF; this.ec02Ins = ec02Ins; } public void setEquinoxRawData(EquinoxRawData eqxRawData, AbstractAF abstractAF, EC02Instance ec02Ins){ this.eqxRawData = eqxRawData; this.abstractAF = abstractAF; this.ec02Ins = ec02Ins; } public ArrayList getHTTPRequest(ArrayList eqxRawList){ ArrayList eqxRawDataList = new ArrayList(); String timeout = null; for (int i = 0; i < eqxRawList.size(); i++) { String type = eqxRawList.get(i).getType(); if (type == null) { eqxRawList.get(i).setType(EQXMsg.REQUEST); } this.msgBuilder = new EC02MSGBuilder(eqxRawList.get(i)); this.msgBuilder.setInvoke(this.ec02Ins.getAFInstance().getInvoke() + i); timeout = eqxRawList.get(i).getTimeout(); EquinoxRawData rowData = this.msgBuilder.getHttpMessage(); this.logDetailOutput(rowData, eqxRawList.get(i).getDataOutput(), eqxRawList.get(i).getNodeTo(), eqxRawList.get(i).getCommand()); eqxRawDataList.add(rowData); } if (timeout != null) { this.ec02Ins.setTimeout(timeout); } this.ec02Ins.getAFInstance().getListStat().add(new Stat(StateConfig.PROJECT_STAT_NAME + " Send Total Armed Event")); return eqxRawDataList; } public EquinoxRawData getRequest(EQXRawInstance eqxRaw) { String type = eqxRaw.getType(); if (type == null) { eqxRaw.setType(EQXMsg.REQUEST); } this.msgBuilder = new EC02MSGBuilder(eqxRaw); this.msgBuilder.setInvoke(this.ec02Ins.getAFInstance().getInvoke()); String timeout = eqxRaw.getTimeout(); if (timeout != null) { this.ec02Ins.setTimeout(timeout); } EquinoxRawData rowData = this.msgBuilder.getHttpMessage(); this.logDetailOutput(rowData, eqxRaw.getDataOutput(), eqxRaw.getNodeTo(), eqxRaw.getCommand()); return rowData; } public EquinoxRawData getRequestJobTracking(EQXRawInstance eqxRaw) { String type = eqxRaw.getType(); if (type == null) { eqxRaw.setType(EQXMsg.REQUEST); } this.msgBuilder = new EC02MSGBuilder(eqxRaw); this.msgBuilder.setInvoke(this.ec02Ins.getAFInstance().getInvoke()); String timeout = eqxRaw.getTimeout(); if (timeout != null) { this.ec02Ins.setTimeout(timeout); } // set orig/invoke String key = eqxRaw.getInvoke(); String orig = ""; String invoke = ""; if (this.eqxRawData != null) { orig = this.eqxRawData.getRawDataAttribute(EQXMsg.ORIG); invoke = this.eqxRawData.getInvoke(); } else { orig = this.ec02Ins.getAFInstance().getOrig(); invoke = this.ec02Ins.getAFInstance().getInvoke(); } if (!(new Invoke(key).eventType).equals(EQXMsg.UNKNOWN)) { Response res = new Response (orig, invoke) ; this.ec02Ins.getAFInstance().setListOrigKey(key, res); // AppLog.d("## RESPONSE[MG]: " + orig + "/" + invoke); } EquinoxRawData rowData = this.msgBuilder.getHttpMessage(); this.logDetailOutput(rowData, eqxRaw.getDataOutput(), eqxRaw.getNodeTo(), eqxRaw.getCommand()); return rowData; } public EquinoxRawData getHTTPResponse(EQXRawInstance eqxRaw){ eqxRaw.setType(EQXMsg.RESPONSE); this.msgBuilder = new EC02MSGBuilder(eqxRaw); String invoke = (eqxRaw.getInvoke() == null) ? this.ec02Ins.getAFInstance().getInvoke() : eqxRaw.getInvoke(); if (invoke != null && !invoke.equals("")) { this.msgBuilder.setInvoke(invoke); } EquinoxRawData rowData = this.msgBuilder.getHttpMessage(); this.logDetailOutput(rowData, eqxRaw.getDataOutput(), eqxRaw.getNodeTo(), eqxRaw.getCommand()); String subState = (eqxRaw.getSubState() == null) ? "" : eqxRaw.getSubState(); if (!subState.equals("")) { rowData.getRawDataAttributes().put("subState", subState); } String timeout = eqxRaw.getTimeout(); if (timeout != null) { this.ec02Ins.setTimeout(timeout); } return this.msgBuilder.getHttpMessage(); } /*public ArrayList getLDAPRequest(ArrayList eqxRawList){ ArrayList eqxRawDataList = new ArrayList(); for (int i = 0; i < eqxRawList.size(); i++) { eqxRawList.get(i).setType(EQXMsg.REQUEST); this.msgBuilder = new EC02MSGBuilder(eqxRawList.get(i)); this.msgBuilder.setInvoke(this.ec02Ins.getAFInstance().getInvoke() + i); eqxRawDataList.add(this.msgBuilder.getLdapMessage()); } String timeoutConf = this.abstractAF.getUtils().getHmWarmConfig().get("LDAP-timeout").get(0); String timeout = (timeoutConf == null) ? this.ec02Ins.getAbstractAF().getUtils().getHmWarmConfig().get("Default-timeout").get(0) : timeoutConf; this.ec02Ins.setTimeout(timeout); return eqxRawDataList; } public EquinoxRawData getLDAPResponse(EQXRawInstance eqxRaw){ eqxRaw.setType(EQXMsg.RESPONSE); this.msgBuilder = new EC02MSGBuilder(eqxRaw); this.msgBuilder.setInvoke(this.ec02Ins.getAFInstance().getInvoke()); return this.msgBuilder.getLdapMessage(); } public ArrayList getSMPPRequest(ArrayList eqxRawList){ ArrayList eqxRawDataList = new ArrayList(); for (int i = 0; i < eqxRawList.size(); i++) { eqxRawList.get(i).setType(EQXMsg.REQUEST); this.msgBuilder = new EC02MSGBuilder(eqxRawList.get(i)); this.msgBuilder.setInvoke(this.ec02Ins.getAFInstance().getInvoke() + i); eqxRawDataList.add(this.msgBuilder.getSMPPMessage()); } String timeoutConf = this.abstractAF.getUtils().getHmWarmConfig().get("SMPP-timeout").get(0); String timeout = (timeoutConf == null) ? this.ec02Ins.getAbstractAF().getUtils().getHmWarmConfig().get("Default-timeout").get(0) : timeoutConf; this.ec02Ins.setTimeout(timeout); return eqxRawDataList; } public EquinoxRawData getSMPPResponse(EQXRawInstance eqxRaw){ eqxRaw.setType(EQXMsg.RESPONSE); this.msgBuilder = new EC02MSGBuilder(eqxRaw); this.msgBuilder.setInvoke(this.ec02Ins.getAFInstance().getInvoke()); return this.msgBuilder.getSMPPMessage(); }*/ public ArrayList getDiameterRequest(ArrayList eqxRawList){ ArrayList eqxRawDataList = new ArrayList(); for (int i = 0; i < eqxRawList.size(); i++) { eqxRawList.get(i).setType(EQXMsg.REQUEST); this.msgBuilder = new EC02MSGBuilder(eqxRawList.get(i)); this.msgBuilder.setInvoke(this.ec02Ins.getAFInstance().getInvoke() + i); eqxRawDataList.add(this.msgBuilder.getDiameterMessage()); } String timeoutConf = this.abstractAF.getUtils().getHmWarmConfig().get("Diameter-timeout").get(0); String timeout = (timeoutConf == null) ? this.ec02Ins.getAbstractAF().getUtils().getHmWarmConfig().get("Default-timeout").get(0) : timeoutConf; this.ec02Ins.setTimeout(timeout); return eqxRawDataList; } public EquinoxRawData getDiameterResponse(EQXRawInstance eqxRaw){ eqxRaw.setType(EQXMsg.RESPONSE); this.msgBuilder = new EC02MSGBuilder(eqxRaw); this.msgBuilder.setInvoke(this.ec02Ins.getAFInstance().getInvoke()); return this.msgBuilder.getDiameterMessage(); } public void getE01Request() { this.getE01Request(false); } public void getE01Request(boolean bool) { String serviceName = this.ec02Ins.getE01Ins().getServiceName(); if (serviceName == null) { serviceName = this.abstractAF.getUtils().getHmWarmConfig().get("Resource-Name-E01").get(0).trim(); } this.abstractAF.getUtils().getGlobalData().configService(serviceName); KeyObject keyobj = new KeyObject(); keyobj.setObjectType(this.ec02Ins.getE01Ins().getObjType()); ArrayList keyList = this.ec02Ins.getE01Ins().getKey(); // for (int i = 0; i < keyList.size(); i++) { // AppLog.d("## key " + i + " " + keyList.get(i)); // keyobj.setKey(String.valueOf(i), keyList.get(i)); // } String[] stringArray = keyList.toArray(new String[keyList.size()]); for (int i = 0; i < stringArray.length; i++) { AppLog.d("## key " + i + " " + stringArray[i]); } AppLog.d("## keyObj :" + stringArray.length); if(this.ec02Ins.getE01Ins().getCmd().equals("search")){ // this.abstractAF.getUtils().getGlobalData().search(keyobj, this.ec02Ins.getE01Ins().getId()); this.abstractAF.getUtils().getGlobalData().search(this.ec02Ins.getE01Ins().getObjType(), stringArray, this.ec02Ins.getE01Ins().getId()); } else if(this.ec02Ins.getE01Ins().getCmd().equals("delete")){ this.abstractAF.getUtils().getGlobalData().delete(keyobj, this.ec02Ins.getE01Ins().getId()); } else if(this.ec02Ins.getE01Ins().getCmd().equals("add")){ this.abstractAF.getUtils().getGlobalData().add(keyobj, this.ec02Ins.getE01Ins().getData(), this.ec02Ins.getE01Ins().getId()); } else if(this.ec02Ins.getE01Ins().getCmd().equals("replace")){ this.abstractAF.getUtils().getGlobalData().replace(keyobj, this.ec02Ins.getE01Ins().getData(), this.ec02Ins.getE01Ins().getId()); } this.abstractAF.getUtils().getGlobalData().setTransactionId(this.ec02Ins.getE01Ins().getInvoke()); // timeout String timeout = this.ec02Ins.getE01Ins().getTimeout(); if (timeout != null) { this.ec02Ins.setTimeout(timeout); } if (bool) { String objType = this.ec02Ins.getE01Ins().getObjType(); this.ec02Ins.getAFInstance().getListStat().add(new Stat(this.ec02Ins.getAFInstance().getCurrentState(), Constant.TYPE_SEND, Constant.TYPE_REQUEST, Constant.TYPE_SUCCESS, objType)); } else { this.ec02Ins.getAFInstance().getListStat().add(new Stat(this.ec02Ins.getAFInstance().getCurrentState(), Constant.TYPE_SEND, Constant.TYPE_REQUEST)); } } public void getE01AtomicRequest() { String command = this.ec02Ins.getAtomic().getCommand(); String atomicName = this.ec02Ins.getAtomic().getName(); if (command.equals(Atomic.command_get)) { this.abstractAF.getUtils().getGlobalData().get(atomicName); } else if(command.equals(Atomic.command_increase)) { long atomicValue = this.ec02Ins.getAtomic().getValue(); this.abstractAF.getUtils().getGlobalData().increase(atomicName, atomicValue, this.ec02Ins.getAtomic().getMin(), this.ec02Ins.getAtomic().getMax()); } else if(command.equals(Atomic.command_clear)) { this.abstractAF.getUtils().getGlobalData().clear(atomicName); } this.abstractAF.getUtils().getGlobalData().setTransactionId(this.ec02Ins.getE01Ins().getInvoke()); this.ec02Ins.getAFInstance().getListStat().add(new Stat(this.ec02Ins.getAFInstance().getCurrentState(), Constant.TYPE_SEND, Constant.TYPE_REQUEST)); // timeout String timeout = this.ec02Ins.getE01Ins().getTimeout(); if (timeout != null) { this.ec02Ins.setTimeout(timeout); } } public EquinoxRawData getUpdateIns(){ this.msgBuilder = new EC02MSGBuilder(); this.ec02Ins.setTimeout(this.abstractAF.getUtils().getHmWarmConfig().get("Update-Instance-timeout").get(0)); return this.msgBuilder.getUpdateIns(); } private void logDetailOutput(EquinoxRawData equinoxRawData, Object data, String nodeTo, String command) { if (Log.debug) { AppLog.d("## LOGDETAIL_OUTPUT NODETO:" + nodeTo + " command:" + command); } // Log Detail Output if (data != null) { String currentState = ""; String cmd = (command == null ) ? StateConfig.getCommandFromState(currentState) : command; if (nodeTo == null && currentState != null) { String eventType = StateConfig.getEventTypeFromSubState(currentState); nodeTo = Global.getNodeFromEventType(eventType); } String invoke = equinoxRawData.getInvoke(); String type = equinoxRawData.getRawDataAttribute("type"); String rawData = EqxStringUtils.getMessage(equinoxRawData, null, false); DetailsLogPrototype detLog = this.ec02Ins.getAFInstance().getDetaillog(); DataBean output = new DataBean(); output.setInvoke(invoke); output.setDirector(nodeTo); output.setCommandName(cmd); if(type.equals("response")) { output.setType(TYPE.RES); } else { output.setType(TYPE.REQ); } output.setJsonData(MessageParser.toJsonObject(data)); output.setRawData(Global.getDetailLogRawData(rawData)); try { detLog.addOutput(output); } catch (CommonLogException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }