Search in sources :

Example 1 with MosaicAddressRestriction

use of io.nem.symbol.sdk.model.restriction.MosaicAddressRestriction in project nem2-sdk-java by nemtech.

the class RestrictionMosaicRepositoryOkHttpImpl method toMosaicAddressRestriction.

private MosaicAddressRestriction toMosaicAddressRestriction(MosaicAddressRestrictionDTO mosaicAddressRestrictionDTO) {
    MosaicAddressRestrictionEntryWrapperDTO dto = mosaicAddressRestrictionDTO.getMosaicRestrictionEntry();
    Map<BigInteger, BigInteger> restrictions = dto.getRestrictions().stream().collect(Collectors.toMap(e -> new BigInteger(e.getKey()), e -> toBigInteger(e.getValue())));
    return new MosaicAddressRestriction(mosaicAddressRestrictionDTO.getId(), ObjectUtils.defaultIfNull(dto.getVersion(), 1), dto.getCompositeHash(), MosaicRestrictionEntryType.rawValueOf(dto.getEntryType().getValue()), MapperUtils.toMosaicId(dto.getMosaicId()), MapperUtils.toAddress(dto.getTargetAddress()), restrictions);
}
Also used : MosaicAddressRestrictionDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.MosaicAddressRestrictionDTO) RestrictionMosaicRepository(io.nem.symbol.sdk.api.RestrictionMosaicRepository) Callable(java.util.concurrent.Callable) MosaicAddressRestrictionEntryWrapperDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.MosaicAddressRestrictionEntryWrapperDTO) RestrictionMosaicRoutesApi(io.nem.symbol.sdk.openapi.okhttp_gson.api.RestrictionMosaicRoutesApi) LinkedHashMap(java.util.LinkedHashMap) MosaicRestrictionSearchCriteria(io.nem.symbol.sdk.api.MosaicRestrictionSearchCriteria) MosaicRestriction(io.nem.symbol.sdk.model.restriction.MosaicRestriction) MosaicRestrictionType(io.nem.symbol.sdk.model.transaction.MosaicRestrictionType) ObjectUtils(org.apache.commons.lang3.ObjectUtils) Map(java.util.Map) MerkleStateInfo(io.nem.symbol.sdk.model.blockchain.MerkleStateInfo) Observable(io.reactivex.Observable) BigInteger(java.math.BigInteger) MosaicGlobalRestrictionDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.MosaicGlobalRestrictionDTO) MosaicGlobalRestrictionEntryRestrictionDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.MosaicGlobalRestrictionEntryRestrictionDTO) MosaicRestrictionEntryTypeEnum(io.nem.symbol.sdk.openapi.okhttp_gson.model.MosaicRestrictionEntryTypeEnum) MapperUtils(io.nem.symbol.core.utils.MapperUtils) ApiClient(io.nem.symbol.sdk.openapi.okhttp_gson.invoker.ApiClient) MosaicGlobalRestriction(io.nem.symbol.sdk.model.restriction.MosaicGlobalRestriction) MosaicRestrictionEntryType(io.nem.symbol.sdk.model.restriction.MosaicRestrictionEntryType) Collectors(java.util.stream.Collectors) Order(io.nem.symbol.sdk.openapi.okhttp_gson.model.Order) MosaicGlobalRestrictionItem(io.nem.symbol.sdk.model.restriction.MosaicGlobalRestrictionItem) MosaicGlobalRestrictionEntryWrapperDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.MosaicGlobalRestrictionEntryWrapperDTO) Page(io.nem.symbol.sdk.api.Page) MosaicAddressRestriction(io.nem.symbol.sdk.model.restriction.MosaicAddressRestriction) MosaicRestrictionsPage(io.nem.symbol.sdk.openapi.okhttp_gson.model.MosaicRestrictionsPage) MosaicAddressRestriction(io.nem.symbol.sdk.model.restriction.MosaicAddressRestriction) BigInteger(java.math.BigInteger) MosaicAddressRestrictionEntryWrapperDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.MosaicAddressRestrictionEntryWrapperDTO)

Example 2 with MosaicAddressRestriction

use of io.nem.symbol.sdk.model.restriction.MosaicAddressRestriction in project nem2-sdk-java by nemtech.

the class RestrictionMosaicRepositoryIntegrationTest method searchAddressRestriction.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void searchAddressRestriction(RepositoryType type) {
    RepositoryFactory repositoryFactory = getRepositoryFactory(type);
    RestrictionMosaicRepository repository = repositoryFactory.createRestrictionMosaicRepository();
    MosaicRestrictionEntryType entryType = MosaicRestrictionEntryType.ADDRESS;
    Page<MosaicRestriction<?>> page = get(repository.search(new MosaicRestrictionSearchCriteria().entryType(entryType)));
    System.out.println(page.getData().size());
    page.getData().forEach(restriction -> {
        Assertions.assertTrue(restriction instanceof MosaicAddressRestriction);
        Assertions.assertEquals(entryType, restriction.getEntryType());
        Assertions.assertNotNull(restriction.getMosaicId());
        Assertions.assertNotNull(restriction.getCompositeHash());
        Assertions.assertFalse(restriction.getRestrictions().isEmpty());
        Assertions.assertNotNull(((MosaicAddressRestriction) restriction).getTargetAddress());
    });
}
Also used : MosaicRestrictionEntryType(io.nem.symbol.sdk.model.restriction.MosaicRestrictionEntryType) MosaicAddressRestriction(io.nem.symbol.sdk.model.restriction.MosaicAddressRestriction) RestrictionMosaicRepository(io.nem.symbol.sdk.api.RestrictionMosaicRepository) RepositoryFactory(io.nem.symbol.sdk.api.RepositoryFactory) MosaicRestriction(io.nem.symbol.sdk.model.restriction.MosaicRestriction) MosaicRestrictionSearchCriteria(io.nem.symbol.sdk.api.MosaicRestrictionSearchCriteria) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with MosaicAddressRestriction

use of io.nem.symbol.sdk.model.restriction.MosaicAddressRestriction in project nem2-sdk-java by nemtech.

the class RestrictionMosaicRepositoryOkHttpImplTest method shouldGetMosaicAddressRestrictions.

