diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/configuration/BadgeConfiguration.java b/service/src/main/java/org/whispersystems/textsecuregcm/configuration/BadgeConfiguration.java index e01614f6a..8564739ac 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/configuration/BadgeConfiguration.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/configuration/BadgeConfiguration.java @@ -7,44 +7,29 @@ package org.whispersystems.textsecuregcm.configuration; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.List; import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; +import org.whispersystems.textsecuregcm.util.ExactlySize; public class BadgeConfiguration { public static final String CATEGORY_TESTING = "testing"; private final String id; private final String category; - private final String ldpi; - private final String mdpi; - private final String hdpi; - private final String xhdpi; - private final String xxhdpi; - private final String xxxhdpi; - private final String lowDetailSvg; - private final String highDetailSvg; + private final List sprites; + private final List svgs; @JsonCreator public BadgeConfiguration( @JsonProperty("id") final String id, @JsonProperty("category") final String category, - @JsonProperty("ldpi") final String ldpi, - @JsonProperty("mdpi") final String mdpi, - @JsonProperty("hdpi") final String hdpi, - @JsonProperty("xhdpi") final String xhdpi, - @JsonProperty("xxhdpi") final String xxhdpi, - @JsonProperty("xxxhdpi") final String xxxhdpi, - @JsonProperty("lowDetailSvg") final String lowDetailSvg, - @JsonProperty("highDetailSvg") final String highDetailSvg) { + @JsonProperty("sprites") final List sprites, + @JsonProperty("svgs") final List svgs) { this.id = id; this.category = category; - this.ldpi = ldpi; - this.mdpi = mdpi; - this.hdpi = hdpi; - this.xhdpi = xhdpi; - this.xxhdpi = xxhdpi; - this.xxxhdpi = xxxhdpi; - this.lowDetailSvg = lowDetailSvg; - this.highDetailSvg = highDetailSvg; + this.sprites = sprites; + this.svgs = svgs; } @NotEmpty @@ -57,47 +42,59 @@ public class BadgeConfiguration { return category; } - @NotEmpty - public String getLdpi() { - return ldpi; + @NotNull + @ExactlySize(6) + public List getSprites() { + return sprites; } - @NotEmpty - public String getMdpi() { - return mdpi; - } - - @NotEmpty - public String getHdpi() { - return hdpi; - } - - @NotEmpty - public String getXhdpi() { - return xhdpi; - } - - @NotEmpty - public String getXxhdpi() { - return xxhdpi; - } - - @NotEmpty - public String getXxxhdpi() { - return xxxhdpi; - } - - @NotEmpty - public String getLowDetailSvg() { - return lowDetailSvg; - } - - @NotEmpty - public String getHighDetailSvg() { - return highDetailSvg; + @NotNull + @ExactlySize(4) + public List getSvgs() { + return svgs; } public boolean isTestBadge() { return CATEGORY_TESTING.equals(category); } + + @Deprecated + public String getLdpi() { + return sprites.get(0); + } + + @Deprecated + public String getMdpi() { + return sprites.get(1); + } + + @Deprecated + public String getHdpi() { + return sprites.get(2); + } + + @Deprecated + public String getXhdpi() { + return sprites.get(3); + } + + @Deprecated + public String getXxhdpi() { + return sprites.get(4); + } + + @Deprecated + public String getXxxhdpi() { + return sprites.get(5); + } + + @Deprecated + public String getLowDetailSvg() { + return svgs.get(0); + } + + @Deprecated + public String getHighDetailSvg() { + return svgs.get(3); + } } diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/util/ExactlySize.java b/service/src/main/java/org/whispersystems/textsecuregcm/util/ExactlySize.java index 6c0145839..de2d68caa 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/util/ExactlySize.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/util/ExactlySize.java @@ -22,6 +22,7 @@ import javax.validation.Payload; @Constraint(validatedBy = { ExactlySizeValidatorForString.class, ExactlySizeValidatorForArraysOfByte.class, + ExactlySizeValidatorForCollection.class, }) @Documented public @interface ExactlySize { diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/util/ExactlySizeValidatorForCollection.java b/service/src/main/java/org/whispersystems/textsecuregcm/util/ExactlySizeValidatorForCollection.java new file mode 100644 index 000000000..df05bee24 --- /dev/null +++ b/service/src/main/java/org/whispersystems/textsecuregcm/util/ExactlySizeValidatorForCollection.java @@ -0,0 +1,16 @@ +/* + * Copyright 2021 Signal Messenger, LLC + * SPDX-License-Identifier: AGPL-3.0-only + */ + +package org.whispersystems.textsecuregcm.util; + +import java.util.Collection; + +public class ExactlySizeValidatorForCollection extends ExactlySizeValidator> { + + @Override + protected int size(final Collection value) { + return value == null ? 0 : value.size(); + } +} diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/badges/ConfiguredProfileBadgeConverterTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/badges/ConfiguredProfileBadgeConverterTest.java index f3df7c867..8e64eef8f 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/badges/ConfiguredProfileBadgeConverterTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/badges/ConfiguredProfileBadgeConverterTest.java @@ -64,7 +64,8 @@ public class ConfiguredProfileBadgeConverterTest { } private static BadgeConfiguration newBadge(int i) { - return new BadgeConfiguration(idFor(i), "other", "l", "m", "h", "x", "xx", "xxx", "s", "S"); + return new BadgeConfiguration( + idFor(i), "other", List.of("l", "m", "h", "x", "xx", "xxx"), List.of("s", "m", "M", "S")); } private BadgesConfiguration createBadges(int count) { diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/DonationControllerTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/DonationControllerTest.java index 41fdab729..734d6d5a1 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/DonationControllerTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/DonationControllerTest.java @@ -89,10 +89,10 @@ class DonationControllerTest { static BadgesConfiguration getBadgesConfiguration() { return new BadgesConfiguration( List.of( - new BadgeConfiguration("TEST", "other", "l", "m", "h", "x", "xx", "xxx", "s", "S"), - new BadgeConfiguration("TEST1", "testing", "l", "m", "h", "x", "xx", "xxx", "s", "S"), - new BadgeConfiguration("TEST2", "testing", "l", "m", "h", "x", "xx", "xxx", "s", "S"), - new BadgeConfiguration("TEST3", "testing", "l", "m", "h", "x", "xx", "xxx", "s", "S")), + new BadgeConfiguration("TEST", "other", List.of("l", "m", "h", "x", "xx", "xxx"), List.of("s", "m", "M", "S")), + new BadgeConfiguration("TEST1", "testing", List.of("l", "m", "h", "x", "xx", "xxx"), List.of("s", "m", "M", "S")), + new BadgeConfiguration("TEST2", "testing", List.of("l", "m", "h", "x", "xx", "xxx"), List.of("s", "m", "M", "S")), + new BadgeConfiguration("TEST3", "testing", List.of("l", "m", "h", "x", "xx", "xxx"), List.of("s", "m", "M", "S"))), List.of("TEST"), Map.of(1L, "TEST1", 2L, "TEST2", 3L, "TEST3")); } diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/ProfileControllerTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/ProfileControllerTest.java index 7f98df85d..ed83488ad 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/ProfileControllerTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/ProfileControllerTest.java @@ -112,10 +112,10 @@ class ProfileControllerTest { new Badge("TEST", "other", "Test Badge", "This badge is in unit tests.", "l", "m", "h", "x", "xx", "xxx", "s", "S") ), new BadgesConfiguration(List.of( - new BadgeConfiguration("TEST", "other", "l", "m", "h", "x", "xx", "xxx", "s", "S"), - new BadgeConfiguration("TEST1", "testing", "l", "m", "h", "x", "xx", "xxx", "s", "S"), - new BadgeConfiguration("TEST2", "testing", "l", "m", "h", "x", "xx", "xxx", "s", "S"), - new BadgeConfiguration("TEST3", "testing", "l", "m", "h", "x", "xx", "xxx", "s", "S") + new BadgeConfiguration("TEST", "other", List.of("l", "m", "h", "x", "xx", "xxx"), List.of("s", "m", "M", "S")), + new BadgeConfiguration("TEST1", "testing", List.of("l", "m", "h", "x", "xx", "xxx"), List.of("s", "m", "M", "S")), + new BadgeConfiguration("TEST2", "testing", List.of("l", "m", "h", "x", "xx", "xxx"), List.of("s", "m", "M", "S")), + new BadgeConfiguration("TEST3", "testing", List.of("l", "m", "h", "x", "xx", "xxx"), List.of("s", "m", "M", "S")) ), List.of("TEST1"), Map.of(1L, "TEST1", 2L, "TEST2", 3L, "TEST3")), s3client, postPolicyGenerator,