use of org.codehaus.jackson.JsonParseException in project openmrs-module-coreapps by openmrs.
the class VisitTypeHelper method getOrderedVisitTypes.
/**
* Returns a list of ordered visit types.
*
* @param visitTypes All the visit types
* @param propertyValue The visit types to order in JSON-like format
* @param visitService
* @return visitTypesOrdered The visit types ordered and merged with the input visit type list
*/
public List<VisitType> getOrderedVisitTypes(List<VisitType> visitTypes, String propertyValue, VisitService visitService) {
Map<Integer, String> order = null;
List<VisitType> visitTypesOrdered = new ArrayList<VisitType>();
if (propertyValue != null) {
try {
order = new ObjectMapper().readValue(propertyValue, HashMap.class);
} catch (JsonParseException e) {
VisitTypeHelper.LOG.error("Unable to parse global property \"" + CoreAppsConstants.VISIT_TYPES_ORDER_PROPERTY + "\"");
} catch (JsonMappingException e) {
VisitTypeHelper.LOG.error("Unable to map global property \"" + CoreAppsConstants.VISIT_TYPES_ORDER_PROPERTY + "\"");
} catch (APIException e) {
VisitTypeHelper.LOG.error("Unable to load global property \"" + CoreAppsConstants.VISIT_TYPES_ORDER_PROPERTY + "\"");
} catch (IOException e) {
VisitTypeHelper.LOG.error("Unable to read global property \"" + CoreAppsConstants.VISIT_TYPES_ORDER_PROPERTY + "\"");
}
}
if (order != null) {
for (int i = 1; i <= order.size(); i++) {
String typeUuid = order.get(Integer.toString(i));
VisitType type = visitService.getVisitTypeByUuid(typeUuid);
if (visitTypes.contains(type)) {
visitTypesOrdered.add(visitService.getVisitTypeByUuid(typeUuid));
}
}
for (VisitType type : visitTypes) {
if (!order.containsValue(type.getUuid())) {
visitTypesOrdered.add(type);
}
}
}
if (!(visitTypes.size() == visitTypesOrdered.size())) {
VisitTypeHelper.LOG.warn("Visit Types order property is not used.");
return visitTypes;
}
return visitTypesOrdered;
}
use of org.codehaus.jackson.JsonParseException in project OpenOLAT by OpenOLAT.
the class EdubaseManagerImpl method fetchBookDetails.
@Override
public BookDetails fetchBookDetails(String bookId) {
BookDetails infoReponse = new BookDetailsImpl();
RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(TIMEOUT_5000_MILLIS).setConnectTimeout(TIMEOUT_5000_MILLIS).setConnectionRequestTimeout(TIMEOUT_5000_MILLIS).build();
String url = String.format(edubaseModule.getInfoverUrl(), bookId);
HttpGet request = new HttpGet(url);
request.setConfig(requestConfig);
try (CloseableHttpClient httpClient = HttpClients.createDefault();
CloseableHttpResponse httpResponse = httpClient.execute(request)) {
String json = EntityUtils.toString(httpResponse.getEntity(), "UTF-8");
ObjectMapper objectMapper = new ObjectMapper();
infoReponse = objectMapper.readValue(json, BookDetailsImpl.class);
} catch (SocketTimeoutException socketTimeoutException) {
log.warn("Socket Timeout while requesting informations of the Edubase book with the id " + bookId);
} catch (JsonParseException | EOFException noesNotExitsException) {
log.debug("Error while requesting informations for the Edubase book with the id " + bookId + ": Book does not exist.");
} catch (Exception e) {
log.error("", e);
}
return infoReponse;
}
use of org.codehaus.jackson.JsonParseException in project carina by qaprosoft.
the class MobileFactory method getDeviceInfo.
/**
* Returns device information from Grid Hub using STF service.
*
* @param seleniumHost - Selenium Grid host
* @param sessionId - Selenium session id
* @return remote device information
*/
private RemoteDevice getDeviceInfo(String seleniumHost, String sessionId) {
RemoteDevice device = null;
try {
HttpClient client = HttpClientBuilder.create().build();
HttpGet request = new HttpGet(seleniumHost.split("wd")[0] + "grid/admin/DeviceInfo?session=" + sessionId);
HttpResponse response = client.execute(request);
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
device = mapper.readValue(response.getEntity().getContent(), RemoteDevice.class);
} catch (JsonParseException e) {
// do nothing as it is direct call to the Appium without selenium
} catch (Exception e) {
LOGGER.error("Unable to get device info: " + e.getMessage());
}
return device;
}
use of org.codehaus.jackson.JsonParseException in project ovirt-engine by oVirt.
the class AttestationService method attestHosts.
public List<AttestationValue> attestHosts(List<String> hosts) {
String pollURI = Config.getValue(ConfigValues.PollUri);
List<AttestationValue> values = new ArrayList<>();
PostMethod postMethod = new PostMethod("/" + pollURI);
try {
postMethod.setRequestEntity(new StringRequestEntity(writeListJson(hosts)));
postMethod.addRequestHeader("Accept", CONTENT_TYPE);
postMethod.addRequestHeader("Content-type", CONTENT_TYPE);
HttpClient httpClient = getClient();
int statusCode = httpClient.executeMethod(postMethod);
String strResponse = postMethod.getResponseBodyAsString();
log.debug("return attested result: {}", strResponse);
if (statusCode == 200) {
values = parsePostedResp(strResponse);
} else {
log.error("attestation error: {}", strResponse);
}
} catch (JsonParseException e) {
log.error("Failed to parse result: {}", e.getMessage());
log.debug("Exception", e);
} catch (IOException e) {
log.error("Failed to attest hosts, make sure hosts are up and reachable: {}", e.getMessage());
log.debug("Exception", e);
} finally {
postMethod.releaseConnection();
}
return values;
}
use of org.codehaus.jackson.JsonParseException in project stanbol by apache.
the class AnalyzedTextParser method parseAnnotation.
private void parseAnnotation(Span span, String key, ObjectNode jValue) throws IOException {
JsonNode jClass = jValue.path("class");
if (!jClass.isTextual()) {
log.warn("unable to parse Annotation {} because 'class' field " + "is not set or not a stringis no JSON object (ignored, json: {}", key, jValue);
return;
}
Class<?> clazz;
try {
clazz = AnalyzedTextParser.class.getClassLoader().loadClass(jClass.getTextValue());
} catch (ClassNotFoundException e) {
log.warn("Unable to parse Annotation " + key + " because the 'class' " + jClass.getTextValue() + " of the " + "the value can not be resolved (ignored, json: " + jValue + ")", e);
return;
}
ValueTypeParser<?> parser = this.valueTypeParserRegistry.getParser(clazz);
Object value;
if (parser != null) {
value = parser.parse(jValue, span.getContext());
} else {
JsonNode valueNode = jValue.path("value");
if (valueNode.isMissingNode()) {
log.warn("unable to parse value for annotation {} because the " + "field 'value' is not present (ignored, json: {}", key, jValue);
return;
} else {
try {
value = mapper.treeToValue(valueNode, clazz);
} catch (JsonParseException e) {
log.warn("unable to parse value for annotation " + key + "because the value can" + "not be converted to the class " + clazz.getName() + "(ignored, json: " + jValue + ")", e);
return;
} catch (JsonMappingException e) {
log.warn("unable to parse value for annotation " + key + "because the value can" + "not be converted to the class " + clazz.getName() + "(ignored, json: " + jValue + ")", e);
return;
}
}
}
JsonNode jProb = jValue.path("prob");
if (!jProb.isDouble()) {
span.addValue(key, Value.value(value));
} else {
span.addValue(key, Value.value(value, jProb.getDoubleValue()));
}
}
Aggregations