Skip to content

Commit

Permalink
Cnde 2018 (#57)
Browse files Browse the repository at this point in the history
* added Local Timestamp to metric collector

* update tz

* tz related
  • Loading branch information
ndduc01 authored Jan 10, 2025
1 parent 25612e5 commit 60bc4ae
Show file tree
Hide file tree
Showing 21 changed files with 50 additions and 147 deletions.
Binary file removed nnd-data-exchange-service/.DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
import gov.cdc.nnddataexchangeservice.shared.model.ExecutionResult;

import java.time.Duration;
import java.time.Instant;
import java.time.LocalDateTime;
import java.util.concurrent.Callable;

public class MetricCollector {
private MetricCollector() {

}
public static <V> ExecutionResult<V> measureExecutionTime(Callable<V> function) throws Exception {
Instant start = Instant.now();
LocalDateTime start = LocalDateTime.now();

// Execute the passed function and capture the result
V result = function.call();

Instant end = Instant.now();
LocalDateTime end = LocalDateTime.now();
Duration duration = Duration.between(start, end);

// Convert the duration to a human-readable format
Expand Down
Binary file modified nnd-data-poll-service/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion nnd-data-poll-service/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ version = '0.0.1-SNAPSHOT'

java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
languageVersion = JavaLanguageVersion.of(21)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@
import gov.cdc.nnddatapollservice.configuration.TimestampAdapter;
import gov.cdc.nnddatapollservice.nbs_odse.dto.EDXActivityDetailLogDto;
import gov.cdc.nnddatapollservice.nbs_odse.dto.EDXActivityLogDto;
import gov.cdc.nnddatapollservice.rdbmodern.dto.NrtObservationCodedDto;
import gov.cdc.nnddatapollservice.rdbmodern.dto.NrtObservationDto;
import gov.cdc.nnddatapollservice.repository.nbs_odse.EDXActivityDetailLogRepository;
import gov.cdc.nnddatapollservice.repository.nbs_odse.EDXActivityLogRepository;
import gov.cdc.nnddatapollservice.repository.nbs_odse.model.EDXActivityDetailLog;
import gov.cdc.nnddatapollservice.repository.nbs_odse.model.EDXActivityLog;
import gov.cdc.nnddatapollservice.share.HandleError;
import jakarta.transaction.Transactional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Qualifier;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package gov.cdc.nnddatapollservice.nbs_odse.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.gson.annotations.SerializedName;
import lombok.*;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package gov.cdc.nnddatapollservice.nbs_odse.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.gson.annotations.SerializedName;
import lombok.*;
import lombok.Getter;
import lombok.Setter;

import java.sql.Timestamp;
import java.time.LocalDateTime;

@Setter
@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
import gov.cdc.nnddatapollservice.rdb.dto.PollDataSyncConfig;
import gov.cdc.nnddatapollservice.service.interfaces.IPollCommonService;
import gov.cdc.nnddatapollservice.service.interfaces.IS3DataService;
import gov.cdc.nnddatapollservice.share.TimestampUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.time.Instant;
import java.util.List;

import static gov.cdc.nnddatapollservice.constant.ConstantValue.*;
Expand Down Expand Up @@ -72,7 +72,7 @@ protected void pollAndPersistRDBMOdernData(String tableName, boolean isInitialLo
logger.info("isInitialLoad {}", isInitialLoad);

logger.info("------lastUpdatedTime to send to exchange api {}", timeStampForPoll);
var timestampWithNull = Timestamp.from(Instant.now());
var timestampWithNull = TimestampUtil.getCurrentTimestamp();
//call data exchange service api
try {
totalRecordCounts = pollCommonService.callDataCountEndpoint(tableName, isInitialLoad, timeStampForPoll);
Expand Down Expand Up @@ -121,7 +121,7 @@ else if (storeInSql) {
}

rawJsonData = pollCommonService.decodeAndDecompress(encodedData);
timestamp = Timestamp.from(Instant.now());
timestamp = TimestampUtil.getCurrentTimestamp();
} catch (Exception e) {
log = e.getMessage();
exceptionAtApiLevel = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
import gov.cdc.nnddatapollservice.rdb.service.interfaces.IRdbDataHandlingService;
import gov.cdc.nnddatapollservice.service.interfaces.IPollCommonService;
import gov.cdc.nnddatapollservice.service.interfaces.IS3DataService;
import gov.cdc.nnddatapollservice.share.TimestampUtil;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.time.Instant;
import java.util.List;

import static gov.cdc.nnddatapollservice.constant.ConstantValue.*;
Expand Down Expand Up @@ -83,7 +83,7 @@ protected void pollAndPersistRDBData(String tableName, boolean isInitialLoad) {
logger.info("isInitialLoad {}", isInitialLoad);

logger.info("------lastUpdatedTime to send to exchange api {}", timeStampForPoll);
var timestampWithNull = Timestamp.from(Instant.now());
var timestampWithNull = TimestampUtil.getCurrentTimestamp();

try {
totalRecordCounts = pollCommonService.callDataCountEndpoint(tableName, isInitialLoad, timeStampForPoll);
Expand Down Expand Up @@ -127,7 +127,7 @@ else if (storeInSql) {


rawJsonData = pollCommonService.decodeAndDecompress(encodedData);
timestamp = Timestamp.from(Instant.now());
timestamp = TimestampUtil.getCurrentTimestamp();
} catch (Exception e) {
log = e.getMessage();
exceptionAtApiLevel = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
import gov.cdc.nnddatapollservice.rdbmodern.service.interfaces.IRdbModernDataHandlingService;
import gov.cdc.nnddatapollservice.service.interfaces.IPollCommonService;
import gov.cdc.nnddatapollservice.service.interfaces.IS3DataService;
import gov.cdc.nnddatapollservice.share.TimestampUtil;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.time.Instant;
import java.util.List;

import static gov.cdc.nnddatapollservice.constant.ConstantValue.*;
Expand Down Expand Up @@ -78,7 +78,7 @@ protected void pollAndPersistRDBMOdernData(String tableName, boolean isInitialLo
logger.info("isInitialLoad {}", isInitialLoad);

logger.info("------lastUpdatedTime to send to exchange api {}", timeStampForPoll);
var timestampWithNull = Timestamp.from(Instant.now());
var timestampWithNull = TimestampUtil.getCurrentTimestamp();
//call data exchange service api
try {
totalRecordCounts = iPollCommonService.callDataCountEndpoint(tableName, isInitialLoad, timeStampForPoll);
Expand Down Expand Up @@ -127,7 +127,7 @@ else if (storeInSql) {
}

rawJsonData = iPollCommonService.decodeAndDecompress(encodedData);
timestamp = Timestamp.from(Instant.now());
timestamp = TimestampUtil.getCurrentTimestamp();
} catch (Exception e) {
log = e.getMessage();
exceptionAtApiLevel = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@

import java.util.Optional;

//@Repository
//public interface TransportQOutRepository extends JpaRepository<TransportQOut, Long> {
// @Query("SELECT MAX(a.recordStatusTime) FROM CNTransportQOut a ")
// Optional<Timestamp> findMaxTimeStamp ();
//
//}
//

@Repository

public interface TransportQOutRepository extends JpaRepository<TransportQOut, Long> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package gov.cdc.nnddatapollservice.repository.rdb_modern.model;

import com.google.gson.annotations.SerializedName;
import gov.cdc.nnddatapollservice.rdbmodern.dto.NrtObservationDto;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package gov.cdc.nnddatapollservice.service;

import gov.cdc.nnddatapollservice.exception.DataPollException;
import gov.cdc.nnddatapollservice.nbs_odse.service.interfaces.INbsOdseDataHandlingService;
import gov.cdc.nnddatapollservice.rdb.service.interfaces.IRdbDataHandlingService;
import gov.cdc.nnddatapollservice.rdbmodern.service.interfaces.IRdbModernDataHandlingService;
import gov.cdc.nnddatapollservice.service.interfaces.IDataPullService;
import gov.cdc.nnddatapollservice.nbs_odse.service.interfaces.INbsOdseDataHandlingService;
import gov.cdc.nnddatapollservice.service.interfaces.INNDDataHandlingService;
import gov.cdc.nnddatapollservice.srte.service.interfaces.ISrteDataHandlingService;
import lombok.extern.slf4j.Slf4j;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import gov.cdc.nnddatapollservice.service.interfaces.ITokenService;
import gov.cdc.nnddatapollservice.share.DataSimplification;
import gov.cdc.nnddatapollservice.share.PollServiceUtil;
import gov.cdc.nnddatapollservice.share.TimestampUtil;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -22,7 +23,6 @@
import java.net.URI;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
Expand Down Expand Up @@ -125,7 +125,7 @@ public boolean checkPollingIsInitailLoad(List<PollDataSyncConfig> configTableLis
}

public String getCurrentTimestamp() {
Timestamp timestamp = Timestamp.from(Instant.now());
Timestamp timestamp = TimestampUtil.getCurrentTimestamp();
SimpleDateFormat formatter = new SimpleDateFormat(TIMESTAMP_FORMAT);
return formatter.format(timestamp);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package gov.cdc.nnddatapollservice.share;

import java.sql.Timestamp;
import java.time.LocalDateTime;

public class TimestampUtil {
public static Timestamp getCurrentTimestamp() {
LocalDateTime localDateTime = LocalDateTime.now();
return Timestamp.valueOf(localDateTime);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import gov.cdc.nnddatapollservice.rdb.dto.PollDataSyncConfig;
import gov.cdc.nnddatapollservice.service.interfaces.IPollCommonService;
import gov.cdc.nnddatapollservice.service.interfaces.IS3DataService;
import gov.cdc.nnddatapollservice.share.TimestampUtil;
import gov.cdc.nnddatapollservice.srte.dao.SrteDataPersistentDAO;
import gov.cdc.nnddatapollservice.srte.service.interfaces.ISrteDataHandlingService;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -13,7 +14,6 @@
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.time.Instant;
import java.util.List;

import static gov.cdc.nnddatapollservice.constant.ConstantValue.*;
Expand Down Expand Up @@ -76,7 +76,7 @@ protected void pollAndPersistSRTEData(String tableName, boolean isInitialLoad) {
Integer totalRecordCounts = 0;

logger.info("------lastUpdatedTime to send to exchange api {}", timeStampForPoll);
var timestampWithNull = Timestamp.from(Instant.now());
var timestampWithNull = TimestampUtil.getCurrentTimestamp();

//call data exchange service api
try {
Expand Down Expand Up @@ -121,7 +121,7 @@ else if (storeInSql) {
String encodedData = "";
encodedData = outboundPollCommonService.callDataExchangeEndpoint(tableName, isInitialLoad, timeStampForPoll, false, String.valueOf(startRow), String.valueOf(endRow));
rawJsonData = outboundPollCommonService.decodeAndDecompress(encodedData);
timestamp = Timestamp.from(Instant.now());
timestamp = TimestampUtil.getCurrentTimestamp();
} catch (Exception e) {
log = e.getMessage();
exceptionAtApiLevel = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import gov.cdc.nnddatapollservice.rdb.dto.PollDataSyncConfig;
import gov.cdc.nnddatapollservice.rdb.dto.RdbDate;
import gov.cdc.nnddatapollservice.share.PollServiceUtil;
import gov.cdc.nnddatapollservice.share.TimestampUtil;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
Expand All @@ -20,7 +21,6 @@
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.util.*;

import static org.junit.jupiter.api.Assertions.assertEquals;
Expand Down Expand Up @@ -192,7 +192,7 @@ void getLastUpdatedTime() throws ParseException {

@Test
void updateLastUpdatedTime() {
Timestamp timestamp = Timestamp.from(Instant.now());
Timestamp timestamp = TimestampUtil.getCurrentTimestamp();

when(jdbcTemplate.update(anyString(), any(), anyString())).thenReturn(1);
rdbDataPersistentDAO.updateLastUpdatedTime("TEST_TABLE", timestamp);
Expand All @@ -205,7 +205,7 @@ void getTableListFromConfig() {
List<PollDataSyncConfig> configTableList = new ArrayList<>();
PollDataSyncConfig config = new PollDataSyncConfig();
config.setTableName("D_PROVIDER");
config.setLastUpdateTime(Timestamp.from(Instant.now()));
config.setLastUpdateTime(TimestampUtil.getCurrentTimestamp());
config.setTableOrder(2);
config.setQuery("");
configTableList.add(config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
import gov.cdc.nnddatapollservice.rdb.dto.PollDataSyncConfig;
import gov.cdc.nnddatapollservice.service.interfaces.IPollCommonService;
import gov.cdc.nnddatapollservice.service.interfaces.IS3DataService;
import gov.cdc.nnddatapollservice.share.TimestampUtil;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import java.sql.Timestamp;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -69,7 +69,7 @@ void handlingExchangedData_withTimestamp() throws DataPollException {
List<PollDataSyncConfig> configTableList = new ArrayList<>();
PollDataSyncConfig config = new PollDataSyncConfig();
config.setTableName("D_ORGANIZATION");
config.setLastUpdateTime(Timestamp.from(Instant.now()));
config.setLastUpdateTime(TimestampUtil.getCurrentTimestamp());
config.setTableOrder(1);
config.setQuery("");
config.setSourceDb("RDB");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
import gov.cdc.nnddatapollservice.rdbmodern.dao.RdbModernDataPersistentDAO;
import gov.cdc.nnddatapollservice.service.interfaces.IPollCommonService;
import gov.cdc.nnddatapollservice.service.interfaces.IS3DataService;
import gov.cdc.nnddatapollservice.share.TimestampUtil;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import java.sql.Timestamp;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -68,7 +68,7 @@ void handlingExchangedData_withTimestamp() throws DataPollException {
List<PollDataSyncConfig> configTableList = new ArrayList<>();
PollDataSyncConfig config = new PollDataSyncConfig();
config.setTableName("TEST");
config.setLastUpdateTime(Timestamp.from(Instant.now()));
config.setLastUpdateTime(TimestampUtil.getCurrentTimestamp());
config.setTableOrder(1);
config.setQuery("");
config.setSourceDb("RDB_MODERN");
Expand Down
Loading

0 comments on commit 60bc4ae

Please sign in to comment.