@Test
public void shouldGetMosaicAddressRestrictions() throws Exception {
    Address address = Address.generateRandom(this.networkType);
    MosaicId mosaicId = MapperUtils.toMosaicId("123");
    MosaicAddressRestrictionDTO dto = new MosaicAddressRestrictionDTO();
    MosaicAddressRestrictionEntryWrapperDTO wrapperDTO = new MosaicAddressRestrictionEntryWrapperDTO();
    dto.setMosaicRestrictionEntry(wrapperDTO);
    MosaicAddressRestrictionEntryDTO entryDTO = new MosaicAddressRestrictionEntryDTO();
    entryDTO.setKey(ConvertUtils.toString(BigInteger.valueOf(1111)));
    entryDTO.setValue("2222");
    List<MosaicAddressRestrictionEntryDTO> restrictions = new ArrayList<>();
    restrictions.add(entryDTO);
    wrapperDTO.setCompositeHash("compositeHash");
    wrapperDTO.setMosaicId(mosaicId.getIdAsHex());
    wrapperDTO.setRestrictions(restrictions);
    wrapperDTO.setEntryType(MosaicRestrictionEntryTypeEnum.NUMBER_0);
    wrapperDTO.setTargetAddress(address.encoded());
    wrapperDTO.setVersion(1);
    mockRemoteCall(toPage(dto));
    List<MosaicRestriction<?>> mosaicAddressRestrictions = repository.search(new MosaicRestrictionSearchCriteria()).toFuture().get().getData();
    Assertions.assertEquals(1, mosaicAddressRestrictions.size());
    MosaicAddressRestriction mosaicAddressRestriction = (MosaicAddressRestriction) mosaicAddressRestrictions.get(0);
    Assertions.assertEquals(wrapperDTO.getCompositeHash(), mosaicAddressRestriction.getCompositeHash());
    Assertions.assertEquals(MosaicRestrictionEntryType.ADDRESS, mosaicAddressRestriction.getEntryType());
    Assertions.assertEquals(mosaicId, mosaicAddressRestriction.getMosaicId());
    Assertions.assertEquals(address, mosaicAddressRestriction.getTargetAddress());
    Assertions.assertEquals(1, mosaicAddressRestriction.getRestrictions().size());
    Assertions.assertEquals(BigInteger.valueOf(2222), mosaicAddressRestriction.getRestrictions().get(BigInteger.valueOf(1111)));
}
Also used : MosaicAddressRestriction(io.nem.symbol.sdk.model.restriction.MosaicAddressRestriction) Address(io.nem.symbol.sdk.model.account.Address) MosaicAddressRestrictionDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.MosaicAddressRestrictionDTO) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) ArrayList(java.util.ArrayList) MosaicAddressRestrictionEntryDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.MosaicAddressRestrictionEntryDTO) MosaicRestriction(io.nem.symbol.sdk.model.restriction.MosaicRestriction) MosaicRestrictionSearchCriteria(io.nem.symbol.sdk.api.MosaicRestrictionSearchCriteria) MosaicAddressRestrictionEntryWrapperDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.MosaicAddressRestrictionEntryWrapperDTO) Test(org.junit.jupiter.api.Test)

Example 4 with MosaicAddressRestriction

use of io.nem.symbol.sdk.model.restriction.MosaicAddressRestriction in project nem2-sdk-java by nemtech.

the class RestrictionMosaicRepositoryOkHttpImplTest method shouldGetMosaicAddressRestriction.

@Test
public void shouldGetMosaicAddressRestriction() throws Exception {
    Address address = Address.generateRandom(this.networkType);
    MosaicId mosaicId = MapperUtils.toMosaicId("123");
    MosaicAddressRestrictionDTO dto = new MosaicAddressRestrictionDTO();
    MosaicAddressRestrictionEntryWrapperDTO wrapperDTO = new MosaicAddressRestrictionEntryWrapperDTO();
    dto.setMosaicRestrictionEntry(wrapperDTO);
    MosaicAddressRestrictionEntryDTO entryDTO = new MosaicAddressRestrictionEntryDTO();
    entryDTO.setKey(ConvertUtils.toString(BigInteger.valueOf(1111)));
    entryDTO.setValue("2222");
    List<MosaicAddressRestrictionEntryDTO> restrictions = new ArrayList<>();
    restrictions.add(entryDTO);
    wrapperDTO.setCompositeHash("compositeHash");
    wrapperDTO.setMosaicId(mosaicId.getIdAsHex());
    wrapperDTO.setRestrictions(restrictions);
    wrapperDTO.setEntryType(MosaicRestrictionEntryTypeEnum.NUMBER_0);
    wrapperDTO.setTargetAddress(address.encoded());
    wrapperDTO.setVersion(1);
    mockRemoteCall(toPage(dto));
    MosaicAddressRestriction mosaicAddressRestriction = (MosaicAddressRestriction) repository.search(new MosaicRestrictionSearchCriteria().targetAddress(address).mosaicId(mosaicId).entryType(MosaicRestrictionEntryType.ADDRESS)).toFuture().get().getData().get(0);
    Assertions.assertEquals(wrapperDTO.getCompositeHash(), mosaicAddressRestriction.getCompositeHash());
    Assertions.assertEquals(MosaicRestrictionEntryType.ADDRESS, mosaicAddressRestriction.getEntryType());
    Assertions.assertEquals(mosaicId, mosaicAddressRestriction.getMosaicId());
    Assertions.assertEquals(address, mosaicAddressRestriction.getTargetAddress());
    Assertions.assertEquals(1, mosaicAddressRestriction.getRestrictions().size());
    Assertions.assertEquals(BigInteger.valueOf(2222), mosaicAddressRestriction.getRestrictions().get((BigInteger.valueOf(1111))));
}
Also used : MosaicAddressRestriction(io.nem.symbol.sdk.model.restriction.MosaicAddressRestriction) Address(io.nem.symbol.sdk.model.account.Address) MosaicAddressRestrictionDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.MosaicAddressRestrictionDTO) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) ArrayList(java.util.ArrayList) MosaicAddressRestrictionEntryDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.MosaicAddressRestrictionEntryDTO) MosaicRestrictionSearchCriteria(io.nem.symbol.sdk.api.MosaicRestrictionSearchCriteria) MosaicAddressRestrictionEntryWrapperDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.MosaicAddressRestrictionEntryWrapperDTO) Test(org.junit.jupiter.api.Test)

