Search in sources :

Example 51 with JsonProcessingException

use of com.fasterxml.jackson.core.JsonProcessingException in project IPK-BrAPI-Validator by plantbreeding.

the class RunnerService method TestAllEndpointsWithFreq.

/**
 * Test all endpoints with a certain frequency set in database
 *
 * @param testCollection Config instance.
 * @param frequency      Get endpoints with this frequency.
 * @return List of TestSuiteReport containing the test results.
 * @throws SQLException SQL connection
 */
public static int TestAllEndpointsWithFreq(TestCollection testCollection, String frequency) throws SQLException {
    List<Resource> l = ResourceService.getAllEndpointsWithFreq(frequency);
    LOGGER.info("Endpoints found: " + l.size());
    int count = 0;
    boolean sent;
    for (int i = 0; i < l.size(); i++) {
        Resource resource = l.get(i);
        TestSuiteReport testSuiteReport = RunnerService.testEndpointWithCall(resource, testCollection);
        final int N = resource.getStoreprev();
        // Get last N reports
        List<TestReport> prevReports = TestReportService.getLastReports(resource, N);
        if (prevReports.size() >= N) {
            // Delete older than last N.
            TestReportService.deleteOlderThan(prevReports.get(prevReports.size() - 1));
        }
        ObjectMapper mapper = new ObjectMapper();
        try {
            TestReport report = new TestReport(resource, mapper.writeValueAsString(testSuiteReport));
            String reportId = TestReportService.saveReport(report);
            testSuiteReport.setId(reportId);
        } catch (JsonProcessingException e) {
            LOGGER.warn("Unable to save report:" + e.getMessage());
        }
        EmailManager manager = new EmailManager(resource);
        manager.setPrevReports(prevReports);
        sent = manager.sendReport(testSuiteReport);
        if (sent) {
            count += 1;
        }
    }
    return count;
}
Also used : EmailManager(de.ipk_gatersleben.bit.bi.bridge.brapicomp.ci.EmailManager) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 52 with JsonProcessingException

use of com.fasterxml.jackson.core.JsonProcessingException in project dal by ctripcorp.

the class DatabaseResource method getOneDB.

@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("getOneDB")
public Status getOneDB(@Context HttpServletRequest request, @FormParam("allinonename") String allinonename) throws Exception {
    try {
        String userNo = RequestUtil.getUserNo(request);
        Status status = Status.OK();
        DalGroupDBDao allDbDao = BeanGetter.getDaoOfDalGroupDB();
        DalGroupDB groupDb = allDbDao.getGroupDBByDbName(allinonename);
        LoginUser user = BeanGetter.getDaoOfLoginUser().getUserByNo(userNo);
        if (!validatePermision(user.getId(), groupDb.getDal_group_id())) {
            status = Status.ERROR();
            status.setInfo("你没有当前DataBase的操作权限.");
            return status;
        }
        try {
            if (DatabaseType.MySQL.getValue().equals(groupDb.getDb_providerName())) {
                groupDb.setDb_providerName(DatabaseType.MySQL.toString());
            } else if (DatabaseType.SQLServer.getValue().equals(groupDb.getDb_providerName())) {
                groupDb.setDb_providerName(DatabaseType.SQLServer.toString());
            } else {
                groupDb.setDb_providerName("no");
            }
            status.setInfo(mapper.writeValueAsString(groupDb));
        } catch (JsonProcessingException e) {
            status = Status.ERROR();
            status.setInfo(e.getMessage());
            return status;
        }
        return Status.OK();
    } catch (Throwable e) {
        LoggerManager.getInstance().error(e);
        Status status = Status.ERROR();
        status.setInfo(e.getMessage());
        return status;
    }
}
Also used : Status(com.ctrip.platform.dal.daogen.domain.Status) DalGroupDBDao(com.ctrip.platform.dal.daogen.dao.DalGroupDBDao) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 53 with JsonProcessingException

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

the class IdentityContractSecurityTest method createWorkPositions.

@Test
public void createWorkPositions() {
    SecurityMockMvcRequestPostProcessors.securityContext(null);
    IdmIdentityDto user = identityService.getByUsername("kopr");
    Map<String, String> body = new HashMap<>();
    body.put("identity", user.getId().toString());
    body.put("position", "TEST_POSITION");
    String jsonContent = null;
    try {
        jsonContent = mapper.writeValueAsString(body);
    } catch (JsonProcessingException e1) {
        e1.printStackTrace();
    }
    int status = 0;
    Exception ex = null;
    try {
        status = getMockMvc().perform(post(BaseDtoController.BASE_PATH + "/identity-contracts").content(jsonContent).contentType(MediaType.APPLICATION_JSON)).andReturn().getResponse().getStatus();
    } catch (Exception e) {
        ex = e;
    }
    assertNull(ex);
    assertEquals(403, status);
    ex = null;
    status = 0;
    try {
        status = getMockMvc().perform(post(BaseDtoController.BASE_PATH + "/identity-contracts").with(authentication(getAuthentication())).contentType(MediaType.APPLICATION_JSON).content(jsonContent)).andReturn().getResponse().getStatus();
    } catch (Exception e) {
        ex = e;
    }
    assertNull(ex);
    assertEquals(201, status);
    logout();
}
Also used : HashMap(java.util.HashMap) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) AbstractRestTest(eu.bcvsolutions.idm.test.api.AbstractRestTest) Test(org.junit.Test)

