-
Notifications
You must be signed in to change notification settings - Fork 6
/
ApplicationConfig.java
130 lines (108 loc) · 4.6 KB
/
ApplicationConfig.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package tfb.status.config;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.errorprone.annotations.Immutable;
import jakarta.inject.Singleton;
import java.util.Objects;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.glassfish.hk2.api.PerLookup;
import org.glassfish.hk2.extras.provides.Provides;
/**
* The parent configuration object for this entire application, containing all
* other component-specific configuration objects.
*
* @param http See {@link HttpServerConfig}.
* @param assets See {@link AssetsConfig}.
* @param mustache See {@link MustacheConfig}.
* @param fileStore See {@link FileStoreConfig}.
* @param runProgressMonitor See {@link RunProgressMonitorConfig}.
* @param runCompleteMailer See {@link RunCompleteMailerConfig}.
* @param share See {@link ShareConfig}.
* @param healthCheck See {@link HealthCheckConfig}.
* @param email The configuration for outbound emails, or {@code null} if
* outbound emails are disabled. See {@link EmailConfig}.
*/
@Immutable
@Singleton
public record ApplicationConfig(@Provides HttpServerConfig http,
@Provides AssetsConfig assets,
@Provides MustacheConfig mustache,
@Provides FileStoreConfig fileStore,
@Provides RunProgressMonitorConfig runProgressMonitor,
@Provides RunCompleteMailerConfig runCompleteMailer,
@Provides ShareConfig share,
@Provides HealthCheckConfig healthCheck,
// This would inherit the @Singleton scope from
// ApplicationConfig, but singletons must not be
// null, so make this @PerLookup instead.
@Provides @PerLookup @Nullable EmailConfig email) {
public ApplicationConfig {
Objects.requireNonNull(http);
Objects.requireNonNull(assets);
Objects.requireNonNull(mustache);
Objects.requireNonNull(fileStore);
Objects.requireNonNull(runProgressMonitor);
Objects.requireNonNull(runCompleteMailer);
Objects.requireNonNull(share);
Objects.requireNonNull(healthCheck);
}
@JsonCreator
public static ApplicationConfig create(
@JsonProperty(value = "http", required = false)
@Nullable HttpServerConfig http,
@JsonProperty(value = "assets", required = false)
@Nullable AssetsConfig assets,
@JsonProperty(value = "mustache", required = false)
@Nullable MustacheConfig mustache,
@JsonProperty(value = "fileStore", required = false)
@Nullable FileStoreConfig fileStore,
@JsonProperty(value = "runProgressMonitor", required = false)
@Nullable RunProgressMonitorConfig runProgressMonitor,
@JsonProperty(value = "runCompleteMailer", required = false)
@Nullable RunCompleteMailerConfig runCompleteMailer,
@JsonProperty(value = "share", required = false)
@Nullable ShareConfig share,
@JsonProperty(value = "healthCheck", required = false)
@Nullable HealthCheckConfig healthCheck,
@JsonProperty(value = "email", required = false)
@Nullable EmailConfig email) {
return new ApplicationConfig(
/* http= */
Objects.requireNonNullElseGet(
http,
() -> HttpServerConfig.defaultConfig()),
/* assets= */
Objects.requireNonNullElseGet(
assets,
() -> AssetsConfig.defaultConfig()),
/* mustache= */
Objects.requireNonNullElseGet(
mustache,
() -> MustacheConfig.defaultConfig()),
/* fileStore= */
Objects.requireNonNullElseGet(
fileStore,
() -> FileStoreConfig.defaultConfig()),
/* runProgressMonitor= */
Objects.requireNonNullElseGet(
runProgressMonitor,
() -> RunProgressMonitorConfig.defaultConfig()),
/* runCompleteMailer= */
Objects.requireNonNullElseGet(
runCompleteMailer,
() -> RunCompleteMailerConfig.defaultConfig()),
/* share= */
Objects.requireNonNullElseGet(
share,
() -> ShareConfig.defaultConfig()),
/* healthCheck= */
Objects.requireNonNullElseGet(
healthCheck,
() -> HealthCheckConfig.defaultConfig()),
/* email= */
email);
}
public static ApplicationConfig defaultConfig() {
return create(null, null, null, null, null, null, null, null, null);
}
}