2323import org .slf4j .Logger ;
2424import org .slf4j .LoggerFactory ;
2525
26- import com .google .common .base .Preconditions ;
27-
2826/**
2927 * ApiConfigurations
3028 * @author Eric Martin
@@ -44,16 +42,20 @@ public class ApiConfigurations {
4442 * @param environment Configured environment name
4543 * @return ApiConfiguration
4644 */
47- public static ApiConfiguration from (final String apiUrl , final String apiKey , final String application , final String environment ) {
48- Preconditions .checkNotNull (apiKey );
49- Preconditions .checkArgument (!apiKey .isEmpty ());
45+ public static ApiConfiguration fromPropertiesWithOverrides (final String apiUrl , final String apiKey , final String application , final String environment ) {
46+ ApiConfiguration props = ApiConfigurations .fromProperties ();
47+
48+ String mergedApiUrl = ((apiUrl != null ) && (0 < apiUrl .length ())) ? apiUrl : props .getApiUrl ();
49+ String mergedApiKey = ((apiKey != null ) && (0 < apiKey .length ())) ? apiKey : props .getApiKey ();
50+ String mergedApplication = ((application != null ) && (0 < application .length ())) ? application : props .getApplication ();
51+ String mergedEnvironment = ((environment != null ) && (0 < environment .length ())) ? environment : props .getEnvironment ();
5052
5153 ApiConfiguration .Builder builder = ApiConfiguration .newBuilder ();
52- builder .apiUrl (apiUrl );
53- builder .apiKey (apiKey );
54- builder .application (application );
55- builder .environment (environment );
56- builder .envDetail (EnvironmentDetails .getEnvironmentDetail (application , environment ));
54+ builder .apiUrl (mergedApiUrl );
55+ builder .apiKey (mergedApiKey );
56+ builder .application (mergedApplication );
57+ builder .environment (mergedEnvironment );
58+ builder .envDetail (EnvironmentDetails .getEnvironmentDetail (mergedApplication , mergedEnvironment ));
5759
5860 return builder .build ();
5961 }
0 commit comments