Example 54 with JsonProcessingException

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

the class TestFilterReportExecutor method generateData.

@Override
protected IdmAttachmentDto generateData(RptReportDto report) {
    try {
        IdmFormInstanceDto formInstance = new IdmFormInstanceDto(report, getFormDefinition(), report.getFilter());
        String username = (String) formInstance.toSinglePersistentValue(IdmIdentity_.username.getName());
        List<IdmIdentityDto> results = TestReportExecutor.identities.stream().filter(identity -> {
            return StringUtils.isEmpty(username) || username.equals(identity.getUsername());
        }).collect(Collectors.toList());
        return createAttachment(report, IOUtils.toInputStream(getMapper().writeValueAsString(results)));
    } catch (FileNotFoundException | JsonProcessingException ex) {
        throw new ReportGenerateException(report.getName(), ex);
    }
}
Also used : IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) Description(org.springframework.context.annotation.Description) IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) AbstractReportExecutor(eu.bcvsolutions.idm.rpt.api.executor.AbstractReportExecutor) FileNotFoundException(java.io.FileNotFoundException) PersistentType(eu.bcvsolutions.idm.core.eav.api.domain.PersistentType) RptReportDto(eu.bcvsolutions.idm.rpt.api.dto.RptReportDto) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Component(org.springframework.stereotype.Component) Lists(com.google.common.collect.Lists) ReportGenerateException(eu.bcvsolutions.idm.rpt.api.exception.ReportGenerateException) IdmIdentity_(eu.bcvsolutions.idm.core.model.entity.IdmIdentity_) IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) FileNotFoundException(java.io.FileNotFoundException) ReportGenerateException(eu.bcvsolutions.idm.rpt.api.exception.ReportGenerateException) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 55 with JsonProcessingException

use of com.fasterxml.jackson.core.JsonProcessingException in project syndesis-qe by syndesisio.

the class AtlasMapperGenerator method processDataShapeIntoFields.

private List<Field> processDataShapeIntoFields(String stepSpecification, DataShapeKinds dsKind) {
    ObjectMapper mapper = new ObjectMapper();
    mapper.enable(DeserializationFeature.UNWRAP_ROOT_VALUE);
    List<Field> fields = null;
    log.debug(stepSpecification);
    if (dsKind.equals(DataShapeKinds.JAVA)) {
        try {
            JavaClass jClass = mapper.readValue(stepSpecification, JavaClass.class);
            jClass = mapper.readValue(stepSpecification, JavaClass.class);
            List<JavaField> jfields = getJavaFields(jClass);
            fields = jfields.stream().map(f -> (Field) f).collect(Collectors.toList());
        } catch (IOException e) {
            log.error("error: {}" + e);
        }
    } else if (dsKind.equals(DataShapeKinds.JSON_SCHEMA) || dsKind.equals(DataShapeKinds.JSON_INSTANCE)) {
        JsonInspectionResponse inspectionResponse = atlasmapEndpoint.inspectJson(generateJsonInspectionRequest(stepSpecification));
        try {
            String mapperString = mapper.writeValueAsString(inspectionResponse);
            log.debug(mapperString);
            fields = inspectionResponse.getJsonDocument().getFields().getField();
        } catch (JsonProcessingException e) {
            log.error("error: {}" + e);
        }
    } else if (dsKind.equals(DataShapeKinds.XML_SCHEMA) || dsKind.equals(DataShapeKinds.XML_INSTANCE)) {
        // TODO(tplevko)
        throw new UnsupportedOperationException("XML support is not implemented yet");
    }
    return fields;
}
Also used : Field(io.atlasmap.v2.Field) JavaField(io.atlasmap.java.v2.JavaField) JavaField(io.atlasmap.java.v2.JavaField) JavaClass(io.atlasmap.java.v2.JavaClass) JsonInspectionResponse(io.atlasmap.json.v2.JsonInspectionResponse) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)153 IOException (java.io.IOException)43 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)42 HashMap (java.util.HashMap)18 ArrayList (java.util.ArrayList)15 Test (org.junit.Test)14 InputStream (java.io.InputStream)11 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 List (java.util.List)8 Map (java.util.Map)8 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)7 ErrorResponseBody (com.nike.riposte.server.error.handler.ErrorResponseBody)6 HttpProcessingState (com.nike.riposte.server.http.HttpProcessingState)6 OutputStreamWriter (java.io.OutputStreamWriter)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 TaskDTO (com.linkedin.thirdeye.datalayer.dto.TaskDTO)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 SimpleDateFormat (java.text.SimpleDateFormat)4 Test (org.testng.annotations.Test)4