use of com.roof.chain.support.NodeResult in project roof-im by madfroglx.
the class ReturnCodeResponseCreateNode method doNode.
public String doNode(Request request, ValueStack valueStack) {
NodeResult nodeResult = valueStack.getPreResult();
Response<Object> response = new Response<>();
response.setState(StringUtils.isBlank(state) ? nodeResult.getState() : state);
response.setMessage(nodeResult.getNext());
response.setResult(nodeResult.getData());
response.setRequestType(valueStack.getAsString(ImConstant.REQUEST_TYPE));
if (request != null) {
response.setSeq(request.getSeq());
}
valueStack.set(ImConstant.RESPONSE, response);
return RESPONSE_CREATE_SUCCESS;
}
use of com.roof.chain.support.NodeResult in project roof-im by madfroglx.
the class GetTmpSecretHandlerNode method doNode.
public NodeResult doNode(GetTmpSecretRequest request, ValueStack valueStack) {
TreeMap<String, Object> config = new TreeMap<>();
config.put("SecretId", secretId);
config.put("SecretKey", secretKey);
/* 请求方法类型 POST、GET */
config.put("RequestMethod", "GET");
/* 区域参数,可选: gz: 广州; sh: 上海; hk: 香港; ca: 北美; 等。 */
config.put("DefaultRegion", "sh");
QcloudApiModuleCenter module = new QcloudApiModuleCenter(new Sts(), config);
TreeMap<String, Object> params = new TreeMap<>();
/* 将需要输入的参数都放入 params 里面,必选参数是必填的。 */
/* DescribeInstances 接口的部分可选参数如下 */
params.put("name", request.getUsername());
String policy = "{\"statement\": [{\"action\": [\"name/cos:GetObject\",\"name/cos:PutObject\"]," + "\"effect\": \"allow\"," + "\"resource\":[\"qcs::cos:" + region + ":uid/" + appId + ":prefix//" + appId + "/im/*\"]}]" + ",\"version\": \"2.0\"}";
params.put("policy", policy);
params.put("durationSeconds", durationSeconds);
/* 在这里指定所要用的签名算法,不指定默认为 HmacSHA1*/
// params.put("SignatureMethod", "HmacSHA256");
/* generateUrl 方法生成请求串, 可用于调试使用 */
String result = null;
try {
NodeResult nodeResult = new NodeResult(GET_TMP_SECRET_SUCCESS);
/* call 方法正式向指定的接口名发送请求,并把请求参数 params 传入,返回即是接口的请求结果。 */
result = module.call(GET_FEDERATION_TOKEN, params);
JSONObject jsonObject = JSONObject.parseObject(result);
if (jsonObject.getInteger("code") != 0) {
LOGGER.error(result);
return new NodeResult(GET_TMP_SECRET_ERROR);
}
JSONObject data = jsonObject.getJSONObject("data");
data.put("region", region);
data.put("bucket", bucket + "-" + appId);
data.put("path", pathPrefix + "/" + DateFormatUtils.format(new Date(), "yyyyMM") + "/");
nodeResult.setData(data);
return nodeResult;
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
return new NodeResult(GET_TMP_SECRET_ERROR);
}
}
use of com.roof.chain.support.NodeResult in project roof-im by madfroglx.
the class MessageRequestHandlerNode method doNode.
public NodeResult<Message> doNode(Message message, ValueStack valueStack) {
// MessageRequest messageRequest;
// if (request instanceof MessageRequest) {
// messageRequest = (MessageRequest) request;
// } else {
// LOGGER.error("request error type : {}, mast be {}",
// request.getClass().getSimpleName(), MessageRequest.class.getSimpleName());
// return new NodeResult<>(NONSUPPORT_REQUEST_TYPE);
// }
String receiver = message.getReceiver();
List<UserState> userStates = userStateService.getStates(receiver);
String connectId = null;
for (UserState userState : userStates) {
if (StringUtils.equals(userState.getServerName(), serverNameBuilder.getName()) && StringUtils.equals(userState.getClientType(), message.getClientType())) {
connectId = userState.getConnectId();
}
}
if (connectId == null) {
return new NodeResult(CANNOT_FOUND_CONNECT);
}
valueStack.set(ImConstant.CONNECT_ID, connectId);
NodeResult result = new NodeResult(MESSAGE_REQUEST_TRANSFORM_SUCCESS);
result.setData(message);
valueStack.set(ImConstant.REQUEST_TYPE, ImConstant.MESSAGE);
return result;
}
use of com.roof.chain.support.NodeResult in project roof-im by madfroglx.
the class OpenSessionHandlerNode method doNode.
@Override
public NodeResult<Session> doNode(OpenSessionRequest request, ValueStack valueStack) {
String sender = request.getSender();
String receiver = request.getReceiver();
if (!userService.exist(sender)) {
return new NodeResult<>(SENDER_NOT_EXIST);
}
if (!userService.exist(receiver)) {
return new NodeResult<>(RECEIVER_NOT_EXIST);
}
// 双方已存在session
Session sessionExist = sessionManager.queryEffective(sender, receiver);
if (sessionExist != null) {
NodeResult<Session> nodeResult = new NodeResult<>(SESSION_ALREADY_EXIST);
nodeResult.setData(sessionExist);
return nodeResult;
}
Session session = sessionManager.open(sender, receiver, request.getStartTime(), request.getEndTime());
NodeResult<Session> nodeResult = new NodeResult<>(OPEN_SESSION_SUCCESS);
nodeResult.setData(session);
return nodeResult;
}
Aggregations