Signed-off-by: Andrew DeMaria <lostonamountain@gmail.com>master
							parent
							
								
									aa8ab6e5fe
								
							
						
					
					
						commit
						9df2660d1e
					
				| @ -1,22 +0,0 @@ | ||||
| package org.libresonic.player.spring; | ||||
| 
 | ||||
| import org.apache.commons.configuration2.ImmutableConfiguration; | ||||
| import org.libresonic.player.service.ApacheCommonsConfigurationService; | ||||
| import org.springframework.context.ApplicationContextInitializer; | ||||
| import org.springframework.core.env.PropertySource; | ||||
| import org.springframework.web.context.ConfigurableWebApplicationContext; | ||||
| 
 | ||||
| public class AdditionalPropertySourceConfigurer implements | ||||
|         ApplicationContextInitializer<ConfigurableWebApplicationContext> { | ||||
| 
 | ||||
|     public void initialize(ConfigurableWebApplicationContext ctx) { | ||||
| 
 | ||||
|         ApacheCommonsConfigurationService configurationService = new ApacheCommonsConfigurationService(); | ||||
|         ImmutableConfiguration snapshot = configurationService.getImmutableSnapshot(); | ||||
| 
 | ||||
|         PropertySource ps = new DatasourceProfileActivatorPropertySource(new CommonsConfigurationPropertySource( | ||||
|                 "libresonic-pre-init-configs", | ||||
|                 snapshot)); | ||||
|         ctx.getEnvironment().getPropertySources().addLast(ps); | ||||
|     } | ||||
| } | ||||
| @ -1,40 +0,0 @@ | ||||
| package org.libresonic.player.spring; | ||||
| 
 | ||||
| import org.apache.commons.lang3.StringUtils; | ||||
| import org.springframework.core.env.PropertySource; | ||||
| 
 | ||||
| public class DatasourceProfileActivatorPropertySource extends PropertySource { | ||||
|     public static final String SPRING_PROFILES_ACTIVE = "spring.profiles.active"; | ||||
|     public static final String DATASOURCE_CONFIG_TYPE = "database.config.type"; | ||||
|     final PropertySource parent; | ||||
| 
 | ||||
|     public DatasourceProfileActivatorPropertySource(PropertySource parent) { | ||||
|         super(parent.getName()); | ||||
|         this.parent = parent; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public Object getProperty(String name) { | ||||
|         if(StringUtils.equalsIgnoreCase(name, SPRING_PROFILES_ACTIVE)) { | ||||
|             String appendTo = ""; | ||||
|             Object existing = parent.getProperty(SPRING_PROFILES_ACTIVE); | ||||
|             if(existing != null && existing instanceof String) { | ||||
|                 appendTo += (String) existing; | ||||
|             } | ||||
|             DataSourceConfigType dataSourceConfigType; | ||||
|             Object rawType = parent.getProperty(DATASOURCE_CONFIG_TYPE); | ||||
|             if(rawType != null && rawType instanceof String) { | ||||
|                 dataSourceConfigType = DataSourceConfigType.valueOf(StringUtils.upperCase((String) rawType)); | ||||
|             } else { | ||||
|                 dataSourceConfigType = DataSourceConfigType.LEGACY; | ||||
|             } | ||||
|             if(StringUtils.isNotBlank(appendTo)) { | ||||
|                 appendTo += ","; | ||||
|             } | ||||
|             appendTo += StringUtils.lowerCase(dataSourceConfigType.name()); | ||||
|             return appendTo; | ||||
|         } else { | ||||
|             return parent.getProperty(name); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,44 @@ | ||||
| package org.libresonic.player.spring; | ||||
| 
 | ||||
| import com.google.common.collect.Lists; | ||||
| import org.apache.commons.configuration2.ImmutableConfiguration; | ||||
| import org.apache.commons.lang3.StringUtils; | ||||
| import org.libresonic.player.service.ApacheCommonsConfigurationService; | ||||
| import org.springframework.context.ApplicationContextInitializer; | ||||
| import org.springframework.core.env.PropertySource; | ||||
| import org.springframework.web.context.ConfigurableWebApplicationContext; | ||||
| 
 | ||||
| import java.util.List; | ||||
| 
 | ||||
| public class LibresonicPropertySourceConfigurer implements | ||||
|         ApplicationContextInitializer<ConfigurableWebApplicationContext> { | ||||
| 
 | ||||
|     public static final String DATASOURCE_CONFIG_TYPE = "database.config.type"; | ||||
| 
 | ||||
|     public void initialize(ConfigurableWebApplicationContext ctx) { | ||||
| 
 | ||||
|         ApacheCommonsConfigurationService configurationService = new ApacheCommonsConfigurationService(); | ||||
|         ImmutableConfiguration snapshot = configurationService.getImmutableSnapshot(); | ||||
| 
 | ||||
|         PropertySource ps = new CommonsConfigurationPropertySource("libresonic-pre-init-configs", snapshot); | ||||
| 
 | ||||
| 
 | ||||
|         ctx.getEnvironment().getPropertySources().addLast(ps); | ||||
| 
 | ||||
|         addDataSourceProfile(ctx); | ||||
|     } | ||||
| 
 | ||||
|     private void addDataSourceProfile(ConfigurableWebApplicationContext ctx) { | ||||
|         DataSourceConfigType dataSourceConfigType; | ||||
|         String rawType = ctx.getEnvironment().getProperty(DATASOURCE_CONFIG_TYPE); | ||||
|         if(StringUtils.isNotBlank(rawType)) { | ||||
|             dataSourceConfigType = DataSourceConfigType.valueOf(StringUtils.upperCase(rawType)); | ||||
|         } else { | ||||
|             dataSourceConfigType = DataSourceConfigType.LEGACY; | ||||
|         } | ||||
|         String dataSourceTypeProfile = StringUtils.lowerCase(dataSourceConfigType.name()); | ||||
|         List<String> existingProfiles = Lists.newArrayList(ctx.getEnvironment().getActiveProfiles()); | ||||
|         existingProfiles.add(dataSourceTypeProfile); | ||||
|         ctx.getEnvironment().setActiveProfiles(existingProfiles.toArray(new String[0])); | ||||
|     } | ||||
| } | ||||
					Loading…
					
					
				
		Reference in new issue