-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ConfigParamsWrapper and Logger
- Loading branch information
Showing
17 changed files
with
154 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 19 additions & 6 deletions
25
...e/src/main/java/org/fugerit/java/simple/config/microprofile/ConfigParamsMicroprofile.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,33 @@ | ||
package org.fugerit.java.simple.config.microprofile; | ||
|
||
import org.eclipse.microprofile.config.Config; | ||
import org.eclipse.microprofile.config.ConfigProvider; | ||
import org.fugerit.java.simple.config.ConfigParams; | ||
import org.fugerit.java.simple.config.AbstractConfigParams; | ||
import org.fugerit.java.simple.config.ConfigParamsDefault; | ||
|
||
import java.util.Optional; | ||
|
||
public class ConfigParamsMicroprofile implements ConfigParams { | ||
public class ConfigParamsMicroprofile extends AbstractConfigParams { | ||
|
||
public ConfigParamsMicroprofile() { | ||
this(ConfigParamsDefault.DEFAULT_NAMESPACE, ConfigProvider.getConfig()); | ||
} | ||
|
||
public ConfigParamsMicroprofile(String namespace, Config config) { | ||
super(namespace); | ||
this.config = config; | ||
} | ||
|
||
private Config config; | ||
|
||
@Override | ||
public String getValue(String name) { | ||
return ConfigProvider.getConfig().getValue( name, String.class ); | ||
protected Optional<String> getOptionalValueNamespace(String name) { | ||
return this.config.getOptionalValue( name, String.class ); | ||
} | ||
|
||
@Override | ||
public Optional<String> getOptionalValue(String name) { | ||
return ConfigProvider.getConfig().getOptionalValue( name, String.class ); | ||
protected String getValueNamespace(String name) { | ||
return this.config.getValue( name, String.class ); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
simple-config/src/main/java/org/fugerit/java/simple/config/AbstractConfigParams.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package org.fugerit.java.simple.config; | ||
|
||
import java.util.Optional; | ||
|
||
public abstract class AbstractConfigParams implements ConfigParams { | ||
|
||
public static final String DEFAULT_NAMESPACE = ""; | ||
|
||
private String configNamespace; | ||
|
||
protected AbstractConfigParams(String configNamespace) { | ||
this.configNamespace = configNamespace == null ? DEFAULT_NAMESPACE : configNamespace; | ||
} | ||
|
||
protected abstract String getValueNamespace( String name ); | ||
|
||
protected abstract Optional<String> getOptionalValueNamespace( String name ); | ||
|
||
protected String toNamespace( String name ) { | ||
return this.configNamespace+name; | ||
} | ||
|
||
@Override | ||
public String getValue(String name) { | ||
return this.getValueNamespace( this.toNamespace( name ) ); | ||
} | ||
|
||
@Override | ||
public Optional<String> getOptionalValue(String name) { | ||
return this.getOptionalValueNamespace( this.toNamespace( name ) ); | ||
} | ||
|
||
} |
28 changes: 10 additions & 18 deletions
28
simple-config/src/main/java/org/fugerit/java/simple/config/ConfigParamsDefault.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,34 @@ | ||
package org.fugerit.java.simple.config; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import java.util.Optional; | ||
import java.util.Properties; | ||
|
||
@Slf4j | ||
public class ConfigParamsDefault implements ConfigParams { | ||
|
||
private String configNamespace; | ||
public class ConfigParamsDefault extends AbstractConfigParams implements ConfigParams { | ||
|
||
private Properties configProperties; | ||
|
||
public ConfigParamsDefault(String configNamespace, Properties configProperties) { | ||
this.configNamespace = configNamespace; | ||
super( configNamespace ); | ||
this.configProperties = configProperties; | ||
} | ||
|
||
public ConfigParamsDefault(Properties configProperties) { | ||
this( "", configProperties ); | ||
} | ||
|
||
@Override | ||
public String getValue(String name) { | ||
String key = this.configNamespace+name; | ||
String value = this.configProperties.getProperty( this.configNamespace+name ); | ||
log.debug( "key : {}, value : {}", key, value ); | ||
return value; | ||
this( DEFAULT_NAMESPACE, configProperties ); | ||
} | ||
|
||
@Override | ||
public Optional<String> getOptionalValue(String name) { | ||
String value = this.getValue( name ); | ||
protected Optional<String> getOptionalValueNamespace(String name) { | ||
String value = this.getValueNamespace( name ); | ||
if ( value == null ) { | ||
return Optional.empty(); | ||
} else { | ||
return Optional.of( value ); | ||
} | ||
} | ||
|
||
@Override | ||
protected String getValueNamespace(String name) { | ||
return this.configProperties.getProperty( name ); | ||
} | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
simple-config/src/main/java/org/fugerit/java/simple/config/ConfigParamsLogger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.fugerit.java.simple.config; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import java.util.Optional; | ||
import java.util.function.BiConsumer; | ||
|
||
@Slf4j | ||
public class ConfigParamsLogger extends ConfigParamsWrapper { | ||
|
||
public static ConfigParams wrapLogDebug( ConfigParams params ) { | ||
return new ConfigParamsLogger( params ); | ||
} | ||
|
||
private BiConsumer<String, Object> logFun; | ||
|
||
public ConfigParamsLogger(final ConfigParams wrapped) { | ||
this( wrapped, ( n, v ) -> log.debug( "wraps : {}, name : {}, value : {} ", wrapped, n, v ) ); | ||
} | ||
|
||
public ConfigParamsLogger(final ConfigParams wrapped, final BiConsumer<String, Object> logFun) { | ||
super( wrapped ); | ||
this.logFun = logFun; | ||
} | ||
|
||
@Override | ||
public String getValue(String name) { | ||
String value = super.getValue( name ); | ||
this.logFun.accept( name, value ); | ||
return value; | ||
} | ||
|
||
@Override | ||
public Optional<String> getOptionalValue(String name) { | ||
Optional<String> value = super.getOptionalValue( name ); | ||
this.logFun.accept( name, value ); | ||
return value; | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
simple-config/src/main/java/org/fugerit/java/simple/config/ConfigParamsWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.fugerit.java.simple.config; | ||
|
||
import java.util.Optional; | ||
|
||
public class ConfigParamsWrapper implements ConfigParams { | ||
|
||
public ConfigParamsWrapper(ConfigParams wrapped) { | ||
this.wrapped = wrapped; | ||
} | ||
|
||
private ConfigParams wrapped; | ||
|
||
@Override | ||
public String getValue(String name) { | ||
return this.wrapped.getValue(name); | ||
} | ||
|
||
@Override | ||
public Optional<String> getOptionalValue(String name) { | ||
return this.wrapped.getOptionalValue(name); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters