Search in sources :

Example 1 with MosaicGlobalRestriction

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

the class RestrictionMosaicRepositoryOkHttpImplTest method shouldMosaicGlobalRestriction.

@Test
public void shouldMosaicGlobalRestriction() throws Exception {
    MosaicId mosaicId = MapperUtils.toMosaicId("123");
    MosaicGlobalRestrictionDTO dto = new MosaicGlobalRestrictionDTO();
    MosaicGlobalRestrictionEntryWrapperDTO wrapperDTO = new MosaicGlobalRestrictionEntryWrapperDTO();
    dto.setMosaicRestrictionEntry(wrapperDTO);
    MosaicGlobalRestrictionEntryDTO entryDTO = new MosaicGlobalRestrictionEntryDTO();
    entryDTO.setKey(ConvertUtils.toString(BigInteger.valueOf(1111)));
    MosaicGlobalRestrictionEntryRestrictionDTO entryRestrictionDto = new MosaicGlobalRestrictionEntryRestrictionDTO();
    entryRestrictionDto.setRestrictionType(MosaicRestrictionTypeEnum.NUMBER_5);
    entryRestrictionDto.setReferenceMosaicId("456");
    entryRestrictionDto.setRestrictionValue(BigInteger.valueOf(3333));
    entryDTO.setRestriction(entryRestrictionDto);
    List<MosaicGlobalRestrictionEntryDTO> restrictions = new ArrayList<>();
    restrictions.add(entryDTO);
    wrapperDTO.setCompositeHash("compositeHash");
    wrapperDTO.setMosaicId(mosaicId.getIdAsHex());
    wrapperDTO.setRestrictions(restrictions);
    wrapperDTO.setEntryType(MosaicRestrictionEntryTypeEnum.NUMBER_1);
    wrapperDTO.setVersion(1);
    mockRemoteCall(toPage(dto));
    MosaicGlobalRestriction mosaicGlobalRestriction = (MosaicGlobalRestriction) repository.search(new MosaicRestrictionSearchCriteria()).toFuture().get().getData().get(0);
    Assertions.assertEquals(wrapperDTO.getCompositeHash(), mosaicGlobalRestriction.getCompositeHash());
    Assertions.assertEquals(MosaicRestrictionEntryType.GLOBAL, mosaicGlobalRestriction.getEntryType());
    Assertions.assertEquals(mosaicId, mosaicGlobalRestriction.getMosaicId());
    Assertions.assertEquals(1, mosaicGlobalRestriction.getRestrictions().size());
    Assertions.assertEquals(BigInteger.valueOf(3333), mosaicGlobalRestriction.getRestrictions().get(BigInteger.valueOf(1111)).getRestrictionValue());
    Assertions.assertEquals("0000000000000456", mosaicGlobalRestriction.getRestrictions().get(BigInteger.valueOf(1111)).getReferenceMosaicId().getIdAsHex());
    Assertions.assertEquals(MosaicRestrictionType.GT, mosaicGlobalRestriction.getRestrictions().get(BigInteger.valueOf((1111))).getRestrictionType());
}
Also used : MosaicGlobalRestrictionEntryDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.MosaicGlobalRestrictionEntryDTO) MosaicGlobalRestrictionEntryRestrictionDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.MosaicGlobalRestrictionEntryRestrictionDTO) MosaicGlobalRestrictionDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.MosaicGlobalRestrictionDTO) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) ArrayList(java.util.ArrayList) MosaicRestrictionSearchCriteria(io.nem.symbol.sdk.api.MosaicRestrictionSearchCriteria) MosaicGlobalRestrictionEntryWrapperDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.MosaicGlobalRestrictionEntryWrapperDTO) MosaicGlobalRestriction(io.nem.symbol.sdk.model.restriction.MosaicGlobalRestriction) Test(org.junit.jupiter.api.Test)

Example 2 with MosaicGlobalRestriction

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

the class RestrictionMosaicRepositoryVertxImpl method toMosaicGlobalRestriction.

