Search in sources :

Example 36 with TypeReference

use of com.fasterxml.jackson.core.type.TypeReference in project nem2-sdk-java by nemtech.

the class TransactionHttp method getTransactionStatuses.

@Override
public Observable<List<TransactionStatus>> getTransactionStatuses(List<String> transactionHashes) {
    JsonObject requestBody = new JsonObject();
    requestBody.put("hashes", transactionHashes);
    return this.client.postAbs(this.url + "/statuses").as(BodyCodec.jsonArray()).rxSendJson(requestBody).toObservable().map(HttpResponse::body).map(json -> objectMapper.<List<TransactionStatusDTO>>readValue(json.toString(), new TypeReference<List<TransactionStatusDTO>>() {
    })).flatMapIterable(item -> item).map(transactionStatusDTO -> new TransactionStatus(transactionStatusDTO.getGroup(), transactionStatusDTO.getStatus(), transactionStatusDTO.getHash(), new Deadline(transactionStatusDTO.getDeadline().extractIntArray()), transactionStatusDTO.getHeight().extractIntArray())).toList().toObservable();
}
Also used : JsonArray(io.vertx.core.json.JsonArray) List(java.util.List) HttpResponse(io.vertx.reactivex.ext.web.client.HttpResponse) BodyCodec(io.vertx.reactivex.ext.web.codec.BodyCodec) MalformedURLException(java.net.MalformedURLException) Observable(io.reactivex.Observable) JsonObject(io.vertx.core.json.JsonObject) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Collectors(java.util.stream.Collectors) io.nem.sdk.model.transaction(io.nem.sdk.model.transaction) JsonObject(io.vertx.core.json.JsonObject) TypeReference(com.fasterxml.jackson.core.type.TypeReference)

Example 37 with TypeReference

use of com.fasterxml.jackson.core.type.TypeReference in project CzechIdMng by bcvsolutions.

the class IdentityReportExecutorIntegrationTest method testDisabledIdentity.

