mirror of
https://github.com/google/nomulus.git
synced 2025-05-14 16:37:13 +02:00
Run automatic Java 8 conversion over codebase
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=171174380
This commit is contained in:
parent
44df5da771
commit
5edb7935ed
190 changed files with 2312 additions and 3096 deletions
|
@ -37,7 +37,6 @@ import java.security.cert.CertificateParsingException;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/** Form fields for validating input for the {@code Registrar} class. */
|
||||
public final class RegistrarFormFields {
|
||||
|
@ -47,30 +46,24 @@ public final class RegistrarFormFields {
|
|||
public static final String ASCII_ERROR = "Please only use ASCII-US characters.";
|
||||
|
||||
private static final Function<String, CidrAddressBlock> CIDR_TRANSFORM =
|
||||
new Function<String, CidrAddressBlock>() {
|
||||
@Nullable
|
||||
@Override
|
||||
public CidrAddressBlock apply(@Nullable String input) {
|
||||
try {
|
||||
return input != null ? CidrAddressBlock.create(input) : null;
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new FormFieldException("Not a valid CIDR notation IP-address block.", e);
|
||||
}
|
||||
}};
|
||||
input -> {
|
||||
try {
|
||||
return input != null ? CidrAddressBlock.create(input) : null;
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new FormFieldException("Not a valid CIDR notation IP-address block.", e);
|
||||
}
|
||||
};
|
||||
|
||||
private static final Function<String, String> HOSTNAME_TRANSFORM =
|
||||
new Function<String, String>() {
|
||||
@Nullable
|
||||
@Override
|
||||
public String apply(@Nullable String input) {
|
||||
if (input == null) {
|
||||
return null;
|
||||
}
|
||||
if (!InternetDomainName.isValid(input)) {
|
||||
throw new FormFieldException("Not a valid hostname.");
|
||||
}
|
||||
return canonicalizeDomainName(input);
|
||||
}};
|
||||
input -> {
|
||||
if (input == null) {
|
||||
return null;
|
||||
}
|
||||
if (!InternetDomainName.isValid(input)) {
|
||||
throw new FormFieldException("Not a valid hostname.");
|
||||
}
|
||||
return canonicalizeDomainName(input);
|
||||
};
|
||||
|
||||
public static final FormField<String, String> NAME_FIELD =
|
||||
FormFields.NAME.asBuilderNamed("registrarName")
|
||||
|
@ -133,20 +126,18 @@ public final class RegistrarFormFields {
|
|||
private static final FormField<String, String> X509_PEM_CERTIFICATE =
|
||||
FormField.named("certificate")
|
||||
.emptyToNull()
|
||||
.transform(new Function<String, String>() {
|
||||
@Nullable
|
||||
@Override
|
||||
public String apply(@Nullable String input) {
|
||||
if (input == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
X509Utils.loadCertificate(input);
|
||||
} catch (CertificateParsingException e) {
|
||||
throw new FormFieldException("Invalid X.509 PEM certificate");
|
||||
}
|
||||
return input;
|
||||
}})
|
||||
.transform(
|
||||
input -> {
|
||||
if (input == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
X509Utils.loadCertificate(input);
|
||||
} catch (CertificateParsingException e) {
|
||||
throw new FormFieldException("Invalid X.509 PEM certificate");
|
||||
}
|
||||
return input;
|
||||
})
|
||||
.build();
|
||||
|
||||
public static final FormField<String, String> CLIENT_CERTIFICATE_FIELD =
|
||||
|
@ -233,48 +224,44 @@ public final class RegistrarFormFields {
|
|||
|
||||
public static final Function<Map<String, ?>, RegistrarContact.Builder>
|
||||
REGISTRAR_CONTACT_TRANSFORM =
|
||||
new Function<Map<String, ?>, RegistrarContact.Builder>() {
|
||||
@Nullable
|
||||
@Override
|
||||
public RegistrarContact.Builder apply(@Nullable Map<String, ?> args) {
|
||||
if (args == null) {
|
||||
return null;
|
||||
}
|
||||
RegistrarContact.Builder builder = new RegistrarContact.Builder();
|
||||
for (String name : CONTACT_NAME_FIELD.extractUntyped(args).asSet()) {
|
||||
builder.setName(name);
|
||||
}
|
||||
for (String emailAddress : CONTACT_EMAIL_ADDRESS_FIELD.extractUntyped(args).asSet()) {
|
||||
builder.setEmailAddress(emailAddress);
|
||||
}
|
||||
for (Boolean visible :
|
||||
CONTACT_VISIBLE_IN_WHOIS_AS_ADMIN_FIELD.extractUntyped(args).asSet()) {
|
||||
builder.setVisibleInWhoisAsAdmin(visible);
|
||||
}
|
||||
for (Boolean visible :
|
||||
CONTACT_VISIBLE_IN_WHOIS_AS_TECH_FIELD.extractUntyped(args).asSet()) {
|
||||
builder.setVisibleInWhoisAsTech(visible);
|
||||
}
|
||||
for (Boolean visible :
|
||||
PHONE_AND_EMAIL_VISIBLE_IN_DOMAIN_WHOIS_AS_ABUSE_FIELD
|
||||
.extractUntyped(args)
|
||||
.asSet()) {
|
||||
builder.setVisibleInDomainWhoisAsAbuse(visible);
|
||||
}
|
||||
for (String phoneNumber : CONTACT_PHONE_NUMBER_FIELD.extractUntyped(args).asSet()) {
|
||||
builder.setPhoneNumber(phoneNumber);
|
||||
}
|
||||
for (String faxNumber : CONTACT_FAX_NUMBER_FIELD.extractUntyped(args).asSet()) {
|
||||
builder.setFaxNumber(faxNumber);
|
||||
}
|
||||
for (Set<RegistrarContact.Type> types : CONTACT_TYPES.extractUntyped(args).asSet()) {
|
||||
builder.setTypes(types);
|
||||
}
|
||||
for (String gaeUserId : CONTACT_GAE_USER_ID_FIELD.extractUntyped(args).asSet()) {
|
||||
builder.setGaeUserId(gaeUserId);
|
||||
}
|
||||
return builder;
|
||||
args -> {
|
||||
if (args == null) {
|
||||
return null;
|
||||
}
|
||||
RegistrarContact.Builder builder = new RegistrarContact.Builder();
|
||||
for (String name : CONTACT_NAME_FIELD.extractUntyped(args).asSet()) {
|
||||
builder.setName(name);
|
||||
}
|
||||
for (String emailAddress : CONTACT_EMAIL_ADDRESS_FIELD.extractUntyped(args).asSet()) {
|
||||
builder.setEmailAddress(emailAddress);
|
||||
}
|
||||
for (Boolean visible :
|
||||
CONTACT_VISIBLE_IN_WHOIS_AS_ADMIN_FIELD.extractUntyped(args).asSet()) {
|
||||
builder.setVisibleInWhoisAsAdmin(visible);
|
||||
}
|
||||
for (Boolean visible :
|
||||
CONTACT_VISIBLE_IN_WHOIS_AS_TECH_FIELD.extractUntyped(args).asSet()) {
|
||||
builder.setVisibleInWhoisAsTech(visible);
|
||||
}
|
||||
for (Boolean visible :
|
||||
PHONE_AND_EMAIL_VISIBLE_IN_DOMAIN_WHOIS_AS_ABUSE_FIELD
|
||||
.extractUntyped(args)
|
||||
.asSet()) {
|
||||
builder.setVisibleInDomainWhoisAsAbuse(visible);
|
||||
}
|
||||
for (String phoneNumber : CONTACT_PHONE_NUMBER_FIELD.extractUntyped(args).asSet()) {
|
||||
builder.setPhoneNumber(phoneNumber);
|
||||
}
|
||||
for (String faxNumber : CONTACT_FAX_NUMBER_FIELD.extractUntyped(args).asSet()) {
|
||||
builder.setFaxNumber(faxNumber);
|
||||
}
|
||||
for (Set<RegistrarContact.Type> types : CONTACT_TYPES.extractUntyped(args).asSet()) {
|
||||
builder.setTypes(types);
|
||||
}
|
||||
for (String gaeUserId : CONTACT_GAE_USER_ID_FIELD.extractUntyped(args).asSet()) {
|
||||
builder.setGaeUserId(gaeUserId);
|
||||
}
|
||||
return builder;
|
||||
};
|
||||
|
||||
public static final FormField<List<Map<String, ?>>, List<RegistrarContact.Builder>>
|
||||
|
@ -349,36 +336,32 @@ public final class RegistrarFormFields {
|
|||
final FormField<String, String> cityField,
|
||||
final FormField<String, String> stateField,
|
||||
final FormField<String, String> zipField) {
|
||||
return new Function<Map<String, ?>, RegistrarAddress>() {
|
||||
@Nullable
|
||||
@Override
|
||||
public RegistrarAddress apply(@Nullable Map<String, ?> args) {
|
||||
if (args == null) {
|
||||
return null;
|
||||
}
|
||||
RegistrarAddress.Builder builder = new RegistrarAddress.Builder();
|
||||
String countryCode = COUNTRY_CODE_FIELD.extractUntyped(args).get();
|
||||
builder.setCountryCode(countryCode);
|
||||
for (List<String> streets : streetField.extractUntyped(args).asSet()) {
|
||||
builder.setStreet(ImmutableList.copyOf(streets));
|
||||
}
|
||||
for (String city : cityField.extractUntyped(args).asSet()) {
|
||||
builder.setCity(city);
|
||||
}
|
||||
for (String state : stateField.extractUntyped(args).asSet()) {
|
||||
if ("US".equals(countryCode)) {
|
||||
state = Ascii.toUpperCase(state);
|
||||
if (!StateCode.US_MAP.containsKey(state)) {
|
||||
throw new FormFieldException(stateField, "Unknown US state code.");
|
||||
}
|
||||
}
|
||||
builder.setState(state);
|
||||
}
|
||||
for (String zip : zipField.extractUntyped(args).asSet()) {
|
||||
builder.setZip(zip);
|
||||
}
|
||||
return builder.build();
|
||||
return args -> {
|
||||
if (args == null) {
|
||||
return null;
|
||||
}
|
||||
RegistrarAddress.Builder builder = new RegistrarAddress.Builder();
|
||||
String countryCode = COUNTRY_CODE_FIELD.extractUntyped(args).get();
|
||||
builder.setCountryCode(countryCode);
|
||||
for (List<String> streets : streetField.extractUntyped(args).asSet()) {
|
||||
builder.setStreet(ImmutableList.copyOf(streets));
|
||||
}
|
||||
for (String city : cityField.extractUntyped(args).asSet()) {
|
||||
builder.setCity(city);
|
||||
}
|
||||
for (String state : stateField.extractUntyped(args).asSet()) {
|
||||
if ("US".equals(countryCode)) {
|
||||
state = Ascii.toUpperCase(state);
|
||||
if (!StateCode.US_MAP.containsKey(state)) {
|
||||
throw new FormFieldException(stateField, "Unknown US state code.");
|
||||
}
|
||||
}
|
||||
builder.setState(state);
|
||||
}
|
||||
for (String zip : zipField.extractUntyped(args).asSet()) {
|
||||
builder.setZip(zip);
|
||||
}
|
||||
return builder.build();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
|
||||
package google.registry.ui.server;
|
||||
|
||||
import static com.google.common.base.MoreObjects.firstNonNull;
|
||||
import static com.google.common.base.Suppliers.memoize;
|
||||
import static com.google.common.io.Resources.asCharSource;
|
||||
import static com.google.common.io.Resources.getResource;
|
||||
|
@ -46,44 +45,43 @@ public final class SoyTemplateUtils {
|
|||
|
||||
/** Returns a memoized supplier containing compiled tofu. */
|
||||
public static Supplier<SoyTofu> createTofuSupplier(final SoyFileInfo... soyInfos) {
|
||||
return memoize(new Supplier<SoyTofu>() {
|
||||
@Override
|
||||
public SoyTofu get() {
|
||||
ConsoleDebug debugMode = ConsoleDebug.get();
|
||||
SoyFileSet.Builder builder = SoyFileSet.builder();
|
||||
for (SoyFileInfo soyInfo : soyInfos) {
|
||||
builder.add(getResource(soyInfo.getClass(), soyInfo.getFileName()));
|
||||
}
|
||||
Map<String, Object> globals = new HashMap<>();
|
||||
try {
|
||||
globals.putAll(SoyUtils.parseCompileTimeGlobals(asCharSource(SOY_GLOBALS, UTF_8)));
|
||||
} catch (SoySyntaxException | IOException e) {
|
||||
throw new RuntimeException("Failed to load soy globals", e);
|
||||
}
|
||||
globals.put("DEBUG", debugMode.ordinal());
|
||||
builder.setCompileTimeGlobals(globals);
|
||||
return builder.build().compileToTofu();
|
||||
}});
|
||||
return memoize(
|
||||
() -> {
|
||||
ConsoleDebug debugMode = ConsoleDebug.get();
|
||||
SoyFileSet.Builder builder = SoyFileSet.builder();
|
||||
for (SoyFileInfo soyInfo : soyInfos) {
|
||||
builder.add(getResource(soyInfo.getClass(), soyInfo.getFileName()));
|
||||
}
|
||||
Map<String, Object> globals = new HashMap<>();
|
||||
try {
|
||||
globals.putAll(SoyUtils.parseCompileTimeGlobals(asCharSource(SOY_GLOBALS, UTF_8)));
|
||||
} catch (SoySyntaxException | IOException e) {
|
||||
throw new RuntimeException("Failed to load soy globals", e);
|
||||
}
|
||||
globals.put("DEBUG", debugMode.ordinal());
|
||||
builder.setCompileTimeGlobals(globals);
|
||||
return builder.build().compileToTofu();
|
||||
});
|
||||
}
|
||||
|
||||
/** Returns a memoized supplier of the thing you pass to {@code setCssRenamingMap()}. */
|
||||
public static Supplier<SoyCssRenamingMap> createCssRenamingMapSupplier(
|
||||
final URL cssMap,
|
||||
final URL cssMapDebug) {
|
||||
return memoize(new Supplier<SoyCssRenamingMap>() {
|
||||
@Override
|
||||
public SoyCssRenamingMap get() {
|
||||
final ImmutableMap<String, String> renames = getCssRenames(cssMap, cssMapDebug);
|
||||
return new SoyCssRenamingMap() {
|
||||
@Override
|
||||
public String get(String cssClassName) {
|
||||
List<String> result = new ArrayList<>();
|
||||
for (String part : CSS_CLASS_SPLITTER.split(cssClassName)) {
|
||||
result.add(firstNonNull(renames.get(part), part));
|
||||
return memoize(
|
||||
() -> {
|
||||
final ImmutableMap<String, String> renames = getCssRenames(cssMap, cssMapDebug);
|
||||
return new SoyCssRenamingMap() {
|
||||
@Override
|
||||
public String get(String cssClassName) {
|
||||
List<String> result = new ArrayList<>();
|
||||
for (String part : CSS_CLASS_SPLITTER.split(cssClassName)) {
|
||||
result.add(renames.getOrDefault(part, part));
|
||||
}
|
||||
return CSS_CLASS_JOINER.join(result);
|
||||
}
|
||||
return CSS_CLASS_JOINER.join(result);
|
||||
}};
|
||||
}});
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
private static ImmutableMap<String, String> getCssRenames(URL cssMap, URL cssMapDebug) {
|
||||
|
|
|
@ -27,7 +27,6 @@ import com.braintreegateway.Transaction;
|
|||
import com.braintreegateway.TransactionRequest;
|
||||
import com.braintreegateway.ValidationError;
|
||||
import com.braintreegateway.ValidationErrors;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.re2j.Pattern;
|
||||
import google.registry.config.RegistryConfig.Config;
|
||||
|
@ -108,15 +107,15 @@ public final class RegistrarPaymentAction implements Runnable, JsonAction {
|
|||
.emptyToNull()
|
||||
.required()
|
||||
.matches(Pattern.compile("-?\\d+(?:\\.\\d+)?"), "Invalid number.")
|
||||
.transform(BigDecimal.class, new Function<String, BigDecimal>() {
|
||||
@Override
|
||||
public BigDecimal apply(String value) {
|
||||
BigDecimal result = new BigDecimal(value);
|
||||
if (result.signum() != 1) {
|
||||
throw new FormFieldException("Must be a positive number.");
|
||||
}
|
||||
return result;
|
||||
}})
|
||||
.transform(
|
||||
BigDecimal.class,
|
||||
value -> {
|
||||
BigDecimal result = new BigDecimal(value);
|
||||
if (result.signum() != 1) {
|
||||
throw new FormFieldException("Must be a positive number.");
|
||||
}
|
||||
return result;
|
||||
})
|
||||
.build();
|
||||
|
||||
private static final FormField<String, CurrencyUnit> CURRENCY_FIELD =
|
||||
|
@ -125,15 +124,15 @@ public final class RegistrarPaymentAction implements Runnable, JsonAction {
|
|||
.emptyToNull()
|
||||
.required()
|
||||
.matches(Pattern.compile("[A-Z]{3}"), "Invalid currency code.")
|
||||
.transform(CurrencyUnit.class, new Function<String, CurrencyUnit>() {
|
||||
@Override
|
||||
public CurrencyUnit apply(String value) {
|
||||
try {
|
||||
return CurrencyUnit.of(value);
|
||||
} catch (IllegalCurrencyException ignored) {
|
||||
throw new FormFieldException("Unknown ISO currency code.");
|
||||
}
|
||||
}})
|
||||
.transform(
|
||||
CurrencyUnit.class,
|
||||
value -> {
|
||||
try {
|
||||
return CurrencyUnit.of(value);
|
||||
} catch (IllegalCurrencyException ignored) {
|
||||
throw new FormFieldException("Unknown ISO currency code.");
|
||||
}
|
||||
})
|
||||
.build();
|
||||
|
||||
private static final FormField<String, String> PAYMENT_METHOD_NONCE_FIELD =
|
||||
|
|
|
@ -15,12 +15,12 @@
|
|||
package google.registry.ui.server.registrar;
|
||||
|
||||
import static com.google.common.base.Functions.toStringFunction;
|
||||
import static com.google.common.collect.ImmutableList.toImmutableList;
|
||||
import static google.registry.security.JsonResponseHelper.Status.ERROR;
|
||||
import static google.registry.security.JsonResponseHelper.Status.SUCCESS;
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
import com.braintreegateway.BraintreeGateway;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import google.registry.braintree.BraintreeRegistrarSyncer;
|
||||
import google.registry.config.RegistryConfig.Config;
|
||||
|
@ -107,14 +107,18 @@ public final class RegistrarPaymentSetupAction implements Runnable, JsonAction {
|
|||
// In order to set the customerId field on the payment, the customer must exist.
|
||||
customerSyncer.sync(registrar);
|
||||
|
||||
return JsonResponseHelper
|
||||
.create(SUCCESS, "Success", asList(
|
||||
return JsonResponseHelper.create(
|
||||
SUCCESS,
|
||||
"Success",
|
||||
asList(
|
||||
ImmutableMap.of(
|
||||
"brainframe", brainframe,
|
||||
"token", braintreeGateway.clientToken().generate(),
|
||||
"currencies",
|
||||
FluentIterable.from(accountIds.keySet())
|
||||
.transform(toStringFunction())
|
||||
.toList())));
|
||||
accountIds
|
||||
.keySet()
|
||||
.stream()
|
||||
.map(toStringFunction())
|
||||
.collect(toImmutableList()))));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,23 +14,22 @@
|
|||
|
||||
package google.registry.ui.server.registrar;
|
||||
|
||||
import static com.google.common.collect.Iterables.any;
|
||||
import static com.google.common.collect.ImmutableSet.toImmutableSet;
|
||||
import static com.google.common.collect.Iterables.concat;
|
||||
import static com.google.common.collect.Sets.difference;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.security.JsonResponseHelper.Status.ERROR;
|
||||
import static google.registry.security.JsonResponseHelper.Status.SUCCESS;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.Streams;
|
||||
import com.googlecode.objectify.Work;
|
||||
import google.registry.config.RegistryConfig.Config;
|
||||
import google.registry.export.sheet.SyncRegistrarsSheetAction;
|
||||
|
@ -53,7 +52,6 @@ import java.util.HashSet;
|
|||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.inject.Inject;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
|
@ -82,11 +80,8 @@ public class RegistrarSettingsAction implements Runnable, JsonActionRunner.JsonA
|
|||
registrarChangesNotificationEmailAddresses;
|
||||
@Inject RegistrarSettingsAction() {}
|
||||
|
||||
private static final Predicate<RegistrarContact> HAS_PHONE = new Predicate<RegistrarContact>() {
|
||||
@Override
|
||||
public boolean apply(RegistrarContact contact) {
|
||||
return contact.getPhoneNumber() != null;
|
||||
}};
|
||||
private static final Predicate<RegistrarContact> HAS_PHONE =
|
||||
contact -> contact.getPhoneNumber() != null;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
@ -160,13 +155,10 @@ public class RegistrarSettingsAction implements Runnable, JsonActionRunner.JsonA
|
|||
|
||||
private Map<String, Object> expandRegistrarWithContacts(Iterable<RegistrarContact> contacts,
|
||||
Registrar registrar) {
|
||||
ImmutableSet<Map<String, Object>> expandedContacts = FluentIterable.from(contacts)
|
||||
.transform(new Function<RegistrarContact, Map<String, Object>>() {
|
||||
@Override
|
||||
public Map<String, Object> apply(RegistrarContact contact) {
|
||||
return contact.toDiffableFieldMap();
|
||||
}})
|
||||
.toSet();
|
||||
ImmutableSet<Map<String, Object>> expandedContacts =
|
||||
Streams.stream(contacts)
|
||||
.map(RegistrarContact::toDiffableFieldMap)
|
||||
.collect(toImmutableSet());
|
||||
// Use LinkedHashMap here to preserve ordering; null values mean we can't use ImmutableMap.
|
||||
LinkedHashMap<String, Object> result = new LinkedHashMap<>();
|
||||
result.putAll(registrar.toDiffableFieldMap());
|
||||
|
@ -286,8 +278,8 @@ public class RegistrarSettingsAction implements Runnable, JsonActionRunner.JsonA
|
|||
Multimap<RegistrarContact.Type, RegistrarContact> newContactsByType,
|
||||
RegistrarContact.Type... types) {
|
||||
for (RegistrarContact.Type type : types) {
|
||||
if (any(oldContactsByType.get(type), HAS_PHONE)
|
||||
&& !any(newContactsByType.get(type), HAS_PHONE)) {
|
||||
if (oldContactsByType.get(type).stream().anyMatch(HAS_PHONE)
|
||||
&& newContactsByType.get(type).stream().noneMatch(HAS_PHONE)) {
|
||||
throw new ContactRequirementException(
|
||||
String.format(
|
||||
"Please provide a phone number for at least one %s contact",
|
||||
|
@ -306,12 +298,7 @@ public class RegistrarSettingsAction implements Runnable, JsonActionRunner.JsonA
|
|||
*/
|
||||
private static Optional<RegistrarContact> getDomainWhoisVisibleAbuseContact(
|
||||
Set<RegistrarContact> contacts) {
|
||||
return Iterables.tryFind(contacts, new Predicate<RegistrarContact>() {
|
||||
@Override
|
||||
public boolean apply(@Nullable RegistrarContact contact) {
|
||||
return contact.getVisibleInDomainWhoisAsAbuse();
|
||||
}
|
||||
});
|
||||
return Iterables.tryFind(contacts, RegistrarContact::getVisibleInDomainWhoisAsAbuse);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -14,12 +14,12 @@
|
|||
|
||||
package google.registry.ui.server.registrar;
|
||||
|
||||
import static com.google.common.collect.ImmutableList.toImmutableList;
|
||||
import static com.google.common.collect.Iterables.toArray;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.Streams;
|
||||
import google.registry.config.RegistryConfig.Config;
|
||||
import google.registry.util.FormattingLogger;
|
||||
import google.registry.util.NonFinalForTesting;
|
||||
|
@ -60,25 +60,25 @@ public class SendEmailUtils {
|
|||
Message msg = emailService.createMessage();
|
||||
msg.setFrom(
|
||||
new InternetAddress(gSuiteOutgoingEmailAddress, gSuiteOutoingEmailDisplayName));
|
||||
List<InternetAddress> emails = FluentIterable
|
||||
.from(addresses)
|
||||
.transform(new Function<String, InternetAddress>() {
|
||||
@Override
|
||||
public InternetAddress apply(String emailAddress) {
|
||||
try {
|
||||
return new InternetAddress(emailAddress, true);
|
||||
} catch (AddressException e) {
|
||||
logger.severefmt(
|
||||
e,
|
||||
"Could not send email to %s with subject '%s'.",
|
||||
emailAddress,
|
||||
subject);
|
||||
// Returning null excludes this address from the list of recipients on the email.
|
||||
return null;
|
||||
}
|
||||
}})
|
||||
.filter(Predicates.notNull())
|
||||
.toList();
|
||||
List<InternetAddress> emails =
|
||||
Streams.stream(addresses)
|
||||
.map(
|
||||
emailAddress -> {
|
||||
try {
|
||||
return new InternetAddress(emailAddress, true);
|
||||
} catch (AddressException e) {
|
||||
logger.severefmt(
|
||||
e,
|
||||
"Could not send email to %s with subject '%s'.",
|
||||
emailAddress,
|
||||
subject);
|
||||
// Returning null excludes this address from the list of recipients on the
|
||||
// email.
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.filter(Predicates.notNull())
|
||||
.collect(toImmutableList());
|
||||
if (emails.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -21,9 +21,7 @@ import static google.registry.util.PreconditionsUtils.checkArgumentPresent;
|
|||
|
||||
import com.google.appengine.api.users.User;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.googlecode.objectify.Key;
|
||||
import google.registry.config.RegistryConfig.Config;
|
||||
import google.registry.model.registrar.Registrar;
|
||||
|
@ -33,7 +31,6 @@ import google.registry.request.auth.AuthResult;
|
|||
import google.registry.request.auth.UserAuthInfo;
|
||||
import google.registry.util.FormattingLogger;
|
||||
import javax.annotation.CheckReturnValue;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
import javax.inject.Inject;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
@ -193,12 +190,9 @@ public class SessionUtils {
|
|||
|
||||
/** Returns {@code true} if {@code gaeUserId} is listed in contacts. */
|
||||
private static boolean hasAccessToRegistrar(Registrar registrar, final String gaeUserId) {
|
||||
return FluentIterable
|
||||
.from(registrar.getContacts())
|
||||
.anyMatch(new Predicate<RegistrarContact>() {
|
||||
@Override
|
||||
public boolean apply(@Nonnull RegistrarContact contact) {
|
||||
return gaeUserId.equals(contact.getGaeUserId());
|
||||
}});
|
||||
return registrar
|
||||
.getContacts()
|
||||
.stream()
|
||||
.anyMatch(contact -> gaeUserId.equals(contact.getGaeUserId()));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue