Refactor two more switch statements to new switch style
This commit is contained in:
parent
d94c171d63
commit
c29d5de1eb
|
@ -14,6 +14,7 @@ import com.google.common.annotations.VisibleForTesting;
|
||||||
import io.dropwizard.auth.Auth;
|
import io.dropwizard.auth.Auth;
|
||||||
import io.micrometer.core.instrument.Metrics;
|
import io.micrometer.core.instrument.Metrics;
|
||||||
import io.micrometer.core.instrument.Tag;
|
import io.micrometer.core.instrument.Tag;
|
||||||
|
import io.micrometer.core.instrument.Tags;
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
@ -47,7 +48,6 @@ import javax.ws.rs.core.Context;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import javax.ws.rs.core.Response.Status;
|
import javax.ws.rs.core.Response.Status;
|
||||||
import io.micrometer.core.instrument.Tags;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -252,15 +252,12 @@ public class AccountController {
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (transport) {
|
switch (transport) {
|
||||||
case "sms":
|
case "sms" -> rateLimiters.getSmsDestinationLimiter().validate(number);
|
||||||
rateLimiters.getSmsDestinationLimiter().validate(number);
|
case "voice" -> {
|
||||||
break;
|
|
||||||
case "voice":
|
|
||||||
rateLimiters.getVoiceDestinationLimiter().validate(number);
|
rateLimiters.getVoiceDestinationLimiter().validate(number);
|
||||||
rateLimiters.getVoiceDestinationDailyLimiter().validate(number);
|
rateLimiters.getVoiceDestinationDailyLimiter().validate(number);
|
||||||
break;
|
}
|
||||||
default:
|
default -> throw new WebApplicationException(Response.status(422).build());
|
||||||
throw new WebApplicationException(Response.status(422).build());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VerificationCode verificationCode = generateVerificationCode(number);
|
VerificationCode verificationCode = generateVerificationCode(number);
|
||||||
|
|
|
@ -5,8 +5,13 @@
|
||||||
|
|
||||||
package org.whispersystems.textsecuregcm.controllers;
|
package org.whispersystems.textsecuregcm.controllers;
|
||||||
|
|
||||||
|
import static org.whispersystems.textsecuregcm.metrics.MetricsUtil.name;
|
||||||
|
|
||||||
import com.codahale.metrics.annotation.Timed;
|
import com.codahale.metrics.annotation.Timed;
|
||||||
import io.dropwizard.auth.Auth;
|
import io.dropwizard.auth.Auth;
|
||||||
|
import io.micrometer.core.instrument.Counter;
|
||||||
|
import io.micrometer.core.instrument.Metrics;
|
||||||
|
import io.micrometer.core.instrument.Tags;
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
import java.time.Clock;
|
import java.time.Clock;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
|
@ -46,9 +51,6 @@ import javax.ws.rs.core.HttpHeaders;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import javax.ws.rs.core.Response.Status;
|
import javax.ws.rs.core.Response.Status;
|
||||||
import io.micrometer.core.instrument.Counter;
|
|
||||||
import io.micrometer.core.instrument.Metrics;
|
|
||||||
import io.micrometer.core.instrument.Tags;
|
|
||||||
import org.apache.commons.codec.DecoderException;
|
import org.apache.commons.codec.DecoderException;
|
||||||
import org.apache.commons.codec.binary.Base64;
|
import org.apache.commons.codec.binary.Base64;
|
||||||
import org.apache.commons.codec.binary.Hex;
|
import org.apache.commons.codec.binary.Hex;
|
||||||
|
@ -70,12 +72,12 @@ import org.whispersystems.textsecuregcm.badges.ProfileBadgeConverter;
|
||||||
import org.whispersystems.textsecuregcm.configuration.BadgeConfiguration;
|
import org.whispersystems.textsecuregcm.configuration.BadgeConfiguration;
|
||||||
import org.whispersystems.textsecuregcm.configuration.BadgesConfiguration;
|
import org.whispersystems.textsecuregcm.configuration.BadgesConfiguration;
|
||||||
import org.whispersystems.textsecuregcm.configuration.dynamic.DynamicConfiguration;
|
import org.whispersystems.textsecuregcm.configuration.dynamic.DynamicConfiguration;
|
||||||
|
import org.whispersystems.textsecuregcm.entities.BaseProfileResponse;
|
||||||
import org.whispersystems.textsecuregcm.entities.CreateProfileRequest;
|
import org.whispersystems.textsecuregcm.entities.CreateProfileRequest;
|
||||||
import org.whispersystems.textsecuregcm.entities.CredentialProfileResponse;
|
import org.whispersystems.textsecuregcm.entities.CredentialProfileResponse;
|
||||||
import org.whispersystems.textsecuregcm.entities.PniCredentialProfileResponse;
|
import org.whispersystems.textsecuregcm.entities.PniCredentialProfileResponse;
|
||||||
import org.whispersystems.textsecuregcm.entities.ProfileAvatarUploadAttributes;
|
import org.whispersystems.textsecuregcm.entities.ProfileAvatarUploadAttributes;
|
||||||
import org.whispersystems.textsecuregcm.entities.ProfileKeyCredentialProfileResponse;
|
import org.whispersystems.textsecuregcm.entities.ProfileKeyCredentialProfileResponse;
|
||||||
import org.whispersystems.textsecuregcm.entities.BaseProfileResponse;
|
|
||||||
import org.whispersystems.textsecuregcm.entities.UserCapabilities;
|
import org.whispersystems.textsecuregcm.entities.UserCapabilities;
|
||||||
import org.whispersystems.textsecuregcm.entities.VersionedProfileResponse;
|
import org.whispersystems.textsecuregcm.entities.VersionedProfileResponse;
|
||||||
import org.whispersystems.textsecuregcm.limits.RateLimiters;
|
import org.whispersystems.textsecuregcm.limits.RateLimiters;
|
||||||
|
@ -92,8 +94,6 @@ import org.whispersystems.textsecuregcm.util.Pair;
|
||||||
import software.amazon.awssdk.services.s3.S3Client;
|
import software.amazon.awssdk.services.s3.S3Client;
|
||||||
import software.amazon.awssdk.services.s3.model.DeleteObjectRequest;
|
import software.amazon.awssdk.services.s3.model.DeleteObjectRequest;
|
||||||
|
|
||||||
import static org.whispersystems.textsecuregcm.metrics.MetricsUtil.name;
|
|
||||||
|
|
||||||
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
|
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
|
||||||
@Path("/v1/profile")
|
@Path("/v1/profile")
|
||||||
public class ProfileController {
|
public class ProfileController {
|
||||||
|
@ -171,17 +171,11 @@ public class ProfileController {
|
||||||
currentAvatar = Optional.of(currentProfile.get().getAvatar());
|
currentAvatar = Optional.of(currentProfile.get().getAvatar());
|
||||||
}
|
}
|
||||||
|
|
||||||
String avatar = null;
|
String avatar = switch (request.getAvatarChange()) {
|
||||||
switch (request.getAvatarChange()) {
|
case UNCHANGED -> currentAvatar.orElse(null);
|
||||||
case UNCHANGED:
|
case CLEAR -> null;
|
||||||
avatar = currentAvatar.orElse(null);
|
case UPDATE -> generateAvatarObjectName();
|
||||||
break;
|
};
|
||||||
case CLEAR:
|
|
||||||
break;
|
|
||||||
case UPDATE:
|
|
||||||
avatar = generateAvatarObjectName();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
profilesManager.set(auth.getAccount().getUuid(),
|
profilesManager.set(auth.getAccount().getUuid(),
|
||||||
new VersionedProfile(
|
new VersionedProfile(
|
||||||
|
|
Loading…
Reference in New Issue