Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Remove dependency on Gson #7

Merged
merged 5 commits into from
Jun 11, 2024
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
7 changes: 1 addition & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,13 @@ plugins {
}

group = 'cloud.eppo'
version = '1.1.0-SNAPSHOT'
version = '2.0.0-SNAPSHOT'
ext.isReleaseVersion = !version.endsWith("SNAPSHOT")

dependencies {
// TODO: Consolidate these into a single JSON parsing dependency
// For RAC DTOs
implementation 'com.fasterxml.jackson.core:jackson-databind:2.17.1'
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.17.1'
implementation 'com.fasterxml.jackson.module:jackson-module-parameter-names:2.17.1'
// For UFC DTOs
implementation 'commons-codec:commons-codec:1.17.0'
implementation "com.google.code.gson:gson:2.9.1"
implementation 'org.slf4j:slf4j-api:2.0.13'
testImplementation platform('org.junit:junit-bom:5.10.0')
testImplementation 'org.junit.jupiter:junit-jupiter'
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/cloud/eppo/Utils.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package cloud.eppo;

import com.google.gson.JsonElement;
import com.fasterxml.jackson.databind.JsonNode;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
Expand All @@ -13,7 +13,7 @@
import org.slf4j.LoggerFactory;

public final class Utils {
private static final SimpleDateFormat isoUtcDateFormat = buildUtcIsoDateFormat();
private static final SimpleDateFormat UTC_ISO_DATE_FORMAT = buildUtcIsoDateFormat();
private static final Logger log = LoggerFactory.getLogger(Utils.class);

public static String getMD5Hex(String input) {
Expand All @@ -33,14 +33,14 @@ public static String getMD5Hex(String input) {
return hashText.toString();
}

public static Date parseUtcISODateElement(JsonElement isoDateStringElement) {
if (isoDateStringElement == null || isoDateStringElement.isJsonNull()) {
public static Date parseUtcISODateElement(JsonNode isoDateStringElement) {
if (isoDateStringElement == null || isoDateStringElement.isNull()) {
return null;
}
String isoDateString = isoDateStringElement.getAsString();
String isoDateString = isoDateStringElement.asText();
Date result = null;
try {
result = isoUtcDateFormat.parse(isoDateString);
result = UTC_ISO_DATE_FORMAT.parse(isoDateString);
} catch (ParseException e) {
// We expect to fail parsing if the date is base 64 encoded
// Thus we'll leave the result null for now and try again with the decoded value
Expand All @@ -50,7 +50,7 @@ public static Date parseUtcISODateElement(JsonElement isoDateStringElement) {
// Date may be encoded
String decodedIsoDateString = base64Decode(isoDateString);
try {
result = isoUtcDateFormat.parse(decodedIsoDateString);
result = UTC_ISO_DATE_FORMAT.parse(decodedIsoDateString);
} catch (ParseException e) {
log.warn("Date \"{}\" not in ISO date format", isoDateString);
}
Expand All @@ -60,7 +60,7 @@ public static Date parseUtcISODateElement(JsonElement isoDateStringElement) {
}

public static String getISODate(Date date) {
return isoUtcDateFormat.format(date);
return UTC_ISO_DATE_FORMAT.format(date);
}

public static String base64Decode(String input) {
Expand Down
56 changes: 21 additions & 35 deletions src/main/java/cloud/eppo/ufc/dto/FlagConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,63 +4,49 @@
import java.util.Map;

public class FlagConfig {
private String key;

private boolean enabled;

private int totalShards;

private VariationType variationType;

private Map<String, Variation> variations;

private List<Allocation> allocations;
private final String key;
private final boolean enabled;
private final int totalShards;
private final VariationType variationType;
private final Map<String, Variation> variations;
private final List<Allocation> allocations;
Comment on lines +7 to +12
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job migrating the DTOs to be immutable 💪


public FlagConfig(
String key,
boolean enabled,
int totalShards,
VariationType variationType,
Map<String, Variation> variations,
List<Allocation> allocations) {
this.key = key;
this.enabled = enabled;
this.totalShards = totalShards;
this.variationType = variationType;
this.variations = variations;
this.allocations = allocations;
}

public String getKey() {
return this.key;
}

public void setKey(String key) {
this.key = key;
}

public int getTotalShards() {
return totalShards;
}

public void setTotalShards(int totalShards) {
this.totalShards = totalShards;
}

public boolean isEnabled() {
return enabled;
}

public void setEnabled(boolean enabled) {
this.enabled = enabled;
}

public VariationType getVariationType() {
return variationType;
}

public void setVariationType(VariationType variationType) {
this.variationType = variationType;
}

public Map<String, Variation> getVariations() {
return variations;
}

public void setVariations(Map<String, Variation> variations) {
this.variations = variations;
}

public List<Allocation> getAllocations() {
return allocations;
}

public void setAllocations(List<Allocation> allocations) {
this.allocations = allocations;
}
}
15 changes: 10 additions & 5 deletions src/main/java/cloud/eppo/ufc/dto/FlagConfigResponse.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
package cloud.eppo.ufc.dto;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class FlagConfigResponse {
private Map<String, FlagConfig> flags;
private final Map<String, FlagConfig> flags;

public Map<String, FlagConfig> getFlags() {
return this.flags;
public FlagConfigResponse(Map<String, FlagConfig> flags) {
this.flags = flags;
}

public void setFlags(Map<String, FlagConfig> flags) {
this.flags = flags;
public FlagConfigResponse() {
this(new ConcurrentHashMap<>());
}

public Map<String, FlagConfig> getFlags() {
return this.flags;
}
}
17 changes: 7 additions & 10 deletions src/main/java/cloud/eppo/ufc/dto/Shard.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,19 @@
import java.util.Set;

public class Shard {
private String salt;
private Set<ShardRange> ranges;
private final String salt;
private final Set<ShardRange> ranges;

public String getSalt() {
return salt;
public Shard(String salt, Set<ShardRange> ranges) {
this.salt = salt;
this.ranges = ranges;
}

public void setSalt(String salt) {
this.salt = salt;
public String getSalt() {
return salt;
}

public Set<ShardRange> getRanges() {
return ranges;
}

public void setRanges(Set<ShardRange> ranges) {
this.ranges = ranges;
}
}
25 changes: 8 additions & 17 deletions src/main/java/cloud/eppo/ufc/dto/Split.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,25 @@
import java.util.Set;

public class Split {
private final String variationKey;
private final Set<Shard> shards;
private final Map<String, String> extraLogging;

private String variationKey;

private Set<Shard> shards;

private Map<String, String> extraLogging;
public Split(String variationKey, Set<Shard> shards, Map<String, String> extraLogging) {
this.variationKey = variationKey;
this.shards = shards;
this.extraLogging = extraLogging;
}

public String getVariationKey() {
return variationKey;
}

public void setVariationKey(String variationKey) {
this.variationKey = variationKey;
}

public Set<Shard> getShards() {
return shards;
}

public void setShards(Set<Shard> shards) {
this.shards = shards;
}

public Map<String, String> getExtraLogging() {
return extraLogging;
}

public void setExtraLogging(Map<String, String> extraLogging) {
this.extraLogging = extraLogging;
}
}
24 changes: 8 additions & 16 deletions src/main/java/cloud/eppo/ufc/dto/TargetingCondition.java
Original file line number Diff line number Diff line change
@@ -1,33 +1,25 @@
package cloud.eppo.ufc.dto;

public class TargetingCondition {
private OperatorType operator;
private final OperatorType operator;
private final String attribute;
private final EppoValue value;

private String attribute;

private EppoValue value;
public TargetingCondition(OperatorType operator, String attribute, EppoValue value) {
this.operator = operator;
this.attribute = attribute;
this.value = value;
}

public OperatorType getOperator() {
return operator;
}

public void setOperator(OperatorType operatorType) {
this.operator = operatorType;
}

public String getAttribute() {
return attribute;
}

public void setAttribute(String attribute) {
this.attribute = attribute;
}

public EppoValue getValue() {
return value;
}

public void setValue(EppoValue value) {
this.value = value;
}
}
9 changes: 4 additions & 5 deletions src/main/java/cloud/eppo/ufc/dto/TargetingRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
import java.util.Set;

public class TargetingRule {
private final Set<TargetingCondition> conditions;

private Set<TargetingCondition> conditions;
public TargetingRule(Set<TargetingCondition> conditions) {
this.conditions = conditions;
}

public Set<TargetingCondition> getConditions() {
return conditions;
}

public void setConditions(Set<TargetingCondition> conditions) {
this.conditions = conditions;
}
}
17 changes: 6 additions & 11 deletions src/main/java/cloud/eppo/ufc/dto/Variation.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
package cloud.eppo.ufc.dto;

public class Variation {
private final String key;
private final EppoValue value;

private String key;

private EppoValue value;
public Variation(String key, EppoValue value) {
this.key = key;
this.value = value;
}

public String getKey() {
return this.key;
}

public void setKey(String key) {
this.key = key;
}

public EppoValue getValue() {
return value;
}

public void setValue(EppoValue value) {
this.value = value;
}
}
22 changes: 0 additions & 22 deletions src/main/java/cloud/eppo/ufc/dto/adapters/DateAdapter.java

This file was deleted.

Loading