Example 5 with MosaicAddressRestriction

use of io.nem.symbol.sdk.model.restriction.MosaicAddressRestriction in project nem2-sdk-java by nemtech.

the class RestrictionMosaicRepositoryVertxImpl method toMosaicAddressRestriction.

private MosaicAddressRestriction toMosaicAddressRestriction(MosaicAddressRestrictionDTO mosaicAddressRestrictionDTO) {
    MosaicAddressRestrictionEntryWrapperDTO dto = mosaicAddressRestrictionDTO.getMosaicRestrictionEntry();
    Map<BigInteger, BigInteger> restrictions = dto.getRestrictions().stream().collect(Collectors.toMap(e -> new BigInteger(e.getKey()), e -> toBigInteger(e.getValue())));
    return new MosaicAddressRestriction(mosaicAddressRestrictionDTO.getId(), ObjectUtils.defaultIfNull(dto.getVersion(), 1), dto.getCompositeHash(), MosaicRestrictionEntryType.rawValueOf(dto.getEntryType().getValue()), MapperUtils.toMosaicId(dto.getMosaicId()), MapperUtils.toAddress(dto.getTargetAddress()), restrictions);
}
Also used : MosaicAddressRestrictionEntryWrapperDTO(io.nem.symbol.sdk.openapi.vertx.model.MosaicAddressRestrictionEntryWrapperDTO) RestrictionMosaicRepository(io.nem.symbol.sdk.api.RestrictionMosaicRepository) RestrictionMosaicRoutesApi(io.nem.symbol.sdk.openapi.vertx.api.RestrictionMosaicRoutesApi) MosaicRestrictionEntryTypeEnum(io.nem.symbol.sdk.openapi.vertx.model.MosaicRestrictionEntryTypeEnum) MosaicRestrictionsPage(io.nem.symbol.sdk.openapi.vertx.model.MosaicRestrictionsPage) LinkedHashMap(java.util.LinkedHashMap) MosaicGlobalRestrictionEntryWrapperDTO(io.nem.symbol.sdk.openapi.vertx.model.MosaicGlobalRestrictionEntryWrapperDTO) MosaicRestrictionSearchCriteria(io.nem.symbol.sdk.api.MosaicRestrictionSearchCriteria) MosaicRestriction(io.nem.symbol.sdk.model.restriction.MosaicRestriction) Order(io.nem.symbol.sdk.openapi.vertx.model.Order) MosaicRestrictionType(io.nem.symbol.sdk.model.transaction.MosaicRestrictionType) ObjectUtils(org.apache.commons.lang3.ObjectUtils) Map(java.util.Map) MerkleStateInfo(io.nem.symbol.sdk.model.blockchain.MerkleStateInfo) MosaicGlobalRestrictionEntryRestrictionDTO(io.nem.symbol.sdk.openapi.vertx.model.MosaicGlobalRestrictionEntryRestrictionDTO) Observable(io.reactivex.Observable) BigInteger(java.math.BigInteger) AsyncResult(io.vertx.core.AsyncResult) MosaicGlobalRestrictionDTO(io.nem.symbol.sdk.openapi.vertx.model.MosaicGlobalRestrictionDTO) MapperUtils(io.nem.symbol.core.utils.MapperUtils) ApiClient(io.nem.symbol.sdk.openapi.vertx.invoker.ApiClient) MosaicAddressRestrictionDTO(io.nem.symbol.sdk.openapi.vertx.model.MosaicAddressRestrictionDTO) RestrictionMosaicRoutesApiImpl(io.nem.symbol.sdk.openapi.vertx.api.RestrictionMosaicRoutesApiImpl) MosaicGlobalRestriction(io.nem.symbol.sdk.model.restriction.MosaicGlobalRestriction) MosaicRestrictionEntryType(io.nem.symbol.sdk.model.restriction.MosaicRestrictionEntryType) Collectors(java.util.stream.Collectors) Consumer(java.util.function.Consumer) MosaicGlobalRestrictionItem(io.nem.symbol.sdk.model.restriction.MosaicGlobalRestrictionItem) Handler(io.vertx.core.Handler) Page(io.nem.symbol.sdk.api.Page) MosaicAddressRestriction(io.nem.symbol.sdk.model.restriction.MosaicAddressRestriction) MosaicAddressRestriction(io.nem.symbol.sdk.model.restriction.MosaicAddressRestriction) BigInteger(java.math.BigInteger) MosaicAddressRestrictionEntryWrapperDTO(io.nem.symbol.sdk.openapi.vertx.model.MosaicAddressRestrictionEntryWrapperDTO)

