Skip to content

Commit

Permalink
#439 Add permissions and fix hibernate converters spring container re…
Browse files Browse the repository at this point in the history
…gistration
  • Loading branch information
bukajsytlos committed Apr 18, 2021
1 parent 5700144 commit 98ba6e1
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 18 deletions.
5 changes: 5 additions & 0 deletions src/inttest/resources/config/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ spring:
name: ${DATABASE_NAME:faf}
username: ${DATABASE_USERNAME:root}
password: ${DATABASE_PASSWORD:banana}
league-datasource:
url: jdbc:mysql://${LEAGUE_DATABASE_ADDRESS:127.0.0.1}/${LEAGUE_DATABASE_NAME:faf-league}?useSSL=false
name: faf-league
username: ${LEAGUE_DATABASE_USERNAME:faf-league-service}
password: ${LEAGUE_DATABASE_PASSWORD:banana}
jpa:
show-sql: true
hibernate:
Expand Down
15 changes: 11 additions & 4 deletions src/main/java/com/faforever/api/config/FafDatasourceConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
import com.faforever.api.config.elide.SpringHibernateDataStore;
import com.yahoo.elide.core.datastore.DataStore;
import org.hibernate.ScrollMode;
import org.hibernate.cfg.AvailableSettings;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
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.hibernate5.SpringBeanContainer;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.transaction.PlatformTransactionManager;
Expand Down Expand Up @@ -40,12 +43,13 @@ public DataSource fafDataSource() {
}