private MosaicGlobalRestriction toMosaicGlobalRestriction(MosaicGlobalRestrictionDTO mosaicGlobalRestrictionDTO) {
    MosaicGlobalRestrictionEntryWrapperDTO dto = mosaicGlobalRestrictionDTO.getMosaicRestrictionEntry();
    Map<BigInteger, MosaicGlobalRestrictionItem> restrictions = dto.getRestrictions().stream().collect(Collectors.toMap(e -> new BigInteger(e.getKey()), e -> toMosaicGlobalRestrictionItem(e.getRestriction()), (x, y) -> y, LinkedHashMap::new));
    return new MosaicGlobalRestriction(mosaicGlobalRestrictionDTO.getId(), ObjectUtils.defaultIfNull(mosaicGlobalRestrictionDTO.getMosaicRestrictionEntry().getVersion(), 1), dto.getCompositeHash(), MosaicRestrictionEntryType.rawValueOf(dto.getEntryType().getValue()), MapperUtils.toMosaicId(dto.getMosaicId()), 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) MosaicGlobalRestrictionItem(io.nem.symbol.sdk.model.restriction.MosaicGlobalRestrictionItem) BigInteger(java.math.BigInteger) MosaicGlobalRestrictionEntryWrapperDTO(io.nem.symbol.sdk.openapi.vertx.model.MosaicGlobalRestrictionEntryWrapperDTO) MosaicGlobalRestriction(io.nem.symbol.sdk.model.restriction.MosaicGlobalRestriction)

Example 3 with MosaicGlobalRestriction

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

the class RestrictionMosaicRepositoryOkHttpImpl method toMosaicGlobalRestriction.

private MosaicGlobalRestriction toMosaicGlobalRestriction(MosaicGlobalRestrictionDTO mosaicGlobalRestrictionDTO) {
    MosaicGlobalRestrictionEntryWrapperDTO dto = mosaicGlobalRestrictionDTO.getMosaicRestrictionEntry();
    Map<BigInteger, MosaicGlobalRestrictionItem> restrictions = dto.getRestrictions().stream().collect(Collectors.toMap(e -> new BigInteger(e.getKey()), e -> toMosaicGlobalRestrictionItem(e.getRestriction()), (x, y) -> y, LinkedHashMap::new));
    return new MosaicGlobalRestriction(mosaicGlobalRestrictionDTO.getId(), ObjectUtils.defaultIfNull(mosaicGlobalRestrictionDTO.getMosaicRestrictionEntry().getVersion(), 1), dto.getCompositeHash(), MosaicRestrictionEntryType.rawValueOf(dto.getEntryType().getValue()), MapperUtils.toMosaicId(dto.getMosaicId()), 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) MosaicGlobalRestrictionItem(io.nem.symbol.sdk.model.restriction.MosaicGlobalRestrictionItem) BigInteger(java.math.BigInteger) MosaicGlobalRestrictionEntryWrapperDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.MosaicGlobalRestrictionEntryWrapperDTO) MosaicGlobalRestriction(io.nem.symbol.sdk.model.restriction.MosaicGlobalRestriction)

Example 4 with MosaicGlobalRestriction

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

the class RestrictionMosaicRepositoryVertxImplTest method shouldGetMosaicGlobalRestrictions.

@Test
public void shouldGetMosaicGlobalRestrictions() throws Exception {
    MosaicId mosaicId = MapperUtils.toMosaicId("123");
    MosaicGlobalRestrictionDTO dto = new MosaicGlobalRestrictionDTO();
    MosaicGlobalRestrictionEntryWrapperDTO wrapperDTO = new MosaicGlobalRestrictionEntryWrapperDTO();
    dto.setMosaicRestrictionEntry(wrapperDTO);
    MosaicGlobalRestrictionEntryDTO entryDTO = new MosaicGlobalRestrictionEntryDTO();
    entryDTO.setKey(ConvertUtils.toString(BigInteger.valueOf(1111)));
    MosaicGlobalRestrictionEntryRestrictionDTO entryRestrictionDto = new MosaicGlobalRestrictionEntryRestrictionDTO();
    entryRestrictionDto.setRestrictionType(MosaicRestrictionTypeEnum.NUMBER_5);
    entryRestrictionDto.setReferenceMosaicId("456");
    entryRestrictionDto.setRestrictionValue(BigInteger.valueOf(3333));
    entryDTO.setRestriction(entryRestrictionDto);
    List<MosaicGlobalRestrictionEntryDTO> restrictions = new ArrayList<>();
    restrictions.add(entryDTO);
    wrapperDTO.setCompositeHash("compositeHash");
    wrapperDTO.setMosaicId(mosaicId.getIdAsHex());
    wrapperDTO.setRestrictions(restrictions);
    wrapperDTO.setVersion(1);
    wrapperDTO.setEntryType(MosaicRestrictionEntryTypeEnum.NUMBER_1);
    mockRemoteCall(toPage(dto));
    List<MosaicRestriction<?>> mosaicGlobalRestrictions = repository.search(new MosaicRestrictionSearchCriteria()).toFuture().get().getData();
    Assertions.assertEquals(1, mosaicGlobalRestrictions.size());
    MosaicGlobalRestriction mosaicGlobalRestriction = (MosaicGlobalRestriction) mosaicGlobalRestrictions.get(0);
    Assertions.assertEquals(wrapperDTO.getCompositeHash(), mosaicGlobalRestriction.getCompositeHash());
    Assertions.assertEquals(MosaicRestrictionEntryType.GLOBAL, mosaicGlobalRestriction.getEntryType());
    Assertions.assertEquals(mosaicId, mosaicGlobalRestriction.getMosaicId());
    Assertions.assertEquals(1, mosaicGlobalRestriction.getRestrictions().size());
    Assertions.assertEquals(BigInteger.valueOf(3333), mosaicGlobalRestriction.getRestrictions().get(BigInteger.valueOf(1111)).getRestrictionValue());
    Assertions.assertEquals("0000000000000456", mosaicGlobalRestriction.getRestrictions().get(BigInteger.valueOf(1111)).getReferenceMosaicId().getIdAsHex());
    Assertions.assertEquals(MosaicRestrictionType.GT, mosaicGlobalRestriction.getRestrictions().get(BigInteger.valueOf(1111)).getRestrictionType());
}
Also used : MosaicGlobalRestrictionEntryDTO(io.nem.symbol.sdk.openapi.vertx.model.MosaicGlobalRestrictionEntryDTO) MosaicGlobalRestrictionEntryRestrictionDTO(io.nem.symbol.sdk.openapi.vertx.model.MosaicGlobalRestrictionEntryRestrictionDTO) MosaicGlobalRestrictionDTO(io.nem.symbol.sdk.openapi.vertx.model.MosaicGlobalRestrictionDTO) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) ArrayList(java.util.ArrayList) MosaicRestriction(io.nem.symbol.sdk.model.restriction.MosaicRestriction) MosaicRestrictionSearchCriteria(io.nem.symbol.sdk.api.MosaicRestrictionSearchCriteria) MosaicGlobalRestrictionEntryWrapperDTO(io.nem.symbol.sdk.openapi.vertx.model.MosaicGlobalRestrictionEntryWrapperDTO) MosaicGlobalRestriction(io.nem.symbol.sdk.model.restriction.MosaicGlobalRestriction) Test(org.junit.jupiter.api.Test)

