Skip to content

Commit

Permalink
Merge pull request #338 from bcgov/grad-release
Browse files Browse the repository at this point in the history
Grad release 1.22
  • Loading branch information
githubmamatha authored Jul 9, 2024
2 parents 5efc19c + 0471f3e commit a9f6478
Show file tree
Hide file tree
Showing 25 changed files with 218 additions and 122 deletions.
8 changes: 5 additions & 3 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>ca.bc.gov.educ</groupId>
<artifactId>educ-grad-trax-api</artifactId>
<version>1.8.56</version>
<version>1.8.57</version>
<name>educ-grad-trax-api</name>
<description>Ministry of Education GRAD TRAX API</description>

Expand Down Expand Up @@ -79,8 +79,10 @@
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
</dependency>


<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.security.oauth2.client.*;
import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository;
import org.springframework.security.oauth2.client.web.DefaultOAuth2AuthorizedClientManager;
import org.springframework.security.oauth2.client.web.OAuth2AuthorizedClientRepository;
import org.springframework.security.oauth2.client.web.reactive.function.client.ServletOAuth2AuthorizedClientExchangeFilterFunction;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.web.client.RestTemplate;
Expand Down Expand Up @@ -80,18 +78,6 @@ public WebClient getInstituteWebClient(OAuth2AuthorizedClientManager authorizedC
.apply(filter.oauth2Configuration())
.build();
}
/*@Bean
public OAuth2AuthorizedClientManager authorizedClientManager(
ClientRegistrationRepository clientRegistrationRepository,
OAuth2AuthorizedClientRepository authorizedClientRepository) {
OAuth2AuthorizedClientProvider authorizedClientProvider = OAuth2AuthorizedClientProviderBuilder.builder()
.clientCredentials()
.build();
DefaultOAuth2AuthorizedClientManager authorizedClientManager = new DefaultOAuth2AuthorizedClientManager(
clientRegistrationRepository, authorizedClientRepository);
authorizedClientManager.setAuthorizedClientProvider(authorizedClientProvider);
return authorizedClientManager;
}*/

