Skip to content

Commit

Permalink
Merge branch 'main' into feat/favouriteOpening
Browse files Browse the repository at this point in the history
  • Loading branch information
paulushcgcj authored Oct 29, 2024
2 parents 38cad6a + 2cded86 commit ce4f6bf
Show file tree
Hide file tree
Showing 32 changed files with 485 additions and 873 deletions.
5 changes: 5 additions & 0 deletions backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@
<artifactId>oracle-free</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<!--<version>5.1.0</version>-->
</dependency>

<!-- Testing -->
<dependency>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ public class ExternalApiConfiguration {
/**
* Creates a RestClient bean for the Forest Client API.
*
* @param providersConfiguration the configuration properties for providers
* @param silvaConfiguration the configuration properties for providers
* @return the configured RestClient instance for the Forest Client API
*/
@Bean
public RestClient forestClientApi(ProvidersConfiguration providersConfiguration) {
public RestClient forestClientApi(SilvaConfiguration silvaConfiguration) {
return RestClient
.builder()
.baseUrl(providersConfiguration.getForestClientBaseUri())
.defaultHeader("X-API-KEY", providersConfiguration.getForestClientApiKey())
.baseUrl(silvaConfiguration.getForestClientApi().getAddress())
.defaultHeader("X-API-KEY", silvaConfiguration.getForestClientApi().getKey())
.defaultHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE)
.build();
}
Expand All @@ -34,10 +34,10 @@ public RestClient forestClientApi(ProvidersConfiguration providersConfiguration)
* @return the configured RestClient instance for the Open Maps API
*/
@Bean
public RestClient openMapsApi() {
public RestClient openMapsApi(SilvaConfiguration silvaConfiguration) {
return RestClient
.builder()
.baseUrl("https://openmaps.gov.bc.ca/geo/ows")
.baseUrl(silvaConfiguration.getOpenMaps().getAddress())
.defaultHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package ca.bc.gov.restapi.results.common.configuration;

import com.zaxxer.hikari.HikariDataSource;
import jakarta.persistence.EntityManagerFactory;
import java.util.Map;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
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.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
* This class holds JPA configurations for the Oracle database.
*/
@Configuration
@EnableJpaRepositories(
basePackages = {"ca.bc.gov.restapi.results.oracle"},
entityManagerFactoryRef = "oracleEntityManagerFactory",
transactionManagerRef = "oracleTransactionManager"
)
@EnableTransactionManagement
public class OracleJpaConfiguration {

@Bean(name = "oracleEntityManagerFactory")
public LocalContainerEntityManagerFactoryBean oracleEntityManagerFactory(
@Qualifier("oracleDataSource") HikariDataSource dataSource,
EntityManagerFactoryBuilder builder
) {
return builder
.dataSource(dataSource)
.properties(Map.of(
"hibernate.dialect", "org.hibernate.dialect.OracleDialect",
"hibernate.boot.allow_jdbc_metadata_access","false",
"hibernate.hikari.connection.provider_class",
"org.hibernate.hikaricp.internal.HikariCPConnectionProvider",
"hibernate.connection.datasource", dataSource
))
.packages("ca.bc.gov.restapi.results.oracle")
.persistenceUnit("oracle")
.build();
}

@Bean(name = "oracleDataSource")
@ConfigurationProperties(prefix = "spring.oracle.hikari")
public HikariDataSource oracleDataSource() {
return DataSourceBuilder.create().type(HikariDataSource.class).build();
}

@Bean(name = "oracleTransactionManager")
public PlatformTransactionManager oracleTransactionManager(
@Qualifier("oracleEntityManagerFactory") final EntityManagerFactory entityManagerFactory
) {
return new JpaTransactionManager(entityManagerFactory);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package ca.bc.gov.restapi.results.common.configuration;

import com.zaxxer.hikari.HikariDataSource;
import jakarta.persistence.EntityManagerFactory;
import java.util.Map;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
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.Primary;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
* This class holds JPA configurations for the Postgres database.
*/
@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(
basePackages = {"ca.bc.gov.restapi.results.postgres"},
entityManagerFactoryRef = "postgresEntityManagerFactory",
transactionManagerRef = "postgresTransactionManager")
public class PostgresJpaConfiguration {

@Primary
@Bean(name = "postgresEntityManagerFactory")
public LocalContainerEntityManagerFactoryBean postgresEntityManagerFactory(
@Qualifier("postgresHikariDataSource") HikariDataSource dataSource,
EntityManagerFactoryBuilder builder
) {
return builder
.dataSource(dataSource)
.properties(Map.of(
"hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect",
"hibernate.boot.allow_jdbc_metadata_access", "false",
"hibernate.hikari.connection.provider_class",
"org.hibernate.hikaricp.internal.HikariCPConnectionProvider",
"hibernate.connection.datasource", dataSource
))
.packages("ca.bc.gov.restapi.results.postgres")
.persistenceUnit("postgres")
.build();
}

@Bean(name = "postgresHikariDataSource")
@ConfigurationProperties(prefix = "spring.datasource.hikari")
@Primary
public HikariDataSource postgresHikariDataSource() {
return DataSourceBuilder.create().type(HikariDataSource.class).build();
}

@Bean(name = "postgresTransactionManager")
@Primary
public PlatformTransactionManager postgresTransactionManager(
@Qualifier("postgresEntityManagerFactory") final EntityManagerFactory entityManagerFactory
) {
return new JpaTransactionManager(entityManagerFactory);
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.cors(Customizer.withDefaults())
.csrf(
customize ->
customize.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()))
customize.csrfTokenRepository(new CookieCsrfTokenRepository()))
.authorizeHttpRequests(
customize ->
customize
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package ca.bc.gov.restapi.results.common.configuration;

import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.With;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

/**
* This class contains configurations for all external APIs like address and keys.
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@With
@Builder
@Configuration
@Component
@ConfigurationProperties("ca.bc.gov.nrs")
public class SilvaConfiguration {

private List<String> dashboardJobUsers;
private List<String> wmsWhitelist;
private List<String> orgUnits;

@NestedConfigurationProperty
private ExternalApiAddress forestClientApi;
@NestedConfigurationProperty
private ExternalApiAddress openMaps;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public static class ExternalApiAddress {

private String address;
private String key;
}

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package ca.bc.gov.restapi.results.common.endpoint;

import ca.bc.gov.restapi.results.common.configuration.SilvaConfiguration;
import ca.bc.gov.restapi.results.common.dto.WmsLayersWhitelistUserDto;
import java.util.List;
import java.util.stream.Stream;
import org.springframework.beans.factory.annotation.Value;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -13,10 +13,10 @@
*/
@RestController
@RequestMapping("/api/secrets")
@RequiredArgsConstructor
public class SecretsServiceEndpoint {

@Value("${nr.results.config.wms-layers.whitelist}")
private String[] wmsLayersWhitelistUsers;
private final SilvaConfiguration silvaConfiguration;

/**
* Get all users allowed to see the WMS layers information.
Expand All @@ -25,6 +25,10 @@ public class SecretsServiceEndpoint {
*/
@GetMapping("/wms-layers-whitelist")
public List<WmsLayersWhitelistUserDto> getWmsLayersWhitelistUsers() {
return Stream.of(wmsLayersWhitelistUsers).map(WmsLayersWhitelistUserDto::new).toList();
return silvaConfiguration
.getWmsWhitelist()
.stream()
.map(WmsLayersWhitelistUserDto::new)
.toList();
}
}

This file was deleted.

Loading

0 comments on commit ce4f6bf

Please sign in to comment.