Example 5 with MosaicGlobalRestriction

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

the class RestrictionMosaicRepositoryOkHttpImplTest method shouldGetMosaicGlobalRestrictions.

@Test
public void shouldGetMosaicGlobalRestrictions() throws Exception {
    MosaicId mosaicId = MapperUtils.toMosaicId("123");
    MosaicGlobalRestrictionDTO dto = new MosaicGlobalRestrictionDTO();
    MosaicGlobalRestrictionEntryWrapperDTO wrapperDTO = new MosaicGlobalRestrictionEntryWrapperDTO();
    dto.setMosaicRestrictionEntry(wrapperDTO);
    MosaicGlobalRestrictionEntryDTO entryDTO = new MosaicGlobalRestrictionEntryDTO();
    entryDTO.setKey(ConvertUtils.toString(BigInteger.valueOf(1111)));
    MosaicGlobalRestrictionEntryRestrictionDTO entryRestrictionDto = new MosaicGlobalRestrictionEntryRestrictionDTO();
    entryRestrictionDto.setRestrictionType(MosaicRestrictionTypeEnum.NUMBER_5);
    entryRestrictionDto.setReferenceMosaicId("456");
    entryRestrictionDto.setRestrictionValue(BigInteger.valueOf(3333));
    entryDTO.setRestriction(entryRestrictionDto);
    List<MosaicGlobalRestrictionEntryDTO> restrictions = new ArrayList<>();
    restrictions.add(entryDTO);
    wrapperDTO.setCompositeHash("compositeHash");
    wrapperDTO.setMosaicId(mosaicId.getIdAsHex());
    wrapperDTO.setRestrictions(restrictions);
    wrapperDTO.setEntryType(MosaicRestrictionEntryTypeEnum.NUMBER_1);
    wrapperDTO.setVersion(1);
    mockRemoteCall(toPage(dto));
    List<MosaicRestriction<?>> mosaicGlobalRestrictions = repository.search(new MosaicRestrictionSearchCriteria()).toFuture().get().getData();
    Assertions.assertEquals(1, mosaicGlobalRestrictions.size());
    MosaicGlobalRestriction mosaicGlobalRestriction = (MosaicGlobalRestriction) mosaicGlobalRestrictions.get(0);
    Assertions.assertEquals(wrapperDTO.getCompositeHash(), mosaicGlobalRestriction.getCompositeHash());
    Assertions.assertEquals(MosaicRestrictionEntryType.GLOBAL, mosaicGlobalRestriction.getEntryType());
    Assertions.assertEquals(mosaicId, mosaicGlobalRestriction.getMosaicId());
    Assertions.assertEquals(1, mosaicGlobalRestriction.getRestrictions().size());
    Assertions.assertEquals(BigInteger.valueOf(3333), mosaicGlobalRestriction.getRestrictions().get(BigInteger.valueOf(1111)).getRestrictionValue());
    Assertions.assertEquals("0000000000000456", mosaicGlobalRestriction.getRestrictions().get(BigInteger.valueOf(1111)).getReferenceMosaicId().getIdAsHex());
    Assertions.assertEquals(MosaicRestrictionType.GT, mosaicGlobalRestriction.getRestrictions().get(BigInteger.valueOf(1111)).getRestrictionType());
}
Also used : MosaicGlobalRestrictionEntryDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.MosaicGlobalRestrictionEntryDTO) MosaicGlobalRestrictionEntryRestrictionDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.MosaicGlobalRestrictionEntryRestrictionDTO) MosaicGlobalRestrictionDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.MosaicGlobalRestrictionDTO) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) ArrayList(java.util.ArrayList) MosaicRestriction(io.nem.symbol.sdk.model.restriction.MosaicRestriction) MosaicRestrictionSearchCriteria(io.nem.symbol.sdk.api.MosaicRestrictionSearchCriteria) MosaicGlobalRestrictionEntryWrapperDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.MosaicGlobalRestrictionEntryWrapperDTO) MosaicGlobalRestriction(io.nem.symbol.sdk.model.restriction.MosaicGlobalRestriction) Test(org.junit.jupiter.api.Test)

