Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public RemoteConfigTemplate getTemplate() throws FirebaseRemoteConfigException {
.addAllHeaders(COMMON_HEADERS);
IncomingHttpResponse response = httpClient.send(request);
TemplateResponse templateResponse = httpClient.parse(response, TemplateResponse.class);
RemoteConfigTemplate template = templateResponse.toRemoteConfigTemplate();
RemoteConfigTemplate template = new RemoteConfigTemplate(templateResponse);
return template.setETag(getETag(response));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.google.firebase.remoteconfig;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;

import com.google.firebase.internal.NonNull;
Expand Down Expand Up @@ -45,6 +44,22 @@ public RemoteConfigParameter() {
conditionalValues = new HashMap<>();
}

RemoteConfigParameter(@NonNull ParameterResponse parameterResponse) {
checkNotNull(parameterResponse);
this.conditionalValues = new HashMap<>();
if (parameterResponse.getConditionalValues() != null) {
for (Map.Entry<String, ParameterValueResponse> entry
: parameterResponse.getConditionalValues().entrySet()) {
this.conditionalValues.put(entry.getKey(),
RemoteConfigParameterValue.fromParameterValueResponse(entry.getValue()));
}
}
ParameterValueResponse responseDefaultValue = parameterResponse.getDefaultValue();
this.defaultValue = (responseDefaultValue == null) ? null
: RemoteConfigParameterValue.fromParameterValueResponse(responseDefaultValue);
this.description = parameterResponse.getDescription();
}

/**
* Gets the default value of the parameter.
*
Expand Down Expand Up @@ -122,9 +137,11 @@ ParameterResponse toParameterResponse() {
for (Map.Entry<String, RemoteConfigParameterValue> entry : conditionalValues.entrySet()) {
conditionalResponseValues.put(entry.getKey(), entry.getValue().toParameterValueResponse());
}
ParameterValueResponse parameterValueResponse = (defaultValue == null) ? null : defaultValue
.toParameterValueResponse();
return new ParameterResponse(parameterValueResponse, description,
conditionalResponseValues);
ParameterValueResponse defaultValueResponse = (defaultValue == null) ? null
: defaultValue.toParameterValueResponse();
return new ParameterResponse()
.setDefaultValue(defaultValueResponse)
.setDescription(description)
.setConditionalValues(conditionalResponseValues);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

package com.google.firebase.remoteconfig;

import static com.google.common.base.Preconditions.checkNotNull;

import com.google.firebase.internal.NonNull;
import com.google.firebase.remoteconfig.internal.TemplateResponse.ParameterValueResponse;

/**
Expand Down Expand Up @@ -44,6 +47,15 @@ public static InAppDefault inAppDefault() {

abstract ParameterValueResponse toParameterValueResponse();

static RemoteConfigParameterValue fromParameterValueResponse(
@NonNull ParameterValueResponse parameterValueResponse) {
checkNotNull(parameterValueResponse);
if (parameterValueResponse.isUseInAppDefault()) {
return RemoteConfigParameterValue.inAppDefault();
}
return RemoteConfigParameterValue.of(parameterValueResponse.getValue());
}

/**
* Represents an explicit Remote Config parameter value with a {@link String} value that the
* parameter is set to.
Expand All @@ -67,7 +79,8 @@ public String getValue() {

@Override
ParameterValueResponse toParameterValueResponse() {
return ParameterValueResponse.ofValue(this.value);
return new ParameterValueResponse()
.setValue(this.value);
}
}

Expand All @@ -78,7 +91,7 @@ public static final class InAppDefault extends RemoteConfigParameterValue {

@Override
ParameterValueResponse toParameterValueResponse() {
return ParameterValueResponse.ofInAppDefaultValue();
return new ParameterValueResponse().setUseInAppDefault(true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ public RemoteConfigTemplate() {
parameters = new HashMap<>();
}

RemoteConfigTemplate(@NonNull TemplateResponse templateResponse) {
checkNotNull(templateResponse);
this.parameters = new HashMap<>();
if (templateResponse.getParameters() != null) {
for (Map.Entry<String, TemplateResponse.ParameterResponse> entry
: templateResponse.getParameters().entrySet()) {
this.parameters.put(entry.getKey(), new RemoteConfigParameter(entry.getValue()));
}
}
}

/**
* Gets the ETag of the template.
*
Expand Down Expand Up @@ -83,6 +94,6 @@ TemplateResponse toTemplateResponse() {
for (Map.Entry<String, RemoteConfigParameter> entry : parameters.entrySet()) {
parameterResponses.put(entry.getKey(), entry.getValue().toParameterResponse());
}
return new TemplateResponse(parameterResponses);
return new TemplateResponse().setParameters(parameterResponses);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,8 @@

package com.google.firebase.remoteconfig.internal;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;

import com.google.api.client.util.Key;
import com.google.firebase.database.annotations.Nullable;
import com.google.firebase.internal.NonNull;
import com.google.firebase.remoteconfig.RemoteConfigParameter;
import com.google.firebase.remoteconfig.RemoteConfigParameterValue;
import com.google.firebase.remoteconfig.RemoteConfigTemplate;

import java.util.Collections;
import java.util.HashMap;

import java.util.Map;

/**
Expand All @@ -39,21 +29,14 @@ public final class TemplateResponse {
@Key("parameters")
private Map<String, ParameterResponse> parameters;

public TemplateResponse() {
parameters = Collections.emptyMap();
public Map<String, ParameterResponse> getParameters() {
return parameters;
}

public TemplateResponse(@NonNull Map<String, ParameterResponse> parameters) {
checkNotNull(parameters, "parameters must not be null.");
public TemplateResponse setParameters(
Map<String, ParameterResponse> parameters) {
this.parameters = parameters;
}

public RemoteConfigTemplate toRemoteConfigTemplate() {
Map<String, RemoteConfigParameter> parameterPublicTypes = new HashMap<>();
for (Map.Entry<String, ParameterResponse> entry : parameters.entrySet()) {
parameterPublicTypes.put(entry.getKey(), entry.getValue().toRemoteConfigParameter());
}
return new RemoteConfigTemplate().setParameters(parameterPublicTypes);
return this;
}

/**
Expand All @@ -71,30 +54,33 @@ public static final class ParameterResponse {
@Key("conditionalValues")
private Map<String, ParameterValueResponse> conditionalValues;

public ParameterResponse() {
conditionalValues = Collections.emptyMap();
public ParameterValueResponse getDefaultValue() {
return defaultValue;
}

public String getDescription() {
return description;
}

public ParameterResponse(@Nullable ParameterValueResponse defaultValue,
@Nullable String description,
@NonNull Map<String, ParameterValueResponse> conditionalValues) {
public Map<String, ParameterValueResponse> getConditionalValues() {
return conditionalValues;
}

public ParameterResponse setDefaultValue(
ParameterValueResponse defaultValue) {
this.defaultValue = defaultValue;
return this;
}

public ParameterResponse setDescription(String description) {
this.description = description;
this.conditionalValues = checkNotNull(conditionalValues);
return this;
}

public RemoteConfigParameter toRemoteConfigParameter() {
Map<String, RemoteConfigParameterValue> conditionalPublicValues = new HashMap<>();
for (Map.Entry<String, ParameterValueResponse> entry : conditionalValues.entrySet()) {
conditionalPublicValues
.put(entry.getKey(), entry.getValue().toRemoteConfigParameterValue());
}
RemoteConfigParameterValue remoteConfigParameterValue =
(defaultValue == null) ? null : defaultValue.toRemoteConfigParameterValue();
return new RemoteConfigParameter()
.setDefaultValue(remoteConfigParameterValue)
.setDescription(description)
.setConditionalValues(conditionalPublicValues);
public ParameterResponse setConditionalValues(
Map<String, ParameterValueResponse> conditionalValues) {
this.conditionalValues = conditionalValues;
return this;
}
}

Expand All @@ -108,29 +94,24 @@ public static final class ParameterValueResponse {
private String value;

@Key("useInAppDefault")
private Boolean inAppDefaultValue;
private Boolean useInAppDefault;

public ParameterValueResponse() {
public String getValue() {
return value;
}

private ParameterValueResponse(String value, Boolean inAppDefaultValue) {
this.value = value;
this.inAppDefaultValue = inAppDefaultValue;
public boolean isUseInAppDefault() {
return Boolean.TRUE.equals(this.useInAppDefault);
}

public static ParameterValueResponse ofValue(String value) {
return new ParameterValueResponse(value, null);
}

public static ParameterValueResponse ofInAppDefaultValue() {
return new ParameterValueResponse(null, true);
public ParameterValueResponse setValue(String value) {
this.value = value;
return this;
}

public RemoteConfigParameterValue toRemoteConfigParameterValue() {
if (this.inAppDefaultValue != null && this.inAppDefaultValue) {
return RemoteConfigParameterValue.inAppDefault();
}
return RemoteConfigParameterValue.of(this.value);
public ParameterValueResponse setUseInAppDefault(boolean useInAppDefault) {
this.useInAppDefault = useInAppDefault;
return this;
}
}
}