All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.webank.wecrosssdk.rpc.WeCrossRPCRest Maven / Gradle / Ivy

There is a newer version: 1.4.0
Show newest version
package com.webank.wecrosssdk.rpc;

import com.webank.wecrosssdk.rpc.methods.Request;
import com.webank.wecrosssdk.rpc.methods.Response;
import com.webank.wecrosssdk.rpc.methods.request.GetDataRequest;
import com.webank.wecrosssdk.rpc.methods.request.ResourcesRequest;
import com.webank.wecrosssdk.rpc.methods.request.SetDataRequest;
import com.webank.wecrosssdk.rpc.methods.request.TransactionRequest;
import com.webank.wecrosssdk.rpc.methods.response.GetDataResponse;
import com.webank.wecrosssdk.rpc.methods.response.ResourcesResponse;
import com.webank.wecrosssdk.rpc.methods.response.SetDataResponse;
import com.webank.wecrosssdk.rpc.methods.response.TransactionResponse;
import com.webank.wecrosssdk.rpc.service.WeCrossService;

public class WeCrossRPCRest implements WeCrossRPC {

    private WeCrossService weCrossService;

    public WeCrossRPCRest(WeCrossService weCrossService) {
        this.weCrossService = weCrossService;
    }

    @Override
    public RemoteCall status(String path) {
        //    String prefix = weCrossService.getWeCrossServer();
        //    String url = RPCUtils.pathToUrl(prefix, path);
        @SuppressWarnings("unchecked")
        Request request = new Request(path, "status", null);
        return new RemoteCall<>(weCrossService, Response.class, request);
    }

    @Override
    public RemoteCall list(Boolean ignoreRemote) {
        ResourcesRequest resourcesRequest = new ResourcesRequest(ignoreRemote);

        @SuppressWarnings("unchecked")
        Request request = new Request("", "list", resourcesRequest);
        return new RemoteCall(weCrossService, ResourcesResponse.class, request);
    }

    @Override
    public RemoteCall getData(String path, String key) {
        GetDataRequest getDataRequest = new GetDataRequest(key);

        @SuppressWarnings("unchecked")
        Request request = new Request(path, "getData", getDataRequest);
        return new RemoteCall(weCrossService, GetDataResponse.class, request);
    }

    @Override
    public RemoteCall setData(String path, String key, String value) {
        SetDataRequest setDataRequest = new SetDataRequest(key, value);

        @SuppressWarnings("unchecked")
        Request request = new Request(path, "setData", setDataRequest);
        return new RemoteCall(weCrossService, SetDataResponse.class, request);
    }

    @Override
    public RemoteCall call(String path, String method, Object... args) {
        TransactionRequest transactionRequest = new TransactionRequest("", method, args);

        @SuppressWarnings("unchecked")
        Request request = new Request(path, "call", transactionRequest);
        return new RemoteCall(
                weCrossService, TransactionResponse.class, request);
    }

    @Override
    public RemoteCall call(
            String path, String[] retTypes, String method, Object... args) {
        TransactionRequest transactionRequest = new TransactionRequest("", retTypes, method, args);

        @SuppressWarnings("unchecked")
        Request request = new Request(path, "call", transactionRequest);
        return new RemoteCall(
                weCrossService, TransactionResponse.class, request);
    }

    @Override
    public RemoteCall callInt(String path, String method, Object... args) {
        return call(path, new String[] {"Int"}, method, args);
    }

    @Override
    public RemoteCall callIntArray(
            String path, String method, Object... args) {
        return call(path, new String[] {"IntArray"}, method, args);
    }

    @Override
    public RemoteCall callString(String path, String method, Object... args) {
        return call(path, new String[] {"String"}, method, args);
    }

    @Override
    public RemoteCall callStringArray(
            String path, String method, Object... args) {
        return call(path, new String[] {"StringArray"}, method, args);
    }

    @Override
    public RemoteCall sendTransaction(
            String path, String method, Object... args) {
        TransactionRequest transactionRequest = new TransactionRequest("", method, args);

        @SuppressWarnings("unchecked")
        Request request =
                new Request(path, "sendTransaction", transactionRequest);
        return new RemoteCall(
                weCrossService, TransactionResponse.class, request);
    }

    @Override
    public RemoteCall sendTransaction(
            String path, String[] retTypes, String method, Object... args) {
        TransactionRequest transactionRequest = new TransactionRequest("", retTypes, method, args);

        @SuppressWarnings("unchecked")
        Request request =
                new Request(path, "sendTransaction", transactionRequest);
        return new RemoteCall(
                weCrossService, TransactionResponse.class, request);
    }

    @Override
    public RemoteCall sendTransactionInt(
            String path, String method, Object... args) {
        return sendTransaction(path, new String[] {"Int"}, method, args);
    }

    @Override
    public RemoteCall sendTransactionIntArray(
            String path, String method, Object... args) {
        return sendTransaction(path, new String[] {"IntArray"}, method, args);
    }

    @Override
    public RemoteCall sendTransactionString(
            String path, String method, Object... args) {
        return sendTransaction(path, new String[] {"String"}, method, args);
    }

    @Override
    public RemoteCall sendTransactionStringArray(
            String path, String method, Object... args) {
        return sendTransaction(path, new String[] {"StringArray"}, method, args);
    }

    public WeCrossService getWeCrossService() {
        return weCrossService;
    }

    public void setWeCrossService(WeCrossService weCrossService) {
        this.weCrossService = weCrossService;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy