private static ImportSummary getPostImportSummary(Response response) { ImportSummary importSummary = null; try { String body = new StringConverter().fromBody(response.getBody(), String.class); Log.d(CLASS_TAG, body); importSummary = DhisController.getInstance().getObjectMapper().readValue(body, ImportSummary.class); } catch (IOException e) { e.printStackTrace(); } catch (ConversionException e) { e.printStackTrace(); } return importSummary; }
private static ImportSummary getPutImportSummary(Response response) { ApiResponse apiResponse = null; try { String body = new StringConverter().fromBody(response.getBody(), String.class); Log.d(CLASS_TAG, body); apiResponse = DhisController.getInstance().getObjectMapper().readValue(body, ApiResponse.class); if (apiResponse != null && apiResponse.getImportSummaries() != null && !apiResponse.getImportSummaries().isEmpty()) { return (apiResponse.getImportSummaries().get(0)); } } catch (IOException e) { e.printStackTrace(); } catch (ConversionException e) { e.printStackTrace(); } return null; }
private static ImportSummary getImportSummary(Response response) { // because the web api almost randomly gives the responses in different forms, this // method checks which one it is that is being returned, and parses accordingly. try { JsonNode node = DhisController.getInstance() .getObjectMapper() .readTree(new StringConverter().fromBody(response.getBody(), String.class)); if (node == null) { return null; } if (node.has("response")) { return getPutImportSummary(response); } else { return getPostImportSummary(response); } } catch (IOException e) { e.printStackTrace(); } catch (ConversionException e) { e.printStackTrace(); } return null; }