Search in sources :

Example 1 with NamespaceName

use of io.nem.sdk.model.namespace.NamespaceName in project nem2-sdk-java by nemtech.

the class NamespaceHttp method getNamespaceNames.

@Override
public Observable<List<NamespaceName>> getNamespaceNames(List<NamespaceId> namespaceIds) {
    JsonObject requestBody = new JsonObject();
    requestBody.put("namespaceIds", namespaceIds.stream().map(id -> UInt64.bigIntegerToHex(id.getId())).collect(Collectors.toList()));
    return this.client.postAbs(this.url + "/namespace/names").as(BodyCodec.jsonArray()).rxSendJson(requestBody).toObservable().map(HttpResponse::body).map(json -> objectMapper.<List<NamespaceNameDTO>>readValue(json.toString(), new TypeReference<List<NamespaceNameDTO>>() {
    })).flatMapIterable(item -> item).map(namespaceNameDTO -> {
        if (namespaceNameDTO.getParentId() != null) {
            return new NamespaceName(new NamespaceId(namespaceNameDTO.getNamespaceId().extractIntArray()), namespaceNameDTO.getName(), new NamespaceId(namespaceNameDTO.getParentId().extractIntArray()));
        } else {
            return new NamespaceName(new NamespaceId(namespaceNameDTO.getNamespaceId().extractIntArray()), namespaceNameDTO.getName());
        }
    }).toList().toObservable();
}
Also used : NamespaceInfo(io.nem.sdk.model.namespace.NamespaceInfo) NamespaceName(io.nem.sdk.model.namespace.NamespaceName) HttpResponse(io.vertx.reactivex.ext.web.client.HttpResponse) MalformedURLException(java.net.MalformedURLException) NamespaceType(io.nem.sdk.model.namespace.NamespaceType) NetworkType(io.nem.sdk.model.blockchain.NetworkType) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) UInt64(io.nem.sdk.model.transaction.UInt64) List(java.util.List) PublicAccount(io.nem.sdk.model.account.PublicAccount) BodyCodec(io.vertx.reactivex.ext.web.codec.BodyCodec) Address(io.nem.sdk.model.account.Address) NamespaceId(io.nem.sdk.model.namespace.NamespaceId) Optional(java.util.Optional) Observable(io.reactivex.Observable) JsonObject(io.vertx.core.json.JsonObject) TypeReference(com.fasterxml.jackson.core.type.TypeReference) NamespaceName(io.nem.sdk.model.namespace.NamespaceName) JsonObject(io.vertx.core.json.JsonObject) TypeReference(com.fasterxml.jackson.core.type.TypeReference) NamespaceId(io.nem.sdk.model.namespace.NamespaceId)

Aggregations

TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 Address (io.nem.sdk.model.account.Address)1 PublicAccount (io.nem.sdk.model.account.PublicAccount)1 NetworkType (io.nem.sdk.model.blockchain.NetworkType)1 NamespaceId (io.nem.sdk.model.namespace.NamespaceId)1 NamespaceInfo (io.nem.sdk.model.namespace.NamespaceInfo)1 NamespaceName (io.nem.sdk.model.namespace.NamespaceName)1 NamespaceType (io.nem.sdk.model.namespace.NamespaceType)1 UInt64 (io.nem.sdk.model.transaction.UInt64)1 Observable (io.reactivex.Observable)1 JsonObject (io.vertx.core.json.JsonObject)1 HttpResponse (io.vertx.reactivex.ext.web.client.HttpResponse)1 BodyCodec (io.vertx.reactivex.ext.web.codec.BodyCodec)1 MalformedURLException (java.net.MalformedURLException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1