mirror of
https://gitee.com/BDWare/agent-backend
synced 2025-04-28 07:02:16 +00:00
42 lines
1.5 KiB
Java
42 lines
1.5 KiB
Java
package org.bdware.server.ws;
|
|
|
|
import com.google.gson.JsonObject;
|
|
import org.bdware.sc.ContractClient;
|
|
import org.bdware.sc.conn.ResultCallback;
|
|
import org.bdware.sc.util.HashUtil;
|
|
import org.bdware.server.action.Action;
|
|
import org.bdware.server.action.CMActions;
|
|
|
|
public class EventActions {
|
|
@Action(async = true, userPermission = 0)
|
|
public void subEvent(JsonObject args, final ResultCallback rcb) {
|
|
JsonObject ret = new JsonObject();
|
|
ret.addProperty("action", "onSubEvent");
|
|
ret.addProperty("status", "Error");
|
|
if (args.has("requestID")) {
|
|
ret.addProperty("responseID", args.get("requestID").getAsString());
|
|
}
|
|
if (!args.has("topic")) {
|
|
ret.addProperty("data", "no topic arg!");
|
|
rcb.onResult(ret.toString());
|
|
return;
|
|
}
|
|
String topic = args.get("topic").getAsString();
|
|
if (args.has("contractID")) {
|
|
String argCID = args.get("contractID").getAsString();
|
|
ContractClient client = CMActions.manager.getClient(argCID);
|
|
if (null == client) {
|
|
ret.addProperty("data", "invalid contract ID or Name!");
|
|
rcb.onResult(ret.toString());
|
|
return;
|
|
}
|
|
String contractID = client.getContractID();
|
|
topic = HashUtil.sha3(contractID + topic);
|
|
}
|
|
CMActions.manager.subEventByClient(topic, rcb.getChannel());
|
|
ret.addProperty("status", "Success");
|
|
ret.addProperty("data", topic);
|
|
rcb.onResult(ret.toString());
|
|
}
|
|
}
|