Aggregations

MosaicRestrictionSearchCriteria (io.nem.symbol.sdk.api.MosaicRestrictionSearchCriteria)8 MosaicAddressRestriction (io.nem.symbol.sdk.model.restriction.MosaicAddressRestriction)8 MosaicRestriction (io.nem.symbol.sdk.model.restriction.MosaicRestriction)6 Address (io.nem.symbol.sdk.model.account.Address)4 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)4 ArrayList (java.util.ArrayList)4 Test (org.junit.jupiter.api.Test)4 RestrictionMosaicRepository (io.nem.symbol.sdk.api.RestrictionMosaicRepository)3 MosaicRestrictionEntryType (io.nem.symbol.sdk.model.restriction.MosaicRestrictionEntryType)3 MosaicAddressRestrictionDTO (io.nem.symbol.sdk.openapi.okhttp_gson.model.MosaicAddressRestrictionDTO)3 MosaicAddressRestrictionEntryWrapperDTO (io.nem.symbol.sdk.openapi.okhttp_gson.model.MosaicAddressRestrictionEntryWrapperDTO)3 MosaicAddressRestrictionDTO (io.nem.symbol.sdk.openapi.vertx.model.MosaicAddressRestrictionDTO)3 MosaicAddressRestrictionEntryWrapperDTO (io.nem.symbol.sdk.openapi.vertx.model.MosaicAddressRestrictionEntryWrapperDTO)3 BigInteger (java.math.BigInteger)3 MapperUtils (io.nem.symbol.core.utils.MapperUtils)2 Page (io.nem.symbol.sdk.api.Page)2 MerkleStateInfo (io.nem.symbol.sdk.model.blockchain.MerkleStateInfo)2 MosaicGlobalRestriction (io.nem.symbol.sdk.model.restriction.MosaicGlobalRestriction)2 MosaicGlobalRestrictionItem (io.nem.symbol.sdk.model.restriction.MosaicGlobalRestrictionItem)2 MosaicRestrictionType (io.nem.symbol.sdk.model.transaction.MosaicRestrictionType)2