@Primary
@Bean(name = "fafEntityManagerFactory")
@Bean
public LocalContainerEntityManagerFactoryBean fafEntityManagerFactory(
EntityManagerFactoryBuilder builder,
DefaultListableBeanFactory beanFactory,
@Qualifier("fafDataSource") DataSource fafDataSource
) {
return builder
final LocalContainerEntityManagerFactoryBean emf = builder
.dataSource(fafDataSource)
.packages(
"com.faforever.api.data.domain",
Expand All @@ -55,18 +59,21 @@ public LocalContainerEntityManagerFactoryBean fafEntityManagerFactory(
"com.faforever.api.featuredmods"
)
.build();
//https://github.com/spring-projects/spring-framework/issues/23968
emf.getJpaPropertyMap().put(AvailableSettings.BEAN_CONTAINER, new SpringBeanContainer(beanFactory));
return emf;
}

@Primary
@Bean
public PlatformTransactionManager fafTransactionManager(
final @Qualifier("fafEntityManagerFactory") LocalContainerEntityManagerFactoryBean fafEntityManagerFactory
@Qualifier("fafEntityManagerFactory") LocalContainerEntityManagerFactoryBean fafEntityManagerFactory
) {
return new JpaTransactionManager(fafEntityManagerFactory.getObject());
}

@Bean
DataStore fafDatastore(
DataStore fafDataStore(
@Qualifier("fafTransactionManager") PlatformTransactionManager fafTransactionManager,
@Qualifier("fafEntityManagerFactory") EntityManager entityManager
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
@Configuration
public class LeagueDatasourceConfig {

public static final String LEAGUE_DATA_SOURCE = "leagueDataSource";
public static final String LEAGUE_TRANSACTION_MANAGER = "leagueTransactionManager";

@Bean
@ConfigurationProperties("spring.league-datasource")
public DataSourceProperties leagueDataSourceProperties() {
Expand All @@ -31,10 +34,10 @@ public DataSource leagueDataSource() {
return leagueDataSourceProperties().initializeDataSourceBuilder().build();
}

@Bean(name = "leagueEntityManagerFactory")
@Bean
public LocalContainerEntityManagerFactoryBean leagueEntityManagerFactory(
EntityManagerFactoryBuilder builder,
@Qualifier("leagueDataSource") DataSource leagueDataSource
@Qualifier(LEAGUE_DATA_SOURCE) DataSource leagueDataSource
) {
return builder
.dataSource(leagueDataSource)
Expand All @@ -46,14 +49,14 @@ public LocalContainerEntityManagerFactoryBean leagueEntityManagerFactory(

@Bean
public PlatformTransactionManager leagueTransactionManager(
final @Qualifier("leagueEntityManagerFactory") LocalContainerEntityManagerFactoryBean leagueEntityManagerFactory
@Qualifier("leagueEntityManagerFactory") LocalContainerEntityManagerFactoryBean leagueEntityManagerFactory
) {
return new JpaTransactionManager(leagueEntityManagerFactory.getObject());
}

@Bean
DataStore leagueDatastore(
@Qualifier("leagueTransactionManager") PlatformTransactionManager leagueTransactionManager,
DataStore leagueDataStore(
@Qualifier(LEAGUE_TRANSACTION_MANAGER) PlatformTransactionManager leagueTransactionManager,
@Qualifier("leagueEntityManagerFactory") EntityManager entityManager
) {
return new SpringHibernateDataStore(leagueTransactionManager, entityManager, true, ScrollMode.FORWARD_ONLY);
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/faforever/api/config/elide/ElideConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ public class ElideConfig {

@Bean
MultiplexManager multiplexDataStore(
DataStore fafDatastore,
DataStore leagueDatastore
DataStore fafDataStore,
DataStore leagueDataStore
) {
return new MultiplexManager(fafDatastore, leagueDatastore);
return new MultiplexManager(fafDataStore, leagueDataStore);
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@Table(name = "leaderboard")
@Include(type = com.faforever.api.league.domain.Leaderboard.TYPE_NAME)
public class Leaderboard {
public static final String TYPE_NAME = "leaderboardV2";
public static final String TYPE_NAME = "leagueLeaderboard";

private Integer id;
private String technicalName;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/faforever/api/league/domain/League.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@Table(name = "league")
@Include(type = League.TYPE_NAME)
public class League extends AbstractEntity {
public static final String TYPE_NAME = "leagueV2";
public static final String TYPE_NAME = "league";

private String technicalName;
private String nameKey;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
@Table(name = "league_season")
@Include(type = LeagueSeason.TYPE_NAME)
public class LeagueSeason {
public static final String TYPE_NAME = "leagueSeasonV2";
public static final String TYPE_NAME = "leagueSeason";

private Integer id;
private League league;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
@Table(name = "league_season_division")
@Include(type = LeagueSeasonDivision.TYPE_NAME)
public class LeagueSeasonDivision {
public static final String TYPE_NAME = "leagueSeasonDivisionV2";
public static final String TYPE_NAME = "leagueSeasonDivision";

private Integer id;
private LeagueSeason leagueSeason;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
@Table(name = "league_season_division_subdivision")
@Include(type = LeagueSeasonDivisionSubdivision.TYPE_NAME)
public class LeagueSeasonDivisionSubdivision {
public static final String TYPE_NAME = "leagueSeasonDivisionSubdivisionV2";
public static final String TYPE_NAME = "leagueSeasonDivisionSubdivision";

private Integer id;
private LeagueSeasonDivision leagueSeasonDivision;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
@Table(name = "league_season_score")
@Include(type = LeagueSeasonScore.TYPE_NAME)
public class LeagueSeasonScore {
public static final String TYPE_NAME = "leagueSeasonScoreV2";
public static final String TYPE_NAME = "leagueSeasonScore";

private Integer id;
private Integer loginId;
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/faforever/api/league/domain/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@ReadPermission(expression = Prefab.ALL)
@CreatePermission(expression = Prefab.NONE)
@UpdatePermission(expression = Prefab.NONE)
@DeletePermission(expression = Prefab.NONE)
package com.faforever.api.league.domain;

import com.faforever.api.data.checks.Prefab;
import com.yahoo.elide.annotation.CreatePermission;
import com.yahoo.elide.annotation.DeletePermission;
import com.yahoo.elide.annotation.ReadPermission;
import com.yahoo.elide.annotation.UpdatePermission;

0 comments on commit 98ba6e1

Please sign in to comment.