@Bean
public OAuth2AuthorizedClientManager authorizedClientManager(
Expand Down
62 changes: 31 additions & 31 deletions api/src/main/java/ca/bc/gov/educ/api/trax/config/RedisConfig.java
Original file line number Diff line number Diff line change
@@ -1,55 +1,55 @@
package ca.bc.gov.educ.api.trax.config;

import ca.bc.gov.educ.api.trax.util.EducGradTraxApiConstants;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisClusterConfiguration;
import org.springframework.data.redis.connection.RedisClusterNode;
import org.springframework.data.redis.connection.RedisNode;
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.repository.configuration.EnableRedisRepositories;
import org.springframework.data.redis.serializer.GenericToStringSerializer;
import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;

import java.time.Duration;
import java.util.HashSet;
import java.util.Set;

@Configuration
@EnableRedisRepositories("ca.bc.gov.educ.api.trax.repository.redis")
public class RedisConfig {
@Autowired
private EducGradTraxApiConstants constants;

@Bean
public JedisConnectionFactory jedisConnectionFactory() {
RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration();
redisStandaloneConfiguration.setHostName(constants.getRedisUrl());
redisStandaloneConfiguration.setPort(Integer.parseInt(constants.getRedisPort()));
redisStandaloneConfiguration.setPassword(constants.getRedisSecret());

//Cluster Configuration
RedisClusterConfiguration redisClusterConfiguration = new RedisClusterConfiguration();
RedisNode node0 = new RedisNode(constants.getRedisUrl(), Integer.parseInt(constants.getRedisPort()));
redisClusterConfiguration.addClusterNode(node0);

RedisClusterNode rcn = new RedisClusterNode(constants.getRedisUrl(), Integer.parseInt(constants.getRedisPort()));

return new JedisConnectionFactory(redisStandaloneConfiguration);
redisClusterConfiguration.addClusterNode(new RedisClusterNode(
constants.getRedisUrl(),
Integer.parseInt(constants.getRedisPort())));
redisClusterConfiguration.setPassword(constants.getRedisSecret());
return new JedisConnectionFactory(redisClusterConfiguration);
}

@Bean
public RedisTemplate<String, Object> redisTemplate() {
final RedisTemplate<String, Object> template = new RedisTemplate<>();
template.setConnectionFactory(jedisConnectionFactory());
template.setKeySerializer(new StringRedisSerializer());
template.setValueSerializer(new GenericToStringSerializer<>(Object.class));
template.setHashKeySerializer(new JdkSerializationRedisSerializer());
template.setHashValueSerializer(new JdkSerializationRedisSerializer());
template.setEnableTransactionSupport(true);
template.afterPropertiesSet();

return template;
public JedisCluster jedisCluster() {
Set<HostAndPort> jedisClusterNodes = new HashSet<>();
jedisClusterNodes.add(
new HostAndPort(constants.getRedisUrl(),
Integer.parseInt(constants.getRedisPort())));

GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
poolConfig.setMaxTotal(8);
poolConfig.setMaxIdle(8);
poolConfig.setMinIdle(0);
poolConfig.setBlockWhenExhausted(true);
poolConfig.setMaxWait(Duration.ofSeconds(1));
poolConfig.setTestWhileIdle(true);
poolConfig.setTimeBetweenEvictionRuns(Duration.ofSeconds(1));

return new JedisCluster(jedisClusterNodes, 5000, 5000, 3,
constants.getRedisUser(), constants.getRedisSecret(),
"educ-grad-trax-api", poolConfig);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ private void checkAndPopulateTraxStudentStatus(TraxStudentEntity traxStudentEnti
newArchiveFlag = "I";
} else if (StringUtils.equals(gradStudentStatus, "TER")) {
newStudStatus = "T";
newArchiveFlag = "I";
newArchiveFlag = "A";
}

if (!StringUtils.equalsIgnoreCase(studStatus, newStudStatus)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
import ca.bc.gov.educ.api.trax.constant.CacheStatus;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import redis.clients.jedis.JedisCluster;

@Slf4j
@Component
public class ServiceHelper<T> {

@Autowired
RedisTemplate<String, String> redisTemplate;
JedisCluster jedisCluster;

public void initializeCache(boolean force, CacheKey cacheKey, T service) {
String cacheStatus = redisTemplate.opsForValue().get(cacheKey.name());
String cacheStatus = jedisCluster.get(cacheKey.name());
cacheStatus = cacheStatus == null ? "" : cacheStatus;
if (CacheStatus.LOADING.name().compareToIgnoreCase(cacheStatus) == 0
|| CacheStatus.READY.name().compareToIgnoreCase(cacheStatus) == 0) {
Expand All @@ -33,9 +33,9 @@ public void initializeCache(boolean force, CacheKey cacheKey, T service) {
}

private void loadCache(CacheKey cacheKey, T service) {
redisTemplate.opsForValue().set(cacheKey.name(), CacheStatus.LOADING.name());
jedisCluster.set(cacheKey.name(), CacheStatus.LOADING.name());
loadDataIntoRedisCache(cacheKey, service);
redisTemplate.opsForValue().set(cacheKey.name(), CacheStatus.READY.name());
jedisCluster.set(cacheKey.name(), CacheStatus.READY.name());
log.info(String.format("Success! - %s is now READY", cacheKey));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ public class EducGradTraxApiConstants {
@Value("${redis.port}")
private String redisPort;

@Value("${redis.user}")
private String redisUser;

@Value("${redis.secret}")
private String redisSecret;

Expand Down
1 change: 1 addition & 0 deletions api/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ nats:
redis:
url: ${REDIS_URL}
port: ${REDIS_PORT}
user: ${REDIS_USER}
secret: ${REDIS_SECRET}

#Scheduler
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
CREATE TABLE "EVENT_HISTORY"
( "EVENT_HISTORY_ID" RAW(16) DEFAULT SYS_GUID() NOT NULL ENABLE,
"EVENT_ID" RAW(16) NOT NULL ENABLE,
"ACKNOWLEDGE_FLAG" VARCHAR2(1) NOT NULL ENABLE,
"CREATE_USER" VARCHAR2(32) DEFAULT USER NOT NULL ENABLE,
"CREATE_DATE" DATE DEFAULT SYSTIMESTAMP NOT NULL ENABLE,
"UPDATE_USER" VARCHAR2(32) DEFAULT USER NOT NULL ENABLE,
"UPDATE_DATE" DATE DEFAULT SYSTIMESTAMP NOT NULL ENABLE,

CONSTRAINT "EVENT_HISTORY_ID_PK" PRIMARY KEY ("EVENT_HISTORY_ID")
USING INDEX TABLESPACE "API_GRAD_IDX" ENABLE
) SEGMENT CREATION IMMEDIATE
NOCOMPRESS LOGGING
TABLESPACE "API_GRAD_DATA" NO INMEMORY ;
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository;
import org.springframework.security.oauth2.client.web.OAuth2AuthorizedClientRepository;
import org.springframework.security.oauth2.client.OAuth2AuthorizedClientService;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import redis.clients.jedis.JedisCluster;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = {EducGradTraxApiApplication.class})
Expand All @@ -42,6 +44,10 @@ public abstract class BaseReplicationServiceTest {
public OAuth2AuthorizedClientRepository oAuth2AuthorizedClientRepository;
@MockBean
public OAuth2AuthorizedClientService oAuth2AuthorizedClientService;
@MockBean
private JedisConnectionFactory jedisConnectionFactoryMock;
@MockBean
private JedisCluster jedisClusterMock;

@Before
public void resetState() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.security.oauth2.client.registration.ClientRegistration;
import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import redis.clients.jedis.JedisCluster;

import java.util.Optional;
import java.util.UUID;
Expand Down Expand Up @@ -53,6 +55,11 @@ public class ChoreographedEventPersistenceServiceTest {

@MockBean
private Subscriber subscriber;
@MockBean
private JedisConnectionFactory jedisConnectionFactory;
@MockBean
private JedisCluster jedisClusterMock;


@TestConfiguration
static class TestConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.security.oauth2.client.registration.ClientRegistration;
import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import redis.clients.jedis.JedisCluster;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -58,6 +60,10 @@ public class CodeServiceTest {

@MockBean
private Subscriber subscriber;
@MockBean
private JedisConnectionFactory jedisConnectionFactoryMock;
@MockBean
private JedisCluster jedisClusterMock;

@TestConfiguration
static class TestConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.security.oauth2.client.registration.ClientRegistration;
import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.reactive.function.client.WebClient;
import redis.clients.jedis.JedisCluster;

import java.util.List;
import java.util.Optional;
Expand All @@ -51,6 +53,10 @@ public class DistrictServiceTest {
@Mock WebClient.RequestBodySpec requestBodyMock;
@Mock WebClient.RequestBodyUriSpec requestBodyUriMock;
@Mock WebClient.ResponseSpec responseMock;
@MockBean
private JedisConnectionFactory jedisConnectionFactoryMock;
@MockBean
private JedisCluster jedisClusterMock;

@MockBean
@Qualifier("default")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.security.oauth2.client.registration.ClientRegistration;
import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import redis.clients.jedis.JedisCluster;

import java.math.BigDecimal;
import java.util.Arrays;
Expand Down Expand Up @@ -51,6 +53,10 @@ public class EdwServiceTest {

@MockBean
private Subscriber subscriber;
@MockBean
private JedisConnectionFactory jedisConnectionFactoryMock;
@MockBean
private JedisCluster jedisClusterMock;


@TestConfiguration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.security.oauth2.client.registration.ClientRegistration;
import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import redis.clients.jedis.JedisCluster;

import static org.mockito.MockitoAnnotations.openMocks;

Expand All @@ -47,6 +49,10 @@ public class GradStudentGraduatedServiceTest {

@MockBean
private Subscriber subscriber;
@MockBean
private JedisConnectionFactory jedisConnectionFactoryMock;
@MockBean
private JedisCluster jedisClusterMock;

@TestConfiguration
static class TestConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.security.oauth2.client.registration.ClientRegistration;
import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import redis.clients.jedis.JedisCluster;

import static org.mockito.MockitoAnnotations.openMocks;

Expand All @@ -47,6 +49,10 @@ public class GradStudentUndoCompletionServiceTest {

@MockBean
private Subscriber subscriber;
@MockBean
private JedisConnectionFactory jedisConnectionFactoryMock;
@MockBean
private JedisCluster jedisClusterMock;

@TestConfiguration
static class TestConfig {
Expand Down
Loading

0 comments on commit a9f6478

Please sign in to comment.