コード例 #1
0
  private static void postTrackedEntityInstance(
      TrackedEntityInstance trackedEntityInstance, DhisApi dhisApi) throws APIException {
    try {
      Response response = dhisApi.postTrackedEntityInstance(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())) {

          // change state and save trackedentityinstance

          // trackedEntityInstance.setState(State.SYNCED);
          trackedEntityInstance.setFromServer(true);
          trackedEntityInstance.save();

          clearFailedItem(FailedItem.TRACKEDENTITYINSTANCE, trackedEntityInstance.getLocalId());
          UpdateTrackedEntityInstanceTimestamp(trackedEntityInstance, dhisApi);
        }
      }
    } catch (APIException apiException) {
      NetworkUtils.handleTrackedEntityInstanceSendException(apiException, trackedEntityInstance);
    }
  }
コード例 #2
0
  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);
    }
  }