Search in sources :

Example 1 with MetadataSearchCriteria

use of io.nem.symbol.sdk.api.MetadataSearchCriteria in project nem2-sdk-java by nemtech.

the class MerkleLoaderIntegrationTest method metadatas.

public List<Arguments> metadatas() {
    RepositoryFactory repositoryFactory = getRepositoryFactory(DEFAULT_REPOSITORY_TYPE);
    MetadataRepository repository = repositoryFactory.createMetadataRepository();
    return getArguments(repository, new MetadataSearchCriteria().order(ORDER_BY));
}
Also used : MetadataRepository(io.nem.symbol.sdk.api.MetadataRepository) MetadataSearchCriteria(io.nem.symbol.sdk.api.MetadataSearchCriteria) RepositoryFactory(io.nem.symbol.sdk.api.RepositoryFactory)

Example 2 with MetadataSearchCriteria

use of io.nem.symbol.sdk.api.MetadataSearchCriteria in project nem2-sdk-java by nemtech.

the class MosaicMetadataIntegrationTest method searchIntegration.

// 
@ParameterizedTest
@EnumSource(RepositoryType.class)
void searchIntegration(RepositoryType type) {
    BigInteger key = MapperUtils.fromHexToBigInteger("000000000000000A");
    Address sourceAddress = Address.createFromEncoded("9852D5EAA9AB038151EEBDD34308B3B2B7D82B92955F298E");
    Address targetAddress = Address.createFromEncoded("9852D5EAA9AB038151EEBDD34308B3B2B7D82B92955F298E");
    MosaicId mosaicId = new MosaicId("213CED6E6BBA6689");
    MetadataType metadataType = MetadataType.MOSAIC;
    Page<Metadata> metadataPage = get(getRepositoryFactory(type).createMetadataRepository().search(new MetadataSearchCriteria().scopedMetadataKey(key).targetId(mosaicId).sourceAddress(sourceAddress).targetAddress(targetAddress).metadataType(metadataType)));
    System.out.println(type + "\n" + toJson(metadataPage));
}
Also used : MetadataSearchCriteria(io.nem.symbol.sdk.api.MetadataSearchCriteria) Address(io.nem.symbol.sdk.model.account.Address) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) MetadataType(io.nem.symbol.sdk.model.metadata.MetadataType) Metadata(io.nem.symbol.sdk.model.metadata.Metadata) BigInteger(java.math.BigInteger) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with MetadataSearchCriteria

use of io.nem.symbol.sdk.api.MetadataSearchCriteria in project nem2-sdk-java by nemtech.

the class NamespaceMetadataIntegrationTest method addMetadataToNamespace.

@ParameterizedTest
@EnumSource(RepositoryType.class)
public void addMetadataToNamespace(RepositoryType type) {
    String namespaceName = "namespace-for-metadata-integration-test-" + Double.valueOf(Math.floor(Math.random() * 10000)).intValue();
    NamespaceId targetNamespaceId = createRootNamespace(type, testAccount, namespaceName);
    System.out.println("Setting metadata " + targetNamespaceId.getIdAsHex());
    String message = "This is the message in the Namespace!";
    BigInteger key = BigInteger.TEN;
    Address targetAddress = testAccount.getAddress();
    MetadataTransactionService metadataTransactionService = new MetadataTransactionServiceImpl(getRepositoryFactory(type));
    Observable<NamespaceMetadataTransactionFactory> namespaceMetadataTransactionFactory = metadataTransactionService.createNamespaceMetadataTransactionFactory(targetAddress, key, message, targetAddress, targetNamespaceId);
    NamespaceMetadataTransaction transaction = get(namespaceMetadataTransactionFactory).build();
    AggregateTransaction aggregateTransaction = AggregateTransactionFactory.createComplete(getNetworkType(), getDeadline(), Collections.singletonList(transaction.toAggregate(testAccount.getPublicAccount()))).maxFee(maxFee).build();
    AggregateTransaction announceCorrectly = announceAndValidate(type, testAccount, aggregateTransaction);
    Assertions.assertEquals(testAccount.getPublicAccount(), announceCorrectly.getSigner().get());
    Assertions.assertEquals(1, announceCorrectly.getInnerTransactions().size());
    Assertions.assertEquals(transaction.getType(), announceCorrectly.getInnerTransactions().get(0).getType());
    NamespaceMetadataTransaction processedTransaction = (NamespaceMetadataTransaction) announceCorrectly.getInnerTransactions().get(0);
    // TODO problem comparing namespaces, sometime they are negative big integers
    Assertions.assertEquals(transaction.getTargetNamespaceId().getIdAsHex(), processedTransaction.getTargetNamespaceId().getIdAsHex());
    Assertions.assertEquals(transaction.getValueSizeDelta(), processedTransaction.getValueSizeDelta());
    Assertions.assertEquals(transaction.getScopedMetadataKey(), processedTransaction.getScopedMetadataKey());
    System.out.println("Metadata '" + message + "' stored!");
    sleep(3000);
    List<Metadata> metadata = get(getRepositoryFactory(type).createMetadataRepository().search(new MetadataSearchCriteria().targetId(targetNamespaceId).metadataType(MetadataType.NAMESPACE))).getData();
    assertMetadata(transaction, metadata);
    assertMetadata(transaction, get(getRepositoryFactory(type).createMetadataRepository().search(new MetadataSearchCriteria().targetId(targetNamespaceId).metadataType(MetadataType.NAMESPACE).scopedMetadataKey(key))).getData());
    assertMetadata(transaction, get(getRepositoryFactory(type).createMetadataRepository().search(new MetadataSearchCriteria().targetId(targetNamespaceId).metadataType(MetadataType.NAMESPACE).targetAddress(targetAddress).scopedMetadataKey(key))).getData());
    Assertions.assertEquals(message, processedTransaction.getValue());
}
Also used : NamespaceMetadataTransaction(io.nem.symbol.sdk.model.transaction.NamespaceMetadataTransaction) MetadataSearchCriteria(io.nem.symbol.sdk.api.MetadataSearchCriteria) Address(io.nem.symbol.sdk.model.account.Address) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) Metadata(io.nem.symbol.sdk.model.metadata.Metadata) MetadataTransactionService(io.nem.symbol.sdk.api.MetadataTransactionService) BigInteger(java.math.BigInteger) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) NamespaceMetadataTransactionFactory(io.nem.symbol.sdk.model.transaction.NamespaceMetadataTransactionFactory) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with MetadataSearchCriteria

