|
24 | 24 | import com.google.firebase.ImplFirebaseTrampolines; |
25 | 25 | import com.google.firebase.internal.CallableOperation; |
26 | 26 | import com.google.firebase.internal.FirebaseService; |
| 27 | +import com.google.firebase.internal.NonNull; |
27 | 28 |
|
28 | 29 | /** |
29 | 30 | * This class is the entry point for all server-side Firebase Remote Config actions. |
@@ -100,6 +101,160 @@ protected Template execute() throws FirebaseRemoteConfigException { |
100 | 101 | }; |
101 | 102 | } |
102 | 103 |
|
| 104 | + /** |
| 105 | + * Gets the requested version of the of the Remote Config template. |
| 106 | + * |
| 107 | + * @param versionNumber The version number of the Remote Config template to look up. |
| 108 | + * @return A {@link Template}. |
| 109 | + * @throws FirebaseRemoteConfigException If an error occurs while getting the template. |
| 110 | + */ |
| 111 | + public Template getTemplateAtVersion( |
| 112 | + @NonNull String versionNumber) throws FirebaseRemoteConfigException { |
| 113 | + return getTemplateAtVersionOp(versionNumber).call(); |
| 114 | + } |
| 115 | + |
| 116 | + /** |
| 117 | + * Gets the requested version of the of the Remote Config template. |
| 118 | + * |
| 119 | + * @param versionNumber The version number of the Remote Config template to look up. |
| 120 | + * @return A {@link Template}. |
| 121 | + * @throws FirebaseRemoteConfigException If an error occurs while getting the template. |
| 122 | + */ |
| 123 | + public Template getTemplateAtVersion(long versionNumber) throws FirebaseRemoteConfigException { |
| 124 | + String versionNumberString = String.valueOf(versionNumber); |
| 125 | + return getTemplateAtVersionOp(versionNumberString).call(); |
| 126 | + } |
| 127 | + |
| 128 | + /** |
| 129 | + * Similar to {@link #getTemplateAtVersion(String versionNumber)} but performs the operation |
| 130 | + * asynchronously. |
| 131 | + * |
| 132 | + * @param versionNumber The version number of the Remote Config template to look up. |
| 133 | + * @return An {@code ApiFuture} that completes with a {@link Template} when |
| 134 | + * the requested template is available. |
| 135 | + */ |
| 136 | + public ApiFuture<Template> getTemplateAtVersionAsync(@NonNull String versionNumber) { |
| 137 | + return getTemplateAtVersionOp(versionNumber).callAsync(app); |
| 138 | + } |
| 139 | + |
| 140 | + /** |
| 141 | + * Similar to {@link #getTemplateAtVersion(long versionNumber)} but performs the operation |
| 142 | + * asynchronously. |
| 143 | + * |
| 144 | + * @param versionNumber The version number of the Remote Config template to look up. |
| 145 | + * @return An {@code ApiFuture} that completes with a {@link Template} when |
| 146 | + * the requested template is available. |
| 147 | + */ |
| 148 | + public ApiFuture<Template> getTemplateAtVersionAsync(long versionNumber) { |
| 149 | + String versionNumberString = String.valueOf(versionNumber); |
| 150 | + return getTemplateAtVersionOp(versionNumberString).callAsync(app); |
| 151 | + } |
| 152 | + |
| 153 | + private CallableOperation<Template, FirebaseRemoteConfigException> getTemplateAtVersionOp( |
| 154 | + final String versionNumber) { |
| 155 | + final FirebaseRemoteConfigClient remoteConfigClient = getRemoteConfigClient(); |
| 156 | + return new CallableOperation<Template, FirebaseRemoteConfigException>() { |
| 157 | + @Override |
| 158 | + protected Template execute() throws FirebaseRemoteConfigException { |
| 159 | + return remoteConfigClient.getTemplateAtVersion(versionNumber); |
| 160 | + } |
| 161 | + }; |
| 162 | + } |
| 163 | + |
| 164 | + /** |
| 165 | + * Publishes a Remote Config template. |
| 166 | + * |
| 167 | + * @param template The Remote Config template to be published. |
| 168 | + * @return The published {@link Template}. |
| 169 | + * @throws FirebaseRemoteConfigException If an error occurs while publishing the template. |
| 170 | + */ |
| 171 | + public Template publishTemplate(@NonNull Template template) throws FirebaseRemoteConfigException { |
| 172 | + return publishTemplateOp(template).call(); |
| 173 | + } |
| 174 | + |
| 175 | + /** |
| 176 | + * Similar to {@link #publishTemplate(Template template)} but performs the operation |
| 177 | + * asynchronously. |
| 178 | + * |
| 179 | + * @param template The Remote Config template to be published. |
| 180 | + * @return An {@code ApiFuture} that completes with a {@link Template} when |
| 181 | + * the provided template is published. |
| 182 | + */ |
| 183 | + public ApiFuture<Template> publishTemplateAsync(@NonNull Template template) { |
| 184 | + return publishTemplateOp(template).callAsync(app); |
| 185 | + } |
| 186 | + |
| 187 | + /** |
| 188 | + * Validates a Remote Config template. |
| 189 | + * |
| 190 | + * @param template The Remote Config template to be validated. |
| 191 | + * @return The validated {@link Template}. |
| 192 | + * @throws FirebaseRemoteConfigException If an error occurs while validating the template. |
| 193 | + */ |
| 194 | + public Template validateTemplate( |
| 195 | + @NonNull Template template) throws FirebaseRemoteConfigException { |
| 196 | + return publishTemplateOp(template, new PublishOptions().setValidateOnly(true)).call(); |
| 197 | + } |
| 198 | + |
| 199 | + /** |
| 200 | + * Similar to {@link #validateTemplate(Template template)} but performs the operation |
| 201 | + * asynchronously. |
| 202 | + * |
| 203 | + * @param template The Remote Config template to be validated. |
| 204 | + * @return An {@code ApiFuture} that completes with a {@link Template} when |
| 205 | + * the provided template is validated. |
| 206 | + */ |
| 207 | + public ApiFuture<Template> validateTemplateAsync(@NonNull Template template) { |
| 208 | + return publishTemplateOp(template, new PublishOptions().setValidateOnly(true)).callAsync(app); |
| 209 | + } |
| 210 | + |
| 211 | + /** |
| 212 | + * Force publishes a Remote Config template. |
| 213 | + * |
| 214 | + * <p>This method forces the Remote Config template to be updated and circumvent the ETag. |
| 215 | + * This approach is not recommended because it risks causing the loss of updates to your |
| 216 | + * Remote Config template if multiple clients are updating the Remote Config template. |
| 217 | + * See <a href="https://firebase.google.com/docs/remote-config/use-config-rest#etag_usage_and_forced_updates"> |
| 218 | + * ETag usage and forced updates</a>. |
| 219 | + * |
| 220 | + * @param template The Remote Config template to be forcefully published. |
| 221 | + * @return The published {@link Template}. |
| 222 | + * @throws FirebaseRemoteConfigException If an error occurs while publishing the template. |
| 223 | + */ |
| 224 | + public Template forcePublishTemplate( |
| 225 | + @NonNull Template template) throws FirebaseRemoteConfigException { |
| 226 | + return publishTemplateOp(template, new PublishOptions().setForcePublish(true)).call(); |
| 227 | + } |
| 228 | + |
| 229 | + /** |
| 230 | + * Similar to {@link #forcePublishTemplate(Template template)} but performs the operation |
| 231 | + * asynchronously. |
| 232 | + * |
| 233 | + * @param template The Remote Config template to be forcefully published. |
| 234 | + * @return An {@code ApiFuture} that completes with a {@link Template} when |
| 235 | + * the provided template is published. |
| 236 | + */ |
| 237 | + public ApiFuture<Template> forcePublishTemplateAsync(@NonNull Template template) { |
| 238 | + return publishTemplateOp(template, new PublishOptions().setForcePublish(true)).callAsync(app); |
| 239 | + } |
| 240 | + |
| 241 | + private CallableOperation<Template, FirebaseRemoteConfigException> publishTemplateOp( |
| 242 | + final Template template) { |
| 243 | + return publishTemplateOp(template, new PublishOptions()); |
| 244 | + } |
| 245 | + |
| 246 | + private CallableOperation<Template, FirebaseRemoteConfigException> publishTemplateOp( |
| 247 | + final Template template, final PublishOptions options) { |
| 248 | + final FirebaseRemoteConfigClient remoteConfigClient = getRemoteConfigClient(); |
| 249 | + return new CallableOperation<Template, FirebaseRemoteConfigException>() { |
| 250 | + @Override |
| 251 | + protected Template execute() throws FirebaseRemoteConfigException { |
| 252 | + return remoteConfigClient |
| 253 | + .publishTemplate(template, options.isValidateOnly(), options.isForcePublish()); |
| 254 | + } |
| 255 | + }; |
| 256 | + } |
| 257 | + |
103 | 258 | @VisibleForTesting |
104 | 259 | FirebaseRemoteConfigClient getRemoteConfigClient() { |
105 | 260 | return remoteConfigClient; |
|
0 commit comments