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;
}
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;
}
}
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();
}
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);
}
}
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;
}
Aggregations