use of io.nem.symbol.sdk.api.MetadataSearchCriteria in project nem2-sdk-java by nemtech.

the class MetadataRepositoryVertxImpl method search.

@Override
public Observable<Page<Metadata>> search(MetadataSearchCriteria criteria) {
    String sourceAddress = toDto(criteria.getSourceAddress());
    String targetAddress = toDto(criteria.getTargetAddress());
    String scopedMetadataKey = toDto(criteria.getScopedMetadataKey());
    String targetId = criteria.getTargetId();
    MetadataTypeEnum metadataType = criteria.getMetadataType() == null ? null : MetadataTypeEnum.fromValue(criteria.getMetadataType().getValue());
    String offset = criteria.getOffset();
    Integer pageSize = criteria.getPageSize();
    Integer pageNumber = criteria.getPageNumber();
    Order order = toDto(criteria.getOrder());
    Consumer<Handler<AsyncResult<MetadataPage>>> callback = handler -> getClient().searchMetadataEntries(sourceAddress, targetAddress, scopedMetadataKey, targetId, metadataType, pageSize, pageNumber, offset, order, handler);
    return exceptionHandling(call(callback).map(page -> this.toPage(page.getPagination(), page.getData().stream().map(this::toMetadata).collect(Collectors.toList()))));
}
Also used : MetadataTypeEnum(io.nem.symbol.sdk.openapi.vertx.model.MetadataTypeEnum) BigInteger(java.math.BigInteger) Order(io.nem.symbol.sdk.openapi.vertx.model.Order) MapperUtils(io.nem.symbol.core.utils.MapperUtils) ApiClient(io.nem.symbol.sdk.openapi.vertx.invoker.ApiClient) ConvertUtils(io.nem.symbol.core.utils.ConvertUtils) MetadataType(io.nem.symbol.sdk.model.metadata.MetadataType) MetadataTypeEnum(io.nem.symbol.sdk.openapi.vertx.model.MetadataTypeEnum) Collectors(java.util.stream.Collectors) MetadataRepository(io.nem.symbol.sdk.api.MetadataRepository) MetadataEntryDTO(io.nem.symbol.sdk.openapi.vertx.model.MetadataEntryDTO) MetadataInfoDTO(io.nem.symbol.sdk.openapi.vertx.model.MetadataInfoDTO) Consumer(java.util.function.Consumer) Order(io.nem.symbol.sdk.openapi.vertx.model.Order) ObjectUtils(org.apache.commons.lang3.ObjectUtils) MetadataSearchCriteria(io.nem.symbol.sdk.api.MetadataSearchCriteria) MerkleStateInfo(io.nem.symbol.sdk.model.blockchain.MerkleStateInfo) MetadataPage(io.nem.symbol.sdk.openapi.vertx.model.MetadataPage) Observable(io.reactivex.Observable) BigInteger(java.math.BigInteger) MetadataRoutesApiImpl(io.nem.symbol.sdk.openapi.vertx.api.MetadataRoutesApiImpl) AsyncResult(io.vertx.core.AsyncResult) Handler(io.vertx.core.Handler) Metadata(io.nem.symbol.sdk.model.metadata.Metadata) MetadataRoutesApi(io.nem.symbol.sdk.openapi.vertx.api.MetadataRoutesApi) Page(io.nem.symbol.sdk.api.Page) MetadataPage(io.nem.symbol.sdk.openapi.vertx.model.MetadataPage) Handler(io.vertx.core.Handler)

