mirror of
https://github.com/google/nomulus.git
synced 2025-05-14 16:37:13 +02:00
Deprecate more fields in RegistryConfig
This primarily addresses issues with TMCH testing mode and email sending utils. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=143710550
This commit is contained in:
parent
c05424b947
commit
25a8bbe890
23 changed files with 203 additions and 265 deletions
|
@ -15,18 +15,17 @@
|
|||
package google.registry.util;
|
||||
|
||||
import static com.google.common.base.Suppliers.memoizeWithExpiration;
|
||||
import static google.registry.config.RegistryConfig.getSingletonCachePersistDuration;
|
||||
import static google.registry.config.RegistryConfig.getSingletonCacheRefreshDuration;
|
||||
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||
import static org.joda.time.Duration.ZERO;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
import google.registry.config.RegistryEnvironment;
|
||||
import org.joda.time.Duration;
|
||||
|
||||
/** Utility methods related to caching. */
|
||||
public class CacheUtils {
|
||||
|
||||
private static final RegistryEnvironment ENVIRONMENT = RegistryEnvironment.get();
|
||||
|
||||
/**
|
||||
* Memoize a supplier, with a short expiration specified in the environment config.
|
||||
*
|
||||
|
@ -34,7 +33,7 @@ public class CacheUtils {
|
|||
* lists downloaded from the TMCH get updated in datastore and the caches need to be refreshed.)
|
||||
*/
|
||||
public static <T> Supplier<T> memoizeWithShortExpiration(Supplier<T> original) {
|
||||
return memoizeForDuration(original, ENVIRONMENT.config().getSingletonCacheRefreshDuration());
|
||||
return memoizeForDuration(original, getSingletonCacheRefreshDuration());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -45,7 +44,7 @@ public class CacheUtils {
|
|||
* while allowing the production config to set the expiration to forever.
|
||||
*/
|
||||
public static <T> Supplier<T> memoizeWithLongExpiration(Supplier<T> original) {
|
||||
return memoizeForDuration(original, ENVIRONMENT.config().getSingletonCachePersistDuration());
|
||||
return memoizeForDuration(original, getSingletonCachePersistDuration());
|
||||
}
|
||||
|
||||
/** Memoize a supplier, with a given expiration. */
|
||||
|
|
|
@ -20,10 +20,9 @@ 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.ImmutableList;
|
||||
import google.registry.config.RegistryConfig;
|
||||
import google.registry.config.RegistryEnvironment;
|
||||
import google.registry.config.ConfigModule.Config;
|
||||
import java.util.List;
|
||||
import javax.inject.Inject;
|
||||
import javax.mail.Message;
|
||||
import javax.mail.internet.AddressException;
|
||||
import javax.mail.internet.InternetAddress;
|
||||
|
@ -33,30 +32,31 @@ import javax.mail.internet.InternetAddress;
|
|||
*/
|
||||
public class SendEmailUtils {
|
||||
|
||||
private static final RegistryConfig CONFIG = RegistryEnvironment.get().config();
|
||||
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
|
||||
|
||||
private final String googleAppsSendFromEmailAddress;
|
||||
private final String googleAppsAdminEmailDisplayName;
|
||||
|
||||
@Inject
|
||||
public SendEmailUtils(
|
||||
@Config("googleAppsSendFromEmailAddress") String googleAppsSendFromEmailAddress,
|
||||
@Config("googleAppsAdminEmailDisplayName") String googleAppsAdminEmailDisplayName) {
|
||||
this.googleAppsSendFromEmailAddress = googleAppsSendFromEmailAddress;
|
||||
this.googleAppsAdminEmailDisplayName = googleAppsAdminEmailDisplayName;
|
||||
}
|
||||
|
||||
@NonFinalForTesting
|
||||
private static SendEmailService emailService = new SendEmailService();
|
||||
|
||||
/**
|
||||
* Sends an email from Nomulus to the specified recipient. Returns true iff sending was
|
||||
* Sends an email from Nomulus to the specified recipient(s). Returns true iff sending was
|
||||
* successful.
|
||||
*/
|
||||
public static boolean sendEmail(String address, String subject, String body) {
|
||||
return sendEmail(ImmutableList.of(address), subject, body);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends an email from Nomulus to the specified recipients. Returns true iff sending was
|
||||
* successful.
|
||||
*/
|
||||
public static boolean sendEmail(Iterable<String> addresses, final String subject, String body) {
|
||||
public boolean sendEmail(Iterable<String> addresses, final String subject, String body) {
|
||||
try {
|
||||
Message msg = emailService.createMessage();
|
||||
msg.setFrom(new InternetAddress(
|
||||
CONFIG.getGoogleAppsSendFromEmailAddress(),
|
||||
CONFIG.getGoogleAppsAdminEmailDisplayName()));
|
||||
msg.setFrom(
|
||||
new InternetAddress(googleAppsSendFromEmailAddress, googleAppsAdminEmailDisplayName));
|
||||
List<InternetAddress> emails = FluentIterable
|
||||
.from(addresses)
|
||||
.transform(new Function<String, InternetAddress>() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue