Source:
public Boolean generatePastAggStat(final DeviceAccountPair deviceAccountPair, final DateTime targetDateLocal, final Integer timeZoneOffset, final Boolean overwrite) { final Long accountId = deviceAccountPair.accountId; final DateTime utcNow = DateTime.now(DateTimeZone.UTC); final DateTime localNow = utcNow.plusMillis(timeZoneOffset); final DateTime latestAllowedDate = localNow.minusDays(1).withTimeAtStartOfDay(); if (targetDateLocal.isAfter(latestAllowedDate)) { LOGGER.error("method=past-aggstat action=skip-compute-agg-stats reason=target-date-past-latest-allowed account_id={}", accountId); return Boolean.FALSE; } targetDateLocal.withTimeAtStartOfDay(); final DeviceId deviceId = DeviceId.create(deviceAccountPair.externalDeviceId); final Optional<AggStats> presentAggStat = aggStatsDAODynamoDB.getSingleStat(accountId, deviceId, targetDateLocal); if (presentAggStat.isPresent() && !overwrite) { LOGGER.debug("action=skip-compute-agg-stats condition=agg-stats-already-present account_id={} target_date_local={}", accountId, targetDateLocal.toString()); return Boolean.FALSE; } final Optional<AggStats> aggStats = computeAggStatsForDay(accountId, deviceId, targetDateLocal, timeZoneOffset); LOGGER.debug("action=computed-agg-stats account_id={} target_date_local={} present={}", accountId, targetDateLocal.toString(), aggStats.isPresent()); if (!aggStats.isPresent()) { LOGGER.info("action=do-nothing reason=agg-stats-absent"); return Boolean.FALSE; } final Boolean successInsert = saveAggStat(aggStats.get()); LOGGER.info("action=insert-agg-stats success={} account_id={} overwite={}", successInsert.toString(), aggStats.get().accountId, overwrite.toString()); return successInsert; }

Target:
public Boolean generatePastAggStat(final DeviceAccountPair deviceAccountPair, final DateTime targetDateLocal, final Integer timeZoneOffset, final Boolean overwrite) { final Long accountId = deviceAccountPair.accountId; final DateTime utcNow = DateTime.now(DateTimeZone.UTC); final DateTime localNow = utcNow.plusMillis(timeZoneOffset); final DateTime latestAllowedDate = localNow.minusDays(1).withTimeAtStartOfDay(); if (targetDateLocal.isAfter(latestAllowedDate)) { LOGGER.error("method=past-aggstat action=skip-compute-agg-stats reason=target-date-past-latest-allowed account_id={}", accountId); return Boolean.FALSE; } targetDateLocal.withTimeAtStartOfDay(); final DeviceId deviceId = DeviceId.create(deviceAccountPair.externalDeviceId); final Optional<AggStats> presentAggStat = aggStatsDAODynamoDB.getSingleStat(accountId, deviceId, targetDateLocal); if (presentAggStat.isPresent() && !overwrite) { LOGGER.debug("action=skip-compute-agg-stats condition=agg-stats-already-present account_id={} target_date_local={}", accountId, targetDateLocal.toString()); return Boolean.FALSE; } final Optional<AggStats> aggStats = computeAggStatsForDay(accountId, deviceId, targetDateLocal, timeZoneOffset); LOGGER.debug("action=computed-agg-stats account_id={} target_date_local={} present={}", accountId, targetDateLocal.toString(), aggStats.isPresent()); if (!aggStats.isPresent()) { LOGGER.info("action=do-nothing reason=agg-stats-absent"); return Boolean.FALSE; } final Boolean successInsert = saveAggStat(aggStats.get()); LOGGER.info("action=insert-agg-stats success={} account_id={} overwite={}", successInsert, aggStats.get().accountId, overwrite); return successInsert; }