Example 5 with MetadataSearchCriteria

use of io.nem.symbol.sdk.api.MetadataSearchCriteria in project nem2-sdk-java by nemtech.

the class AccountMetadataIntegrationTest method addMetadataToAccount.

@ParameterizedTest
@EnumSource(RepositoryType.class)
public void addMetadataToAccount(RepositoryType type) {
    BigInteger key = SerializationUtils.toUnsignedBigInteger(RandomUtils.generateRandomInt(100000) + Long.MAX_VALUE);
    Assertions.assertTrue(key.compareTo(BigInteger.ZERO) > 0);
    System.out.println("Key: " + key);
    String message = "This is the message for this account! 汉字" + key;
    System.out.println("Storing message '" + message + "' in account metadata " + testAccount.getAddress().plain());
    AccountMetadataTransaction transaction = AccountMetadataTransactionFactory.create(getNetworkType(), getDeadline(), testAccount.getAddress(), key, StringEncoder.getBytes(message)).maxFee(maxFee).build();
    AccountMetadataTransaction processedTransaction = announceAggregateAndValidate(type, transaction, testAccount).getLeft();
    Assertions.assertEquals(transaction.getValueSizeDelta(), processedTransaction.getValueSizeDelta());
    Assertions.assertEquals(transaction.getScopedMetadataKey(), processedTransaction.getScopedMetadataKey());
    sleep(1000);
    Metadata metadata = assertMetadata(transaction, get(getRepositoryFactory(type).createMetadataRepository().search(new MetadataSearchCriteria().metadataType(MetadataType.ACCOUNT).sourceAddress(testAccount.getAddress()))).getData());
    assertMetadata(transaction, get(getRepositoryFactory(type).createMetadataRepository().search(new MetadataSearchCriteria().metadataType(MetadataType.ACCOUNT).sourceAddress(testAccount.getAddress()).scopedMetadataKey(metadata.getScopedMetadataKey()))).getData());
    assertMetadata(transaction, get(getRepositoryFactory(type).createMetadataRepository().search(new MetadataSearchCriteria().metadataType(MetadataType.ACCOUNT).sourceAddress(testAccount.getAddress()).targetAddress(testAccount.getAddress()).scopedMetadataKey(metadata.getScopedMetadataKey()))).getData());
    Assertions.assertArrayEquals(StringEncoder.getBytes(message), processedTransaction.getValue());
}
Also used : MetadataSearchCriteria(io.nem.symbol.sdk.api.MetadataSearchCriteria) AccountMetadataTransaction(io.nem.symbol.sdk.model.transaction.AccountMetadataTransaction) Metadata(io.nem.symbol.sdk.model.metadata.Metadata) BigInteger(java.math.BigInteger) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

MetadataSearchCriteria (io.nem.symbol.sdk.api.MetadataSearchCriteria)25 BigInteger (java.math.BigInteger)19 Test (org.junit.jupiter.api.Test)15 Metadata (io.nem.symbol.sdk.model.metadata.Metadata)14 Page (io.nem.symbol.sdk.api.Page)8 Address (io.nem.symbol.sdk.model.account.Address)5 MosaicMetadataTransactionFactory (io.nem.symbol.sdk.model.transaction.MosaicMetadataTransactionFactory)4 NamespaceMetadataTransactionFactory (io.nem.symbol.sdk.model.transaction.NamespaceMetadataTransactionFactory)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 EnumSource (org.junit.jupiter.params.provider.EnumSource)4 MetadataRepository (io.nem.symbol.sdk.api.MetadataRepository)3 RepositoryCallException (io.nem.symbol.sdk.api.RepositoryCallException)3 MetadataType (io.nem.symbol.sdk.model.metadata.MetadataType)3 NamespaceId (io.nem.symbol.sdk.model.namespace.NamespaceId)3 AccountMetadataTransactionFactory (io.nem.symbol.sdk.model.transaction.AccountMetadataTransactionFactory)3 ConvertUtils (io.nem.symbol.core.utils.ConvertUtils)2 MetadataTransactionService (io.nem.symbol.sdk.api.MetadataTransactionService)2 RepositoryFactory (io.nem.symbol.sdk.api.RepositoryFactory)2 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)2 AggregateTransaction (io.nem.symbol.sdk.model.transaction.AggregateTransaction)2