@Test
@Transactional
public void testDisabledIdentity() throws IOException {
    // prepare test identities
    IdmIdentityDto identityOne = helper.createIdentity();
    IdmIdentityDto identityDisabled = helper.createIdentity();
    identityService.disable(identityDisabled.getId());
    // 
    // prepare report filter
    RptReportDto report = new RptReportDto(UUID.randomUUID());
    report.setExecutorName(reportExecutor.getName());
    IdmFormDto filter = new IdmFormDto();
    IdmFormDefinitionDto definition = reportExecutor.getFormDefinition();
    IdmFormValueDto disabled = new IdmFormValueDto(definition.getMappedAttributeByCode(IdmIdentityFilter.PARAMETER_DISABLED));
    disabled.setValue(false);
    filter.getValues().add(disabled);
    filter.setFormDefinition(definition.getId());
    report.setFilter(filter);
    // 
    // generate report
    report = reportExecutor.generate(report);
    Assert.assertNotNull(report.getData());
    List<IdmIdentityDto> identityRoles = mapper.readValue(attachmentManager.getAttachmentData(report.getData()), new TypeReference<List<IdmIdentityDto>>() {
    });
    // 
    // test
    Assert.assertTrue(identityRoles.stream().anyMatch(i -> i.equals(identityOne)));
    Assert.assertFalse(identityRoles.stream().anyMatch(i -> i.equals(identityDisabled)));
    // 
    attachmentManager.deleteAttachments(report);
}
Also used : Autowired(org.springframework.beans.factory.annotation.Autowired) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) IdmIdentityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter) After(org.junit.After) IdmFormDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDto) TestHelper(eu.bcvsolutions.idm.test.api.TestHelper) Qualifier(org.springframework.beans.factory.annotation.Qualifier) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) TypeReference(com.fasterxml.jackson.core.type.TypeReference) LoginService(eu.bcvsolutions.idm.core.security.api.service.LoginService) Before(org.junit.Before) InitTestData(eu.bcvsolutions.idm.InitTestData) AttachmentManager(eu.bcvsolutions.idm.core.ecm.api.service.AttachmentManager) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) Test(org.junit.Test) UUID(java.util.UUID) RptReportDto(eu.bcvsolutions.idm.rpt.api.dto.RptReportDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) List(java.util.List) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Assert(org.junit.Assert) LoginDto(eu.bcvsolutions.idm.core.security.api.dto.LoginDto) Transactional(org.springframework.transaction.annotation.Transactional) IdmFormDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) List(java.util.List) RptReportDto(eu.bcvsolutions.idm.rpt.api.dto.RptReportDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 38 with TypeReference

use of com.fasterxml.jackson.core.type.TypeReference in project CzechIdMng by bcvsolutions.

the class IdentityReportExecutorIntegrationTest method testDisabledIdentity.

@Test
@Transactional
public void testDisabledIdentity() throws IOException {
    // prepare test identities
    IdmIdentityDto identityOne = helper.createIdentity();
    IdmIdentityDto identityDisabled = helper.createIdentity();
    identityService.disable(identityDisabled.getId());
    // 
    // prepare report filter
    RptReportDto report = new RptReportDto(UUID.randomUUID());
    report.setExecutorName(reportExecutor.getName());
    IdmFormDto filter = new IdmFormDto();
    IdmFormDefinitionDto definition = reportExecutor.getFormDefinition();
    IdmFormValueDto disabled = new IdmFormValueDto(definition.getMappedAttributeByCode(IdmIdentityFilter.PARAMETER_DISABLED));
    disabled.setValue(false);
    filter.getValues().add(disabled);
    filter.setFormDefinition(definition.getId());
    report.setFilter(filter);
    // 
    // generate report
    report = reportExecutor.generate(report);
    Assert.assertNotNull(report.getData());
    List<IdmIdentityDto> identityRoles = mapper.readValue(attachmentManager.getAttachmentData(report.getData()), new TypeReference<List<IdmIdentityDto>>() {
    });
    // 
    // test
    Assert.assertTrue(identityRoles.stream().anyMatch(i -> i.equals(identityOne)));
    Assert.assertFalse(identityRoles.stream().anyMatch(i -> i.equals(identityDisabled)));
    // 
    attachmentManager.deleteAttachments(report);
}
Also used : Autowired(org.springframework.beans.factory.annotation.Autowired) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) IdmIdentityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter) After(org.junit.After) IdmFormDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDto) TestHelper(eu.bcvsolutions.idm.test.api.TestHelper) Qualifier(org.springframework.beans.factory.annotation.Qualifier) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) TypeReference(com.fasterxml.jackson.core.type.TypeReference) LoginService(eu.bcvsolutions.idm.core.security.api.service.LoginService) Before(org.junit.Before) InitTestData(eu.bcvsolutions.idm.InitTestData) IdentityReportXlsxRenderer(eu.bcvsolutions.idm.rpt.renderer.IdentityReportXlsxRenderer) AttachmentManager(eu.bcvsolutions.idm.core.ecm.api.service.AttachmentManager) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) Test(org.junit.Test) UUID(java.util.UUID) RptReportDto(eu.bcvsolutions.idm.rpt.api.dto.RptReportDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) List(java.util.List) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Assert(org.junit.Assert) LoginDto(eu.bcvsolutions.idm.core.security.api.dto.LoginDto) Transactional(org.springframework.transaction.annotation.Transactional) IdmFormDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) List(java.util.List) RptReportDto(eu.bcvsolutions.idm.rpt.api.dto.RptReportDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 39 with TypeReference

use of com.fasterxml.jackson.core.type.TypeReference in project cas by apereo.

the class JsonResourceInterruptInquirer method readResourceForInterrupts.

@SneakyThrows
private void readResourceForInterrupts() {
    this.interrupts = new LinkedHashMap<>();
    if (ResourceUtils.doesResourceExist(resource)) {
        try (Reader reader = new InputStreamReader(resource.getInputStream(), StandardCharsets.UTF_8)) {
            final TypeReference<Map<String, InterruptResponse>> personList = new TypeReference<Map<String, InterruptResponse>>() {
            };
            this.interrupts = MAPPER.readValue(JsonValue.readHjson(reader).toString(), personList);
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) TypeReference(com.fasterxml.jackson.core.type.TypeReference) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) SneakyThrows(lombok.SneakyThrows)

Example 40 with TypeReference

use of com.fasterxml.jackson.core.type.TypeReference in project grakn by graknlabs.

the class StorageConfig method parseStringToMap.

private static Map<String, Object> parseStringToMap(String yaml) {
    ObjectMapper mapper = new ObjectMapper(new YAMLFactory().enable(YAMLGenerator.Feature.MINIMIZE_QUOTES));
    try {
        TypeReference<Map<String, Object>> reference = new TypeReference<Map<String, Object>>() {
        };
        Map<String, Object> yamlParams = mapper.readValue(yaml, reference);
        return Maps.transformValues(yamlParams, value -> value == null ? EMPTY_VALUE : value);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : YAMLFactory(com.fasterxml.jackson.dataformat.yaml.YAMLFactory) TypeReference(com.fasterxml.jackson.core.type.TypeReference) IOException(java.io.IOException) ImmutableMap(com.google.common.collect.ImmutableMap) AbstractMap(java.util.AbstractMap) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

TypeReference (com.fasterxml.jackson.core.type.TypeReference)87 IOException (java.io.IOException)34 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)31 Test (org.junit.Test)25 Map (java.util.Map)19 List (java.util.List)16 HashMap (java.util.HashMap)12 ArrayList (java.util.ArrayList)11 StringWriter (java.io.StringWriter)8 BaseMandrillAnonymousListResponse (com.cribbstechnologies.clients.mandrill.model.response.BaseMandrillAnonymousListResponse)7 ImmutableMap (com.google.common.collect.ImmutableMap)7 InputStream (java.io.InputStream)7 MalformedURLException (java.net.MalformedURLException)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 Collectors (java.util.stream.Collectors)5 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)4 AuditInfo (io.druid.audit.AuditInfo)4 PublicAccount (io.nem.sdk.model.account.PublicAccount)4 NetworkType (io.nem.sdk.model.blockchain.NetworkType)4 NamespaceId (io.nem.sdk.model.namespace.NamespaceId)4