Aggregations

MosaicRestrictionSearchCriteria (io.nem.symbol.sdk.api.MosaicRestrictionSearchCriteria)7 MosaicGlobalRestriction (io.nem.symbol.sdk.model.restriction.MosaicGlobalRestriction)7 MosaicRestriction (io.nem.symbol.sdk.model.restriction.MosaicRestriction)5 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 MosaicGlobalRestrictionDTO (io.nem.symbol.sdk.openapi.okhttp_gson.model.MosaicGlobalRestrictionDTO)3 MosaicGlobalRestrictionEntryRestrictionDTO (io.nem.symbol.sdk.openapi.okhttp_gson.model.MosaicGlobalRestrictionEntryRestrictionDTO)3 MosaicGlobalRestrictionEntryWrapperDTO (io.nem.symbol.sdk.openapi.okhttp_gson.model.MosaicGlobalRestrictionEntryWrapperDTO)3 MosaicGlobalRestrictionDTO (io.nem.symbol.sdk.openapi.vertx.model.MosaicGlobalRestrictionDTO)3 MosaicGlobalRestrictionEntryRestrictionDTO (io.nem.symbol.sdk.openapi.vertx.model.MosaicGlobalRestrictionEntryRestrictionDTO)3 MosaicGlobalRestrictionEntryWrapperDTO (io.nem.symbol.sdk.openapi.vertx.model.MosaicGlobalRestrictionEntryWrapperDTO)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 MosaicAddressRestriction (io.nem.symbol.sdk.model.restriction.MosaicAddressRestriction)2 MosaicGlobalRestrictionItem (io.nem.symbol.sdk.model.restriction.MosaicGlobalRestrictionItem)2 MosaicRestrictionType (io.nem.symbol.sdk.model.transaction.MosaicRestrictionType)2