Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cnde 1957 - data sync for edx activities #55

Merged
merged 5 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,19 @@ public class DataExchangeGenericService implements IDataExchangeGenericService {
private final JdbcTemplate jdbcTemplate;
private final JdbcTemplate srteJdbcTemplate;
private final JdbcTemplate rdbModernJdbcTemplate;
private final JdbcTemplate odseJdbcTemplate;
private final Gson gson;

public DataExchangeGenericService(DataSyncConfigRepository dataSyncConfigRepository,
@Qualifier("rdbJdbcTemplate") JdbcTemplate jdbcTemplate,
@Qualifier("srteJdbcTemplate") JdbcTemplate srteJdbcTemplate,
@Qualifier("rdbModernJdbcTemplate") JdbcTemplate rdbModernJdbcTemplate) {
@Qualifier("rdbModernJdbcTemplate") JdbcTemplate rdbModernJdbcTemplate,
@Qualifier("odseJdbcTemplate") JdbcTemplate odseJdbcTemplate) {
this.dataSyncConfigRepository = dataSyncConfigRepository;
this.jdbcTemplate = jdbcTemplate;
this.srteJdbcTemplate = srteJdbcTemplate;
this.rdbModernJdbcTemplate = rdbModernJdbcTemplate;
this.odseJdbcTemplate = odseJdbcTemplate;

this.gson = new GsonBuilder()
.registerTypeAdapter(Timestamp.class, TimestampAdapter.getTimestampSerializer())
Expand Down Expand Up @@ -74,7 +77,11 @@ private Integer executeQueryForTotalRecords(String query, String sourceDb) throw
return srteJdbcTemplate.queryForObject(query, Integer.class);
} else if (sourceDb.equalsIgnoreCase(DB_RDB_MODERN)) {
return rdbModernJdbcTemplate.queryForObject(query, Integer.class);
} else {
}
else if (sourceDb.equalsIgnoreCase("NBS_ODSE")) {
return odseJdbcTemplate.queryForObject(query, Integer.class);
}
else {
throw new DataExchangeException("Database Not Supported: " + sourceDb);
}
} catch (Exception e) {
Expand Down Expand Up @@ -131,7 +138,11 @@ private List<Map<String, Object>> executeQueryForData(String query, String sourc
return jdbcTemplate.queryForList(query);
} else if (sourceDb.equalsIgnoreCase(DB_RDB_MODERN)) {
return rdbModernJdbcTemplate.queryForList(query);
} else {
} else if (sourceDb.equalsIgnoreCase("NBS_ODSE")) {
return odseJdbcTemplate.queryForList(query);
}

else {
throw new DataExchangeException("DB IS NOT SUPPORTED: " + sourceDb);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,3 +503,49 @@ VALUES
WHERE RowNum BETWEEN :startRow AND :endRow;')
;


INSERT INTO [RDB].[dbo].[data_sync_config]
(table_name, source_db, query, query_with_null_timestamp, query_count, query_with_pagination)
VALUES
('EDX_ACTIVITY_LOG', 'NBS_ODSE',
'SELECT *
FROM EDX_ACTIVITY_LOG
WHERE record_status_time :operator :timestamp;',
NULL,
'SELECT COUNT(*)
FROM EDX_ACTIVITY_LOG
WHERE record_status_time :operator :timestamp;',
'WITH PaginatedResults AS (
SELECT *, ROW_NUMBER() OVER (ORDER BY record_status_time ASC) AS RowNum
FROM EDX_ACTIVITY_LOG
WHERE record_status_time :operator :timestamp
)
SELECT * FROM PaginatedResults
WHERE RowNum BETWEEN :startRow AND :endRow;')
;

INSERT INTO [RDB].[dbo].[data_sync_config]
(table_name, source_db, query, query_with_null_timestamp, query_count, query_with_pagination)
VALUES
('EDX_ACTIVITY_DETAIL_LOG', 'NBS_ODSE',
'SELECT logg.record_status_time, detail.*
FROM EDX_ACTIVITY_DETAIL_LOG AS detail
INNER JOIN EDX_ACTIVITY_LOG AS logg
ON detail.edx_activity_log_uid = logg.edx_activity_log_uid
WHERE logg.record_status_time :operator :timestamp;',
NULL,
'SELECT COUNT(*)
FROM EDX_ACTIVITY_DETAIL_LOG AS detail
INNER JOIN EDX_ACTIVITY_LOG AS logg
ON detail.edx_activity_log_uid = logg.edx_activity_log_uid
WHERE logg.record_status_time :operator :timestamp;',
'WITH PaginatedResults AS (
SELECT logg.record_status_time, detail.*, ROW_NUMBER() OVER (ORDER BY logg.record_status_time ASC) AS RowNum
FROM EDX_ACTIVITY_DETAIL_LOG AS detail
INNER JOIN EDX_ACTIVITY_LOG AS logg
ON detail.edx_activity_log_uid = logg.edx_activity_log_uid
WHERE logg.record_status_time :operator :timestamp
)
SELECT * FROM PaginatedResults
WHERE RowNum BETWEEN :startRow AND :endRow;')
;
Binary file modified nnd-data-poll-service/.DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
Expand Down Expand Up @@ -42,6 +43,7 @@ public class DataIngestDataSourceConfig {
private String dbUserPassword;

@Bean(name = "ingestDataSource")
@Lazy
public DataSource ingestDataSource() {
DataSourceBuilder dataSourceBuilder = DataSourceBuilder.create();

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package gov.cdc.nnddatapollservice.configuration;

import jakarta.persistence.EntityManagerFactory;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.PlatformTransactionManager;

import javax.sql.DataSource;
import java.util.HashMap;

@Configuration
@EnableJpaRepositories(
entityManagerFactoryRef = "nbsOdseEntityManagerFactory",
transactionManagerRef = "nbsOdseTransactionManager",
basePackages = {
"gov.cdc.nnddatapollservice.repository.nbs_odse",
}
)
public class NbsOdseDataSourceConfig {
@Value("${spring.datasource.driverClassName}")
private String driverClassName;

@Value("${spring.datasource.odse.url}")
private String dbUrl;

@Value("${spring.datasource.username}")
private String dbUserName;

@Value("${spring.datasource.password}")
private String dbUserPassword;

@Bean(name = "nbsOdseDataSource")
@Lazy
public DataSource nbsOdseDataSource() {
DataSourceBuilder dataSourceBuilder = DataSourceBuilder.create();

dataSourceBuilder.driverClassName(driverClassName);
dataSourceBuilder.url(dbUrl);
dataSourceBuilder.username(dbUserName);
dataSourceBuilder.password(dbUserPassword);

return dataSourceBuilder.build();
}
@Bean(name = "nbsOdseJdbcTemplate")
public JdbcTemplate nbsOdseJdbcTemplate(@Qualifier("nbsOdseDataSource") DataSource dataSource) {
return new JdbcTemplate(dataSource);
}


// JPA Configurations

@Bean(name = "nbsOdseEntityManagerFactoryBuilder")
public EntityManagerFactoryBuilder nbsOdseEntityManagerFactoryBuilder() {
return new EntityManagerFactoryBuilder(new HibernateJpaVendorAdapter(), new HashMap<>(), null);
}

@Bean(name = "nbsOdseEntityManagerFactory")
public LocalContainerEntityManagerFactoryBean nbsOdseEntityManagerFactory(
@Qualifier("nbsOdseEntityManagerFactoryBuilder") EntityManagerFactoryBuilder builder,
@Qualifier("nbsOdseDataSource") DataSource dataSource) {
return builder
.dataSource(dataSource)
.packages("gov.cdc.nnddatapollservice.repository.nbs_odse") // Adjust package for your entities
.persistenceUnit("nbsodse")
.build();
}

@Bean(name = "nbsOdseTransactionManager")
public PlatformTransactionManager nbsOdseTransactionManager(
@Qualifier("nbsOdseEntityManagerFactory") EntityManagerFactory entityManagerFactory) {
return new JpaTransactionManager(entityManagerFactory);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.orm.jpa.JpaTransactionManager;
Expand Down Expand Up @@ -40,6 +41,7 @@ public class RdbDataSourceConfig {
private String dbUserPassword;

@Bean(name = "rdbDataSource")
@Lazy
public DataSource rdbDataSource() {
DataSourceBuilder dataSourceBuilder = DataSourceBuilder.create();

Expand Down
Loading
Loading