Invoke.java 2.76 KB
package th.co.ais.ssbsrfc.config;

import java.util.UUID;

import th.co.ais.ssbsrfc.utils.Global;

public class Invoke {
	public String nodeName;	// UDC, SRFC, SDF
	public String key;	// 6681234567
	public String cmd = null;	// callBackUrl, getFile
	public String eventType = null;	// Incoming_UDC_Response
	public String unique;
	public Object dev = null;	// for developer
	
	private static final String DELIMITER = ".";
	
	public String getNodeName() {
		return nodeName;
	}

	public void setNodeName(String nodeName) {
		this.nodeName = nodeName;
	}

	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}

	public String getCmd() {
		return cmd;
	}

	public void setCmd(String cmd) {
		this.cmd = cmd;
	}

	public String getUnique() {
		return unique;
	}

	public String getEventType() {
		return eventType;
	}

	public void setEventType(String eventType) {
		this.eventType = eventType;
	}

	public void setUnique(String unique) {
		this.unique = unique;
	}
	
	public static String genUniqueId()
	{
		UUID uuid = UUID.randomUUID();
		return uuid.toString();
	}
	
	public Object getDev() {
		return dev;
	}

	public void setDev(Object dev) {
		this.dev = dev;
	}
	
	public Invoke() {}

	public Invoke(String invokeString)
	{
		String[] strSplit = null;
		if(invokeString != null)
		{
			strSplit = invokeString.split("[\\"+DELIMITER+"]");
			if(strSplit.length == 5)
			{
				this.nodeName = strSplit[0];
				this.key = strSplit[1];
				this.cmd = strSplit[2];
				this.eventType = strSplit[3];
				this.unique = strSplit[4];
			} else if (strSplit.length == 6) {
				this.nodeName = strSplit[0];
				this.key = strSplit[1];
				this.cmd = strSplit[2];
				this.eventType = strSplit[3];
				this.unique = strSplit[4];
				this.dev = strSplit[5];
			}
		}
	}

	public Invoke(String _key, String _eventType) {
		super();
		String _cmd = StateConfig.getCommandFromEventType(eventType);
		String _node = Global.getNodeFromEventType(eventType);
		this.nodeName = _node;
		this.key = _key;
		this.cmd = _cmd;
		this.eventType = _eventType;
		UUID uuid = UUID.randomUUID();
		this.unique = uuid.toString();
	}

	public Invoke(String _nodeName, String _key, String _cmd, String _eventType, String _unique)
	{
		// TODO check . in all variable (if have)
		this.nodeName = _nodeName;
		this.key = _key;
		this.cmd = _cmd;
		this.eventType = _eventType;
		if(_unique == null)
		{
			UUID uuid = UUID.randomUUID();
			this.unique = uuid.toString();
		} 
		else
		{
			this.unique = _unique;
		}
	}
	
	public String toString()
	{
		String strInvoke ="";		
		strInvoke = this.nodeName + DELIMITER + this.key + DELIMITER + this.cmd + DELIMITER + this.eventType + DELIMITER + this.unique;
		if(this.dev != null) {
			strInvoke += DELIMITER + this.dev.toString();
		}
		return strInvoke;
	}
}