private static void UpdateTrackedEntityInstanceTimestamp( TrackedEntityInstance trackedEntityInstance, DhisApi dhisApi) throws APIException { try { final Map<String, String> QUERY_PARAMS = new HashMap<>(); QUERY_PARAMS.put("fields", "created,lastUpdated"); TrackedEntityInstance updatedTrackedEntityInstance = dhisApi.getTrackedEntityInstance( trackedEntityInstance.getTrackedEntityInstance(), QUERY_PARAMS); // merging updated timestamp to local trackedentityinstance model trackedEntityInstance.setCreated(updatedTrackedEntityInstance.getCreated()); trackedEntityInstance.setLastUpdated(updatedTrackedEntityInstance.getLastUpdated()); trackedEntityInstance.save(); } catch (APIException apiException) { NetworkUtils.handleApiException(apiException); } }
private static void putTrackedEntityInstance( TrackedEntityInstance trackedEntityInstance, DhisApi dhisApi) throws APIException { try { Response response = dhisApi.putTrackedEntityInstance( trackedEntityInstance.getTrackedEntityInstance(), trackedEntityInstance); if (response.getStatus() == 200) { ImportSummary importSummary = getImportSummary(response); handleImportSummary( importSummary, FailedItem.TRACKEDENTITYINSTANCE, trackedEntityInstance.getLocalId()); if (ImportSummary.SUCCESS.equals(importSummary.getStatus()) || ImportSummary.OK.equals(importSummary.getStatus())) { // trackedentityinstance.setState(State.SYNCED); trackedEntityInstance.setFromServer(true); trackedEntityInstance.save(); clearFailedItem(FailedItem.TRACKEDENTITYINSTANCE, trackedEntityInstance.getLocalId()); UpdateTrackedEntityInstanceTimestamp(trackedEntityInstance, dhisApi); } } } catch (APIException apiException) { NetworkUtils.handleTrackedEntityInstanceSendException(apiException, trackedEntityInstance); } }