Run automatic Java 8 conversion over codebase

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=171174380
This commit is contained in:
mcilwain 2017-10-05 10:48:38 -07:00 committed by Ben McIlwain
parent 44df5da771
commit 5edb7935ed
190 changed files with 2312 additions and 3096 deletions

View file

@ -21,7 +21,6 @@ import static google.registry.util.DateTimeUtils.END_OF_TIME;
import static google.registry.util.DateTimeUtils.earliestOf; import static google.registry.util.DateTimeUtils.earliestOf;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.googlecode.objectify.Key; import com.googlecode.objectify.Key;
import com.googlecode.objectify.Work; import com.googlecode.objectify.Work;
@ -167,10 +166,7 @@ class CommitLogCheckpointStrategy {
ImmutableMap<Integer, DateTime> computeBucketCheckpointTimes( ImmutableMap<Integer, DateTime> computeBucketCheckpointTimes(
ImmutableMap<Integer, DateTime> firstPassTimes, ImmutableMap<Integer, DateTime> firstPassTimes,
final DateTime threshold) { final DateTime threshold) {
return ImmutableMap.copyOf(transformValues(firstPassTimes, new Function<DateTime, DateTime>() { return ImmutableMap.copyOf(
@Override transformValues(firstPassTimes, firstPassTime -> earliestOf(firstPassTime, threshold)));
public DateTime apply(DateTime firstPassTime) {
return earliestOf(firstPassTime, threshold);
}}));
} }
} }

View file

@ -16,6 +16,7 @@ package google.registry.backup;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Verify.verifyNotNull; import static com.google.common.base.Verify.verifyNotNull;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.collect.Iterables.concat; import static com.google.common.collect.Iterables.concat;
import static com.google.common.collect.Lists.partition; import static com.google.common.collect.Lists.partition;
import static google.registry.backup.BackupUtils.GcsMetadataKeys.LOWER_BOUND_CHECKPOINT; import static google.registry.backup.BackupUtils.GcsMetadataKeys.LOWER_BOUND_CHECKPOINT;
@ -29,15 +30,14 @@ import static google.registry.util.DateTimeUtils.isAtOrAfter;
import static google.registry.util.FormattingLogger.getLoggerForCallerClass; import static google.registry.util.FormattingLogger.getLoggerForCallerClass;
import static java.nio.channels.Channels.newOutputStream; import static java.nio.channels.Channels.newOutputStream;
import static java.util.Arrays.asList; import static java.util.Arrays.asList;
import static java.util.Comparator.comparingLong;
import com.google.appengine.tools.cloudstorage.GcsFileOptions; import com.google.appengine.tools.cloudstorage.GcsFileOptions;
import com.google.appengine.tools.cloudstorage.GcsFilename; import com.google.appengine.tools.cloudstorage.GcsFilename;
import com.google.appengine.tools.cloudstorage.GcsService; import com.google.appengine.tools.cloudstorage.GcsService;
import com.google.common.base.Function;
import com.google.common.collect.ComparisonChain;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Streams;
import com.googlecode.objectify.Key; import com.googlecode.objectify.Key;
import google.registry.config.RegistryConfig.Config; import google.registry.config.RegistryConfig.Config;
import google.registry.model.ImmutableObject; import google.registry.model.ImmutableObject;
@ -52,7 +52,6 @@ import google.registry.util.FormattingLogger;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.Collection; import java.util.Collection;
import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -152,21 +151,17 @@ public final class ExportCommitLogDiffAction implements Runnable {
// transaction-consistent by virtue of our checkpoint strategy and our customized Ofy; see // transaction-consistent by virtue of our checkpoint strategy and our customized Ofy; see
// CommitLogCheckpointStrategy for the proof. We break ties by sorting on bucket ID to ensure // CommitLogCheckpointStrategy for the proof. We break ties by sorting on bucket ID to ensure
// a deterministic order. // a deterministic order.
return FluentIterable.from(upperCheckpoint.getBucketTimestamps().keySet()) return upperCheckpoint
.transformAndConcat(new Function<Integer, Iterable<Key<CommitLogManifest>>>() { .getBucketTimestamps()
@Override .keySet()
public Iterable<Key<CommitLogManifest>> apply(Integer bucketNum) { .stream()
return loadDiffKeysFromBucket(lowerCheckpoint, upperCheckpoint, bucketNum); .flatMap(
}}) bucketNum ->
.toSortedList(new Comparator<Key<CommitLogManifest>>() { Streams.stream(loadDiffKeysFromBucket(lowerCheckpoint, upperCheckpoint, bucketNum)))
@Override .sorted(
public int compare(Key<CommitLogManifest> a, Key<CommitLogManifest> b) { comparingLong(Key<CommitLogManifest>::getId)
// Compare keys by timestamp (which is encoded in the id as millis), then by bucket id. .thenComparingLong(a -> a.getParent().getId()))
return ComparisonChain.start() .collect(toImmutableList());
.compare(a.getId(), b.getId())
.compare(a.getParent().getId(), b.getParent().getId())
.result();
}});
} }
/** /**

View file

@ -37,7 +37,6 @@ import java.io.IOException;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.concurrent.Callable;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import javax.inject.Inject; import javax.inject.Inject;
import org.joda.time.DateTime; import org.joda.time.DateTime;
@ -113,12 +112,7 @@ class GcsDiffFileLister {
final String filename = listItems.next().getName(); final String filename = listItems.next().getName();
DateTime upperBoundTime = DateTime.parse(filename.substring(DIFF_FILE_PREFIX.length())); DateTime upperBoundTime = DateTime.parse(filename.substring(DIFF_FILE_PREFIX.length()));
if (isInRange(upperBoundTime, fromTime, toTime)) { if (isInRange(upperBoundTime, fromTime, toTime)) {
upperBoundTimesToMetadata.put(upperBoundTime, executor.submit( upperBoundTimesToMetadata.put(upperBoundTime, executor.submit(() -> getMetadata(filename)));
new Callable<GcsFileMetadata>() {
@Override
public GcsFileMetadata call() throws Exception {
return getMetadata(filename);
}}));
lastUpperBoundTime = latestOf(upperBoundTime, lastUpperBoundTime); lastUpperBoundTime = latestOf(upperBoundTime, lastUpperBoundTime);
} }
} }

View file

@ -52,7 +52,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import java.util.concurrent.Callable;
import javax.inject.Inject; import javax.inject.Inject;
import org.joda.time.DateTime; import org.joda.time.DateTime;
@ -117,15 +116,15 @@ public class RestoreCommitLogsAction implements Runnable {
} }
} }
// Restore the CommitLogCheckpointRoot and CommitLogBuckets. // Restore the CommitLogCheckpointRoot and CommitLogBuckets.
saveOfy(FluentIterable.from(bucketTimestamps.entrySet()) saveOfy(
.transform(new Function<Entry<Integer, DateTime>, ImmutableObject> () { FluentIterable.from(bucketTimestamps.entrySet())
@Override .transform(
public ImmutableObject apply(Entry<Integer, DateTime> entry) { (Function<Entry<Integer, DateTime>, ImmutableObject>)
return new CommitLogBucket.Builder() entry ->
new CommitLogBucket.Builder()
.setBucketNum(entry.getKey()) .setBucketNum(entry.getKey())
.setLastWrittenTime(entry.getValue()) .setLastWrittenTime(entry.getValue())
.build(); .build())
}})
.append(CommitLogCheckpointRoot.create(lastCheckpoint.getCheckpointTime()))); .append(CommitLogCheckpointRoot.create(lastCheckpoint.getCheckpointTime())));
} }
@ -153,11 +152,7 @@ public class RestoreCommitLogsAction implements Runnable {
try { try {
deleteResult.now(); deleteResult.now();
} catch (Exception e) { } catch (Exception e) {
retry(new Runnable() { retry(() -> deleteAsync(manifest.getDeletions()).now());
@Override
public void run() {
deleteAsync(manifest.getDeletions()).now();
}});
} }
return manifest; return manifest;
} }
@ -167,11 +162,7 @@ public class RestoreCommitLogsAction implements Runnable {
logger.info("Would have saved " + entitiesToSave); logger.info("Would have saved " + entitiesToSave);
return; return;
} }
retry(new Runnable() { retry(() -> datastoreService.put(entitiesToSave));
@Override
public void run() {
datastoreService.put(entitiesToSave);
}});
} }
private void saveOfy(final Iterable<? extends ImmutableObject> objectsToSave) { private void saveOfy(final Iterable<? extends ImmutableObject> objectsToSave) {
@ -179,11 +170,7 @@ public class RestoreCommitLogsAction implements Runnable {
logger.info("Would have saved " + asList(objectsToSave)); logger.info("Would have saved " + asList(objectsToSave));
return; return;
} }
retry(new Runnable() { retry(() -> ofy().saveWithoutBackup().entities(objectsToSave).now());
@Override
public void run() {
ofy().saveWithoutBackup().entities(objectsToSave).now();
}});
} }
private Result<?> deleteAsync(Set<Key<?>> keysToDelete) { private Result<?> deleteAsync(Set<Key<?>> keysToDelete) {
@ -198,12 +185,10 @@ public class RestoreCommitLogsAction implements Runnable {
/** Retrier for saves and deletes, since we can't proceed with any failures. */ /** Retrier for saves and deletes, since we can't proceed with any failures. */
private void retry(final Runnable runnable) { private void retry(final Runnable runnable) {
retrier.callWithRetry( retrier.callWithRetry(
new Callable<Void>() { () -> {
@Override
public Void call() throws Exception {
runnable.run(); runnable.run();
return null; return null;
}}, },
RuntimeException.class); RuntimeException.class);
} }
} }

View file

@ -18,6 +18,7 @@ import static com.google.appengine.api.taskqueue.QueueConstants.maxLeaseCount;
import static com.google.appengine.api.taskqueue.QueueFactory.getQueue; import static com.google.appengine.api.taskqueue.QueueFactory.getQueue;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Preconditions.checkState;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.math.IntMath.divide; import static com.google.common.math.IntMath.divide;
import static com.googlecode.objectify.Key.getKind; import static com.googlecode.objectify.Key.getKind;
import static google.registry.flows.ResourceFlowUtils.denyPendingTransfer; import static google.registry.flows.ResourceFlowUtils.denyPendingTransfer;
@ -52,8 +53,6 @@ import com.google.appengine.tools.mapreduce.Mapper;
import com.google.appengine.tools.mapreduce.Reducer; import com.google.appengine.tools.mapreduce.Reducer;
import com.google.appengine.tools.mapreduce.ReducerInput; import com.google.appengine.tools.mapreduce.ReducerInput;
import com.google.auto.value.AutoValue; import com.google.auto.value.AutoValue;
import com.google.common.base.Function;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.HashMultiset; import com.google.common.collect.HashMultiset;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
@ -94,7 +93,6 @@ import google.registry.util.SystemClock;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.Callable;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import org.joda.time.DateTime; import org.joda.time.DateTime;
@ -180,22 +178,11 @@ public class DeleteContactsAndHostsAction implements Runnable {
return; return;
} }
final List<TaskHandle> tasks = final List<TaskHandle> tasks =
FluentIterable.from(deletionRequests) deletionRequests.stream().map(DeletionRequest::task).collect(toImmutableList());
.transform(
new Function<DeletionRequest, TaskHandle>() {
@Override
public TaskHandle apply(DeletionRequest deletionRequest) {
return deletionRequest.task();
}
})
.toList();
retrier.callWithRetry( retrier.callWithRetry(
new Callable<Void>() { () -> {
@Override
public Void call() throws Exception {
queue.deleteTask(tasks); queue.deleteTask(tasks);
return null; return null;
}
}, },
TransientFailureException.class); TransientFailureException.class);
for (DeletionRequest deletionRequest : deletionRequests) { for (DeletionRequest deletionRequest : deletionRequests) {

View file

@ -15,6 +15,7 @@
package google.registry.batch; package google.registry.batch;
import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Preconditions.checkState;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static google.registry.flows.ResourceFlowUtils.updateForeignKeyIndexDeletionTime; import static google.registry.flows.ResourceFlowUtils.updateForeignKeyIndexDeletionTime;
import static google.registry.mapreduce.MapreduceRunner.PARAM_DRY_RUN; import static google.registry.mapreduce.MapreduceRunner.PARAM_DRY_RUN;
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
@ -24,11 +25,8 @@ import static google.registry.request.Action.Method.POST;
import static org.joda.time.DateTimeZone.UTC; import static org.joda.time.DateTimeZone.UTC;
import com.google.appengine.tools.mapreduce.Mapper; import com.google.appengine.tools.mapreduce.Mapper;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Splitter; import com.google.common.base.Splitter;
import com.google.common.base.Strings; import com.google.common.base.Strings;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
@ -94,21 +92,11 @@ public class DeleteProberDataAction implements Runnable {
} }
private static ImmutableSet<String> getProberRoidSuffixes() { private static ImmutableSet<String> getProberRoidSuffixes() {
return FluentIterable.from(getTldsOfType(TldType.TEST)) return getTldsOfType(TldType.TEST)
.filter(new Predicate<String>() { .stream()
@Override .filter(tld -> tld.endsWith(".test"))
public boolean apply(String tld) { .map(tld -> Registry.get(tld).getRoidSuffix())
// Extra sanity check to prevent us from nuking prod data if a real TLD accidentally .collect(toImmutableSet());
// gets set to type TEST.
return tld.endsWith(".test");
}})
.transform(
new Function<String, String>() {
@Override
public String apply(String tld) {
return Registry.get(tld).getRoidSuffix();
}})
.toSet();
} }
/** Provides the map method that runs for each existing DomainBase entity. */ /** Provides the map method that runs for each existing DomainBase entity. */

View file

@ -15,6 +15,7 @@
package google.registry.batch; package google.registry.batch;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static com.google.common.collect.Sets.difference; import static com.google.common.collect.Sets.difference;
import static google.registry.mapreduce.MapreduceRunner.PARAM_DRY_RUN; import static google.registry.mapreduce.MapreduceRunner.PARAM_DRY_RUN;
import static google.registry.mapreduce.inputs.EppResourceInputs.createChildEntityInput; import static google.registry.mapreduce.inputs.EppResourceInputs.createChildEntityInput;
@ -32,13 +33,11 @@ import static google.registry.util.PipelineUtils.createJobPath;
import com.google.appengine.tools.mapreduce.Mapper; import com.google.appengine.tools.mapreduce.Mapper;
import com.google.appengine.tools.mapreduce.Reducer; import com.google.appengine.tools.mapreduce.Reducer;
import com.google.appengine.tools.mapreduce.ReducerInput; import com.google.appengine.tools.mapreduce.ReducerInput;
import com.google.common.base.Function;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import com.google.common.base.Predicate;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Range; import com.google.common.collect.Range;
import com.google.common.collect.Streams;
import com.googlecode.objectify.Key; import com.googlecode.objectify.Key;
import com.googlecode.objectify.VoidWork; import com.googlecode.objectify.VoidWork;
import com.googlecode.objectify.Work; import com.googlecode.objectify.Work;
@ -262,14 +261,10 @@ public class ExpandRecurringBillingEventsAction implements Runnable {
DateTime cursorTime, DateTime cursorTime,
DateTime executeTime, DateTime executeTime,
final Registry tld) { final Registry tld) {
return FluentIterable.from(eventTimes) return Streams.stream(eventTimes)
.transform(new Function<DateTime, DateTime>() { .map(eventTime -> eventTime.plus(tld.getAutoRenewGracePeriodLength()))
@Override
public DateTime apply(DateTime eventTime) {
return eventTime.plus(tld.getAutoRenewGracePeriodLength());
}})
.filter(Range.closedOpen(cursorTime, executeTime)) .filter(Range.closedOpen(cursorTime, executeTime))
.toSet(); .collect(toImmutableSet());
} }
/** /**
@ -279,19 +274,13 @@ public class ExpandRecurringBillingEventsAction implements Runnable {
private ImmutableSet<DateTime> getExistingBillingTimes( private ImmutableSet<DateTime> getExistingBillingTimes(
Iterable<BillingEvent.OneTime> oneTimesForDomain, Iterable<BillingEvent.OneTime> oneTimesForDomain,
final BillingEvent.Recurring recurringEvent) { final BillingEvent.Recurring recurringEvent) {
return FluentIterable.from(oneTimesForDomain) return Streams.stream(oneTimesForDomain)
.filter(new Predicate<BillingEvent.OneTime>() { .filter(
@Override billingEvent ->
public boolean apply(OneTime billingEvent) { Key.create(recurringEvent)
return Key.create(recurringEvent) .equals(billingEvent.getCancellationMatchingBillingEvent()))
.equals(billingEvent.getCancellationMatchingBillingEvent()); .map(OneTime::getBillingTime)
}}) .collect(toImmutableSet());
.transform(new Function<OneTime, DateTime>() {
@Override
public DateTime apply(OneTime billingEvent) {
return billingEvent.getBillingTime();
}})
.toSet();
} }
} }

View file

@ -17,6 +17,7 @@ package google.registry.batch;
import static com.google.appengine.api.taskqueue.QueueConstants.maxLeaseCount; import static com.google.appengine.api.taskqueue.QueueConstants.maxLeaseCount;
import static com.google.appengine.api.taskqueue.QueueFactory.getQueue; import static com.google.appengine.api.taskqueue.QueueFactory.getQueue;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static google.registry.flows.async.AsyncFlowEnqueuer.PARAM_HOST_KEY; import static google.registry.flows.async.AsyncFlowEnqueuer.PARAM_HOST_KEY;
import static google.registry.flows.async.AsyncFlowEnqueuer.PARAM_REQUESTED_TIME; import static google.registry.flows.async.AsyncFlowEnqueuer.PARAM_REQUESTED_TIME;
import static google.registry.flows.async.AsyncFlowEnqueuer.QUEUE_ASYNC_HOST_RENAME; import static google.registry.flows.async.AsyncFlowEnqueuer.QUEUE_ASYNC_HOST_RENAME;
@ -38,8 +39,6 @@ import com.google.appengine.tools.mapreduce.Mapper;
import com.google.appengine.tools.mapreduce.Reducer; import com.google.appengine.tools.mapreduce.Reducer;
import com.google.appengine.tools.mapreduce.ReducerInput; import com.google.appengine.tools.mapreduce.ReducerInput;
import com.google.auto.value.AutoValue; import com.google.auto.value.AutoValue;
import com.google.common.base.Function;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.googlecode.objectify.Key; import com.googlecode.objectify.Key;
@ -61,7 +60,6 @@ import google.registry.util.SystemClock;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.Callable;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
@ -180,12 +178,11 @@ public class RefreshDnsOnHostRenameAction implements Runnable {
} }
if (referencingHostKey != null) { if (referencingHostKey != null) {
retrier.callWithRetry( retrier.callWithRetry(
new Callable<Void>() { () -> {
@Override
public Void call() throws Exception {
dnsQueue.addDomainRefreshTask(domain.getFullyQualifiedDomainName()); dnsQueue.addDomainRefreshTask(domain.getFullyQualifiedDomainName());
return null; return null;
}}, TransientFailureException.class); },
TransientFailureException.class);
logger.infofmt( logger.infofmt(
"Enqueued DNS refresh for domain %s referenced by host %s.", "Enqueued DNS refresh for domain %s referenced by host %s.",
domain.getFullyQualifiedDomainName(), referencingHostKey); domain.getFullyQualifiedDomainName(), referencingHostKey);
@ -244,22 +241,13 @@ public class RefreshDnsOnHostRenameAction implements Runnable {
return; return;
} }
final List<TaskHandle> tasks = final List<TaskHandle> tasks =
FluentIterable.from(refreshRequests) refreshRequests.stream().map(DnsRefreshRequest::task).collect(toImmutableList());
.transform(
new Function<DnsRefreshRequest, TaskHandle>() {
@Override
public TaskHandle apply(DnsRefreshRequest refreshRequest) {
return refreshRequest.task();
}
})
.toList();
retrier.callWithRetry( retrier.callWithRetry(
new Callable<Void>() { () -> {
@Override
public Void call() throws Exception {
queue.deleteTask(tasks); queue.deleteTask(tasks);
return null; return null;
}}, TransientFailureException.class); },
TransientFailureException.class);
for (DnsRefreshRequest refreshRequest : refreshRequests) { for (DnsRefreshRequest refreshRequest : refreshRequests) {
asyncFlowMetrics.recordAsyncFlowResult(DNS_REFRESH, result, refreshRequest.requestedTime()); asyncFlowMetrics.recordAsyncFlowResult(DNS_REFRESH, result, refreshRequest.requestedTime());
} }

View file

@ -15,6 +15,7 @@
package google.registry.batch; package google.registry.batch;
import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Preconditions.checkState;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static com.google.common.collect.Iterables.getOnlyElement; import static com.google.common.collect.Iterables.getOnlyElement;
import static com.googlecode.objectify.Key.getKind; import static com.googlecode.objectify.Key.getKind;
import static google.registry.model.EppResourceUtils.isActive; import static google.registry.model.EppResourceUtils.isActive;
@ -36,7 +37,6 @@ import com.google.appengine.tools.mapreduce.ReducerInput;
import com.google.appengine.tools.mapreduce.inputs.DatastoreKeyInput; import com.google.appengine.tools.mapreduce.inputs.DatastoreKeyInput;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.googlecode.objectify.Key; import com.googlecode.objectify.Key;
@ -259,18 +259,24 @@ public class VerifyEntityIntegrityAction implements Runnable {
verifyExistence(key, domain.getTransferData().getServerApproveAutorenewEvent()); verifyExistence(key, domain.getTransferData().getServerApproveAutorenewEvent());
verifyExistence(key, domain.getTransferData().getServerApproveAutorenewPollMessage()); verifyExistence(key, domain.getTransferData().getServerApproveAutorenewPollMessage());
verifyExistence(key, domain.getTransferData().getServerApproveBillingEvent()); verifyExistence(key, domain.getTransferData().getServerApproveBillingEvent());
verifyExistence(key, FluentIterable verifyExistence(
.from(domain.getTransferData().getServerApproveEntities()) key,
.transform( domain
new Function<Key<? extends TransferServerApproveEntity>, .getTransferData()
.getServerApproveEntities()
.stream()
.map(
new Function<
Key<? extends TransferServerApproveEntity>,
Key<TransferServerApproveEntity>>() { Key<TransferServerApproveEntity>>() {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public Key<TransferServerApproveEntity> apply( public Key<TransferServerApproveEntity> apply(
Key<? extends TransferServerApproveEntity> key) { Key<? extends TransferServerApproveEntity> key) {
return (Key<TransferServerApproveEntity>) key; return (Key<TransferServerApproveEntity>) key;
}}) }
.toSet()); })
.collect(toImmutableSet()));
verifyExistence(key, domain.getApplication()); verifyExistence(key, domain.getApplication());
verifyExistence(key, domain.getAutorenewBillingEvent()); verifyExistence(key, domain.getAutorenewBillingEvent());
for (GracePeriod gracePeriod : domain.getGracePeriods()) { for (GracePeriod gracePeriod : domain.getGracePeriods()) {

View file

@ -21,19 +21,16 @@ import static google.registry.batch.EntityIntegrityAlertsSchema.FIELD_SCANTIME;
import static google.registry.batch.EntityIntegrityAlertsSchema.FIELD_SOURCE; import static google.registry.batch.EntityIntegrityAlertsSchema.FIELD_SOURCE;
import static google.registry.batch.EntityIntegrityAlertsSchema.FIELD_TARGET; import static google.registry.batch.EntityIntegrityAlertsSchema.FIELD_TARGET;
import static google.registry.batch.EntityIntegrityAlertsSchema.TABLE_ID; import static google.registry.batch.EntityIntegrityAlertsSchema.TABLE_ID;
import static java.util.stream.Collectors.joining;
import com.google.api.services.bigquery.Bigquery; import com.google.api.services.bigquery.Bigquery;
import com.google.api.services.bigquery.Bigquery.Tabledata.InsertAll; import com.google.api.services.bigquery.Bigquery.Tabledata.InsertAll;
import com.google.api.services.bigquery.model.TableDataInsertAllRequest; import com.google.api.services.bigquery.model.TableDataInsertAllRequest;
import com.google.api.services.bigquery.model.TableDataInsertAllRequest.Rows; import com.google.api.services.bigquery.model.TableDataInsertAllRequest.Rows;
import com.google.api.services.bigquery.model.TableDataInsertAllResponse; import com.google.api.services.bigquery.model.TableDataInsertAllResponse;
import com.google.api.services.bigquery.model.TableDataInsertAllResponse.InsertErrors;
import com.google.auto.factory.AutoFactory; import com.google.auto.factory.AutoFactory;
import com.google.auto.factory.Provided; import com.google.auto.factory.Provided;
import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import google.registry.bigquery.BigqueryFactory; import google.registry.bigquery.BigqueryFactory;
@ -183,30 +180,26 @@ public class VerifyEntityIntegrityStreamer {
new TableDataInsertAllRequest().setRows(rows)); new TableDataInsertAllRequest().setRows(rows));
Callable<Void> callable = Callable<Void> callable =
new Callable<Void>() { () -> {
@Override
public Void call() throws Exception {
TableDataInsertAllResponse response = request.execute(); TableDataInsertAllResponse response = request.execute();
// Turn errors on the response object into RuntimeExceptions that the retrier will // Turn errors on the response object into RuntimeExceptions that the retrier will
// retry. // retry.
if (response.getInsertErrors() != null && !response.getInsertErrors().isEmpty()) { if (response.getInsertErrors() != null && !response.getInsertErrors().isEmpty()) {
throw new RuntimeException( throw new RuntimeException(
FluentIterable.from(response.getInsertErrors()) response
.transform( .getInsertErrors()
new Function<InsertErrors, String>() { .stream()
@Override .map(
public String apply(InsertErrors error) { error -> {
try { try {
return error.toPrettyString(); return error.toPrettyString();
} catch (IOException e) { } catch (IOException e) {
return error.toString(); return error.toString();
} }
}
}) })
.join(Joiner.on('\n'))); .collect(joining("\n")));
} }
return null; return null;
}
}; };
retrier.callWithRetry(callable, RuntimeException.class); retrier.callWithRetry(callable, RuntimeException.class);
} catch (IOException e) { } catch (IOException e) {

View file

@ -73,7 +73,6 @@ import java.io.IOException;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.joda.time.DateTime; import org.joda.time.DateTime;
@ -693,20 +692,15 @@ public class BigqueryConnection implements AutoCloseable {
final Job job, final Job job,
final T result, final T result,
@Nullable final AbstractInputStreamContent data) { @Nullable final AbstractInputStreamContent data) {
return service.submit(new Callable<T>() { return service.submit(
@Override () -> {
public T call() {
runJob(job, data); runJob(job, data);
return result; return result;
}}); });
} }
private ListenableFuture<Job> runJobToCompletion(final Job job) { private ListenableFuture<Job> runJobToCompletion(final Job job) {
return service.submit(new Callable<Job>() { return service.submit(() -> runJob(job, null));
@Override
public Job call() {
return runJob(job, null);
}});
} }
/** Helper that returns true if a dataset with this name exists. */ /** Helper that returns true if a dataset with this name exists. */

View file

@ -16,7 +16,6 @@ package google.registry.config;
import static com.google.common.base.Suppliers.memoize; import static com.google.common.base.Suppliers.memoize;
import static google.registry.config.ConfigUtils.makeUrl; import static google.registry.config.ConfigUtils.makeUrl;
import static google.registry.config.YamlUtils.getConfigSettings;
import static java.lang.annotation.RetentionPolicy.RUNTIME; import static java.lang.annotation.RetentionPolicy.RUNTIME;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
@ -1270,11 +1269,7 @@ public final class RegistryConfig {
* change the contents of the YAML config files. * change the contents of the YAML config files.
*/ */
private static final Supplier<RegistryConfigSettings> CONFIG_SETTINGS = private static final Supplier<RegistryConfigSettings> CONFIG_SETTINGS =
memoize(new Supplier<RegistryConfigSettings>() { memoize(YamlUtils::getConfigSettings);
@Override
public RegistryConfigSettings get() {
return getConfigSettings();
}});
private RegistryConfig() {} private RegistryConfig() {}
} }

View file

@ -19,7 +19,7 @@ import static com.google.appengine.api.taskqueue.TaskOptions.Builder.withUrl;
import static com.google.common.base.Predicates.in; import static com.google.common.base.Predicates.in;
import static com.google.common.base.Predicates.not; import static com.google.common.base.Predicates.not;
import static com.google.common.base.Strings.nullToEmpty; import static com.google.common.base.Strings.nullToEmpty;
import static com.google.common.collect.Iterables.concat; import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static com.google.common.collect.Iterables.getFirst; import static com.google.common.collect.Iterables.getFirst;
import static com.google.common.collect.Multimaps.filterKeys; import static com.google.common.collect.Multimaps.filterKeys;
import static com.google.common.collect.Sets.difference; import static com.google.common.collect.Sets.difference;
@ -36,6 +36,7 @@ import com.google.common.base.Optional;
import com.google.common.collect.ImmutableListMultimap; import com.google.common.collect.ImmutableListMultimap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import com.google.common.collect.Streams;
import google.registry.request.Action; import google.registry.request.Action;
import google.registry.request.Parameter; import google.registry.request.Parameter;
import google.registry.request.ParameterMap; import google.registry.request.ParameterMap;
@ -116,11 +117,13 @@ public final class TldFanoutAction implements Runnable {
public void run() { public void run() {
Set<String> tlds = Set<String> tlds =
difference( difference(
ImmutableSet.copyOf( Streams.concat(
concat( Streams.stream(runInEmpty ? ImmutableSet.of("") : ImmutableSet.<String>of()),
runInEmpty ? ImmutableSet.of("") : ImmutableSet.<String>of(), Streams.stream(
forEachRealTld ? getTldsOfType(REAL) : ImmutableSet.<String>of(), forEachRealTld ? getTldsOfType(REAL) : ImmutableSet.<String>of()),
forEachTestTld ? getTldsOfType(TEST) : ImmutableSet.<String>of())), Streams.stream(
forEachTestTld ? getTldsOfType(TEST) : ImmutableSet.<String>of()))
.collect(toImmutableSet()),
excludes); excludes);
Multimap<String, String> flowThruParams = filterKeys(params, not(in(CONTROL_PARAMS))); Multimap<String, String> flowThruParams = filterKeys(params, not(in(CONTROL_PARAMS)));
Queue taskQueue = getQueue(queue); Queue taskQueue = getQueue(queue);

View file

@ -284,14 +284,11 @@ public class CloudDnsWriter extends BaseDnsWriter {
@VisibleForTesting @VisibleForTesting
Callable<Void> getMutateZoneCallback( Callable<Void> getMutateZoneCallback(
final ImmutableMap<String, ImmutableSet<ResourceRecordSet>> desiredRecords) { final ImmutableMap<String, ImmutableSet<ResourceRecordSet>> desiredRecords) {
return new Callable<Void>() { return () -> {
@Override
public Void call() throws IOException, ZoneStateException {
// Fetch all existing records for names that this writer is trying to modify // Fetch all existing records for names that this writer is trying to modify
Builder<ResourceRecordSet> existingRecords = new Builder<>(); Builder<ResourceRecordSet> existingRecords = new Builder<>();
for (String domainName : desiredRecords.keySet()) { for (String domainName : desiredRecords.keySet()) {
List<ResourceRecordSet> existingRecordsForDomain = List<ResourceRecordSet> existingRecordsForDomain = getResourceRecordsForDomain(domainName);
getResourceRecordsForDomain(domainName);
existingRecords.addAll(existingRecordsForDomain); existingRecords.addAll(existingRecordsForDomain);
// Fetch glue records for in-bailiwick nameservers // Fetch glue records for in-bailiwick nameservers
@ -316,7 +313,6 @@ public class CloudDnsWriter extends BaseDnsWriter {
// Delete all existing records and add back the desired records // Delete all existing records and add back the desired records
updateResourceRecords(flattenedDesiredRecords.build(), existingRecords.build()); updateResourceRecords(flattenedDesiredRecords.build(), existingRecords.build());
return null; return null;
}
}; };
} }

View file

@ -18,15 +18,12 @@ import static com.google.appengine.api.datastore.DatastoreServiceFactory.getData
import static com.google.appengine.api.taskqueue.QueueFactory.getQueue; import static com.google.appengine.api.taskqueue.QueueFactory.getQueue;
import static com.google.common.base.Strings.nullToEmpty; import static com.google.common.base.Strings.nullToEmpty;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.Query; import com.google.appengine.api.datastore.Query;
import com.google.appengine.api.modules.ModulesService; import com.google.appengine.api.modules.ModulesService;
import com.google.appengine.api.modules.ModulesServiceFactory; import com.google.appengine.api.modules.ModulesServiceFactory;
import com.google.appengine.api.taskqueue.TaskHandle; import com.google.appengine.api.taskqueue.TaskHandle;
import com.google.appengine.api.taskqueue.TaskOptions; import com.google.appengine.api.taskqueue.TaskOptions;
import com.google.appengine.api.taskqueue.TaskOptions.Method; import com.google.appengine.api.taskqueue.TaskOptions.Method;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.FluentIterable; import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
@ -91,18 +88,10 @@ public class DatastoreBackupService {
public Iterable<DatastoreBackupInfo> findAllByNamePrefix(final String namePrefix) { public Iterable<DatastoreBackupInfo> findAllByNamePrefix(final String namePrefix) {
// Need the raw DatastoreService to access the internal _AE_Backup_Information entities. // Need the raw DatastoreService to access the internal _AE_Backup_Information entities.
// TODO(b/19081037): make an Objectify entity class for these raw Datastore entities instead. // TODO(b/19081037): make an Objectify entity class for these raw Datastore entities instead.
return FluentIterable return FluentIterable.from(
.from(getDatastoreService().prepare(new Query(BACKUP_INFO_KIND)).asIterable()) getDatastoreService().prepare(new Query(BACKUP_INFO_KIND)).asIterable())
.filter(new Predicate<Entity>() { .filter(entity -> nullToEmpty((String) entity.getProperty("name")).startsWith(namePrefix))
@Override .transform(DatastoreBackupInfo::new);
public boolean apply(Entity entity) {
return nullToEmpty((String) entity.getProperty("name")).startsWith(namePrefix);
}})
.transform(new Function<Entity, DatastoreBackupInfo>() {
@Override
public DatastoreBackupInfo apply(Entity entity) {
return new DatastoreBackupInfo(entity);
}});
} }
/** /**

View file

@ -14,6 +14,8 @@
package google.registry.export; package google.registry.export;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.request.Action.Method.POST; import static google.registry.request.Action.Method.POST;
import static google.registry.util.CollectionUtils.nullToEmpty; import static google.registry.util.CollectionUtils.nullToEmpty;
@ -21,13 +23,11 @@ import static google.registry.util.RegistrarUtils.normalizeClientId;
import static javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR; import static javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
import static javax.servlet.http.HttpServletResponse.SC_OK; import static javax.servlet.http.HttpServletResponse.SC_OK;
import com.google.common.base.Function;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import com.google.common.base.Predicate;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.google.common.collect.Streams;
import com.googlecode.objectify.VoidWork; import com.googlecode.objectify.VoidWork;
import google.registry.config.RegistryConfig.Config; import google.registry.config.RegistryConfig.Config;
import google.registry.groups.GroupsConnection; import google.registry.groups.GroupsConnection;
@ -44,7 +44,6 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.Callable;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import javax.inject.Inject; import javax.inject.Inject;
@ -118,16 +117,14 @@ public final class SyncGroupMembersAction implements Runnable {
*/ */
@Override @Override
public void run() { public void run() {
List<Registrar> dirtyRegistrars = FluentIterable.from(Registrar.loadAllCached()) List<Registrar> dirtyRegistrars =
.filter(new Predicate<Registrar>() { Streams.stream(Registrar.loadAllCached())
@Override .filter(
public boolean apply(Registrar registrar) { registrar ->
// Only grab active registrars that require syncing and are of the correct type. registrar.isLive()
return registrar.isLive()
&& registrar.getContactsRequireSyncing() && registrar.getContactsRequireSyncing()
&& registrar.getType() == Registrar.Type.REAL; && registrar.getType() == Registrar.Type.REAL)
}}) .collect(toImmutableList());
.toList();
if (dirtyRegistrars.isEmpty()) { if (dirtyRegistrars.isEmpty()) {
sendResponse(Result.NOT_MODIFIED, null); sendResponse(Result.NOT_MODIFIED, null);
return; return;
@ -137,12 +134,12 @@ public final class SyncGroupMembersAction implements Runnable {
new ImmutableMap.Builder<>(); new ImmutableMap.Builder<>();
for (final Registrar registrar : dirtyRegistrars) { for (final Registrar registrar : dirtyRegistrars) {
try { try {
retrier.callWithRetry(new Callable<Void>() { retrier.callWithRetry(
@Override () -> {
public Void call() throws Exception {
syncRegistrarContacts(registrar); syncRegistrarContacts(registrar);
return null; return null;
}}, RuntimeException.class); },
RuntimeException.class);
resultsBuilder.put(registrar, Optional.<Throwable>absent()); resultsBuilder.put(registrar, Optional.<Throwable>absent());
} catch (Throwable e) { } catch (Throwable e) {
logger.severe(e, e.getMessage()); logger.severe(e, e.getMessage());
@ -193,18 +190,12 @@ public final class SyncGroupMembersAction implements Runnable {
groupKey = getGroupEmailAddressForContactType( groupKey = getGroupEmailAddressForContactType(
registrar.getClientId(), type, gSuiteDomainName); registrar.getClientId(), type, gSuiteDomainName);
Set<String> currentMembers = groupsConnection.getMembersOfGroup(groupKey); Set<String> currentMembers = groupsConnection.getMembersOfGroup(groupKey);
Set<String> desiredMembers = FluentIterable.from(registrarContacts) Set<String> desiredMembers =
.filter(new Predicate<RegistrarContact>() { registrarContacts
@Override .stream()
public boolean apply(RegistrarContact contact) { .filter(contact -> contact.getTypes().contains(type))
return contact.getTypes().contains(type); .map(RegistrarContact::getEmailAddress)
}}) .collect(toImmutableSet());
.transform(new Function<RegistrarContact, String>() {
@Override
public String apply(RegistrarContact contact) {
return contact.getEmailAddress();
}})
.toSet();
for (String email : Sets.difference(desiredMembers, currentMembers)) { for (String email : Sets.difference(desiredMembers, currentMembers)) {
groupsConnection.addMemberToGroup(groupKey, email, Role.MEMBER); groupsConnection.addMemberToGroup(groupKey, email, Role.MEMBER);
totalAdded++; totalAdded++;

View file

@ -15,6 +15,7 @@
package google.registry.export.sheet; package google.registry.export.sheet;
import static com.google.common.base.MoreObjects.firstNonNull; import static com.google.common.base.MoreObjects.firstNonNull;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static google.registry.model.common.Cursor.CursorType.SYNC_REGISTRAR_SHEET; import static google.registry.model.common.Cursor.CursorType.SYNC_REGISTRAR_SHEET;
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.model.registrar.RegistrarContact.Type.ABUSE; import static google.registry.model.registrar.RegistrarContact.Type.ABUSE;
@ -26,10 +27,8 @@ import static google.registry.model.registrar.RegistrarContact.Type.TECH;
import static google.registry.model.registrar.RegistrarContact.Type.WHOIS; import static google.registry.model.registrar.RegistrarContact.Type.WHOIS;
import static google.registry.util.DateTimeUtils.START_OF_TIME; import static google.registry.util.DateTimeUtils.START_OF_TIME;
import com.google.common.base.Function;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSortedSet; import com.google.common.collect.ImmutableSortedSet;
@ -77,25 +76,19 @@ class SyncRegistrarsSheet {
final DateTime executionTime = clock.nowUtc(); final DateTime executionTime = clock.nowUtc();
sheetSynchronizer.synchronize( sheetSynchronizer.synchronize(
spreadsheetId, spreadsheetId,
FluentIterable.from(
new Ordering<Registrar>() { new Ordering<Registrar>() {
@Override @Override
public int compare(Registrar left, Registrar right) { public int compare(Registrar left, Registrar right) {
return left.getClientId().compareTo(right.getClientId()); return left.getClientId().compareTo(right.getClientId());
} }
}.immutableSortedCopy(Registrar.loadAllCached())) }.immutableSortedCopy(Registrar.loadAllCached())
.stream()
.filter( .filter(
new Predicate<Registrar>() { registrar ->
@Override registrar.getType() == Registrar.Type.REAL
public boolean apply(Registrar registrar) { || registrar.getType() == Registrar.Type.OTE)
return registrar.getType() == Registrar.Type.REAL .map(
|| registrar.getType() == Registrar.Type.OTE; registrar -> {
}
})
.transform(
new Function<Registrar, ImmutableMap<String, String>>() {
@Override
public ImmutableMap<String, String> apply(Registrar registrar) {
ImmutableMap.Builder<String, String> builder = new ImmutableMap.Builder<>(); ImmutableMap.Builder<String, String> builder = new ImmutableMap.Builder<>();
ImmutableSortedSet<RegistrarContact> contacts = registrar.getContacts(); ImmutableSortedSet<RegistrarContact> contacts = registrar.getContacts();
RegistrarAddress address = RegistrarAddress address =
@ -136,24 +129,10 @@ class SyncRegistrarsSheet {
builder.put("billingContacts", convertContacts(contacts, byType(BILLING))); builder.put("billingContacts", convertContacts(contacts, byType(BILLING)));
builder.put( builder.put(
"contactsMarkedAsWhoisAdmin", "contactsMarkedAsWhoisAdmin",
convertContacts( convertContacts(contacts, RegistrarContact::getVisibleInWhoisAsAdmin));
contacts,
new Predicate<RegistrarContact>() {
@Override
public boolean apply(RegistrarContact contact) {
return contact.getVisibleInWhoisAsAdmin();
}
}));
builder.put( builder.put(
"contactsMarkedAsWhoisTech", "contactsMarkedAsWhoisTech",
convertContacts( convertContacts(contacts, RegistrarContact::getVisibleInWhoisAsTech));
contacts,
new Predicate<RegistrarContact>() {
@Override
public boolean apply(RegistrarContact contact) {
return contact.getVisibleInWhoisAsTech();
}
}));
builder.put("emailAddress", convert(registrar.getEmailAddress())); builder.put("emailAddress", convert(registrar.getEmailAddress()));
builder.put("address.street", convert(address.getStreet())); builder.put("address.street", convert(address.getStreet()));
builder.put("address.city", convert(address.getCity())); builder.put("address.city", convert(address.getCity()));
@ -172,9 +151,8 @@ class SyncRegistrarsSheet {
builder.put("referralUrl", convert(registrar.getReferralUrl())); builder.put("referralUrl", convert(registrar.getReferralUrl()));
builder.put("icannReferralEmail", convert(registrar.getIcannReferralEmail())); builder.put("icannReferralEmail", convert(registrar.getIcannReferralEmail()));
return builder.build(); return builder.build();
}
}) })
.toList()); .collect(toImmutableList()));
ofy().transact(new VoidWork() { ofy().transact(new VoidWork() {
@Override @Override
public void vrun() { public void vrun() {
@ -201,11 +179,7 @@ class SyncRegistrarsSheet {
} }
private static Predicate<RegistrarContact> byType(final RegistrarContact.Type type) { private static Predicate<RegistrarContact> byType(final RegistrarContact.Type type) {
return new Predicate<RegistrarContact>() { return contact -> contact.getTypes().contains(type);
@Override
public boolean apply(RegistrarContact contact) {
return contact.getTypes().contains(type);
}};
} }
/** Converts a value to a string representation that can be stored in a spreadsheet cell. */ /** Converts a value to a string representation that can be stored in a spreadsheet cell. */

View file

@ -134,10 +134,8 @@ public class SyncRegistrarsSheetAction implements Runnable {
} }
String sheetLockName = String.format("%s: %s", LOCK_NAME, sheetId.get()); String sheetLockName = String.format("%s: %s", LOCK_NAME, sheetId.get());
Callable<Void> runner = new Callable<Void>() { Callable<Void> runner =
@Nullable () -> {
@Override
public Void call() throws IOException {
try { try {
syncRegistrarsSheet.run(sheetId.get()); syncRegistrarsSheet.run(sheetId.get());
Result.OK.send(response, null); Result.OK.send(response, null);
@ -145,7 +143,6 @@ public class SyncRegistrarsSheetAction implements Runnable {
Result.FAILED.send(response, e); Result.FAILED.send(response, e);
} }
return null; return null;
}
}; };
if (!lockHandler.executeWithLocks(runner, null, timeout, sheetLockName)) { if (!lockHandler.executeWithLocks(runner, null, timeout, sheetLockName)) {
// If we fail to acquire the lock, it probably means lots of updates are happening at once, in // If we fail to acquire the lock, it probably means lots of updates are happening at once, in

View file

@ -14,15 +14,12 @@
package google.registry.flows; package google.registry.flows;
import static com.google.common.collect.Iterables.any;
import static com.google.common.collect.Sets.difference; import static com.google.common.collect.Sets.difference;
import static com.google.common.collect.Sets.intersection; import static com.google.common.collect.Sets.intersection;
import static google.registry.model.domain.fee.Fee.FEE_EXTENSION_URIS; import static google.registry.model.domain.fee.Fee.FEE_EXTENSION_URIS;
import static google.registry.model.eppcommon.ProtocolDefinition.ServiceExtension.getCommandExtensionUri; import static google.registry.model.eppcommon.ProtocolDefinition.ServiceExtension.getCommandExtensionUri;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import com.google.common.base.Predicate;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import google.registry.flows.EppException.CommandUseErrorException; import google.registry.flows.EppException.CommandUseErrorException;
@ -130,7 +127,13 @@ public final class ExtensionManager {
ImmutableSet<Class<? extends CommandExtension>> implementedExtensions) ImmutableSet<Class<? extends CommandExtension>> implementedExtensions)
throws UnsupportedRepeatedExtensionException { throws UnsupportedRepeatedExtensionException {
for (Class<? extends CommandExtension> implemented : implementedExtensions) { for (Class<? extends CommandExtension> implemented : implementedExtensions) {
if (FluentIterable.from(suppliedExtensionInstances).filter(implemented).size() > 1) { if ((int)
suppliedExtensionInstances
.stream()
.filter(implemented::isInstance)
.map(implemented::cast)
.count()
> 1) {
throw new UnsupportedRepeatedExtensionException(); throw new UnsupportedRepeatedExtensionException();
} }
} }
@ -143,13 +146,9 @@ public final class ExtensionManager {
ImmutableSet.Builder<Class<? extends CommandExtension>> unimplementedExtensionsBuilder = ImmutableSet.Builder<Class<? extends CommandExtension>> unimplementedExtensionsBuilder =
new ImmutableSet.Builder<>(); new ImmutableSet.Builder<>();
for (final CommandExtension instance : suppliedExtensionInstances) { for (final CommandExtension instance : suppliedExtensionInstances) {
if (!any( if (implementedExtensionClasses
implementedExtensionClasses, .stream()
new Predicate<Class<? extends CommandExtension>>() { .noneMatch(implementedExtensionClass -> implementedExtensionClass.isInstance(instance))) {
@Override
public boolean apply(Class<? extends CommandExtension> implementedExtensionClass) {
return implementedExtensionClass.isInstance(instance);
}})) {
unimplementedExtensionsBuilder.add(instance.getClass()); unimplementedExtensionsBuilder.add(instance.getClass());
} }
} }

View file

@ -30,7 +30,6 @@ import com.google.common.base.Optional;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.googlecode.objectify.Key; import com.googlecode.objectify.Key;
import com.googlecode.objectify.Work; import com.googlecode.objectify.Work;
@ -178,25 +177,31 @@ public final class ResourceFlowUtils {
final Class<R> resourceClass, final Class<R> resourceClass,
final Function<DomainBase, ImmutableSet<?>> getPotentialReferences) throws EppException { final Function<DomainBase, ImmutableSet<?>> getPotentialReferences) throws EppException {
// Enter a transactionless context briefly. // Enter a transactionless context briefly.
EppException failfastException = ofy().doTransactionless(new Work<EppException>() { EppException failfastException =
ofy()
.doTransactionless(
new Work<EppException>() {
@Override @Override
public EppException run() { public EppException run() {
final ForeignKeyIndex<R> fki = ForeignKeyIndex.load(resourceClass, targetId, now); final ForeignKeyIndex<R> fki =
ForeignKeyIndex.load(resourceClass, targetId, now);
if (fki == null) { if (fki == null) {
return new ResourceDoesNotExistException(resourceClass, targetId); return new ResourceDoesNotExistException(resourceClass, targetId);
} }
// Query for the first few linked domains, and if found, actually load them. The query is /* Query for the first few linked domains, and if found, actually load them. The
// eventually consistent and so might be very stale, but the direct load will not be stale, * query is eventually consistent and so might be very stale, but the direct
// just non-transactional. If we find at least one actual reference then we can reliably * load will not be stale, just non-transactional. If we find at least one
// fail. If we don't find any, we can't trust the query and need to do the full mapreduce. * actual reference then we can reliably fail. If we don't find any, we can't
* trust the query and need to do the full mapreduce.
*/
Iterable<Key<DomainBase>> keys = Iterable<Key<DomainBase>> keys =
queryForLinkedDomains(fki.getResourceKey(), now).limit(FAILFAST_CHECK_COUNT).keys(); queryForLinkedDomains(fki.getResourceKey(), now)
Predicate<DomainBase> predicate = new Predicate<DomainBase>() { .limit(FAILFAST_CHECK_COUNT)
@Override .keys();
public boolean apply(DomainBase domain) { Predicate<DomainBase> predicate =
return getPotentialReferences.apply(domain).contains(fki.getResourceKey()); domain ->
}}; getPotentialReferences.apply(domain).contains(fki.getResourceKey());
return Iterables.any(ofy().load().keys(keys).values(), predicate) return ofy().load().keys(keys).values().stream().anyMatch(predicate)
? new ResourceToDeleteIsReferencedException() ? new ResourceToDeleteIsReferencedException()
: null; : null;
} }
@ -339,13 +344,8 @@ public final class ResourceFlowUtils {
return; return;
} }
// The roid should match one of the contacts. // The roid should match one of the contacts.
Optional<Key<ContactResource>> foundContact = tryFind( Optional<Key<ContactResource>> foundContact =
domain.getReferencedContacts(), tryFind(domain.getReferencedContacts(), key -> key.getName().equals(authRepoId));
new Predicate<Key<ContactResource>>() {
@Override
public boolean apply(Key<ContactResource> key) {
return key.getName().equals(authRepoId);
}});
if (!foundContact.isPresent()) { if (!foundContact.isPresent()) {
throw new BadAuthInfoForResourceException(); throw new BadAuthInfoForResourceException();
} }

View file

@ -26,7 +26,6 @@ import google.registry.model.eppcommon.Trid;
import google.registry.model.host.HostResource; import google.registry.model.host.HostResource;
import google.registry.util.FormattingLogger; import google.registry.util.FormattingLogger;
import google.registry.util.Retrier; import google.registry.util.Retrier;
import java.util.concurrent.Callable;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import org.joda.time.DateTime; import org.joda.time.DateTime;
@ -107,11 +106,11 @@ public final class AsyncFlowEnqueuer {
* enqueuing a task. * enqueuing a task.
*/ */
private void addTaskToQueueWithRetry(final Queue queue, final TaskOptions task) { private void addTaskToQueueWithRetry(final Queue queue, final TaskOptions task) {
retrier.callWithRetry(new Callable<Void>() { retrier.callWithRetry(
@Override () -> {
public Void call() throws Exception {
queue.add(task); queue.add(task);
return null; return null;
}}, TransientFailureException.class); },
TransientFailureException.class);
} }
} }

View file

@ -23,7 +23,6 @@ import static google.registry.flows.ResourceFlowUtils.verifyResourceOwnership;
import static google.registry.model.eppoutput.Result.Code.SUCCESS_WITH_ACTION_PENDING; import static google.registry.model.eppoutput.Result.Code.SUCCESS_WITH_ACTION_PENDING;
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
import com.google.common.base.Function;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.googlecode.objectify.Key; import com.googlecode.objectify.Key;
@ -69,13 +68,6 @@ public final class ContactDeleteFlow implements TransactionalFlow {
StatusValue.PENDING_DELETE, StatusValue.PENDING_DELETE,
StatusValue.SERVER_DELETE_PROHIBITED); StatusValue.SERVER_DELETE_PROHIBITED);
private static final Function<DomainBase, ImmutableSet<?>> GET_REFERENCED_CONTACTS =
new Function<DomainBase, ImmutableSet<?>>() {
@Override
public ImmutableSet<?> apply(DomainBase domain) {
return domain.getReferencedContacts();
}};
@Inject ExtensionManager extensionManager; @Inject ExtensionManager extensionManager;
@Inject @ClientId String clientId; @Inject @ClientId String clientId;
@Inject @TargetId String targetId; @Inject @TargetId String targetId;
@ -93,7 +85,7 @@ public final class ContactDeleteFlow implements TransactionalFlow {
extensionManager.validate(); extensionManager.validate();
validateClientIsLoggedIn(clientId); validateClientIsLoggedIn(clientId);
DateTime now = ofy().getTransactionTime(); DateTime now = ofy().getTransactionTime();
failfastForAsyncDelete(targetId, now, ContactResource.class, GET_REFERENCED_CONTACTS); failfastForAsyncDelete(targetId, now, ContactResource.class, DomainBase::getReferencedContacts);
ContactResource existingContact = loadAndVerifyExistence(ContactResource.class, targetId, now); ContactResource existingContact = loadAndVerifyExistence(ContactResource.class, targetId, now);
verifyNoDisallowedStatuses(existingContact, DISALLOWED_STATUSES); verifyNoDisallowedStatuses(existingContact, DISALLOWED_STATUSES);
verifyOptionalAuthInfo(authInfo, existingContact); verifyOptionalAuthInfo(authInfo, existingContact);

View file

@ -14,8 +14,7 @@
package google.registry.flows.domain; package google.registry.flows.domain;
import static com.google.common.collect.Iterables.filter; import static com.google.common.collect.MoreCollectors.onlyElement;
import static com.google.common.collect.Iterables.getOnlyElement;
import static google.registry.flows.FlowUtils.validateClientIsLoggedIn; import static google.registry.flows.FlowUtils.validateClientIsLoggedIn;
import static google.registry.flows.ResourceFlowUtils.verifyResourceDoesNotExist; import static google.registry.flows.ResourceFlowUtils.verifyResourceDoesNotExist;
import static google.registry.flows.domain.DomainFlowUtils.cloneAndLinkReferences; import static google.registry.flows.domain.DomainFlowUtils.cloneAndLinkReferences;
@ -39,6 +38,7 @@ import static google.registry.util.DateTimeUtils.leapSafeAddYears;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Streams;
import com.google.common.net.InternetDomainName; import com.google.common.net.InternetDomainName;
import com.googlecode.objectify.Key; import com.googlecode.objectify.Key;
import dagger.Lazy; import dagger.Lazy;
@ -212,7 +212,10 @@ public class DomainAllocateFlow implements TransactionalFlow {
private <T extends ImmutableObject> T getOnly( private <T extends ImmutableObject> T getOnly(
Iterable<? extends ImmutableObject> objects, Class<T> clazz) { Iterable<? extends ImmutableObject> objects, Class<T> clazz) {
return getOnlyElement(filter(objects, clazz)); return Streams.stream(objects)
.filter(clazz::isInstance)
.map(clazz::cast)
.collect(onlyElement());
} }
private void verifyIsSuperuser() throws OnlySuperuserCanAllocateException { private void verifyIsSuperuser() throws OnlySuperuserCanAllocateException {

View file

@ -14,6 +14,7 @@
package google.registry.flows.domain; package google.registry.flows.domain;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.collect.Iterables.getOnlyElement; import static com.google.common.collect.Iterables.getOnlyElement;
import static google.registry.flows.FlowUtils.persistEntityChanges; import static google.registry.flows.FlowUtils.persistEntityChanges;
import static google.registry.flows.FlowUtils.validateClientIsLoggedIn; import static google.registry.flows.FlowUtils.validateClientIsLoggedIn;
@ -43,8 +44,6 @@ import static google.registry.model.index.DomainApplicationIndex.loadActiveAppli
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.model.registry.label.ReservedList.matchesAnchorTenantReservation; import static google.registry.model.registry.label.ReservedList.matchesAnchorTenantReservation;
import com.google.common.base.Function;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.net.InternetDomainName; import com.google.common.net.InternetDomainName;
@ -94,7 +93,6 @@ import google.registry.model.registry.Registry;
import google.registry.model.registry.Registry.TldState; import google.registry.model.registry.Registry.TldState;
import google.registry.model.reporting.HistoryEntry; import google.registry.model.reporting.HistoryEntry;
import google.registry.model.reporting.IcannReportingTypes.ActivityReportField; import google.registry.model.reporting.IcannReportingTypes.ActivityReportField;
import google.registry.model.smd.AbstractSignedMark;
import google.registry.model.smd.EncodedSignedMark; import google.registry.model.smd.EncodedSignedMark;
import javax.inject.Inject; import javax.inject.Inject;
import org.joda.time.DateTime; import org.joda.time.DateTime;
@ -244,7 +242,8 @@ public final class DomainApplicationCreateFlow implements TransactionalFlow {
.setDomainName(domainName) .setDomainName(domainName)
.setYears(years) .setYears(years)
.build()); .build());
DomainApplication newApplication = new DomainApplication.Builder() DomainApplication newApplication =
new DomainApplication.Builder()
.setCreationTrid(trid) .setCreationTrid(trid)
.setCreationClientId(clientId) .setCreationClientId(clientId)
.setPersistedCurrentSponsorClientId(clientId) .setPersistedCurrentSponsorClientId(clientId)
@ -261,14 +260,12 @@ public final class DomainApplicationCreateFlow implements TransactionalFlow {
.setFullyQualifiedDomainName(targetId) .setFullyQualifiedDomainName(targetId)
.setNameservers(command.getNameservers()) .setNameservers(command.getNameservers())
.setContacts(command.getContacts()) .setContacts(command.getContacts())
.setEncodedSignedMarks(FluentIterable .setEncodedSignedMarks(
.from(launchCreate.getSignedMarks()) launchCreate
.transform(new Function<AbstractSignedMark, EncodedSignedMark>() { .getSignedMarks()
@Override .stream()
public EncodedSignedMark apply(AbstractSignedMark abstractSignedMark) { .map(abstractSignedMark -> (EncodedSignedMark) abstractSignedMark)
return (EncodedSignedMark) abstractSignedMark; .collect(toImmutableList()))
}})
.toList())
.build(); .build();
HistoryEntry historyEntry = HistoryEntry historyEntry =
buildHistoryEntry(newApplication.getRepoId(), command.getPeriod(), now); buildHistoryEntry(newApplication.getRepoId(), command.getPeriod(), now);

View file

@ -28,8 +28,6 @@ import static google.registry.model.registry.label.ReservationType.getTypeOfHigh
import static google.registry.pricing.PricingEngineProxy.isDomainPremium; import static google.registry.pricing.PricingEngineProxy.isDomainPremium;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import com.google.common.base.Predicate;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
@ -46,7 +44,6 @@ import google.registry.flows.annotations.ReportingSpec;
import google.registry.flows.custom.DomainCheckFlowCustomLogic; import google.registry.flows.custom.DomainCheckFlowCustomLogic;
import google.registry.flows.custom.DomainCheckFlowCustomLogic.BeforeResponseParameters; import google.registry.flows.custom.DomainCheckFlowCustomLogic.BeforeResponseParameters;
import google.registry.flows.custom.DomainCheckFlowCustomLogic.BeforeResponseReturnData; import google.registry.flows.custom.DomainCheckFlowCustomLogic.BeforeResponseReturnData;
import google.registry.model.domain.DomainApplication;
import google.registry.model.domain.DomainCommand.Check; import google.registry.model.domain.DomainCommand.Check;
import google.registry.model.domain.DomainResource; import google.registry.model.domain.DomainResource;
import google.registry.model.domain.fee.FeeCheckCommandExtension; import google.registry.model.domain.fee.FeeCheckCommandExtension;
@ -176,12 +173,9 @@ public final class DomainCheckFlow implements Flow {
} }
Registry registry = Registry.get(domainName.parent().toString()); Registry registry = Registry.get(domainName.parent().toString());
if (PENDING_ALLOCATION_TLD_STATES.contains(registry.getTldState(now)) if (PENDING_ALLOCATION_TLD_STATES.contains(registry.getTldState(now))
&& FluentIterable.from(loadActiveApplicationsByDomainName(domainName.toString(), now)) && loadActiveApplicationsByDomainName(domainName.toString(), now)
.anyMatch(new Predicate<DomainApplication>() { .stream()
@Override .anyMatch(input -> !input.getApplicationStatus().isFinalStatus())) {
public boolean apply(DomainApplication input) {
return !input.getApplicationStatus().isFinalStatus();
}})) {
return Optional.of("Pending allocation"); return Optional.of("Pending allocation");
} }
ImmutableSet<ReservationType> reservationTypes = getReservationTypes(domainName); ImmutableSet<ReservationType> reservationTypes = getReservationTypes(domainName);

View file

@ -41,13 +41,12 @@ import static google.registry.util.DomainNameUtils.ACE_PREFIX;
import com.google.common.base.CharMatcher; import com.google.common.base.CharMatcher;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import com.google.common.base.Predicate;
import com.google.common.base.Splitter; import com.google.common.base.Splitter;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.google.common.collect.Streams;
import com.google.common.net.InternetDomainName; import com.google.common.net.InternetDomainName;
import com.googlecode.objectify.Key; import com.googlecode.objectify.Key;
import google.registry.flows.EppException; import google.registry.flows.EppException;
@ -940,11 +939,12 @@ public class DomainFlowUtils {
.order("modificationTime") .order("modificationTime")
.list(); .list();
Optional<HistoryEntry> entryToCancel = Optional<HistoryEntry> entryToCancel =
FluentIterable.from(recentHistoryEntries) Optional.fromJavaUtil(
Streams.findLast(
recentHistoryEntries
.stream()
.filter( .filter(
new Predicate<HistoryEntry>() { historyEntry -> {
@Override
public boolean apply(HistoryEntry historyEntry) {
// Look for add and renew transaction records that have yet to be reported // Look for add and renew transaction records that have yet to be reported
for (DomainTransactionRecord record : for (DomainTransactionRecord record :
historyEntry.getDomainTransactionRecords()) { historyEntry.getDomainTransactionRecords()) {
@ -954,10 +954,7 @@ public class DomainFlowUtils {
} }
} }
return false; return false;
} })));
})
// We only want to cancel out the most recent add or renewal
.last();
ImmutableSet.Builder<DomainTransactionRecord> recordsBuilder = new ImmutableSet.Builder<>(); ImmutableSet.Builder<DomainTransactionRecord> recordsBuilder = new ImmutableSet.Builder<>();
if (entryToCancel.isPresent()) { if (entryToCancel.isPresent()) {
for (DomainTransactionRecord record : entryToCancel.get().getDomainTransactionRecords()) { for (DomainTransactionRecord record : entryToCancel.get().getDomainTransactionRecords()) {

View file

@ -14,8 +14,8 @@
package google.registry.flows.domain; package google.registry.flows.domain;
import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterables.getOnlyElement; import static com.google.common.collect.Iterables.getOnlyElement;
import static com.google.common.collect.MoreCollectors.onlyElement;
import static google.registry.util.DateTimeUtils.END_OF_TIME; import static google.registry.util.DateTimeUtils.END_OF_TIME;
import com.google.common.base.Optional; import com.google.common.base.Optional;
@ -61,14 +61,29 @@ public final class DomainTransferUtils {
if (transferPeriod.getValue() != 0) { if (transferPeriod.getValue() != 0) {
// Unless superuser sets period to 0, add a transfer billing event. // Unless superuser sets period to 0, add a transfer billing event.
transferDataBuilder.setServerApproveBillingEvent( transferDataBuilder.setServerApproveBillingEvent(
Key.create(getOnlyElement(filter(serverApproveEntities, BillingEvent.OneTime.class)))); Key.create(
serverApproveEntities
.stream()
.filter(BillingEvent.OneTime.class::isInstance)
.map(BillingEvent.OneTime.class::cast)
.collect(onlyElement())));
} }
return transferDataBuilder return transferDataBuilder
.setTransferStatus(TransferStatus.PENDING) .setTransferStatus(TransferStatus.PENDING)
.setServerApproveAutorenewEvent(Key.create( .setServerApproveAutorenewEvent(
getOnlyElement(filter(serverApproveEntities, BillingEvent.Recurring.class)))) Key.create(
.setServerApproveAutorenewPollMessage(Key.create( serverApproveEntities
getOnlyElement(filter(serverApproveEntities, PollMessage.Autorenew.class)))) .stream()
.filter(BillingEvent.Recurring.class::isInstance)
.map(BillingEvent.Recurring.class::cast)
.collect(onlyElement())))
.setServerApproveAutorenewPollMessage(
Key.create(
serverApproveEntities
.stream()
.filter(PollMessage.Autorenew.class::isInstance)
.map(PollMessage.Autorenew.class::cast)
.collect(onlyElement())))
.setServerApproveEntities(serverApproveEntityKeys.build()) .setServerApproveEntities(serverApproveEntityKeys.build())
.setTransferPeriod(transferPeriod) .setTransferPeriod(transferPeriod)
.build(); .build();

View file

@ -14,7 +14,7 @@
package google.registry.flows.domain; package google.registry.flows.domain;
import static com.google.common.collect.Iterables.concat; import static com.google.common.collect.ImmutableList.toImmutableList;
import static google.registry.util.CollectionUtils.nullToEmpty; import static google.registry.util.CollectionUtils.nullToEmpty;
import static google.registry.util.CollectionUtils.nullToEmptyImmutableCopy; import static google.registry.util.CollectionUtils.nullToEmptyImmutableCopy;
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull; import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
@ -26,6 +26,7 @@ import google.registry.model.domain.fee.BaseFee;
import google.registry.model.domain.fee.BaseFee.FeeType; import google.registry.model.domain.fee.BaseFee.FeeType;
import google.registry.model.domain.fee.Credit; import google.registry.model.domain.fee.Credit;
import google.registry.model.domain.fee.Fee; import google.registry.model.domain.fee.Fee;
import java.util.stream.Stream;
import org.joda.money.CurrencyUnit; import org.joda.money.CurrencyUnit;
import org.joda.money.Money; import org.joda.money.Money;
@ -102,7 +103,7 @@ public class FeesAndCredits extends ImmutableObject implements Buildable {
/** Returns all fees and credits for the event. */ /** Returns all fees and credits for the event. */
public ImmutableList<BaseFee> getFeesAndCredits() { public ImmutableList<BaseFee> getFeesAndCredits() {
return ImmutableList.copyOf(concat(getFees(), getCredits())); return Stream.concat(getFees().stream(), getCredits().stream()).collect(toImmutableList());
} }
@Override @Override

View file

@ -23,7 +23,6 @@ import static google.registry.flows.host.HostFlowUtils.validateHostName;
import static google.registry.model.eppoutput.Result.Code.SUCCESS_WITH_ACTION_PENDING; import static google.registry.model.eppoutput.Result.Code.SUCCESS_WITH_ACTION_PENDING;
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.googlecode.objectify.Key; import com.googlecode.objectify.Key;
import google.registry.flows.EppException; import google.registry.flows.EppException;
@ -71,13 +70,6 @@ public final class HostDeleteFlow implements TransactionalFlow {
StatusValue.PENDING_DELETE, StatusValue.PENDING_DELETE,
StatusValue.SERVER_DELETE_PROHIBITED); StatusValue.SERVER_DELETE_PROHIBITED);
private static final Function<DomainBase, ImmutableSet<?>> GET_NAMESERVERS =
new Function<DomainBase, ImmutableSet<?>>() {
@Override
public ImmutableSet<?> apply(DomainBase domain) {
return domain.getNameservers();
}};
@Inject ExtensionManager extensionManager; @Inject ExtensionManager extensionManager;
@Inject @ClientId String clientId; @Inject @ClientId String clientId;
@Inject @TargetId String targetId; @Inject @TargetId String targetId;
@ -95,7 +87,7 @@ public final class HostDeleteFlow implements TransactionalFlow {
validateClientIsLoggedIn(clientId); validateClientIsLoggedIn(clientId);
DateTime now = ofy().getTransactionTime(); DateTime now = ofy().getTransactionTime();
validateHostName(targetId); validateHostName(targetId);
failfastForAsyncDelete(targetId, now, HostResource.class, GET_NAMESERVERS); failfastForAsyncDelete(targetId, now, HostResource.class, DomainBase::getNameservers);
HostResource existingHost = loadAndVerifyExistence(HostResource.class, targetId, now); HostResource existingHost = loadAndVerifyExistence(HostResource.class, targetId, now);
verifyNoDisallowedStatuses(existingHost, DISALLOWED_STATUSES); verifyNoDisallowedStatuses(existingHost, DISALLOWED_STATUSES);
if (!isSuperuser) { if (!isSuperuser) {

View file

@ -18,11 +18,10 @@ import static google.registry.model.EppResourceUtils.isActive;
import static google.registry.model.EppResourceUtils.loadByForeignKey; import static google.registry.model.EppResourceUtils.loadByForeignKey;
import static google.registry.model.registry.Registries.findTldForName; import static google.registry.model.registry.Registries.findTldForName;
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull; import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
import static java.util.stream.Collectors.joining;
import com.google.common.base.Ascii; import com.google.common.base.Ascii;
import com.google.common.base.Joiner;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import com.google.common.collect.Iterables;
import com.google.common.net.InternetDomainName; import com.google.common.net.InternetDomainName;
import google.registry.flows.EppException; import google.registry.flows.EppException;
import google.registry.flows.EppException.AuthorizationErrorException; import google.registry.flows.EppException.AuthorizationErrorException;
@ -98,8 +97,12 @@ public class HostFlowUtils {
return Optional.absent(); return Optional.absent();
} }
// This is a subordinate host // This is a subordinate host
String domainName = Joiner.on('.').join(Iterables.skip( String domainName =
hostName.parts(), hostName.parts().size() - (tld.get().parts().size() + 1))); hostName
.parts()
.stream()
.skip(hostName.parts().size() - (tld.get().parts().size() + 1))
.collect(joining("."));
DomainResource superordinateDomain = loadByForeignKey(DomainResource.class, domainName, now); DomainResource superordinateDomain = loadByForeignKey(DomainResource.class, domainName, now);
if (superordinateDomain == null || !isActive(superordinateDomain, now)) { if (superordinateDomain == null || !isActive(superordinateDomain, now)) {
throw new SuperordinateDomainDoesNotExistException(domainName); throw new SuperordinateDomainDoesNotExistException(domainName);

View file

@ -29,7 +29,6 @@ import google.registry.config.RegistryConfig.Config;
import google.registry.keyring.api.KeyringException; import google.registry.keyring.api.KeyringException;
import google.registry.util.Retrier; import google.registry.util.Retrier;
import java.io.IOException; import java.io.IOException;
import java.util.concurrent.Callable;
import javax.inject.Inject; import javax.inject.Inject;
/** The {@link KmsConnection} which talks to Cloud KMS. */ /** The {@link KmsConnection} which talks to Cloud KMS. */
@ -137,13 +136,7 @@ class KmsConnectionImpl implements KmsConnection {
public byte[] decrypt(final String cryptoKeyName, final String encodedCiphertext) { public byte[] decrypt(final String cryptoKeyName, final String encodedCiphertext) {
try { try {
return retrier.callWithRetry( return retrier.callWithRetry(
new Callable<byte[]>() { () -> attemptDecrypt(cryptoKeyName, encodedCiphertext), IOException.class);
@Override
public byte[] call() throws IOException {
return attemptDecrypt(cryptoKeyName, encodedCiphertext);
}
},
IOException.class);
} catch (RuntimeException e) { } catch (RuntimeException e) {
throw new KeyringException( throw new KeyringException(
String.format("CloudKMS decrypt operation failed for secret %s", cryptoKeyName), e); String.format("CloudKMS decrypt operation failed for secret %s", cryptoKeyName), e);

View file

@ -17,6 +17,7 @@ package google.registry.loadtest;
import static com.google.appengine.api.taskqueue.QueueConstants.maxTasksPerAdd; import static com.google.appengine.api.taskqueue.QueueConstants.maxTasksPerAdd;
import static com.google.appengine.api.taskqueue.QueueFactory.getQueue; import static com.google.appengine.api.taskqueue.QueueFactory.getQueue;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.collect.Lists.partition; import static com.google.common.collect.Lists.partition;
import static com.google.common.collect.Lists.transform; import static com.google.common.collect.Lists.transform;
import static google.registry.security.XsrfTokenManager.X_CSRF_TOKEN; import static google.registry.security.XsrfTokenManager.X_CSRF_TOKEN;
@ -27,7 +28,6 @@ import static org.joda.time.DateTimeZone.UTC;
import com.google.appengine.api.taskqueue.TaskOptions; import com.google.appengine.api.taskqueue.TaskOptions;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterators; import com.google.common.collect.Iterators;
import google.registry.config.RegistryEnvironment; import google.registry.config.RegistryEnvironment;
@ -247,12 +247,12 @@ public class LoadTestAction implements Runnable {
startSecond)); startSecond));
tasks.addAll( tasks.addAll(
createTasks( createTasks(
FluentIterable.from( createNumCopies(xmlDomainCreateTmpl, successfulDomainCreatesPerSecond)
createNumCopies(xmlDomainCreateTmpl, successfulDomainCreatesPerSecond)) .stream()
.transform(randomNameReplacer("%domain%", MAX_DOMAIN_LABEL_LENGTH)) .map(randomNameReplacer("%domain%", MAX_DOMAIN_LABEL_LENGTH))
.transform(listNameReplacer("%contact%", contactNames)) .map(listNameReplacer("%contact%", contactNames))
.transform(listNameReplacer("%host%", hostPrefixes)) .map(listNameReplacer("%host%", hostPrefixes))
.toList(), .collect(toImmutableList()),
startSecond)); startSecond));
} }
ImmutableList<TaskOptions> taskOptions = tasks.build(); ImmutableList<TaskOptions> taskOptions = tasks.build();
@ -308,19 +308,11 @@ public class LoadTestAction implements Runnable {
private Function<String, String> listNameReplacer(final String toReplace, List<String> choices) { private Function<String, String> listNameReplacer(final String toReplace, List<String> choices) {
final Iterator<String> iterator = Iterators.cycle(choices); final Iterator<String> iterator = Iterators.cycle(choices);
return new Function<String, String>() { return xml -> xml.replace(toReplace, iterator.next());
@Override
public String apply(String xml) {
return xml.replace(toReplace, iterator.next());
}};
} }
private Function<String, String> randomNameReplacer(final String toReplace, final int numChars) { private Function<String, String> randomNameReplacer(final String toReplace, final int numChars) {
return new Function<String, String>() { return xml -> xml.replace(toReplace, getRandomLabel(numChars));
@Override
public String apply(String xml) {
return xml.replace(toReplace, getRandomLabel(numChars));
}};
} }
private String getRandomLabel(int numChars) { private String getRandomLabel(int numChars) {

View file

@ -30,7 +30,6 @@ import google.registry.util.FormattingLogger;
import google.registry.util.Retrier; import google.registry.util.Retrier;
import google.registry.util.SystemSleeper; import google.registry.util.SystemSleeper;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.concurrent.Callable;
import org.joda.time.DateTime; import org.joda.time.DateTime;
/** {@link InputReader} that maps over {@link CommitLogManifest}. */ /** {@link InputReader} that maps over {@link CommitLogManifest}. */
@ -138,12 +137,7 @@ class CommitLogManifestReader extends InputReader<Key<CommitLogManifest>> {
final Cursor currentCursor = queryIterator.getCursor(); final Cursor currentCursor = queryIterator.getCursor();
try { try {
return retrier.callWithRetry( return retrier.callWithRetry(
new Callable<Key<CommitLogManifest>>() { () -> queryIterator.next(),
@Override
public Key<CommitLogManifest> call() {
return queryIterator.next();
}
},
new Retrier.FailureReporter() { new Retrier.FailureReporter() {
@Override @Override
public void beforeRetry(Throwable thrown, int failures, int maxAttempts) { public void beforeRetry(Throwable thrown, int failures, int maxAttempts) {
@ -155,8 +149,7 @@ class CommitLogManifestReader extends InputReader<Key<CommitLogManifest>> {
public void afterFinalFailure(Throwable thrown, int failures) { public void afterFinalFailure(Throwable thrown, int failures) {
logger.severefmt( logger.severefmt(
"Max retry attempts reached trying to read item %d/%d. Giving up.", "Max retry attempts reached trying to read item %d/%d. Giving up.",
loaded, loaded, total);
total);
} }
}, },
DatastoreTimeoutException.class); DatastoreTimeoutException.class);

View file

@ -14,13 +14,13 @@
package google.registry.mapreduce.inputs; package google.registry.mapreduce.inputs;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static google.registry.model.EntityClasses.CLASS_TO_KIND_FUNCTION; import static google.registry.model.EntityClasses.CLASS_TO_KIND_FUNCTION;
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
import com.google.appengine.api.datastore.Cursor; import com.google.appengine.api.datastore.Cursor;
import com.google.appengine.api.datastore.QueryResultIterator; import com.google.appengine.api.datastore.QueryResultIterator;
import com.google.appengine.tools.mapreduce.InputReader; import com.google.appengine.tools.mapreduce.InputReader;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.googlecode.objectify.Key; import com.googlecode.objectify.Key;
import com.googlecode.objectify.cmd.Query; import com.googlecode.objectify.cmd.Query;
@ -138,6 +138,6 @@ abstract class EppResourceBaseReader<T> extends InputReader<T> {
// Ignore EppResource when finding kinds, since it doesn't have one and doesn't imply filtering. // Ignore EppResource when finding kinds, since it doesn't have one and doesn't imply filtering.
return resourceClasses.contains(EppResource.class) return resourceClasses.contains(EppResource.class)
? ImmutableSet.<String>of() ? ImmutableSet.<String>of()
: FluentIterable.from(resourceClasses).transform(CLASS_TO_KIND_FUNCTION).toSet(); : resourceClasses.stream().map(CLASS_TO_KIND_FUNCTION).collect(toImmutableSet());
} }
} }

View file

@ -116,17 +116,12 @@ public final class EntityClasses {
/** /**
* Function that converts an Objectify-registered class to its Datastore kind name. * Function that converts an Objectify-registered class to its Datastore kind name.
* *
* <p>Note that this mapping is not one-to-one, since polymorphic subclasses of an entity all * <p>Note that this mapping is not one-to-one, since polymorphic subclasses of an entity all have
* have the same Datastore kind. (In theory, two distinct top-level entities could also map to * the same Datastore kind. (In theory, two distinct top-level entities could also map to the same
* the same kind since it's just {@code class.getSimpleName()}, but we test against that.) * kind since it's just {@code class.getSimpleName()}, but we test against that.)
*/ */
public static final Function<Class<? extends ImmutableObject>, String> CLASS_TO_KIND_FUNCTION = public static final Function<Class<? extends ImmutableObject>, String> CLASS_TO_KIND_FUNCTION =
new Function<Class<? extends ImmutableObject>, String>() { (Class<? extends ImmutableObject> clazz) -> Key.getKind(clazz);
@Override
public String apply(Class<? extends ImmutableObject> clazz) {
return Key.getKind(clazz);
}
};
private EntityClasses() {} private EntityClasses() {}
} }

View file

@ -172,11 +172,7 @@ public final class EppResourceUtils {
* Iterables.transform() over a collection of EppResources. * Iterables.transform() over a collection of EppResources.
*/ */
public static <T extends EppResource> Function<T, T> transformAtTime(final DateTime now) { public static <T extends EppResource> Function<T, T> transformAtTime(final DateTime now) {
return new Function<T, T>() { return (T resource) -> cloneProjectedAtTime(resource, now);
@Override
public T apply(T resource) {
return cloneProjectedAtTime(resource, now);
}};
} }
/** /**

View file

@ -14,6 +14,8 @@
package google.registry.model; package google.registry.model;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static com.google.common.collect.Iterables.transform; import static com.google.common.collect.Iterables.transform;
import static com.google.common.collect.Maps.transformValues; import static com.google.common.collect.Maps.transformValues;
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
@ -22,7 +24,6 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.googlecode.objectify.Key; import com.googlecode.objectify.Key;
import com.googlecode.objectify.annotation.Ignore; import com.googlecode.objectify.annotation.Ignore;
@ -157,13 +158,15 @@ public abstract class ImmutableObject implements Cloneable {
}}; }};
/** Helper function to recursively convert a ImmutableObject to a Map of generic objects. */ /** Helper function to recursively convert a ImmutableObject to a Map of generic objects. */
private static final Function<Object, Object> TO_MAP_HELPER = new Function<Object, Object>() { private static final Function<Object, Object> TO_MAP_HELPER =
new Function<Object, Object>() {
@Override @Override
public Object apply(Object o) { public Object apply(Object o) {
if (o == null) { if (o == null) {
return null; return null;
} else if (o instanceof ImmutableObject) { } else if (o instanceof ImmutableObject) {
// LinkedHashMap to preserve field ordering and because ImmutableMap forbids null values. // LinkedHashMap to preserve field ordering and because ImmutableMap forbids null
// values.
Map<String, Object> result = new LinkedHashMap<>(); Map<String, Object> result = new LinkedHashMap<>();
for (Entry<Field, Object> entry : ModelUtils.getFieldValues(o).entrySet()) { for (Entry<Field, Object> entry : ModelUtils.getFieldValues(o).entrySet()) {
result.put(entry.getKey().getName(), apply(entry.getValue())); result.put(entry.getKey().getName(), apply(entry.getValue()));
@ -172,15 +175,16 @@ public abstract class ImmutableObject implements Cloneable {
} else if (o instanceof Map) { } else if (o instanceof Map) {
return Maps.transformValues((Map<?, ?>) o, this); return Maps.transformValues((Map<?, ?>) o, this);
} else if (o instanceof Set) { } else if (o instanceof Set) {
return FluentIterable.from((Set<?>) o).transform(this).toSet(); return ((Set<?>) o).stream().map(this).collect(toImmutableSet());
} else if (o instanceof Collection) { } else if (o instanceof Collection) {
return FluentIterable.from((Collection<?>) o).transform(this).toList(); return ((Collection<?>) o).stream().map(this).collect(toImmutableList());
} else if (o instanceof Number || o instanceof Boolean) { } else if (o instanceof Number || o instanceof Boolean) {
return o; return o;
} else { } else {
return o.toString(); return o.toString();
} }
}}; }
};
/** Returns a map of all object fields (including sensitive data) that's used to produce diffs. */ /** Returns a map of all object fields (including sensitive data) that's used to produce diffs. */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")

View file

@ -14,9 +14,10 @@
package google.registry.model; package google.registry.model;
import com.google.common.base.Function; import static com.google.common.collect.ImmutableList.toImmutableList;
import com.google.common.base.Functions; import com.google.common.base.Functions;
import com.google.common.collect.FluentIterable; import com.google.common.collect.Streams;
import java.util.Collections; import java.util.Collections;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
@ -29,14 +30,6 @@ import javax.annotation.Nullable;
* list is passed as {@code null}, it'll be substituted with empty list. Lists are not mutable. * list is passed as {@code null}, it'll be substituted with empty list. Lists are not mutable.
*/ */
public final class JsonMapBuilder { public final class JsonMapBuilder {
private static final Function<Jsonifiable, Map<String, Object>> TO_JSON_OBJECT =
new Function<Jsonifiable, Map<String, Object>>() {
@Override
public Map<String, Object> apply(Jsonifiable input) {
return input.toJsonMap();
}};
private final Map<String, Object> map = new LinkedHashMap<>(); private final Map<String, Object> map = new LinkedHashMap<>();
public JsonMapBuilder put(String name, @Nullable Boolean value) { public JsonMapBuilder put(String name, @Nullable Boolean value) {
@ -70,15 +63,21 @@ public final class JsonMapBuilder {
} }
public <T> JsonMapBuilder putListOfStrings(String name, @Nullable Iterable<T> value) { public <T> JsonMapBuilder putListOfStrings(String name, @Nullable Iterable<T> value) {
map.put(name, value == null ? Collections.EMPTY_LIST map.put(
: FluentIterable.from(value).transform(Functions.toStringFunction()).toList()); name,
value == null
? Collections.EMPTY_LIST
: Streams.stream(value).map(Functions.toStringFunction()).collect(toImmutableList()));
return this; return this;
} }
public JsonMapBuilder putListOfJsonObjects( public JsonMapBuilder putListOfJsonObjects(
String name, @Nullable Iterable<? extends Jsonifiable> value) { String name, @Nullable Iterable<? extends Jsonifiable> value) {
map.put(name, value == null ? Collections.EMPTY_LIST map.put(
: FluentIterable.from(value).transform(TO_JSON_OBJECT).toList()); name,
value == null
? Collections.EMPTY_LIST
: Streams.stream(value).map(Jsonifiable::toJsonMap).collect(toImmutableList()));
return this; return this;
} }

View file

@ -17,7 +17,6 @@ package google.registry.model;
import static com.google.common.base.Predicates.instanceOf; import static com.google.common.base.Predicates.instanceOf;
import static com.google.common.base.Predicates.isNull; import static com.google.common.base.Predicates.isNull;
import static com.google.common.base.Predicates.or; import static com.google.common.base.Predicates.or;
import static com.google.common.collect.Iterables.all;
import static com.google.common.collect.Lists.newArrayList; import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Maps.transformValues; import static com.google.common.collect.Maps.transformValues;
import static com.google.common.collect.Sets.newLinkedHashSet; import static com.google.common.collect.Sets.newLinkedHashSet;
@ -34,6 +33,7 @@ import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedMap; import com.google.common.collect.ImmutableSortedMap;
import com.google.common.collect.Ordering; import com.google.common.collect.Ordering;
import com.google.common.collect.Streams;
import com.googlecode.objectify.Key; import com.googlecode.objectify.Key;
import com.googlecode.objectify.annotation.Id; import com.googlecode.objectify.annotation.Id;
import com.googlecode.objectify.annotation.Ignore; import com.googlecode.objectify.annotation.Ignore;
@ -95,25 +95,21 @@ public class ModelUtils {
body = FluentIterable.from(clazz.getEnumConstants()); body = FluentIterable.from(clazz.getEnumConstants());
} else { } else {
stringBuilder.append("class "); stringBuilder.append("class ");
body = FluentIterable.from(getAllFields(clazz).values()) body =
.filter(new Predicate<Field>() { FluentIterable.from(getAllFields(clazz).values())
@Override .filter((Field field) -> !field.isAnnotationPresent(Ignore.class))
public boolean apply(Field field) { .transform(
return !field.isAnnotationPresent(Ignore.class); (Field field) -> {
}}) String annotation =
.transform(new Function<Field, Object>() { field.isAnnotationPresent(Id.class)
@Override
public Object apply(Field field) {
String annotation = field.isAnnotationPresent(Id.class)
? "@Id " ? "@Id "
: field.isAnnotationPresent(Parent.class) : field.isAnnotationPresent(Parent.class) ? "@Parent " : "";
? "@Parent " String type =
: ""; field.getType().isArray()
String type = field.getType().isArray()
? field.getType().getComponentType().getName() + "[]" ? field.getType().getComponentType().getName() + "[]"
: field.getGenericType().toString().replaceFirst("class ", ""); : field.getGenericType().toString().replaceFirst("class ", "");
return String.format("%s%s %s", annotation, type, field.getName()); return String.format("%s%s %s", annotation, type, field.getName());
}}); });
} }
return stringBuilder return stringBuilder
.append(clazz.getName()).append(" {\n ") .append(clazz.getName()).append(" {\n ")
@ -212,7 +208,8 @@ public class ModelUtils {
} }
/** Functional helper for {@link #cloneEmptyToNull}. */ /** Functional helper for {@link #cloneEmptyToNull}. */
private static final Function<Object, ?> CLONE_EMPTY_TO_NULL = new Function<Object, Object>() { private static final Function<Object, ?> CLONE_EMPTY_TO_NULL =
new Function<Object, Object>() {
@Override @Override
public Object apply(Object obj) { public Object apply(Object obj) {
if (obj instanceof ImmutableSortedMap) { if (obj instanceof ImmutableSortedMap) {
@ -228,12 +225,13 @@ public class ModelUtils {
} }
Predicate<Object> immutableObjectOrNull = or(isNull(), instanceOf(ImmutableObject.class)); Predicate<Object> immutableObjectOrNull = or(isNull(), instanceOf(ImmutableObject.class));
if ((obj instanceof Set || obj instanceof List) if ((obj instanceof Set || obj instanceof List)
&& all((Iterable<?>) obj, immutableObjectOrNull)) { && Streams.stream((Iterable<?>) obj).allMatch(immutableObjectOrNull)) {
// Recurse into sets and lists, but only if they contain ImmutableObjects. // Recurse into sets and lists, but only if they contain ImmutableObjects.
FluentIterable<?> fluent = FluentIterable.from((Iterable<?>) obj).transform(this); FluentIterable<?> fluent = FluentIterable.from((Iterable<?>) obj).transform(this);
return (obj instanceof List) ? newArrayList(fluent) : newLinkedHashSet(fluent); return (obj instanceof List) ? newArrayList(fluent) : newLinkedHashSet(fluent);
} }
if (obj instanceof Map && all(((Map<?, ?>) obj).values(), immutableObjectOrNull)) { if (obj instanceof Map
&& ((Map<?, ?>) obj).values().stream().allMatch(immutableObjectOrNull)) {
// Recurse into maps with ImmutableObject values. // Recurse into maps with ImmutableObject values.
return transformValues((Map<?, ?>) obj, this); return transformValues((Map<?, ?>) obj, this);
} }
@ -250,7 +248,8 @@ public class ModelUtils {
return copy; return copy;
} }
return obj; return obj;
}}; }
};
/** Returns a clone of the object and sets empty collections, arrays, maps and strings to null. */ /** Returns a clone of the object and sets empty collections, arrays, maps and strings to null. */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")

View file

@ -16,10 +16,8 @@ package google.registry.model;
import static com.google.common.base.Predicates.or; import static com.google.common.base.Predicates.or;
import static com.google.common.base.Predicates.subtypeOf; import static com.google.common.base.Predicates.subtypeOf;
import static java.util.stream.Collectors.joining;
import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.Ordering; import com.google.common.collect.Ordering;
import java.util.ArrayDeque; import java.util.ArrayDeque;
import java.util.Queue; import java.util.Queue;
@ -60,14 +58,11 @@ public final class SchemaVersion {
* types (for classes), or else a list of all possible values (for enums). * types (for classes), or else a list of all possible values (for enums).
*/ */
public static String getSchema() { public static String getSchema() {
return FluentIterable.from(getAllPersistedTypes()) return getAllPersistedTypes()
.stream()
.filter(or(subtypeOf(Enum.class), subtypeOf(ImmutableObject.class))) .filter(or(subtypeOf(Enum.class), subtypeOf(ImmutableObject.class)))
.transform(new Function<Class<?>, String>() { .map(ModelUtils::getSchema)
@Override .collect(joining("\n"));
public String apply(Class<?> clazz) {
return ModelUtils.getSchema(clazz);
}})
.join(Joiner.on('\n'));
} }
private SchemaVersion() {} private SchemaVersion() {}

View file

@ -14,15 +14,13 @@
package google.registry.model.billing; package google.registry.model.billing;
import static com.google.common.collect.ImmutableSortedSet.toImmutableSortedSet;
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
import com.google.common.base.Function;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSortedSet; import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.common.collect.Maps.EntryTransformer;
import com.google.common.collect.Ordering; import com.google.common.collect.Ordering;
import com.googlecode.objectify.cmd.Query; import com.googlecode.objectify.cmd.Query;
import google.registry.model.CacheUtils; import google.registry.model.CacheUtils;
@ -38,19 +36,11 @@ public final class RegistrarBillingUtils {
private static final Supplier<ImmutableSortedSet<CurrencyUnit>> CURRENCIES_CACHE = private static final Supplier<ImmutableSortedSet<CurrencyUnit>> CURRENCIES_CACHE =
CacheUtils.memoizeWithShortExpiration( CacheUtils.memoizeWithShortExpiration(
new Supplier<ImmutableSortedSet<CurrencyUnit>>() { () ->
@Override Registries.getTlds()
public ImmutableSortedSet<CurrencyUnit> get() { .stream()
return FluentIterable .map((String tld) -> Registry.get(tld).getCurrency())
.from(Registries.getTlds()) .collect(toImmutableSortedSet(Ordering.natural())));
.transform(new Function<String, CurrencyUnit>() {
@Override
public CurrencyUnit apply(String tld) {
return Registry.get(tld).getCurrency();
}})
.toSortedSet(Ordering.natural());
}
});
/** /**
* Returns set of currencies in which registrars may be billed. * Returns set of currencies in which registrars may be billed.
@ -69,28 +59,25 @@ public final class RegistrarBillingUtils {
*/ */
public static ImmutableMap<CurrencyUnit, Query<RegistrarBillingEntry>> getBillingEntryQueries( public static ImmutableMap<CurrencyUnit, Query<RegistrarBillingEntry>> getBillingEntryQueries(
final Registrar registrar) { final Registrar registrar) {
return Maps.toMap(getCurrencies(), return Maps.toMap(
new Function<CurrencyUnit, Query<RegistrarBillingEntry>>() { getCurrencies(),
@Override (CurrencyUnit currency) ->
public Query<RegistrarBillingEntry> apply(CurrencyUnit currency) { ofy()
return ofy().load() .load()
.type(RegistrarBillingEntry.class) .type(RegistrarBillingEntry.class)
.ancestor(registrar) .ancestor(registrar)
.filter("currency", currency) .filter("currency", currency)
.order("-created"); .order("-created"));
}});
} }
/** Returns amount of money registrar currently owes registry in each currency. */ /** Returns amount of money registrar currently owes registry in each currency. */
public static Map<CurrencyUnit, Money> loadBalance(Registrar registrar) { public static Map<CurrencyUnit, Money> loadBalance(Registrar registrar) {
return Maps.transformEntries(getBillingEntryQueries(registrar), return Maps.transformEntries(
new EntryTransformer<CurrencyUnit, Query<RegistrarBillingEntry>, Money>() { getBillingEntryQueries(registrar),
@Override (CurrencyUnit currency, Query<RegistrarBillingEntry> query) -> {
public Money transformEntry(
CurrencyUnit currency, Query<RegistrarBillingEntry> query) {
RegistrarBillingEntry entry = query.first().now(); RegistrarBillingEntry entry = query.first().now();
return entry != null ? entry.getBalance() : Money.zero(currency); return entry != null ? entry.getBalance() : Money.zero(currency);
}}); });
} }
private RegistrarBillingUtils() {} private RegistrarBillingUtils() {}

View file

@ -16,15 +16,16 @@ package google.registry.model.billing;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.model.registry.Registries.assertTldExists; import static google.registry.model.registry.Registries.assertTldExists;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import com.google.common.collect.ComparisonChain; import com.google.common.collect.ComparisonChain;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.Ordering; import com.google.common.collect.Ordering;
import com.google.common.collect.Streams;
import com.googlecode.objectify.Key; import com.googlecode.objectify.Key;
import com.googlecode.objectify.annotation.Entity; import com.googlecode.objectify.annotation.Entity;
import com.googlecode.objectify.annotation.Id; import com.googlecode.objectify.annotation.Id;
@ -216,7 +217,8 @@ public final class RegistrarCredit extends ImmutableObject implements Buildable
* <p>The resulting list sorts the credits first by type and then by creation time. * <p>The resulting list sorts the credits first by type and then by creation time.
*/ */
public static ImmutableList<RegistrarCredit> loadAllForRegistrar(Registrar registrar) { public static ImmutableList<RegistrarCredit> loadAllForRegistrar(Registrar registrar) {
return FluentIterable.from(ofy().load().type(RegistrarCredit.class).ancestor(registrar)) return Streams.stream(ofy().load().type(RegistrarCredit.class).ancestor(registrar))
.toSortedList(CREDIT_PRIORITY_ORDERING); .sorted(CREDIT_PRIORITY_ORDERING)
.collect(toImmutableList());
} }
} }

View file

@ -20,7 +20,6 @@ import static com.google.common.base.Preconditions.checkState;
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import com.google.common.collect.ForwardingNavigableMap; import com.google.common.collect.ForwardingNavigableMap;
import com.google.common.collect.ImmutableSortedMap; import com.google.common.collect.ImmutableSortedMap;
@ -193,15 +192,11 @@ public final class RegistrarCreditBalance extends ImmutableObject implements Bui
*/ */
@VisibleForTesting @VisibleForTesting
BalanceMap(Map<DateTime, ? extends Map<DateTime, Money>> data) { BalanceMap(Map<DateTime, ? extends Map<DateTime, Money>> data) {
delegate = ImmutableSortedMap.copyOf( delegate =
ImmutableSortedMap.copyOf(
Maps.transformValues( Maps.transformValues(
data, data,
new Function<Map<DateTime, Money>, ImmutableSortedMap<DateTime, Money>>() { (Map<DateTime, Money> map) -> ImmutableSortedMap.copyOf(map, Ordering.natural())),
@Override
public ImmutableSortedMap<DateTime, Money> apply(Map<DateTime, Money> map) {
return ImmutableSortedMap.copyOf(map, Ordering.natural());
}
}),
Ordering.natural()); Ordering.natural());
} }

View file

@ -21,7 +21,6 @@ import static google.registry.util.DateTimeUtils.isAtOrAfter;
import static google.registry.util.DateTimeUtils.isBeforeOrAt; import static google.registry.util.DateTimeUtils.isBeforeOrAt;
import static org.joda.time.DateTimeZone.UTC; import static org.joda.time.DateTimeZone.UTC;
import com.google.common.base.Function;
import com.google.common.base.Splitter; import com.google.common.base.Splitter;
import com.google.common.collect.ContiguousSet; import com.google.common.collect.ContiguousSet;
import com.google.common.collect.FluentIterable; import com.google.common.collect.FluentIterable;
@ -85,11 +84,7 @@ public class TimeOfYear extends ImmutableObject {
normalizedRange.lowerEndpoint().getYear(), normalizedRange.lowerEndpoint().getYear(),
normalizedRange.upperEndpoint().getYear()); normalizedRange.upperEndpoint().getYear());
return FluentIterable.from(ContiguousSet.create(yearRange, integers())) return FluentIterable.from(ContiguousSet.create(yearRange, integers()))
.transform(new Function<Integer, DateTime>() { .transform(this::getDateTimeWithYear)
@Override
public DateTime apply(Integer year) {
return getDateTimeWithYear(year);
}})
.filter(normalizedRange); .filter(normalizedRange);
} }

View file

@ -20,7 +20,6 @@ import static google.registry.util.CollectionUtils.nullToEmpty;
import static google.registry.util.DateTimeUtils.START_OF_TIME; import static google.registry.util.DateTimeUtils.START_OF_TIME;
import static google.registry.util.DateTimeUtils.latestOf; import static google.registry.util.DateTimeUtils.latestOf;
import com.google.common.base.Function;
import com.google.common.collect.ForwardingMap; import com.google.common.collect.ForwardingMap;
import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.ImmutableSortedMap; import com.google.common.collect.ImmutableSortedMap;
@ -103,18 +102,17 @@ public class TimedTransitionProperty<V, T extends TimedTransitionProperty.TimedT
checkArgument( checkArgument(
Ordering.natural().equals(valueMap.comparator()), Ordering.natural().equals(valueMap.comparator()),
"Timed transition value map must have transition time keys in chronological order"); "Timed transition value map must have transition time keys in chronological order");
return Maps.transformEntries(valueMap, new Maps.EntryTransformer<DateTime, V, T>() { return Maps.transformEntries(
// For each entry in the input value map, make the output map have an entry at the valueMap,
// corresponding time that points to a transition containing that time and that value. (DateTime transitionTime, V value) -> {
@Override checkArgument(
public T transformEntry(DateTime transitionTime, V value) { !transitionTime.isBefore(START_OF_TIME),
checkArgument(!transitionTime.isBefore(START_OF_TIME),
"Timed transition times cannot be earlier than START_OF_TIME / Unix Epoch"); "Timed transition times cannot be earlier than START_OF_TIME / Unix Epoch");
T subclass = TypeUtils.instantiate(timedTransitionSubclass); T subclass = TypeUtils.instantiate(timedTransitionSubclass);
((TimedTransition<V>) subclass).transitionTime = transitionTime; ((TimedTransition<V>) subclass).transitionTime = transitionTime;
subclass.setValue(value); subclass.setValue(value);
return subclass; return subclass;
}}); });
} }
/** /**
@ -288,13 +286,7 @@ public class TimedTransitionProperty<V, T extends TimedTransitionProperty.TimedT
/** Returns the map of DateTime to value that is the "natural" representation of this property. */ /** Returns the map of DateTime to value that is the "natural" representation of this property. */
public ImmutableSortedMap<DateTime, V> toValueMap() { public ImmutableSortedMap<DateTime, V> toValueMap() {
return ImmutableSortedMap.copyOfSorted(Maps.transformValues( return ImmutableSortedMap.copyOfSorted(Maps.transformValues(backingMap, T::getValue));
backingMap,
new Function<T, V>() {
@Override
public V apply(T timedTransition) {
return timedTransition.getValue();
}}));
} }
/** /**

View file

@ -17,7 +17,6 @@ package google.registry.model.contact;
import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Preconditions.checkState;
import static google.registry.util.CollectionUtils.nullToEmpty; import static google.registry.util.CollectionUtils.nullToEmpty;
import com.google.common.base.Function;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import google.registry.model.ImmutableObject; import google.registry.model.ImmutableObject;
import google.registry.model.contact.PostalInfo.Type; import google.registry.model.contact.PostalInfo.Type;
@ -67,11 +66,7 @@ public class ContactCommand {
// There can be no more than 2 postalInfos (enforced by the schema), and if there are 2 they // There can be no more than 2 postalInfos (enforced by the schema), and if there are 2 they
// must be of different types (not enforced). If the type is repeated, uniqueIndex will throw. // must be of different types (not enforced). If the type is repeated, uniqueIndex will throw.
checkState(nullToEmpty(postalInfo).size() <= 2); checkState(nullToEmpty(postalInfo).size() <= 2);
return Maps.uniqueIndex(nullToEmpty(postalInfo), new Function<PostalInfo, Type>() { return Maps.uniqueIndex(nullToEmpty(postalInfo), PostalInfo::getType);
@Override
public Type apply(PostalInfo info) {
return info.getType();
}});
} }
public ContactPhoneNumber getVoice() { public ContactPhoneNumber getVoice() {

View file

@ -15,13 +15,12 @@
package google.registry.model.contact; package google.registry.model.contact;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static google.registry.model.EppResourceUtils.projectResourceOntoBuilderAtTime; import static google.registry.model.EppResourceUtils.projectResourceOntoBuilderAtTime;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import com.google.common.base.Predicates; import com.google.common.base.Predicates;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.googlecode.objectify.annotation.Entity; import com.googlecode.objectify.annotation.Entity;
import com.googlecode.objectify.annotation.IgnoreSave; import com.googlecode.objectify.annotation.IgnoreSave;
import com.googlecode.objectify.annotation.Index; import com.googlecode.objectify.annotation.Index;
@ -33,6 +32,7 @@ import google.registry.model.annotations.ExternalMessagingName;
import google.registry.model.annotations.ReportedOn; import google.registry.model.annotations.ReportedOn;
import google.registry.model.contact.PostalInfo.Type; import google.registry.model.contact.PostalInfo.Type;
import google.registry.model.transfer.TransferData; import google.registry.model.transfer.TransferData;
import java.util.stream.Stream;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import org.joda.time.DateTime; import org.joda.time.DateTime;
@ -170,10 +170,9 @@ public class ContactResource extends EppResource implements
*/ */
@XmlElement(name = "postalInfo") @XmlElement(name = "postalInfo")
public ImmutableList<PostalInfo> getPostalInfosAsList() { public ImmutableList<PostalInfo> getPostalInfosAsList() {
return FluentIterable return Stream.of(localizedPostalInfo, internationalizedPostalInfo)
.from(Lists.newArrayList(localizedPostalInfo, internationalizedPostalInfo))
.filter(Predicates.notNull()) .filter(Predicates.notNull())
.toList(); .collect(toImmutableList());
} }
@Override @Override

View file

@ -17,8 +17,8 @@ package google.registry.model.domain;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Predicates.not; import static com.google.common.base.Predicates.not;
import static com.google.common.base.Strings.emptyToNull; import static com.google.common.base.Strings.emptyToNull;
import static com.google.common.collect.Iterables.all; import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static com.google.common.collect.Iterables.any; import static com.google.common.collect.ImmutableSortedSet.toImmutableSortedSet;
import static com.google.common.collect.Sets.difference; import static com.google.common.collect.Sets.difference;
import static com.google.common.collect.Sets.union; import static com.google.common.collect.Sets.union;
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
@ -30,9 +30,7 @@ import static google.registry.util.DomainNameUtils.canonicalizeDomainName;
import static google.registry.util.DomainNameUtils.getTldFromDomainName; import static google.registry.util.DomainNameUtils.getTldFromDomainName;
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull; import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
import com.google.common.base.Function;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedSet; import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.Ordering; import com.google.common.collect.Ordering;
@ -49,6 +47,7 @@ import google.registry.model.domain.launch.LaunchNotice;
import google.registry.model.domain.secdns.DelegationSignerData; import google.registry.model.domain.secdns.DelegationSignerData;
import google.registry.model.host.HostResource; import google.registry.model.host.HostResource;
import java.util.Set; import java.util.Set;
import java.util.stream.Stream;
/** Shared base class for {@link DomainResource} and {@link DomainApplication}. */ /** Shared base class for {@link DomainResource} and {@link DomainApplication}. */
@ReportedOn @ReportedOn
@ -134,33 +133,28 @@ public abstract class DomainBase extends EppResource {
/** Loads and returns the fully qualified host names of all linked nameservers. */ /** Loads and returns the fully qualified host names of all linked nameservers. */
public ImmutableSortedSet<String> loadNameserverFullyQualifiedHostNames() { public ImmutableSortedSet<String> loadNameserverFullyQualifiedHostNames() {
return FluentIterable.from(ofy().load().keys(getNameservers()).values()) return ofy()
.transform( .load()
new Function<HostResource, String>() { .keys(getNameservers())
@Override .values()
public String apply(HostResource host) { .stream()
return host.getFullyQualifiedHostName(); .map(HostResource::getFullyQualifiedHostName)
} .collect(toImmutableSortedSet(Ordering.natural()));
})
.toSortedSet(Ordering.natural());
} }
/** A key to the registrant who registered this domain. */ /** A key to the registrant who registered this domain. */
public Key<ContactResource> getRegistrant() { public Key<ContactResource> getRegistrant() {
return FluentIterable return nullToEmpty(allContacts)
.from(nullToEmpty(allContacts)) .stream()
.filter(IS_REGISTRANT) .filter(IS_REGISTRANT)
.first() .findFirst()
.get() .get()
.getContactKey(); .getContactKey();
} }
/** Associated contacts for the domain (other than registrant). */ /** Associated contacts for the domain (other than registrant). */
public ImmutableSet<DesignatedContact> getContacts() { public ImmutableSet<DesignatedContact> getContacts() {
return FluentIterable return nullToEmpty(allContacts).stream().filter(not(IS_REGISTRANT)).collect(toImmutableSet());
.from(nullToEmpty(allContacts))
.filter(not(IS_REGISTRANT))
.toSet();
} }
public DomainAuthInfo getAuthInfo() { public DomainAuthInfo getAuthInfo() {
@ -183,11 +177,7 @@ public abstract class DomainBase extends EppResource {
/** Predicate to determine if a given {@link DesignatedContact} is the registrant. */ /** Predicate to determine if a given {@link DesignatedContact} is the registrant. */
private static final Predicate<DesignatedContact> IS_REGISTRANT = private static final Predicate<DesignatedContact> IS_REGISTRANT =
new Predicate<DesignatedContact>() { (DesignatedContact contact) -> DesignatedContact.Type.REGISTRANT.equals(contact.type);
@Override
public boolean apply(DesignatedContact contact) {
return DesignatedContact.Type.REGISTRANT.equals(contact.type);
}};
/** An override of {@link EppResource#asBuilder} with tighter typing. */ /** An override of {@link EppResource#asBuilder} with tighter typing. */
@Override @Override
@ -208,7 +198,7 @@ public abstract class DomainBase extends EppResource {
T instance = getInstance(); T instance = getInstance();
checkArgumentNotNull( checkArgumentNotNull(
emptyToNull(instance.fullyQualifiedDomainName), "Missing fullyQualifiedDomainName"); emptyToNull(instance.fullyQualifiedDomainName), "Missing fullyQualifiedDomainName");
checkArgument(any(instance.allContacts, IS_REGISTRANT), "Missing registrant"); checkArgument(instance.allContacts.stream().anyMatch(IS_REGISTRANT), "Missing registrant");
instance.tld = getTldFromDomainName(instance.fullyQualifiedDomainName); instance.tld = getTldFromDomainName(instance.fullyQualifiedDomainName);
return super.build(); return super.build();
} }
@ -255,13 +245,13 @@ public abstract class DomainBase extends EppResource {
} }
public B setContacts(ImmutableSet<DesignatedContact> contacts) { public B setContacts(ImmutableSet<DesignatedContact> contacts) {
checkArgument(all(contacts, not(IS_REGISTRANT)), "Registrant cannot be a contact"); checkArgument(contacts.stream().noneMatch(IS_REGISTRANT), "Registrant cannot be a contact");
// Replace the non-registrant contacts inside allContacts. // Replace the non-registrant contacts inside allContacts.
getInstance().allContacts = FluentIterable getInstance().allContacts =
.from(nullToEmpty(getInstance().allContacts)) Stream.concat(
.filter(IS_REGISTRANT) nullToEmpty(getInstance().allContacts).stream().filter(IS_REGISTRANT),
.append(contacts) contacts.stream())
.toSet(); .collect(toImmutableSet());
return thisCastToDerived(); return thisCastToDerived();
} }

View file

@ -27,7 +27,6 @@ import static google.registry.util.CollectionUtils.nullToEmpty;
import static google.registry.util.CollectionUtils.nullToEmptyImmutableCopy; import static google.registry.util.CollectionUtils.nullToEmptyImmutableCopy;
import static google.registry.util.CollectionUtils.union; import static google.registry.util.CollectionUtils.union;
import com.google.common.base.Function;
import com.google.common.base.MoreObjects; import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
@ -458,13 +457,7 @@ public class DomainCommand {
throw new InvalidReferencesException( throw new InvalidReferencesException(
clazz, ImmutableSet.copyOf(difference(foreignKeys, fkis.keySet()))); clazz, ImmutableSet.copyOf(difference(foreignKeys, fkis.keySet())));
} }
return ImmutableMap.copyOf(transformValues( return ImmutableMap.copyOf(transformValues(fkis, ForeignKeyIndex::getResourceKey));
fkis,
new Function<ForeignKeyIndex<T>, Key<T>>() {
@Override
public Key<T> apply(ForeignKeyIndex<T> fki) {
return fki.getResourceKey();
}}));
} }
/** Exception to throw when referenced objects don't exist. */ /** Exception to throw when referenced objects don't exist. */

View file

@ -16,14 +16,12 @@ package google.registry.model.domain.rgp;
import static com.google.common.base.Predicates.equalTo; import static com.google.common.base.Predicates.equalTo;
import static com.google.common.base.Predicates.not; import static com.google.common.base.Predicates.not;
import static java.util.Arrays.asList; import static com.google.common.collect.ImmutableMap.toImmutableMap;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
import google.registry.model.translators.EnumToAttributeAdapter; import google.registry.model.translators.EnumToAttributeAdapter;
import google.registry.model.translators.EnumToAttributeAdapter.EppEnum; import google.registry.model.translators.EnumToAttributeAdapter.EppEnum;
import java.util.stream.Stream;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
@ -101,15 +99,12 @@ public enum GracePeriodStatus implements EppEnum {
/** Provide a quick lookup of GracePeriodStatus from XML name. */ /** Provide a quick lookup of GracePeriodStatus from XML name. */
private static final ImmutableMap<String, GracePeriodStatus> XML_NAME_TO_GRACE_PERIOD_STATUS = private static final ImmutableMap<String, GracePeriodStatus> XML_NAME_TO_GRACE_PERIOD_STATUS =
Maps.uniqueIndex( Stream.of(GracePeriodStatus.values())
// SUNRUSH_ADD isn't a real grace period type visible in EPP XML, so exclude it. .filter(not(equalTo(SUNRUSH_ADD)))
Iterables.filter(asList(GracePeriodStatus.values()), not(equalTo(SUNRUSH_ADD))), .collect(
new Function<GracePeriodStatus, String>() { toImmutableMap(
@Override (GracePeriodStatus gracePeriodStatus) -> gracePeriodStatus.xmlName,
public String apply(GracePeriodStatus gracePeriodStatus) { value -> value));
return gracePeriodStatus.xmlName;
}
});
@XmlAttribute(name = "s") @XmlAttribute(name = "s")
private final String xmlName; private final String xmlName;

View file

@ -14,11 +14,9 @@
package google.registry.model.eppcommon; package google.registry.model.eppcommon;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static com.google.common.collect.Maps.uniqueIndex; import static com.google.common.collect.Maps.uniqueIndex;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import google.registry.model.domain.allocate.AllocateCreateExtension; import google.registry.model.domain.allocate.AllocateCreateExtension;
@ -98,16 +96,9 @@ public class ProtocolDefinition {
} }
/** Converts a service extension enum to its URI. */ /** Converts a service extension enum to its URI. */
private static final Function<ServiceExtension, String> TO_URI_FUNCTION =
new Function<ServiceExtension, String>() {
@Override
public String apply(ServiceExtension serviceExtension) {
return serviceExtension.getUri();
}};
/** This stores a map from URI back to the service extension enum. */ /** This stores a map from URI back to the service extension enum. */
private static final ImmutableMap<String, ServiceExtension> serviceExtensionByUri = private static final ImmutableMap<String, ServiceExtension> serviceExtensionByUri =
uniqueIndex(EnumSet.allOf(ServiceExtension.class), TO_URI_FUNCTION); uniqueIndex(EnumSet.allOf(ServiceExtension.class), ServiceExtension::getUri);
/** Returns the service extension enum associated with a URI, or null if none are associated. */ /** Returns the service extension enum associated with a URI, or null if none are associated. */
public static ServiceExtension getServiceExtensionFromUri(String uri) { public static ServiceExtension getServiceExtensionFromUri(String uri) {
@ -116,16 +107,11 @@ public class ProtocolDefinition {
/** A set of all the visible extension URIs. */ /** A set of all the visible extension URIs. */
private static final ImmutableSet<String> visibleServiceExtensionUris = private static final ImmutableSet<String> visibleServiceExtensionUris =
FluentIterable.from(EnumSet.allOf(ServiceExtension.class)) EnumSet.allOf(ServiceExtension.class)
.filter( .stream()
new Predicate<ServiceExtension>() { .filter(ServiceExtension::getVisible)
@Override .map(ServiceExtension::getUri)
public boolean apply(ServiceExtension serviceExtension) { .collect(toImmutableSet());
return serviceExtension.getVisible();
}
})
.transform(TO_URI_FUNCTION)
.toSet();
/** Return the set of all visible service extension URIs. */ /** Return the set of all visible service extension URIs. */
public static ImmutableSet<String> getVisibleServiceExtensionUris() { public static ImmutableSet<String> getVisibleServiceExtensionUris() {

View file

@ -19,7 +19,6 @@ import static google.registry.util.CollectionUtils.nullToEmptyImmutableCopy;
import com.google.common.base.Ascii; import com.google.common.base.Ascii;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import google.registry.model.ImmutableObject; import google.registry.model.ImmutableObject;
@ -153,7 +152,13 @@ public class EppInput extends ImmutableObject {
/** Get the extension based on type, or null. If there are multiple, it chooses the first. */ /** Get the extension based on type, or null. If there are multiple, it chooses the first. */
@Nullable @Nullable
public <E extends CommandExtension> E getSingleExtension(Class<E> clazz) { public <E extends CommandExtension> E getSingleExtension(Class<E> clazz) {
return FluentIterable.from(getCommandWrapper().getExtensions()).filter(clazz).first().orNull(); return getCommandWrapper()
.getExtensions()
.stream()
.filter(clazz::isInstance)
.map(clazz::cast)
.findFirst()
.orElse(null);
} }
/** A tag that goes inside of an EPP {@literal <command>}. */ /** A tag that goes inside of an EPP {@literal <command>}. */

View file

@ -17,7 +17,7 @@ package google.registry.model.eppoutput;
import static google.registry.util.CollectionUtils.forceEmptyToNull; import static google.registry.util.CollectionUtils.forceEmptyToNull;
import static google.registry.util.CollectionUtils.nullToEmptyImmutableCopy; import static google.registry.util.CollectionUtils.nullToEmptyImmutableCopy;
import com.google.common.collect.FluentIterable; import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import google.registry.model.Buildable; import google.registry.model.Buildable;
import google.registry.model.ImmutableObject; import google.registry.model.ImmutableObject;
@ -157,7 +157,9 @@ public class EppResponse extends ImmutableObject implements ResponseOrGreeting {
@Nullable @Nullable
public ResponseExtension getFirstExtensionOfType(Class<? extends ResponseExtension> clazz) { public ResponseExtension getFirstExtensionOfType(Class<? extends ResponseExtension> clazz) {
return FluentIterable.from(extensions).filter(clazz).first().orNull(); return Optional.fromJavaUtil(
extensions.stream().filter(clazz::isInstance).map(clazz::cast).findFirst())
.orNull();
} }
@Nullable @Nullable

View file

@ -18,7 +18,6 @@ import static com.google.common.collect.Maps.filterValues;
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.util.TypeUtils.instantiate; import static google.registry.util.TypeUtils.instantiate;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.googlecode.objectify.Key; import com.googlecode.objectify.Key;
@ -166,10 +165,6 @@ public abstract class ForeignKeyIndex<E extends EppResource> extends BackupGroup
Class<E> clazz, Iterable<String> foreignKeys, final DateTime now) { Class<E> clazz, Iterable<String> foreignKeys, final DateTime now) {
return filterValues( return filterValues(
ofy().load().type(mapToFkiClass(clazz)).ids(foreignKeys), ofy().load().type(mapToFkiClass(clazz)).ids(foreignKeys),
new Predicate<ForeignKeyIndex<?>>() { (ForeignKeyIndex<?> fki) -> now.isBefore(fki.deletionTime));
@Override
public boolean apply(ForeignKeyIndex<?> fki) {
return now.isBefore(fki.deletionTime);
}});
} }
} }

View file

@ -16,14 +16,13 @@ package google.registry.model.ofy;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.collect.DiscreteDomain.integers; import static com.google.common.collect.DiscreteDomain.integers;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static google.registry.config.RegistryConfig.getCommitLogBucketCount; import static google.registry.config.RegistryConfig.getCommitLogBucketCount;
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.util.DateTimeUtils.START_OF_TIME; import static google.registry.util.DateTimeUtils.START_OF_TIME;
import com.google.common.base.Function;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.collect.ContiguousSet; import com.google.common.collect.ContiguousSet;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedSet; import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.Range; import com.google.common.collect.Range;
@ -137,13 +136,10 @@ public class CommitLogBucket extends ImmutableObject implements Buildable {
/** Returns all commit log bucket keys, in ascending order by bucket ID. */ /** Returns all commit log bucket keys, in ascending order by bucket ID. */
public static ImmutableSet<Key<CommitLogBucket>> getAllBucketKeys() { public static ImmutableSet<Key<CommitLogBucket>> getAllBucketKeys() {
return FluentIterable.from(getBucketIds()) return getBucketIds()
.transform(new Function<Integer, Key<CommitLogBucket>>() { .stream()
@Override .map(CommitLogBucket::getBucketKeyUnsafe)
public Key<CommitLogBucket> apply(Integer bucketId) { .collect(toImmutableSet());
return getBucketKeyUnsafe(bucketId);
}})
.toSet();
} }
@Override @Override

View file

@ -17,6 +17,7 @@ package google.registry.model.ofy;
import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Preconditions.checkState;
import static com.google.common.base.Predicates.in; import static com.google.common.base.Predicates.in;
import static com.google.common.base.Predicates.not; import static com.google.common.base.Predicates.not;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static com.google.common.collect.Maps.filterKeys; import static com.google.common.collect.Maps.filterKeys;
import static com.google.common.collect.Sets.difference; import static com.google.common.collect.Sets.difference;
import static com.google.common.collect.Sets.union; import static com.google.common.collect.Sets.union;
@ -25,7 +26,6 @@ import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.util.DateTimeUtils.isBeforeOrAt; import static google.registry.util.DateTimeUtils.isBeforeOrAt;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.googlecode.objectify.Key; import com.googlecode.objectify.Key;
@ -150,14 +150,13 @@ class CommitLoggedWork<R> extends VoidWork {
ImmutableSet.copyOf(filterKeys(rootsForTouchedKeys, not(in(touchedKeys))).values()); ImmutableSet.copyOf(filterKeys(rootsForTouchedKeys, not(in(touchedKeys))).values());
manifest = CommitLogManifest.create(info.bucketKey, info.transactionTime, info.getDeletes()); manifest = CommitLogManifest.create(info.bucketKey, info.transactionTime, info.getDeletes());
final Key<CommitLogManifest> manifestKey = Key.create(manifest); final Key<CommitLogManifest> manifestKey = Key.create(manifest);
mutations = FluentIterable mutations =
.from(union(info.getSaves(), untouchedRootsWithTouchedChildren)) union(info.getSaves(), untouchedRootsWithTouchedChildren)
.transform(new Function<Object, ImmutableObject>() { .stream()
@Override .map(
public CommitLogMutation apply(Object saveEntity) { (Function<Object, ImmutableObject>)
return CommitLogMutation.create(manifestKey, saveEntity); (Object saveEntity) -> CommitLogMutation.create(manifestKey, saveEntity))
}}) .collect(toImmutableSet());
.toSet();
ofy().saveWithoutBackup() ofy().saveWithoutBackup()
.entities(new ImmutableSet.Builder<>() .entities(new ImmutableSet.Builder<>()
.add(manifest) .add(manifest)

View file

@ -29,7 +29,7 @@ import com.google.appengine.api.taskqueue.TransientFailureException;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables; import com.google.common.collect.Streams;
import com.googlecode.objectify.Key; import com.googlecode.objectify.Key;
import com.googlecode.objectify.Objectify; import com.googlecode.objectify.Objectify;
import com.googlecode.objectify.ObjectifyFactory; import com.googlecode.objectify.ObjectifyFactory;
@ -136,7 +136,7 @@ public class Ofy {
@Override @Override
protected void handleDeletion(Iterable<Key<?>> keys) { protected void handleDeletion(Iterable<Key<?>> keys) {
assertInTransaction(); assertInTransaction();
checkState(Iterables.all(keys, notNull()), "Can't delete a null key."); checkState(Streams.stream(keys).allMatch(notNull()), "Can't delete a null key.");
checkProhibitedAnnotations(keys, NotBackedUp.class, VirtualEntity.class); checkProhibitedAnnotations(keys, NotBackedUp.class, VirtualEntity.class);
TRANSACTION_INFO.get().putDeletes(keys); TRANSACTION_INFO.get().putDeletes(keys);
} }
@ -168,7 +168,7 @@ public class Ofy {
@Override @Override
protected void handleSave(Iterable<?> entities) { protected void handleSave(Iterable<?> entities) {
assertInTransaction(); assertInTransaction();
checkState(Iterables.all(entities, notNull()), "Can't save a null entity."); checkState(Streams.stream(entities).allMatch(notNull()), "Can't save a null entity.");
checkProhibitedAnnotations(entities, NotBackedUp.class, VirtualEntity.class); checkProhibitedAnnotations(entities, NotBackedUp.class, VirtualEntity.class);
ImmutableMap<Key<?>, ?> keysToEntities = uniqueIndex(entities, OBJECTS_TO_KEYS); ImmutableMap<Key<?>, ?> keysToEntities = uniqueIndex(entities, OBJECTS_TO_KEYS);
TRANSACTION_INFO.get().putSaves(keysToEntities); TRANSACTION_INFO.get().putSaves(keysToEntities);

View file

@ -15,7 +15,6 @@
package google.registry.model.ofy; package google.registry.model.ofy;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import com.google.common.base.Predicate;
import com.google.common.collect.FluentIterable; import com.google.common.collect.FluentIterable;
import com.googlecode.objectify.Key; import com.googlecode.objectify.Key;
import com.googlecode.objectify.Objectify; import com.googlecode.objectify.Objectify;
@ -43,17 +42,20 @@ class TimestampInversionException extends RuntimeException {
} }
private TimestampInversionException(DateTime transactionTime, String problem) { private TimestampInversionException(DateTime transactionTime, String problem) {
super(Joiner.on('\n').join( super(
Joiner.on('\n')
.join(
String.format( String.format(
"Timestamp inversion between transaction time (%s) and %s", "Timestamp inversion between transaction time (%s) and %s",
transactionTime, transactionTime, problem),
problem), getFileAndLine(
getFileAndLine(FluentIterable.from(new Exception().getStackTrace()) FluentIterable.from(new Exception().getStackTrace())
.firstMatch(new Predicate<StackTraceElement>() { .firstMatch(
@Override (StackTraceElement element) ->
public boolean apply(StackTraceElement element) { !element
return !element.getClassName().startsWith(Objectify.class.getPackage().getName()) .getClassName()
&& !element.getClassName().startsWith(Ofy.class.getName()); .startsWith(Objectify.class.getPackage().getName())
}}).get()))); && !element.getClassName().startsWith(Ofy.class.getName()))
.get())));
} }
} }

View file

@ -16,6 +16,7 @@ package google.registry.model.ofy;
import static com.google.common.base.Functions.constant; import static com.google.common.base.Functions.constant;
import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Preconditions.checkState;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static com.google.common.collect.Maps.filterValues; import static com.google.common.collect.Maps.filterValues;
import static com.google.common.collect.Maps.toMap; import static com.google.common.collect.Maps.toMap;
import static google.registry.model.ofy.CommitLogBucket.getArbitraryBucketId; import static google.registry.model.ofy.CommitLogBucket.getArbitraryBucketId;
@ -23,7 +24,6 @@ import static google.registry.model.ofy.ObjectifyService.ofy;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.base.Predicates; import com.google.common.base.Predicates;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.googlecode.objectify.Key; import com.googlecode.objectify.Key;
@ -88,9 +88,11 @@ class TransactionInfo {
} }
ImmutableSet<Object> getSaves() { ImmutableSet<Object> getSaves() {
return FluentIterable return changesBuilder
.from(changesBuilder.build().values()) .build()
.values()
.stream()
.filter(Predicates.not(IS_DELETE)) .filter(Predicates.not(IS_DELETE))
.toSet(); .collect(toImmutableSet());
} }
} }

View file

@ -14,6 +14,7 @@
package google.registry.model.poll; package google.registry.model.poll;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static google.registry.util.CollectionUtils.forceEmptyToNull; import static google.registry.util.CollectionUtils.forceEmptyToNull;
import static google.registry.util.CollectionUtils.nullToEmpty; import static google.registry.util.CollectionUtils.nullToEmpty;
import static google.registry.util.DateTimeUtils.END_OF_TIME; import static google.registry.util.DateTimeUtils.END_OF_TIME;
@ -24,6 +25,7 @@ import com.google.common.base.Converter;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import com.google.common.collect.FluentIterable; import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.Streams;
import com.googlecode.objectify.Key; import com.googlecode.objectify.Key;
import com.googlecode.objectify.annotation.Entity; import com.googlecode.objectify.annotation.Entity;
import com.googlecode.objectify.annotation.EntitySubclass; import com.googlecode.objectify.annotation.EntitySubclass;
@ -235,26 +237,48 @@ public abstract class PollMessage extends ImmutableObject
public Builder setResponseData(ImmutableList<? extends ResponseData> responseData) { public Builder setResponseData(ImmutableList<? extends ResponseData> responseData) {
FluentIterable<? extends ResponseData> iterable = FluentIterable.from(responseData); FluentIterable<? extends ResponseData> iterable = FluentIterable.from(responseData);
getInstance().contactPendingActionNotificationResponses = forceEmptyToNull( getInstance().contactPendingActionNotificationResponses =
iterable.filter(ContactPendingActionNotificationResponse.class).toList()); forceEmptyToNull(
getInstance().contactTransferResponses = forceEmptyToNull( Streams.stream(iterable)
iterable.filter(ContactTransferResponse.class).toList()); .filter(ContactPendingActionNotificationResponse.class::isInstance)
getInstance().domainPendingActionNotificationResponses = forceEmptyToNull( .map(ContactPendingActionNotificationResponse.class::cast)
iterable.filter(DomainPendingActionNotificationResponse.class).toList()); .collect(toImmutableList()));
getInstance().domainTransferResponses = forceEmptyToNull( getInstance().contactTransferResponses =
iterable.filter(DomainTransferResponse.class).toList()); forceEmptyToNull(
getInstance().hostPendingActionNotificationResponses = forceEmptyToNull( Streams.stream(iterable)
iterable.filter(HostPendingActionNotificationResponse.class).toList()); .filter(ContactTransferResponse.class::isInstance)
.map(ContactTransferResponse.class::cast)
.collect(toImmutableList()));
getInstance().domainPendingActionNotificationResponses =
forceEmptyToNull(
Streams.stream(iterable)
.filter(DomainPendingActionNotificationResponse.class::isInstance)
.map(DomainPendingActionNotificationResponse.class::cast)
.collect(toImmutableList()));
getInstance().domainTransferResponses =
forceEmptyToNull(
Streams.stream(iterable)
.filter(DomainTransferResponse.class::isInstance)
.map(DomainTransferResponse.class::cast)
.collect(toImmutableList()));
getInstance().hostPendingActionNotificationResponses =
forceEmptyToNull(
Streams.stream(iterable)
.filter(HostPendingActionNotificationResponse.class::isInstance)
.map(HostPendingActionNotificationResponse.class::cast)
.collect(toImmutableList()));
return this; return this;
} }
public Builder setResponseExtensions( public Builder setResponseExtensions(
ImmutableList<? extends ResponseExtension> responseExtensions) { ImmutableList<? extends ResponseExtension> responseExtensions) {
getInstance().launchInfoResponseExtension = FluentIterable getInstance().launchInfoResponseExtension =
.from(responseExtensions) responseExtensions
.filter(LaunchInfoResponseExtension.class) .stream()
.first() .filter(LaunchInfoResponseExtension.class::isInstance)
.orNull(); .map(LaunchInfoResponseExtension.class::cast)
.findFirst()
.orElse(null);
return this; return this;
} }
} }

View file

@ -21,6 +21,7 @@ import static com.google.common.base.Predicates.in;
import static com.google.common.base.Predicates.notNull; import static com.google.common.base.Predicates.notNull;
import static com.google.common.base.Strings.emptyToNull; import static com.google.common.base.Strings.emptyToNull;
import static com.google.common.base.Strings.nullToEmpty; import static com.google.common.base.Strings.nullToEmpty;
import static com.google.common.collect.ImmutableSortedSet.toImmutableSortedSet;
import static com.google.common.collect.Sets.immutableEnumSet; import static com.google.common.collect.Sets.immutableEnumSet;
import static com.google.common.io.BaseEncoding.base64; import static com.google.common.io.BaseEncoding.base64;
import static google.registry.config.RegistryConfig.getDefaultRegistrarReferralUrl; import static google.registry.config.RegistryConfig.getDefaultRegistrarReferralUrl;
@ -35,13 +36,13 @@ import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
import static google.registry.util.X509Utils.getCertificateHash; import static google.registry.util.X509Utils.getCertificateHash;
import static google.registry.util.X509Utils.loadCertificate; import static google.registry.util.X509Utils.loadCertificate;
import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Comparator.comparing;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.base.Predicates; import com.google.common.base.Predicates;
import com.google.common.base.Strings; import com.google.common.base.Strings;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
@ -50,6 +51,7 @@ import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.Ordering; import com.google.common.collect.Ordering;
import com.google.common.collect.Range; import com.google.common.collect.Range;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.google.common.collect.Streams;
import com.google.re2j.Pattern; import com.google.re2j.Pattern;
import com.googlecode.objectify.Key; import com.googlecode.objectify.Key;
import com.googlecode.objectify.Work; import com.googlecode.objectify.Work;
@ -193,12 +195,9 @@ public class Registrar extends ImmutableObject implements Buildable, Jsonifiable
* Compare two instances of {@link RegistrarContact} by their email addresses lexicographically. * Compare two instances of {@link RegistrarContact} by their email addresses lexicographically.
*/ */
private static final Comparator<RegistrarContact> CONTACT_EMAIL_COMPARATOR = private static final Comparator<RegistrarContact> CONTACT_EMAIL_COMPARATOR =
new Comparator<RegistrarContact>() { comparing(
@Override (RegistrarContact arg) -> arg.getEmailAddress(),
public int compare(RegistrarContact rc1, RegistrarContact rc2) { (String leftProperty, String rightProperty) -> leftProperty.compareTo(rightProperty));
return rc1.getEmailAddress().compareTo(rc2.getEmailAddress());
}
};
/** /**
* A caching {@link Supplier} of a clientId to {@link Registrar} map. * A caching {@link Supplier} of a clientId to {@link Registrar} map.
@ -207,19 +206,21 @@ public class Registrar extends ImmutableObject implements Buildable, Jsonifiable
* query inside an unrelated client-affecting transaction. * query inside an unrelated client-affecting transaction.
*/ */
private static final Supplier<ImmutableMap<String, Registrar>> CACHE_BY_CLIENT_ID = private static final Supplier<ImmutableMap<String, Registrar>> CACHE_BY_CLIENT_ID =
memoizeWithShortExpiration(new Supplier<ImmutableMap<String, Registrar>>() { memoizeWithShortExpiration(
@Override () ->
public ImmutableMap<String, Registrar> get() { ofy()
return ofy().doTransactionless(new Work<ImmutableMap<String, Registrar>>() { .doTransactionless(
new Work<ImmutableMap<String, Registrar>>() {
@Override @Override
public ImmutableMap<String, Registrar> run() { public ImmutableMap<String, Registrar> run() {
ImmutableMap.Builder<String, Registrar> builder = new ImmutableMap.Builder<>(); ImmutableMap.Builder<String, Registrar> builder =
new ImmutableMap.Builder<>();
for (Registrar registrar : loadAll()) { for (Registrar registrar : loadAll()) {
builder.put(registrar.getClientId(), registrar); builder.put(registrar.getClientId(), registrar);
} }
return builder.build(); return builder.build();
}}); }
}}); }));
@Parent @Parent
Key<EntityGroupRoot> parent = getCrossTldKey(); Key<EntityGroupRoot> parent = getCrossTldKey();
@ -421,14 +422,13 @@ public class Registrar extends ImmutableObject implements Buildable, Jsonifiable
BillingMethod billingMethod; BillingMethod billingMethod;
@NonFinalForTesting @NonFinalForTesting
private static Supplier<byte[]> saltSupplier = new Supplier<byte[]>() { private static Supplier<byte[]> saltSupplier =
@Override () -> {
public byte[] get() {
// There are 32 bytes in a sha-256 hash, and the salt should generally be the same size. // There are 32 bytes in a sha-256 hash, and the salt should generally be the same size.
byte[] salt = new byte[32]; byte[] salt = new byte[32];
new SecureRandom().nextBytes(salt); new SecureRandom().nextBytes(salt);
return salt; return salt;
}}; };
public String getClientId() { public String getClientId() {
return clientIdentifier; return clientIdentifier;
@ -576,9 +576,9 @@ public class Registrar extends ImmutableObject implements Buildable, Jsonifiable
* address. * address.
*/ */
public ImmutableSortedSet<RegistrarContact> getContacts() { public ImmutableSortedSet<RegistrarContact> getContacts() {
return FluentIterable.from(getContactsIterable()) return Streams.stream(getContactsIterable())
.filter(notNull()) .filter(notNull())
.toSortedSet(CONTACT_EMAIL_COMPARATOR); .collect(toImmutableSortedSet(CONTACT_EMAIL_COMPARATOR));
} }
/** /**
@ -586,16 +586,10 @@ public class Registrar extends ImmutableObject implements Buildable, Jsonifiable
* their email address. * their email address.
*/ */
public ImmutableSortedSet<RegistrarContact> getContactsOfType(final RegistrarContact.Type type) { public ImmutableSortedSet<RegistrarContact> getContactsOfType(final RegistrarContact.Type type) {
return FluentIterable.from(getContactsIterable()) return Streams.stream(getContactsIterable())
.filter(notNull()) .filter(notNull())
.filter( .filter((@Nullable RegistrarContact contact) -> contact.getTypes().contains(type))
new Predicate<RegistrarContact>() { .collect(toImmutableSortedSet(CONTACT_EMAIL_COMPARATOR));
@Override
public boolean apply(@Nullable RegistrarContact contact) {
return contact.getTypes().contains(type);
}
})
.toSortedSet(CONTACT_EMAIL_COMPARATOR);
} }
private Iterable<RegistrarContact> getContactsIterable() { private Iterable<RegistrarContact> getContactsIterable() {

View file

@ -16,17 +16,17 @@ package google.registry.model.registrar;
import static com.google.common.base.Functions.toStringFunction; import static com.google.common.base.Functions.toStringFunction;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Iterables.transform; import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static com.google.common.collect.Sets.difference; import static com.google.common.collect.Sets.difference;
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.util.CollectionUtils.nullToEmptyImmutableSortedCopy; import static google.registry.util.CollectionUtils.nullToEmptyImmutableSortedCopy;
import static google.registry.util.ObjectifyUtils.OBJECTS_TO_KEYS; import static google.registry.util.ObjectifyUtils.OBJECTS_TO_KEYS;
import static java.util.stream.Collectors.joining;
import com.google.common.base.Enums; import com.google.common.base.Enums;
import com.google.common.base.Joiner;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedSet; import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.Streams;
import com.googlecode.objectify.Key; import com.googlecode.objectify.Key;
import com.googlecode.objectify.VoidWork; import com.googlecode.objectify.VoidWork;
import com.googlecode.objectify.annotation.Entity; import com.googlecode.objectify.annotation.Entity;
@ -141,7 +141,9 @@ public class RegistrarContact extends ImmutableObject implements Jsonifiable {
} }
public static ImmutableSet<Type> typesFromStrings(Iterable<String> typeNames) { public static ImmutableSet<Type> typesFromStrings(Iterable<String> typeNames) {
return FluentIterable.from(typeNames).transform(Enums.stringConverter(Type.class)).toSet(); return Streams.stream(typeNames)
.map(Enums.stringConverter(Type.class))
.collect(toImmutableSet());
} }
/** /**
@ -154,15 +156,25 @@ public class RegistrarContact extends ImmutableObject implements Jsonifiable {
*/ */
public static void updateContacts( public static void updateContacts(
final Registrar registrar, final Set<RegistrarContact> contacts) { final Registrar registrar, final Set<RegistrarContact> contacts) {
ofy().transact(new VoidWork() { ofy()
.transact(
new VoidWork() {
@Override @Override
public void vrun() { public void vrun() {
ofy().delete().keys(difference( ofy()
.delete()
.keys(
difference(
ImmutableSet.copyOf( ImmutableSet.copyOf(
ofy().load().type(RegistrarContact.class).ancestor(registrar).keys()), ofy()
FluentIterable.from(contacts).transform(OBJECTS_TO_KEYS).toSet())); .load()
.type(RegistrarContact.class)
.ancestor(registrar)
.keys()),
contacts.stream().map(OBJECTS_TO_KEYS).collect(toImmutableSet())));
ofy().save().entities(contacts); ofy().save().entities(contacts);
}}); }
});
} }
public Key<Registrar> getParent() { public Key<Registrar> getParent() {
@ -260,7 +272,7 @@ public class RegistrarContact extends ImmutableObject implements Jsonifiable {
.put("emailAddress", emailAddress) .put("emailAddress", emailAddress)
.put("phoneNumber", phoneNumber) .put("phoneNumber", phoneNumber)
.put("faxNumber", faxNumber) .put("faxNumber", faxNumber)
.put("types", Joiner.on(',').join(transform(getTypes(), toStringFunction()))) .put("types", getTypes().stream().map(toStringFunction()).collect(joining(",")))
.put("visibleInWhoisAsAdmin", visibleInWhoisAsAdmin) .put("visibleInWhoisAsAdmin", visibleInWhoisAsAdmin)
.put("visibleInWhoisAsTech", visibleInWhoisAsTech) .put("visibleInWhoisAsTech", visibleInWhoisAsTech)
.put("visibleInDomainWhoisAsAbuse", visibleInDomainWhoisAsAbuse) .put("visibleInDomainWhoisAsAbuse", visibleInDomainWhoisAsAbuse)

View file

@ -19,6 +19,7 @@ import static com.google.common.base.Predicates.equalTo;
import static com.google.common.base.Predicates.in; import static com.google.common.base.Predicates.in;
import static com.google.common.base.Predicates.not; import static com.google.common.base.Predicates.not;
import static com.google.common.base.Strings.emptyToNull; import static com.google.common.base.Strings.emptyToNull;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static com.google.common.collect.Maps.filterValues; import static com.google.common.collect.Maps.filterValues;
import static google.registry.model.CacheUtils.memoizeWithShortExpiration; import static google.registry.model.CacheUtils.memoizeWithShortExpiration;
import static google.registry.model.common.EntityGroupRoot.getCrossTldKey; import static google.registry.model.common.EntityGroupRoot.getCrossTldKey;
@ -28,9 +29,9 @@ import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Streams;
import com.google.common.net.InternetDomainName; import com.google.common.net.InternetDomainName;
import com.googlecode.objectify.Work; import com.googlecode.objectify.Work;
import google.registry.model.registry.Registry.TldType; import google.registry.model.registry.Registry.TldType;
@ -50,19 +51,22 @@ public final class Registries {
* query inside an unrelated client-affecting transaction. * query inside an unrelated client-affecting transaction.
*/ */
private static Supplier<ImmutableMap<String, TldType>> createFreshCache() { private static Supplier<ImmutableMap<String, TldType>> createFreshCache() {
return memoizeWithShortExpiration(new Supplier<ImmutableMap<String, TldType>>() { return memoizeWithShortExpiration(
@Override () ->
public ImmutableMap<String, TldType> get() { ofy()
return ofy().doTransactionless(new Work<ImmutableMap<String, TldType>>() { .doTransactionless(
new Work<ImmutableMap<String, TldType>>() {
@Override @Override
public ImmutableMap<String, TldType> run() { public ImmutableMap<String, TldType> run() {
ImmutableMap.Builder<String, TldType> builder = new ImmutableMap.Builder<>(); ImmutableMap.Builder<String, TldType> builder =
for (Registry registry : ofy().load().type(Registry.class).ancestor(getCrossTldKey())) { new ImmutableMap.Builder<>();
for (Registry registry :
ofy().load().type(Registry.class).ancestor(getCrossTldKey())) {
builder.put(registry.getTldStr(), registry.getTldType()); builder.put(registry.getTldStr(), registry.getTldType());
} }
return builder.build(); return builder.build();
}}); }
}}); }));
} }
/** Manually reset the static cache backing the methods on this class. */ /** Manually reset the static cache backing the methods on this class. */
@ -93,7 +97,8 @@ public final class Registries {
for (String tld : tlds) { for (String tld : tlds) {
checkArgumentNotNull(emptyToNull(tld), "Null or empty TLD specified"); checkArgumentNotNull(emptyToNull(tld), "Null or empty TLD specified");
} }
ImmutableSet<String> badTlds = FluentIterable.from(tlds).filter(not(in(getTlds()))).toSet(); ImmutableSet<String> badTlds =
Streams.stream(tlds).filter(not(in(getTlds()))).collect(toImmutableSet());
checkArgument(badTlds.isEmpty(), "TLDs do not exist: %s", Joiner.on(", ").join(badTlds)); checkArgument(badTlds.isEmpty(), "TLDs do not exist: %s", Joiner.on(", ").join(badTlds));
return tlds; return tlds;
} }

View file

@ -18,6 +18,7 @@ import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Predicates.equalTo; import static com.google.common.base.Predicates.equalTo;
import static com.google.common.base.Predicates.not; import static com.google.common.base.Predicates.not;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static google.registry.config.RegistryConfig.getSingletonCacheRefreshDuration; import static google.registry.config.RegistryConfig.getSingletonCacheRefreshDuration;
import static google.registry.model.common.EntityGroupRoot.getCrossTldKey; import static google.registry.model.common.EntityGroupRoot.getCrossTldKey;
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
@ -34,7 +35,6 @@ import com.google.common.base.Predicate;
import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader; import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache; import com.google.common.cache.LoadingCache;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedMap; import com.google.common.collect.ImmutableSortedMap;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
@ -799,15 +799,12 @@ public class Registry extends ImmutableObject implements Buildable {
} }
} }
ImmutableSet<Entry<String, Collection<String>>> conflicts = ImmutableSet<Entry<String, Collection<String>>> conflicts =
FluentIterable.from(allAuthCodes.asMap().entrySet()) allAuthCodes
.filter( .asMap()
new Predicate<Entry<String, Collection<String>>>() { .entrySet()
@Override .stream()
public boolean apply(Entry<String, Collection<String>> entry) { .filter((Entry<String, Collection<String>> entry) -> entry.getValue().size() > 1)
return entry.getValue().size() > 1; .collect(toImmutableSet());
}
})
.toSet();
checkArgument( checkArgument(
conflicts.isEmpty(), conflicts.isEmpty(),
"Cannot set reserved lists because of auth code conflicts for labels: %s", "Cannot set reserved lists because of auth code conflicts for labels: %s",
@ -837,14 +834,7 @@ public class Registry extends ImmutableObject implements Buildable {
ImmutableSortedMap<DateTime, Money> renewCostsMap) { ImmutableSortedMap<DateTime, Money> renewCostsMap) {
checkArgumentNotNull(renewCostsMap, "Renew billing costs map cannot be null"); checkArgumentNotNull(renewCostsMap, "Renew billing costs map cannot be null");
checkArgument( checkArgument(
Iterables.all( renewCostsMap.values().stream().allMatch(Money::isPositiveOrZero),
renewCostsMap.values(),
new Predicate<Money>() {
@Override
public boolean apply(Money amount) {
return amount.isPositiveOrZero();
}
}),
"Renew billing cost cannot be negative"); "Renew billing cost cannot be negative");
getInstance().renewBillingCostTransitions = getInstance().renewBillingCostTransitions =
TimedTransitionProperty.fromValueMap(renewCostsMap, BillingCostTransition.class); TimedTransitionProperty.fromValueMap(renewCostsMap, BillingCostTransition.class);
@ -855,14 +845,7 @@ public class Registry extends ImmutableObject implements Buildable {
public Builder setEapFeeSchedule(ImmutableSortedMap<DateTime, Money> eapFeeSchedule) { public Builder setEapFeeSchedule(ImmutableSortedMap<DateTime, Money> eapFeeSchedule) {
checkArgumentNotNull(eapFeeSchedule, "EAP schedule map cannot be null"); checkArgumentNotNull(eapFeeSchedule, "EAP schedule map cannot be null");
checkArgument( checkArgument(
Iterables.all( eapFeeSchedule.values().stream().allMatch(Money::isPositiveOrZero),
eapFeeSchedule.values(),
new Predicate<Money>() {
@Override
public boolean apply(Money amount) {
return amount.isPositiveOrZero();
}
}),
"EAP fee cannot be negative"); "EAP fee cannot be negative");
getInstance().eapFeeSchedule = getInstance().eapFeeSchedule =
TimedTransitionProperty.fromValueMap(eapFeeSchedule, BillingCostTransition.class); TimedTransitionProperty.fromValueMap(eapFeeSchedule, BillingCostTransition.class);
@ -939,17 +922,12 @@ public class Registry extends ImmutableObject implements Buildable {
instance.getServerStatusChangeCost().getCurrencyUnit().equals(instance.currency), instance.getServerStatusChangeCost().getCurrencyUnit().equals(instance.currency),
"Server status change cost must be in the registry's currency"); "Server status change cost must be in the registry's currency");
Predicate<Money> currencyCheck = Predicate<Money> currencyCheck =
new Predicate<Money>() { (Money money) -> money.getCurrencyUnit().equals(instance.currency);
@Override
public boolean apply(Money money) {
return money.getCurrencyUnit().equals(instance.currency);
}
};
checkArgument( checkArgument(
Iterables.all(instance.getRenewBillingCostTransitions().values(), currencyCheck), instance.getRenewBillingCostTransitions().values().stream().allMatch(currencyCheck),
"Renew cost must be in the registry's currency"); "Renew cost must be in the registry's currency");
checkArgument( checkArgument(
Iterables.all(instance.eapFeeSchedule.toValueMap().values(), currencyCheck), instance.eapFeeSchedule.toValueMap().values().stream().allMatch(currencyCheck),
"All EAP fees must be in the registry's currency"); "All EAP fees must be in the registry's currency");
checkArgumentNotNull( checkArgumentNotNull(
instance.pricingEngineClassName, "All registries must have a configured pricing engine"); instance.pricingEngineClassName, "All registries must have a configured pricing engine");

View file

@ -15,6 +15,7 @@
package google.registry.model.registry.label; package google.registry.model.registry.label;
import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Preconditions.checkState;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static com.google.common.collect.Iterables.partition; import static com.google.common.collect.Iterables.partition;
import static google.registry.model.common.EntityGroupRoot.getCrossTldKey; import static google.registry.model.common.EntityGroupRoot.getCrossTldKey;
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
@ -30,12 +31,11 @@ import static org.joda.time.DateTimeZone.UTC;
import com.google.auto.value.AutoValue; import com.google.auto.value.AutoValue;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import com.google.common.cache.CacheLoader.InvalidCacheLoadException; import com.google.common.cache.CacheLoader.InvalidCacheLoadException;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Streams;
import com.googlecode.objectify.Key; import com.googlecode.objectify.Key;
import com.googlecode.objectify.VoidWork; import com.googlecode.objectify.VoidWork;
import com.googlecode.objectify.Work; import com.googlecode.objectify.Work;
@ -202,15 +202,9 @@ public final class PremiumListUtils {
@VisibleForTesting @VisibleForTesting
public static ImmutableSet<PremiumListEntry> parentPremiumListEntriesOnRevision( public static ImmutableSet<PremiumListEntry> parentPremiumListEntriesOnRevision(
Iterable<PremiumListEntry> entries, final Key<PremiumListRevision> revisionKey) { Iterable<PremiumListEntry> entries, final Key<PremiumListRevision> revisionKey) {
return FluentIterable.from(entries) return Streams.stream(entries)
.transform( .map((PremiumListEntry entry) -> entry.asBuilder().setParent(revisionKey).build())
new Function<PremiumListEntry, PremiumListEntry>() { .collect(toImmutableSet());
@Override
public PremiumListEntry apply(PremiumListEntry entry) {
return entry.asBuilder().setParent(revisionKey).build();
}
})
.toSet();
} }
/** Deletes the PremiumList and all of its child entities. */ /** Deletes the PremiumList and all of its child entities. */

View file

@ -17,6 +17,7 @@ package google.registry.model.registry.label;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Preconditions.checkState;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static com.google.common.collect.Iterables.getOnlyElement; import static com.google.common.collect.Iterables.getOnlyElement;
import static google.registry.config.RegistryConfig.getDomainLabelListCacheDuration; import static google.registry.config.RegistryConfig.getDomainLabelListCacheDuration;
import static google.registry.model.common.EntityGroupRoot.getCrossTldKey; import static google.registry.model.common.EntityGroupRoot.getCrossTldKey;
@ -28,14 +29,12 @@ import static google.registry.util.CollectionUtils.nullToEmpty;
import static java.util.concurrent.TimeUnit.MILLISECONDS; import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static org.joda.time.DateTimeZone.UTC; import static org.joda.time.DateTimeZone.UTC;
import com.google.common.base.Function;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import com.google.common.base.Splitter; import com.google.common.base.Splitter;
import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader; import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache; import com.google.common.cache.LoadingCache;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.net.InternetDomainName; import com.google.common.net.InternetDomainName;
@ -217,15 +216,10 @@ public final class ReservedList
if (label.length() == 0) { if (label.length() == 0) {
return ImmutableSet.of(FULLY_BLOCKED); return ImmutableSet.of(FULLY_BLOCKED);
} }
return FluentIterable.from(getReservedListEntries(label, tld)) return getReservedListEntries(label, tld)
.transform( .stream()
new Function<ReservedListEntry, ReservationType>() { .map((ReservedListEntry reservedListEntry) -> reservedListEntry.reservationType)
@Override .collect(toImmutableSet());
public ReservationType apply(ReservedListEntry reservedListEntry) {
return reservedListEntry.reservationType;
}
})
.toSet();
} }
/** /**

View file

@ -25,7 +25,6 @@ import static google.registry.util.DateTimeUtils.START_OF_TIME;
import static google.registry.util.DateTimeUtils.isBeforeOrAt; import static google.registry.util.DateTimeUtils.isBeforeOrAt;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.collect.FluentIterable; import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
@ -93,31 +92,36 @@ public class SignedMarkRevocationList extends ImmutableObject {
* single {@link SignedMarkRevocationList} object. * single {@link SignedMarkRevocationList} object.
*/ */
private static final Supplier<SignedMarkRevocationList> CACHE = private static final Supplier<SignedMarkRevocationList> CACHE =
memoizeWithShortExpiration(new Supplier<SignedMarkRevocationList>() { memoizeWithShortExpiration(
@Override () ->
public SignedMarkRevocationList get() { ofy()
// Open a new transactional read even if we are in a transaction currently. .transactNewReadOnly(
return ofy().transactNewReadOnly(new Work<SignedMarkRevocationList>() { new Work<SignedMarkRevocationList>() {
@Override @Override
public SignedMarkRevocationList run() { public SignedMarkRevocationList run() {
Iterable<SignedMarkRevocationList> shards = ofy() Iterable<SignedMarkRevocationList> shards =
ofy()
.load() .load()
.type(SignedMarkRevocationList.class) .type(SignedMarkRevocationList.class)
.ancestor(getCrossTldKey()); .ancestor(getCrossTldKey());
DateTime creationTime = DateTime creationTime =
isEmpty(shards) isEmpty(shards)
? START_OF_TIME ? START_OF_TIME
: checkNotNull(Iterables.get(shards, 0).creationTime, "creationTime"); : checkNotNull(
ImmutableMap.Builder<String, DateTime> revokes = new ImmutableMap.Builder<>(); Iterables.get(shards, 0).creationTime, "creationTime");
ImmutableMap.Builder<String, DateTime> revokes =
new ImmutableMap.Builder<>();
for (SignedMarkRevocationList shard : shards) { for (SignedMarkRevocationList shard : shards) {
revokes.putAll(shard.revokes); revokes.putAll(shard.revokes);
checkState( checkState(
creationTime.equals(shard.creationTime), creationTime.equals(shard.creationTime),
"Inconsistent creation times: %s vs. %s", creationTime, shard.creationTime); "Inconsistent creation times: %s vs. %s",
creationTime,
shard.creationTime);
} }
return create(creationTime, revokes.build()); return create(creationTime, revokes.build());
}}); }
}}); }));
/** Return a single logical instance that combines all Datastore shards. */ /** Return a single logical instance that combines all Datastore shards. */
public static SignedMarkRevocationList get() { public static SignedMarkRevocationList get() {
@ -154,25 +158,34 @@ public class SignedMarkRevocationList extends ImmutableObject {
/** Save this list to Datastore in sharded form. Returns {@code this}. */ /** Save this list to Datastore in sharded form. Returns {@code this}. */
public SignedMarkRevocationList save() { public SignedMarkRevocationList save() {
ofy().transact(new VoidWork() { ofy()
.transact(
new VoidWork() {
@Override @Override
public void vrun() { public void vrun() {
ofy().deleteWithoutBackup().keys(ofy() ofy()
.deleteWithoutBackup()
.keys(
ofy()
.load() .load()
.type(SignedMarkRevocationList.class) .type(SignedMarkRevocationList.class)
.ancestor(getCrossTldKey()) .ancestor(getCrossTldKey())
.keys()); .keys());
ofy().saveWithoutBackup().entities(FluentIterable ofy()
.from(CollectionUtils.partitionMap(revokes, SHARD_SIZE)) .saveWithoutBackup()
.transform(new Function<ImmutableMap<String, DateTime>, SignedMarkRevocationList>() { .entities(
@Override FluentIterable.from(CollectionUtils.partitionMap(revokes, SHARD_SIZE))
public SignedMarkRevocationList apply(ImmutableMap<String, DateTime> shardRevokes) { .transform(
SignedMarkRevocationList shard = create(creationTime, shardRevokes); (ImmutableMap<String, DateTime> shardRevokes) -> {
SignedMarkRevocationList shard =
create(creationTime, shardRevokes);
shard.id = allocateId(); shard.id = allocateId();
shard.isShard = true; // Avoid the exception in disallowUnshardedSaves(). shard.isShard =
true; // Avoid the exception in disallowUnshardedSaves().
return shard; return shard;
}})); }));
}}); }
});
return this; return this;
} }

View file

@ -23,7 +23,6 @@ import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.util.DateTimeUtils.START_OF_TIME; import static google.registry.util.DateTimeUtils.START_OF_TIME;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.googlecode.objectify.Key; import com.googlecode.objectify.Key;
@ -96,9 +95,7 @@ public class ClaimsListShard extends ImmutableObject {
private static final Retrier LOADER_RETRIER = new Retrier(new SystemSleeper(), 2); private static final Retrier LOADER_RETRIER = new Retrier(new SystemSleeper(), 2);
private static final Callable<ClaimsListShard> LOADER_CALLABLE = private static final Callable<ClaimsListShard> LOADER_CALLABLE =
new Callable<ClaimsListShard>() { () -> {
@Override
public ClaimsListShard call() throws Exception {
// Find the most recent revision. // Find the most recent revision.
Key<ClaimsListRevision> revisionKey = getCurrentRevision(); Key<ClaimsListRevision> revisionKey = getCurrentRevision();
@ -113,10 +110,8 @@ public class ClaimsListShard extends ImmutableObject {
List<ClaimsListShard> shards = List<ClaimsListShard> shards =
Concurrent.transform( Concurrent.transform(
shardKeys, shardKeys,
new Function<Key<ClaimsListShard>, ClaimsListShard>() { (final Key<ClaimsListShard> key) ->
@Override ofy()
public ClaimsListShard apply(final Key<ClaimsListShard> key) {
return ofy()
.transactNewReadOnly( .transactNewReadOnly(
new Work<ClaimsListShard>() { new Work<ClaimsListShard>() {
@Override @Override
@ -127,9 +122,7 @@ public class ClaimsListShard extends ImmutableObject {
"Key not found when loading claims list shards."); "Key not found when loading claims list shards.");
return claimsListShard; return claimsListShard;
} }
}); }));
}
});
// Combine the shards together and return the concatenated ClaimsList. // Combine the shards together and return the concatenated ClaimsList.
if (!shards.isEmpty()) { if (!shards.isEmpty()) {
@ -143,7 +136,6 @@ public class ClaimsListShard extends ImmutableObject {
} }
} }
return create(creationTime, ImmutableMap.copyOf(combinedLabelsToKeys)); return create(creationTime, ImmutableMap.copyOf(combinedLabelsToKeys));
}
}; };
/** /**
@ -152,12 +144,7 @@ public class ClaimsListShard extends ImmutableObject {
*/ */
private static final Supplier<ClaimsListShard> CACHE = private static final Supplier<ClaimsListShard> CACHE =
memoizeWithShortExpiration( memoizeWithShortExpiration(
new Supplier<ClaimsListShard>() { () -> LOADER_RETRIER.callWithRetry(LOADER_CALLABLE, IllegalStateException.class));
@Override
public ClaimsListShard get() {
return LOADER_RETRIER.callWithRetry(LOADER_CALLABLE, IllegalStateException.class);
}
});
public DateTime getCreationTime() { public DateTime getCreationTime() {
return creationTime; return creationTime;
@ -186,11 +173,12 @@ public class ClaimsListShard extends ImmutableObject {
final Key<ClaimsListRevision> parentKey = ClaimsListRevision.createKey(); final Key<ClaimsListRevision> parentKey = ClaimsListRevision.createKey();
// Save the ClaimsList shards in separate transactions. // Save the ClaimsList shards in separate transactions.
Concurrent.transform(CollectionUtils.partitionMap(labelsToKeys, shardSize), Concurrent.transform(
new Function<ImmutableMap<String, String>, ClaimsListShard>() { CollectionUtils.partitionMap(labelsToKeys, shardSize),
@Override (final ImmutableMap<String, String> labelsToKeysShard) ->
public ClaimsListShard apply(final ImmutableMap<String, String> labelsToKeysShard) { ofy()
return ofy().transactNew(new Work<ClaimsListShard>() { .transactNew(
new Work<ClaimsListShard>() {
@Override @Override
public ClaimsListShard run() { public ClaimsListShard run() {
ClaimsListShard shard = create(creationTime, labelsToKeysShard); ClaimsListShard shard = create(creationTime, labelsToKeysShard);
@ -198,8 +186,8 @@ public class ClaimsListShard extends ImmutableObject {
shard.parent = parentKey; shard.parent = parentKey;
ofy().saveWithoutBackup().entity(shard); ofy().saveWithoutBackup().entity(shard);
return shard; return shard;
}}); }
}}); }));
// Persist the new revision, thus causing the newly created shards to go live. // Persist the new revision, thus causing the newly created shards to go live.
ofy().transactNew(new VoidWork() { ofy().transactNew(new VoidWork() {

View file

@ -153,9 +153,7 @@ public class EventMetric extends AbstractMetric<Distribution> {
lock.lock(); lock.lock();
try { try {
if (!values.containsKey(labelValues)) { values.computeIfAbsent(labelValues, k -> new MutableDistribution(distributionFitter));
values.put(labelValues, new MutableDistribution(distributionFitter));
}
values.get(labelValues).add(sample, count); values.get(labelValues).add(sample, count);
valueStartTimestamps.putIfAbsent(labelValues, startTimestamp); valueStartTimestamps.putIfAbsent(labelValues, startTimestamp);

View file

@ -14,7 +14,6 @@
package google.registry.monitoring.metrics; package google.registry.monitoring.metrics;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
@ -57,9 +56,7 @@ final class MetricMetrics {
"Count of Timeseries being pushed to Monitoring API", "Count of Timeseries being pushed to Monitoring API",
"Timeseries Count", "Timeseries Count",
LABELS, LABELS,
new Supplier<ImmutableMap<ImmutableList<String>, Long>>() { () -> {
@Override
public ImmutableMap<ImmutableList<String>, Long> get() {
HashMap<ImmutableList<String>, Long> timeseriesCount = new HashMap<>(); HashMap<ImmutableList<String>, Long> timeseriesCount = new HashMap<>();
for (Metric<?> metric : MetricRegistryImpl.getDefault().getRegisteredMetrics()) { for (Metric<?> metric : MetricRegistryImpl.getDefault().getRegisteredMetrics()) {
@ -77,7 +74,6 @@ final class MetricMetrics {
} }
return ImmutableMap.copyOf(timeseriesCount); return ImmutableMap.copyOf(timeseriesCount);
}
}, },
Long.class); Long.class);

View file

@ -67,15 +67,11 @@ abstract class AbstractMetricSubject<T, S extends AbstractMetricSubject<T, S>>
* Function to convert a metric point to a nice string representation for use in error messages. * Function to convert a metric point to a nice string representation for use in error messages.
*/ */
protected final Function<MetricPoint<T>, String> metricPointConverter = protected final Function<MetricPoint<T>, String> metricPointConverter =
new Function<MetricPoint<T>, String>() { metricPoint ->
@Override String.format(
public String apply(MetricPoint<T> metricPoint) {
return String.format(
"%s => %s", "%s => %s",
Joiner.on(':').join(metricPoint.labelValues()), Joiner.on(':').join(metricPoint.labelValues()),
getMessageRepresentation(metricPoint.value())); getMessageRepresentation(metricPoint.value()));
}
};
protected AbstractMetricSubject(FailureMetadata metadata, Metric<T> actual) { protected AbstractMetricSubject(FailureMetadata metadata, Metric<T> actual) {
super(metadata, checkNotNull(actual)); super(metadata, checkNotNull(actual));

View file

@ -19,7 +19,6 @@ import static com.google.common.truth.Truth.assertAbout;
import com.google.common.collect.BoundType; import com.google.common.collect.BoundType;
import com.google.common.collect.Range; import com.google.common.collect.Range;
import com.google.common.truth.FailureMetadata; import com.google.common.truth.FailureMetadata;
import com.google.common.truth.Subject;
import google.registry.monitoring.metrics.Distribution; import google.registry.monitoring.metrics.Distribution;
import google.registry.monitoring.metrics.Metric; import google.registry.monitoring.metrics.Metric;
import google.registry.monitoring.metrics.MetricPoint; import google.registry.monitoring.metrics.MetricPoint;
@ -48,15 +47,9 @@ public final class DistributionMetricSubject
extends AbstractMetricSubject<Distribution, DistributionMetricSubject> { extends AbstractMetricSubject<Distribution, DistributionMetricSubject> {
/** {@link Subject.Factory} for assertions about {@link Metric<Distribution>} objects. */ /** {@link Subject.Factory} for assertions about {@link Metric<Distribution>} objects. */
private static final Subject.Factory<DistributionMetricSubject, Metric<Distribution>>
SUBJECT_FACTORY =
// The Truth extensibility documentation indicates that the target should be nullable.
(FailureMetadata failureMetadata, @Nullable Metric<Distribution> target) ->
new DistributionMetricSubject(failureMetadata, target);
/** Static assertThat({@link Metric<Distribution>}) shortcut method. */ /** Static assertThat({@link Metric<Distribution>}) shortcut method. */
public static DistributionMetricSubject assertThat(@Nullable Metric<Distribution> metric) { public static DistributionMetricSubject assertThat(@Nullable Metric<Distribution> metric) {
return assertAbout(SUBJECT_FACTORY).that(metric); return assertAbout(DistributionMetricSubject::new).that(metric);
} }
private DistributionMetricSubject(FailureMetadata metadata, Metric<Distribution> actual) { private DistributionMetricSubject(FailureMetadata metadata, Metric<Distribution> actual) {

View file

@ -17,7 +17,6 @@ package google.registry.monitoring.metrics.contrib;
import static com.google.common.truth.Truth.assertAbout; import static com.google.common.truth.Truth.assertAbout;
import com.google.common.truth.FailureMetadata; import com.google.common.truth.FailureMetadata;
import com.google.common.truth.Subject;
import google.registry.monitoring.metrics.Metric; import google.registry.monitoring.metrics.Metric;
import google.registry.monitoring.metrics.MetricPoint; import google.registry.monitoring.metrics.MetricPoint;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -45,14 +44,9 @@ import javax.annotation.Nullable;
public final class LongMetricSubject extends AbstractMetricSubject<Long, LongMetricSubject> { public final class LongMetricSubject extends AbstractMetricSubject<Long, LongMetricSubject> {
/** {@link Subject.Factory} for assertions about {@link Metric<Long>} objects. */ /** {@link Subject.Factory} for assertions about {@link Metric<Long>} objects. */
private static final Subject.Factory<LongMetricSubject, Metric<Long>> SUBJECT_FACTORY =
// The Truth extensibility documentation indicates that the target should be nullable.
(FailureMetadata failureMetadata, @Nullable Metric<Long> target) ->
new LongMetricSubject(failureMetadata, target);
/** Static assertThat({@link Metric<Long>}) shortcut method. */ /** Static assertThat({@link Metric<Long>}) shortcut method. */
public static LongMetricSubject assertThat(@Nullable Metric<Long> metric) { public static LongMetricSubject assertThat(@Nullable Metric<Long> metric) {
return assertAbout(SUBJECT_FACTORY).that(metric); return assertAbout(LongMetricSubject::new).that(metric);
} }
private LongMetricSubject(FailureMetadata metadata, Metric<Long> actual) { private LongMetricSubject(FailureMetadata metadata, Metric<Long> actual) {

View file

@ -19,14 +19,11 @@ import static com.google.common.base.Predicates.not;
import static com.google.common.collect.Multimaps.filterKeys; import static com.google.common.collect.Multimaps.filterKeys;
import static google.registry.request.Action.Method.POST; import static google.registry.request.Action.Method.POST;
import static google.registry.util.FormattingLogger.getLoggerForCallerClass; import static google.registry.util.FormattingLogger.getLoggerForCallerClass;
import static java.util.stream.Collectors.joining;
import com.google.api.services.bigquery.Bigquery; import com.google.api.services.bigquery.Bigquery;
import com.google.api.services.bigquery.model.TableDataInsertAllRequest; import com.google.api.services.bigquery.model.TableDataInsertAllRequest;
import com.google.api.services.bigquery.model.TableDataInsertAllResponse; import com.google.api.services.bigquery.model.TableDataInsertAllResponse;
import com.google.api.services.bigquery.model.TableDataInsertAllResponse.InsertErrors;
import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableListMultimap; import com.google.common.collect.ImmutableListMultimap;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
@ -85,18 +82,19 @@ public class MetricsExportAction implements Runnable {
.execute(); .execute();
if (response.getInsertErrors() != null && !response.getInsertErrors().isEmpty()) { if (response.getInsertErrors() != null && !response.getInsertErrors().isEmpty()) {
throw new RuntimeException(FluentIterable throw new RuntimeException(
.from(response.getInsertErrors()) response
.transform(new Function<InsertErrors, String>() { .getInsertErrors()
@Override .stream()
public String apply(InsertErrors error) { .map(
error -> {
try { try {
return error.toPrettyString(); return error.toPrettyString();
} catch (IOException e) { } catch (IOException e) {
return error.toString(); return error.toString();
} }
}}) })
.join(Joiner.on('\n'))); .collect(joining("\n")));
} }
} catch (Throwable e) { } catch (Throwable e) {
logger.warningfmt("Caught Unknown Exception: %s", e); logger.warningfmt("Caught Unknown Exception: %s", e);

View file

@ -61,12 +61,7 @@ public class WhiteboxModule {
@Provides @Provides
@Named("insertIdGenerator") @Named("insertIdGenerator")
static Supplier<String> provideInsertIdGenerator() { static Supplier<String> provideInsertIdGenerator() {
return new Supplier<String>() { return () -> UUID.randomUUID().toString();
@Override
public String get() {
return UUID.randomUUID().toString();
}
};
} }
/** Provides an EppMetric builder with the request ID and startTimestamp already initialized. */ /** Provides an EppMetric builder with the request ID and startTimestamp already initialized. */

View file

@ -14,16 +14,16 @@
package google.registry.rdap; package google.registry.rdap;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.rdap.RdapUtils.getRegistrarByIanaIdentifier; import static google.registry.rdap.RdapUtils.getRegistrarByIanaIdentifier;
import static google.registry.request.Action.Method.GET; import static google.registry.request.Action.Method.GET;
import static google.registry.request.Action.Method.HEAD; import static google.registry.request.Action.Method.HEAD;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import com.google.common.base.Predicate;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Streams;
import com.google.common.primitives.Booleans; import com.google.common.primitives.Booleans;
import com.google.common.primitives.Longs; import com.google.common.primitives.Longs;
import com.googlecode.objectify.cmd.Query; import com.googlecode.objectify.cmd.Query;
@ -156,17 +156,13 @@ public class RdapEntitySearchAction extends RdapActionBase {
} }
// Get the registrar matches. // Get the registrar matches.
ImmutableList<Registrar> registrars = ImmutableList<Registrar> registrars =
FluentIterable.from(Registrar.loadAllCached()) Streams.stream(Registrar.loadAllCached())
.filter( .filter(
new Predicate<Registrar>() { registrar ->
@Override partialStringQuery.matches(registrar.getRegistrarName())
public boolean apply(Registrar registrar) { && shouldBeVisible(registrar))
return partialStringQuery.matches(registrar.getRegistrarName())
&& shouldBeVisible(registrar);
}
})
.limit(rdapResultSetMaxSize + 1) .limit(rdapResultSetMaxSize + 1)
.toList(); .collect(toImmutableList());
// Get the contact matches and return the results, fetching an additional contact to detect // Get the contact matches and return the results, fetching an additional contact to detect
// truncation. If we are including deleted entries, we must fetch more entries, in case some // truncation. If we are including deleted entries, we must fetch more entries, in case some
// get excluded due to permissioning. // get excluded due to permissioning.

View file

@ -15,12 +15,12 @@
package google.registry.rdap; package google.registry.rdap;
import static com.google.common.base.Strings.nullToEmpty; import static com.google.common.base.Strings.nullToEmpty;
import static com.google.common.collect.ImmutableSortedSet.toImmutableSortedSet;
import static google.registry.model.EppResourceUtils.isLinked; import static google.registry.model.EppResourceUtils.isLinked;
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.util.CollectionUtils.union; import static google.registry.util.CollectionUtils.union;
import static google.registry.util.DomainNameUtils.ACE_PREFIX; import static google.registry.util.DomainNameUtils.ACE_PREFIX;
import com.google.common.base.Function;
import com.google.common.base.Functions; import com.google.common.base.Functions;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import com.google.common.base.Predicates; import com.google.common.base.Predicates;
@ -30,6 +30,7 @@ import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.common.collect.Ordering; import com.google.common.collect.Ordering;
import com.google.common.collect.Streams;
import com.google.common.net.InetAddresses; import com.google.common.net.InetAddresses;
import com.googlecode.objectify.Key; import com.googlecode.objectify.Key;
import google.registry.config.RdapNoticeDescriptor; import google.registry.config.RdapNoticeDescriptor;
@ -282,19 +283,11 @@ public class RdapJsonFormatter {
/** Sets the ordering for hosts; just use the fully qualified host name. */ /** Sets the ordering for hosts; just use the fully qualified host name. */
private static final Ordering<HostResource> HOST_RESOURCE_ORDERING = private static final Ordering<HostResource> HOST_RESOURCE_ORDERING =
Ordering.natural().onResultOf(new Function<HostResource, String>() { Ordering.natural().onResultOf(HostResource::getFullyQualifiedHostName);
@Override
public String apply(HostResource host) {
return host.getFullyQualifiedHostName();
}});
/** Sets the ordering for designated contacts; order them in a fixed order by contact type. */ /** Sets the ordering for designated contacts; order them in a fixed order by contact type. */
private static final Ordering<DesignatedContact> DESIGNATED_CONTACT_ORDERING = private static final Ordering<DesignatedContact> DESIGNATED_CONTACT_ORDERING =
Ordering.natural().onResultOf(new Function<DesignatedContact, DesignatedContact.Type>() { Ordering.natural().onResultOf(DesignatedContact::getType);
@Override
public DesignatedContact.Type apply(DesignatedContact designatedContact) {
return designatedContact.getType();
}});
ImmutableMap<String, Object> getJsonTosNotice(String rdapLinkBase) { ImmutableMap<String, Object> getJsonTosNotice(String rdapLinkBase) {
return getJsonHelpNotice(rdapTosPath, rdapLinkBase); return getJsonHelpNotice(rdapTosPath, rdapLinkBase);
@ -1076,15 +1069,9 @@ public class RdapJsonFormatter {
.filter(Predicates.not(Predicates.equalTo(RdapStatus.ACTIVE))) .filter(Predicates.not(Predicates.equalTo(RdapStatus.ACTIVE)))
.append(RdapStatus.REMOVED); .append(RdapStatus.REMOVED);
} }
return iterable return Streams.stream(iterable)
.transform( .map(RdapStatus::getDisplayName)
new Function<RdapStatus, String>() { .collect(toImmutableSortedSet(Ordering.natural()))
@Override
public String apply(RdapStatus status) {
return status.getDisplayName();
}
})
.toSortedSet(Ordering.natural())
.asList(); .asList();
} }

View file

@ -17,7 +17,6 @@ package google.registry.rdap;
import static com.google.common.collect.Iterables.tryFind; import static com.google.common.collect.Iterables.tryFind;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import com.google.common.base.Predicate;
import google.registry.model.registrar.Registrar; import google.registry.model.registrar.Registrar;
/** Utility functions for RDAP. */ /** Utility functions for RDAP. */
@ -29,11 +28,9 @@ public final class RdapUtils {
static Optional<Registrar> getRegistrarByIanaIdentifier(final long ianaIdentifier) { static Optional<Registrar> getRegistrarByIanaIdentifier(final long ianaIdentifier) {
return tryFind( return tryFind(
Registrar.loadAllCached(), Registrar.loadAllCached(),
new Predicate<Registrar>() { registrar -> {
@Override
public boolean apply(Registrar registrar) {
Long registrarIanaIdentifier = registrar.getIanaIdentifier(); Long registrarIanaIdentifier = registrar.getIanaIdentifier();
return (registrarIanaIdentifier != null) && (registrarIanaIdentifier == ianaIdentifier); return (registrarIanaIdentifier != null) && (registrarIanaIdentifier == ianaIdentifier);
}}); });
} }
} }

View file

@ -89,9 +89,8 @@ class EscrowTaskRunner {
Duration timeout, Duration timeout,
final CursorType cursorType, final CursorType cursorType,
final Duration interval) { final Duration interval) {
Callable<Void> lockRunner = new Callable<Void>() { Callable<Void> lockRunner =
@Override () -> {
public Void call() throws Exception {
logger.info("tld=" + registry.getTld()); logger.info("tld=" + registry.getTld());
DateTime startOfToday = clock.nowUtc().withTimeAtStartOfDay(); DateTime startOfToday = clock.nowUtc().withTimeAtStartOfDay();
Cursor cursor = ofy().load().key(Cursor.createKey(cursorType, registry)).now(); Cursor cursor = ofy().load().key(Cursor.createKey(cursorType, registry)).now();
@ -101,14 +100,19 @@ class EscrowTaskRunner {
} }
logger.info("cursor=" + nextRequiredRun); logger.info("cursor=" + nextRequiredRun);
task.runWithLock(nextRequiredRun); task.runWithLock(nextRequiredRun);
ofy().transact(new VoidWork() { ofy()
.transact(
new VoidWork() {
@Override @Override
public void vrun() { public void vrun() {
ofy().save().entity( ofy()
.save()
.entity(
Cursor.create(cursorType, nextRequiredRun.plus(interval), registry)); Cursor.create(cursorType, nextRequiredRun.plus(interval), registry));
}}); }
});
return null; return null;
}}; };
String lockName = String.format("%s %s", task.getClass().getSimpleName(), registry.getTld()); String lockName = String.format("%s %s", task.getClass().getSimpleName(), registry.getTld());
if (!lockHandler.executeWithLocks(lockRunner, tld, timeout, lockName)) { if (!lockHandler.executeWithLocks(lockRunner, tld, timeout, lockName)) {
// This will happen if either: a) the task is double-executed; b) the task takes a long time // This will happen if either: a) the task is double-executed; b) the task takes a long time

View file

@ -23,7 +23,6 @@ import static javax.servlet.http.HttpServletResponse.SC_NO_CONTENT;
import com.google.common.base.Ascii; import com.google.common.base.Ascii;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSetMultimap; import com.google.common.collect.ImmutableSetMultimap;
@ -262,16 +261,14 @@ public final class RdeStagingAction implements Runnable {
return ImmutableSetMultimap.copyOf( return ImmutableSetMultimap.copyOf(
Multimaps.filterValues( Multimaps.filterValues(
pendingDepositChecker.getTldsAndWatermarksPendingDepositForRdeAndBrda(), pendingDepositChecker.getTldsAndWatermarksPendingDepositForRdeAndBrda(),
new Predicate<PendingDeposit>() { pending -> {
@Override
public boolean apply(PendingDeposit pending) {
if (clock.nowUtc().isBefore(pending.watermark().plus(transactionCooldown))) { if (clock.nowUtc().isBefore(pending.watermark().plus(transactionCooldown))) {
logger.infofmt("Ignoring within %s cooldown: %s", transactionCooldown, pending); logger.infofmt("Ignoring within %s cooldown: %s", transactionCooldown, pending);
return false; return false;
} else { } else {
return true; return true;
} }
}})); }));
} }
private ImmutableSetMultimap<String, PendingDeposit> getManualPendingDeposits() { private ImmutableSetMultimap<String, PendingDeposit> getManualPendingDeposits() {

View file

@ -15,18 +15,18 @@
package google.registry.rde; package google.registry.rde;
import static com.google.common.base.Strings.nullToEmpty; import static com.google.common.base.Strings.nullToEmpty;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static google.registry.model.EppResourceUtils.loadAtPointInTime; import static google.registry.model.EppResourceUtils.loadAtPointInTime;
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
import com.google.appengine.tools.mapreduce.Mapper; import com.google.appengine.tools.mapreduce.Mapper;
import com.google.auto.value.AutoValue; import com.google.auto.value.AutoValue;
import com.google.common.base.Function;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSetMultimap; import com.google.common.collect.ImmutableSetMultimap;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.common.collect.Streams;
import com.googlecode.objectify.Result; import com.googlecode.objectify.Result;
import google.registry.model.EppResource; import google.registry.model.EppResource;
import google.registry.model.contact.ContactResource; import google.registry.model.contact.ContactResource;
@ -96,25 +96,16 @@ public final class RdeStagingMapper extends Mapper<EppResource, PendingDeposit,
// Get the set of all point-in-time watermarks we need, to minimize rewinding. // Get the set of all point-in-time watermarks we need, to minimize rewinding.
ImmutableSet<DateTime> dates = ImmutableSet<DateTime> dates =
FluentIterable Streams.stream(
.from(shouldEmitOnAllTlds shouldEmitOnAllTlds
? pendings.values() ? pendings.values()
: pendings.get(((DomainResource) resource).getTld())) : pendings.get(((DomainResource) resource).getTld()))
.transform(new Function<PendingDeposit, DateTime>() { .map(PendingDeposit::watermark)
@Override .collect(toImmutableSet());
public DateTime apply(PendingDeposit pending) {
return pending.watermark();
}})
.toSet();
// Launch asynchronous fetches of point-in-time representations of resource. // Launch asynchronous fetches of point-in-time representations of resource.
ImmutableMap<DateTime, Result<EppResource>> resourceAtTimes = ImmutableMap<DateTime, Result<EppResource>> resourceAtTimes =
ImmutableMap.copyOf(Maps.asMap(dates, ImmutableMap.copyOf(Maps.asMap(dates, input -> loadAtPointInTime(resource, input)));
new Function<DateTime, Result<EppResource>>() {
@Override
public Result<EppResource> apply(DateTime input) {
return loadAtPointInTime(resource, input);
}}));
// Convert resource to an XML fragment for each watermark/mode pair lazily and cache the result. // Convert resource to an XML fragment for each watermark/mode pair lazily and cache the result.
Fragmenter fragmenter = new Fragmenter(resourceAtTimes); Fragmenter fragmenter = new Fragmenter(resourceAtTimes);

View file

@ -101,12 +101,11 @@ public final class RdeStagingReducer extends Reducer<PendingDeposit, DepositFrag
@Override @Override
public void reduce(final PendingDeposit key, final ReducerInput<DepositFragment> fragments) { public void reduce(final PendingDeposit key, final ReducerInput<DepositFragment> fragments) {
Callable<Void> lockRunner = new Callable<Void>() { Callable<Void> lockRunner =
@Override () -> {
public Void call() throws Exception {
reduceWithLock(key, fragments); reduceWithLock(key, fragments);
return null; return null;
}}; };
String lockName = String.format("RdeStaging %s %s", key.tld(), key.mode()); String lockName = String.format("RdeStaging %s %s", key.tld(), key.mode());
if (!lockHandler.executeWithLocks(lockRunner, null, lockTimeout, lockName)) { if (!lockHandler.executeWithLocks(lockRunner, null, lockTimeout, lockName)) {
logger.warningfmt("Lock in use: %s", lockName); logger.warningfmt("Lock in use: %s", lockName);

View file

@ -59,7 +59,6 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.URI; import java.net.URI;
import java.util.concurrent.Callable;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import org.bouncycastle.openpgp.PGPKeyPair; import org.bouncycastle.openpgp.PGPKeyPair;
@ -157,12 +156,10 @@ public final class RdeUploadAction implements Runnable, EscrowTask {
verifyFileExists(reportFilename); verifyFileExists(reportFilename);
final long xmlLength = readXmlLength(xmlLengthFilename); final long xmlLength = readXmlLength(xmlLengthFilename);
retrier.callWithRetry( retrier.callWithRetry(
new Callable<Void>() { () -> {
@Override
public Void call() throws Exception {
upload(xmlFilename, xmlLength, watermark, name); upload(xmlFilename, xmlLength, watermark, name);
return null; return null;
}}, },
JSchException.class); JSchException.class);
ofy().transact(new VoidWork() { ofy().transact(new VoidWork() {
@Override @Override

View file

@ -20,12 +20,11 @@ import static google.registry.model.EppResourceUtils.loadByForeignKey;
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.model.registry.Registries.findTldForName; import static google.registry.model.registry.Registries.findTldForName;
import static google.registry.util.PipelineUtils.createJobPath; import static google.registry.util.PipelineUtils.createJobPath;
import static java.util.stream.Collectors.joining;
import com.google.appengine.tools.mapreduce.Mapper; import com.google.appengine.tools.mapreduce.Mapper;
import com.google.common.base.Joiner;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.common.net.InternetDomainName; import com.google.common.net.InternetDomainName;
import com.googlecode.objectify.Key; import com.googlecode.objectify.Key;
import com.googlecode.objectify.Work; import com.googlecode.objectify.Work;
@ -196,10 +195,11 @@ public class RdeHostLinkAction implements Runnable {
} }
// This is a subordinate host // This is a subordinate host
String domainName = String domainName =
Joiner.on('.') hostName
.join( .parts()
Iterables.skip( .stream()
hostName.parts(), hostName.parts().size() - (tld.get().parts().size() + 1))); .skip(hostName.parts().size() - (tld.get().parts().size() + 1))
.collect(joining("."));
DomainResource superordinateDomain = loadByForeignKey(DomainResource.class, domainName, now); DomainResource superordinateDomain = loadByForeignKey(DomainResource.class, domainName, now);
// Hosts can't be linked if domains import hasn't been run // Hosts can't be linked if domains import hasn't been run
checkState( checkState(

View file

@ -16,13 +16,12 @@ package google.registry.rde.imports;
import static com.google.common.base.Predicates.equalTo; import static com.google.common.base.Predicates.equalTo;
import static com.google.common.base.Predicates.not; import static com.google.common.base.Predicates.not;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.rde.imports.RdeImportUtils.generateTridForImport; import static google.registry.rde.imports.RdeImportUtils.generateTridForImport;
import com.google.common.base.Function;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.googlecode.objectify.Key; import com.googlecode.objectify.Key;
import google.registry.model.contact.ContactAddress; import google.registry.model.contact.ContactAddress;
import google.registry.model.contact.ContactPhoneNumber; import google.registry.model.contact.ContactPhoneNumber;
@ -54,23 +53,6 @@ final class XjcToContactResourceConverter extends XjcToEppResourceConverter {
XmlToEnumMapper.create(PostalInfo.Type.values()); XmlToEnumMapper.create(PostalInfo.Type.values());
private static final XmlToEnumMapper<TransferStatus> TRANSFER_STATUS_MAPPER = private static final XmlToEnumMapper<TransferStatus> TRANSFER_STATUS_MAPPER =
XmlToEnumMapper.create(TransferStatus.values()); XmlToEnumMapper.create(TransferStatus.values());
private static final Function<XjcContactIntLocType, PostalInfoChoice> choiceConverter =
new Function<XjcContactIntLocType, PostalInfoChoice>() {
@Override
public PostalInfoChoice apply(XjcContactIntLocType choice) {
return convertPostalInfoChoice(choice);
}
};
private static final Function<XjcContactStatusType, StatusValue> STATUS_VALUE_CONVERTER =
new Function<XjcContactStatusType, StatusValue>() {
@Override
public StatusValue apply(XjcContactStatusType status) {
return convertStatusValue(status);
}
};
/** Converts {@link XjcRdeContact} to {@link ContactResource}. */ /** Converts {@link XjcRdeContact} to {@link ContactResource}. */
static ContactResource convertContact(XjcRdeContact contact) { static ContactResource convertContact(XjcRdeContact contact) {
ofy().save().entity( ofy().save().entity(
@ -88,11 +70,12 @@ final class XjcToContactResourceConverter extends XjcToEppResourceConverter {
return new ContactResource.Builder() return new ContactResource.Builder()
.setRepoId(contact.getRoid()) .setRepoId(contact.getRoid())
.setStatusValues( .setStatusValues(
FluentIterable.from(contact.getStatuses()) contact
.transform(STATUS_VALUE_CONVERTER) .getStatuses()
// LINKED is implicit and should not be imported onto the new contact. .stream()
.map(XjcToContactResourceConverter::convertStatusValue)
.filter(not(equalTo(StatusValue.LINKED))) .filter(not(equalTo(StatusValue.LINKED)))
.toSet()) .collect(toImmutableSet()))
.setLocalizedPostalInfo( .setLocalizedPostalInfo(
getPostalInfoOfType(contact.getPostalInfos(), XjcContactPostalInfoEnumType.LOC)) getPostalInfoOfType(contact.getPostalInfos(), XjcContactPostalInfoEnumType.LOC))
.setInternationalizedPostalInfo( .setInternationalizedPostalInfo(
@ -160,9 +143,24 @@ final class XjcToContactResourceConverter extends XjcToEppResourceConverter {
} }
return new Disclose.Builder() return new Disclose.Builder()
.setFlag(disclose.isFlag()) .setFlag(disclose.isFlag())
.setNames(ImmutableList.copyOf(Lists.transform(disclose.getNames(), choiceConverter))) .setNames(
.setOrgs(ImmutableList.copyOf(Lists.transform(disclose.getOrgs(), choiceConverter))) disclose
.setAddrs(ImmutableList.copyOf(Lists.transform(disclose.getAddrs(), choiceConverter))) .getNames()
.stream()
.map(XjcToContactResourceConverter::convertPostalInfoChoice)
.collect(toImmutableList()))
.setOrgs(
disclose
.getOrgs()
.stream()
.map(XjcToContactResourceConverter::convertPostalInfoChoice)
.collect(toImmutableList()))
.setAddrs(
disclose
.getAddrs()
.stream()
.map(XjcToContactResourceConverter::convertPostalInfoChoice)
.collect(toImmutableList()))
.build(); .build();
} }

View file

@ -16,7 +16,7 @@ package google.registry.rde.imports;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Preconditions.checkState;
import static com.google.common.collect.Iterables.transform; import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static google.registry.util.DomainNameUtils.canonicalizeDomainName; import static google.registry.util.DomainNameUtils.canonicalizeDomainName;
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull; import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
import static org.joda.time.DateTimeZone.UTC; import static org.joda.time.DateTimeZone.UTC;
@ -24,7 +24,6 @@ import static org.joda.time.DateTimeZone.UTC;
import com.google.common.base.Ascii; import com.google.common.base.Ascii;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.net.InternetDomainName; import com.google.common.net.InternetDomainName;
import com.googlecode.objectify.Key; import com.googlecode.objectify.Key;
import google.registry.model.billing.BillingEvent; import google.registry.model.billing.BillingEvent;
@ -80,18 +79,8 @@ final class XjcToDomainResourceConverter extends XjcToEppResourceConverter {
private static final XmlToEnumMapper<TransferStatus> TRANSFER_STATUS_MAPPER = private static final XmlToEnumMapper<TransferStatus> TRANSFER_STATUS_MAPPER =
XmlToEnumMapper.create(TransferStatus.values()); XmlToEnumMapper.create(TransferStatus.values());
private static final Function<XjcDomainStatusType, StatusValue> STATUS_CONVERTER =
new Function<XjcDomainStatusType, StatusValue>() {
@Override
public StatusValue apply(XjcDomainStatusType status) {
return convertStatusType(status);
}
};
private static final Function<String, Key<HostResource>> HOST_OBJ_CONVERTER = private static final Function<String, Key<HostResource>> HOST_OBJ_CONVERTER =
new Function<String, Key<HostResource>>() { fullyQualifiedHostName -> {
@Override
public Key<HostResource> apply(String fullyQualifiedHostName) {
// host names are always lower case // host names are always lower case
fullyQualifiedHostName = canonicalizeDomainName(fullyQualifiedHostName); fullyQualifiedHostName = canonicalizeDomainName(fullyQualifiedHostName);
Key<HostResource> key = Key<HostResource> key =
@ -101,23 +90,6 @@ final class XjcToDomainResourceConverter extends XjcToEppResourceConverter {
key != null, key != null,
String.format("HostResource not found with name '%s'", fullyQualifiedHostName)); String.format("HostResource not found with name '%s'", fullyQualifiedHostName));
return key; return key;
}
};
private static final Function<XjcDomainContactType, DesignatedContact> CONTACT_CONVERTER =
new Function<XjcDomainContactType, DesignatedContact>() {
@Override
public DesignatedContact apply(XjcDomainContactType contact) {
return convertContactType(contact);
}
};
private static final Function<XjcSecdnsDsDataType, DelegationSignerData> SECDNS_CONVERTER =
new Function<XjcSecdnsDsDataType, DelegationSignerData>() {
@Override
public DelegationSignerData apply(XjcSecdnsDsDataType secdns) {
return convertSecdnsDsDataType(secdns);
}
}; };
/** Converts {@link XjcRgpStatusType} to {@link GracePeriod} */ /** Converts {@link XjcRgpStatusType} to {@link GracePeriod} */
@ -198,21 +170,40 @@ final class XjcToDomainResourceConverter extends XjcToEppResourceConverter {
.setLastEppUpdateTime(domain.getUpDate()) .setLastEppUpdateTime(domain.getUpDate())
.setLastEppUpdateClientId(domain.getUpRr() == null ? null : domain.getUpRr().getValue()) .setLastEppUpdateClientId(domain.getUpRr() == null ? null : domain.getUpRr().getValue())
.setLastTransferTime(domain.getTrDate()) .setLastTransferTime(domain.getTrDate())
.setStatusValues(ImmutableSet.copyOf(transform(domain.getStatuses(), STATUS_CONVERTER))) .setStatusValues(
domain
.getStatuses()
.stream()
.map(XjcToDomainResourceConverter::convertStatusType)
.collect(toImmutableSet()))
.setNameservers(convertNameservers(domain.getNs())) .setNameservers(convertNameservers(domain.getNs()))
.setGracePeriods( .setGracePeriods(
ImmutableSet.copyOf(transform(domain.getRgpStatuses(), gracePeriodConverter))) domain
.setContacts(ImmutableSet.copyOf(transform(domain.getContacts(), CONTACT_CONVERTER))) .getRgpStatuses()
.stream()
.map(gracePeriodConverter)
.collect(toImmutableSet()))
.setContacts(
domain
.getContacts()
.stream()
.map(XjcToDomainResourceConverter::convertContactType)
.collect(toImmutableSet()))
.setDsData( .setDsData(
domain.getSecDNS() == null domain.getSecDNS() == null
? ImmutableSet.<DelegationSignerData>of() ? ImmutableSet.<DelegationSignerData>of()
: ImmutableSet.copyOf( : domain
transform(domain.getSecDNS().getDsDatas(), SECDNS_CONVERTER))) .getSecDNS()
.getDsDatas()
.stream()
.map(XjcToDomainResourceConverter::convertSecdnsDsDataType)
.collect(toImmutableSet()))
.setTransferData(convertDomainTransferData(domain.getTrnData())) .setTransferData(convertDomainTransferData(domain.getTrnData()))
// authInfo pw must be a token between 6 and 16 characters in length // authInfo pw must be a token between 6 and 16 characters in length
// generate a token of 16 characters as the default authInfo pw // generate a token of 16 characters as the default authInfo pw
.setAuthInfo(DomainAuthInfo .setAuthInfo(
.create(PasswordAuth.create(stringGenerator.createString(16), domain.getRoid()))); DomainAuthInfo.create(
PasswordAuth.create(stringGenerator.createString(16), domain.getRoid())));
checkArgumentNotNull( checkArgumentNotNull(
domain.getRegistrant(), "Registrant is missing for domain '%s'", domain.getName()); domain.getRegistrant(), "Registrant is missing for domain '%s'", domain.getName());
builder = builder.setRegistrant(convertRegistrant(domain.getRegistrant())); builder = builder.setRegistrant(convertRegistrant(domain.getRegistrant()));
@ -237,7 +228,7 @@ final class XjcToDomainResourceConverter extends XjcToEppResourceConverter {
checkArgument( checkArgument(
ns.getHostAttrs() == null || ns.getHostAttrs().isEmpty(), ns.getHostAttrs() == null || ns.getHostAttrs().isEmpty(),
"Host attributes are not yet supported"); "Host attributes are not yet supported");
return ImmutableSet.copyOf(Iterables.transform(ns.getHostObjs(), HOST_OBJ_CONVERTER)); return ns.getHostObjs().stream().map(HOST_OBJ_CONVERTER).collect(toImmutableSet());
} }
/** Converts {@link XjcRdeDomainTransferDataType} to {@link TransferData}. */ /** Converts {@link XjcRdeDomainTransferDataType} to {@link TransferData}. */

View file

@ -16,14 +16,12 @@ package google.registry.rde.imports;
import static com.google.common.base.Predicates.in; import static com.google.common.base.Predicates.in;
import static com.google.common.base.Predicates.not; import static com.google.common.base.Predicates.not;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.rde.imports.RdeImportUtils.generateTridForImport; import static google.registry.rde.imports.RdeImportUtils.generateTridForImport;
import static google.registry.util.DomainNameUtils.canonicalizeDomainName; import static google.registry.util.DomainNameUtils.canonicalizeDomainName;
import com.google.common.base.Function;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import com.google.common.net.InetAddresses; import com.google.common.net.InetAddresses;
import com.googlecode.objectify.Key; import com.googlecode.objectify.Key;
import google.registry.model.eppcommon.StatusValue; import google.registry.model.eppcommon.StatusValue;
@ -37,23 +35,6 @@ import java.net.InetAddress;
/** Utility class that converts an {@link XjcRdeHost} into a {@link HostResource}. */ /** Utility class that converts an {@link XjcRdeHost} into a {@link HostResource}. */
public class XjcToHostResourceConverter extends XjcToEppResourceConverter { public class XjcToHostResourceConverter extends XjcToEppResourceConverter {
private static final Function<XjcHostStatusType, StatusValue> STATUS_VALUE_CONVERTER =
new Function<XjcHostStatusType, StatusValue>() {
@Override
public StatusValue apply(XjcHostStatusType status) {
return convertStatusType(status);
}
};
private static final Function<XjcHostAddrType, InetAddress> ADDR_CONVERTER =
new Function<XjcHostAddrType, InetAddress>() {
@Override
public InetAddress apply(XjcHostAddrType addr) {
return convertAddrType(addr);
}
};
static HostResource convert(XjcRdeHost host) { static HostResource convert(XjcRdeHost host) {
// TODO(b/35384052): Handle subordinate hosts correctly by setting superordinateDomaina and // TODO(b/35384052): Handle subordinate hosts correctly by setting superordinateDomaina and
// lastSuperordinateChange fields. // lastSuperordinateChange fields.
@ -81,13 +62,16 @@ public class XjcToHostResourceConverter extends XjcToEppResourceConverter {
.setCreationClientId(host.getCrRr().getValue()) .setCreationClientId(host.getCrRr().getValue())
.setLastEppUpdateClientId(host.getUpRr() == null ? null : host.getUpRr().getValue()) .setLastEppUpdateClientId(host.getUpRr() == null ? null : host.getUpRr().getValue())
.setStatusValues( .setStatusValues(
FluentIterable.from(host.getStatuses()) host.getStatuses()
.transform(STATUS_VALUE_CONVERTER) .stream()
// LINKED is implicit and should not be imported onto the new host. .map(XjcToHostResourceConverter::convertStatusType)
// PENDING_TRANSFER is a property of the superordinate host.
.filter(not(in(ImmutableSet.of(StatusValue.LINKED, StatusValue.PENDING_TRANSFER)))) .filter(not(in(ImmutableSet.of(StatusValue.LINKED, StatusValue.PENDING_TRANSFER))))
.toSet()) .collect(toImmutableSet()))
.setInetAddresses(ImmutableSet.copyOf(Lists.transform(host.getAddrs(), ADDR_CONVERTER))) .setInetAddresses(
host.getAddrs()
.stream()
.map(XjcToHostResourceConverter::convertAddrType)
.collect(toImmutableSet()))
.build(); .build();
} }

View file

@ -22,7 +22,6 @@ import static javax.servlet.http.HttpServletResponse.SC_OK;
import com.google.api.services.bigquery.model.TableFieldSchema; import com.google.api.services.bigquery.model.TableFieldSchema;
import com.google.appengine.tools.cloudstorage.GcsFilename; import com.google.appengine.tools.cloudstorage.GcsFilename;
import com.google.common.base.Function;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import com.google.common.base.Throwables; import com.google.common.base.Throwables;
import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.ArrayListMultimap;
@ -130,16 +129,7 @@ public final class IcannReportingStagingAction implements Runnable {
} }
private Iterable<String> getHeaders(ImmutableSet<TableFieldSchema> fields) { private Iterable<String> getHeaders(ImmutableSet<TableFieldSchema> fields) {
return Iterables.transform( return Iterables.transform(fields, schema -> schema.getName().replace('_', '-'));
fields,
new Function<TableFieldSchema, String>() {
@Override
public String apply(TableFieldSchema schema) {
// Change from '_' delimiters (Bigquery-compatible) to '-' (ICANN specification)
return schema.getName().replace('_', '-');
}
}
);
} }
private void stageActivityReports ( private void stageActivityReports (

View file

@ -32,11 +32,9 @@ import google.registry.request.Response;
import google.registry.request.auth.Auth; import google.registry.request.auth.Auth;
import google.registry.util.FormattingLogger; import google.registry.util.FormattingLogger;
import google.registry.util.Retrier; import google.registry.util.Retrier;
import google.registry.xml.XmlException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.concurrent.Callable;
import javax.inject.Inject; import javax.inject.Inject;
/** /**
@ -82,16 +80,16 @@ public final class IcannReportingUploadAction implements Runnable {
gcsFilename.getObjectName(), gcsFilename.getObjectName(),
gcsFilename.getBucketName()); gcsFilename.getBucketName());
retrier.callWithRetry(new Callable<Void>() { retrier.callWithRetry(
@Override () -> {
public Void call() throws IOException, XmlException {
final byte[] payload = readReportFromGcs(gcsFilename); final byte[] payload = readReportFromGcs(gcsFilename);
icannReporter.send(payload, tld, yearMonth, reportType); icannReporter.send(payload, tld, yearMonth, reportType);
response.setContentType(PLAIN_TEXT_UTF_8); response.setContentType(PLAIN_TEXT_UTF_8);
response.setPayload( response.setPayload(
String.format("OK, sending: %s", new String(payload, StandardCharsets.UTF_8))); String.format("OK, sending: %s", new String(payload, StandardCharsets.UTF_8)));
return null; return null;
}}, IOException.class); },
IOException.class);
} }
private byte[] readReportFromGcs(GcsFilename reportFilename) throws IOException { private byte[] readReportFromGcs(GcsFilename reportFilename) throws IOException {

View file

@ -128,12 +128,7 @@ public final class Modules {
public static final class AppIdentityCredentialModule { public static final class AppIdentityCredentialModule {
@Provides @Provides
static Function<Set<String>, AppIdentityCredential> provideAppIdentityCredential() { static Function<Set<String>, AppIdentityCredential> provideAppIdentityCredential() {
return new Function<Set<String>, AppIdentityCredential>() { return AppIdentityCredential::new;
@Override
public AppIdentityCredential apply(Set<String> scopes) {
return new AppIdentityCredential(scopes);
}
};
} }
} }
@ -200,12 +195,7 @@ public final class Modules {
@Provides @Provides
static Function<Set<String>, GoogleCredential> provideScopedGoogleCredential( static Function<Set<String>, GoogleCredential> provideScopedGoogleCredential(
final Provider<GoogleCredential> googleCredentialProvider) { final Provider<GoogleCredential> googleCredentialProvider) {
return new Function<Set<String>, GoogleCredential>() { return scopes -> googleCredentialProvider.get().createScoped(scopes);
@Override
public GoogleCredential apply(Set<String> scopes) {
return googleCredentialProvider.get().createScoped(scopes);
}
};
} }
/** /**

View file

@ -95,9 +95,7 @@ final class Router {
} }
private static Function<Object, ?> newInstantiator(final Method method) { private static Function<Object, ?> newInstantiator(final Method method) {
return new Function<Object, Object>() { return component -> {
@Override
public Object apply(Object component) {
try { try {
return method.invoke(component); return method.invoke(component);
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
@ -110,6 +108,6 @@ final class Router {
throw new AssertionError( throw new AssertionError(
"Component's @Action factory method somehow threw checked exception", e); "Component's @Action factory method somehow threw checked exception", e);
} }
}}; };
} }
} }

View file

@ -14,10 +14,11 @@
package google.registry.request; package google.registry.request;
import com.google.common.base.Function; import static java.util.stream.Collectors.joining;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Streams;
import java.util.Map; import java.util.Map;
/** /**
@ -139,14 +140,8 @@ public class RouterDisplayHelper {
.build()); .build());
return headerToString(formatString) return headerToString(formatString)
+ String.format("%n") + String.format("%n")
+ FluentIterable.from(routes) + Streams.stream(routes)
.transform( .map(route -> routeToString(route, formatString))
new Function<Route, String>() { .collect(joining(String.format("%n")));
@Override
public String apply(Route route) {
return routeToString(route, formatString);
}
})
.join(Joiner.on(String.format("%n")));
} }
} }

View file

@ -18,19 +18,18 @@ import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Preconditions.checkState;
import static com.google.common.base.Strings.emptyToNull; import static com.google.common.base.Strings.emptyToNull;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.collect.Iterables.transform; import static com.google.common.collect.Iterables.transform;
import static com.google.common.io.BaseEncoding.base16; import static com.google.common.io.BaseEncoding.base16;
import static google.registry.flows.EppXmlTransformer.unmarshal; import static google.registry.flows.EppXmlTransformer.unmarshal;
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.tools.CommandUtilities.addHeader; import static google.registry.tools.CommandUtilities.addHeader;
import static java.util.stream.Collectors.joining;
import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters; import com.beust.jcommander.Parameters;
import com.google.common.base.Ascii; import com.google.common.base.Ascii;
import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter; import com.google.common.base.Splitter;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.template.soy.data.SoyMapData; import com.google.template.soy.data.SoyMapData;
import com.googlecode.objectify.Key; import com.googlecode.objectify.Key;
@ -43,7 +42,6 @@ import google.registry.model.domain.DomainCommand;
import google.registry.model.domain.Period; import google.registry.model.domain.Period;
import google.registry.model.domain.launch.ApplicationStatus; import google.registry.model.domain.launch.ApplicationStatus;
import google.registry.model.domain.launch.LaunchNotice; import google.registry.model.domain.launch.LaunchNotice;
import google.registry.model.domain.secdns.DelegationSignerData;
import google.registry.model.eppinput.EppInput; import google.registry.model.eppinput.EppInput;
import google.registry.model.eppinput.EppInput.ResourceCommandWrapper; import google.registry.model.eppinput.EppInput.ResourceCommandWrapper;
import google.registry.model.reporting.HistoryEntry; import google.registry.model.reporting.HistoryEntry;
@ -51,6 +49,7 @@ import google.registry.model.smd.SignedMark;
import google.registry.tools.soy.DomainAllocateSoyInfo; import google.registry.tools.soy.DomainAllocateSoyInfo;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects;
/** Command to allocated a domain from a domain application. */ /** Command to allocated a domain from a domain application. */
@Parameters(separators = " =", commandDescription = "Allocate a domain application") @Parameters(separators = " =", commandDescription = "Allocate a domain application")
@ -68,20 +67,33 @@ final class AllocateDomainCommand extends MutatingEppToolCommand {
protected String postExecute() throws Exception { protected String postExecute() throws Exception {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
// Check to see that we allocated everything. // Check to see that we allocated everything.
return builder.append(ofy().transactNewReadOnly(new Work<String>() { return builder
.append(
ofy()
.transactNewReadOnly(
new Work<String>() {
@Override @Override
public String run() { public String run() {
String failureMessage = FluentIterable String failureMessage =
.from(ofy().load().keys(applicationKeys).values()) ofy()
.transform(new Function<DomainApplication, String>() { .load()
@Override .keys(applicationKeys)
public String apply(DomainApplication application) { .values()
return application.getApplicationStatus() == ApplicationStatus.ALLOCATED .stream()
? null : application.getFullyQualifiedDomainName(); .map(
}}) application ->
.join(Joiner.on('\n').skipNulls()); application.getApplicationStatus()
return failureMessage.isEmpty() ? "ALL SUCCEEDED" : addHeader("FAILURES", failureMessage); == ApplicationStatus.ALLOCATED
}})).toString(); ? null
: application.getFullyQualifiedDomainName())
.filter(Objects::nonNull)
.collect(joining("\n"));
return failureMessage.isEmpty()
? "ALL SUCCEEDED"
: addHeader("FAILURES", failureMessage);
}
}))
.toString();
} }
/** Extract the registration period from the XML used to create the domain application. */ /** Extract the registration period from the XML used to create the domain application. */
@ -96,16 +108,15 @@ final class AllocateDomainCommand extends MutatingEppToolCommand {
protected void initMutatingEppToolCommand() { protected void initMutatingEppToolCommand() {
checkArgument(superuser, "This command MUST be run as --superuser."); checkArgument(superuser, "This command MUST be run as --superuser.");
setSoyTemplate(DomainAllocateSoyInfo.getInstance(), DomainAllocateSoyInfo.CREATE); setSoyTemplate(DomainAllocateSoyInfo.getInstance(), DomainAllocateSoyInfo.CREATE);
ofy().transactNewReadOnly(new VoidWork() { ofy()
.transactNewReadOnly(
new VoidWork() {
@Override @Override
public void vrun() { public void vrun() {
Iterable<Key<DomainApplication>> keys = transform( Iterable<Key<DomainApplication>> keys =
transform(
Splitter.on(',').split(ids), Splitter.on(',').split(ids),
new Function<String, Key<DomainApplication>>() { applicationId -> Key.create(DomainApplication.class, applicationId));
@Override
public Key<DomainApplication> apply(String applicationId) {
return Key.create(DomainApplication.class, applicationId);
}});
for (DomainApplication application : ofy().load().keys(keys).values()) { for (DomainApplication application : ofy().load().keys(keys).values()) {
// If the application is already allocated print a warning but do not fail. // If the application is already allocated print a warning but do not fail.
if (application.getApplicationStatus() == ApplicationStatus.ALLOCATED) { if (application.getApplicationStatus() == ApplicationStatus.ALLOCATED) {
@ -113,14 +124,17 @@ final class AllocateDomainCommand extends MutatingEppToolCommand {
"Application %s has already been allocated\n", application.getRepoId()); "Application %s has already been allocated\n", application.getRepoId());
continue; continue;
} }
// Ensure domain doesn't already have a final status which it shouldn't be updated from. // Ensure domain doesn't already have a final status which it shouldn't be updated
// from.
checkState( checkState(
!application.getApplicationStatus().isFinalStatus(), !application.getApplicationStatus().isFinalStatus(),
"Application has final status %s", "Application has final status %s",
application.getApplicationStatus()); application.getApplicationStatus());
try { try {
HistoryEntry history = checkNotNull( HistoryEntry history =
ofy().load() checkNotNull(
ofy()
.load()
.type(HistoryEntry.class) .type(HistoryEntry.class)
.ancestor(checkNotNull(application)) .ancestor(checkNotNull(application))
.order("modificationTime") .order("modificationTime")
@ -132,42 +146,53 @@ final class AllocateDomainCommand extends MutatingEppToolCommand {
emptyToNull(history.getTrid().getClientTransactionId()); emptyToNull(history.getTrid().getClientTransactionId());
Period period = checkNotNull(extractPeriodFromXml(history.getXmlBytes())); Period period = checkNotNull(extractPeriodFromXml(history.getXmlBytes()));
checkArgument(period.getUnit() == Period.Unit.YEARS); checkArgument(period.getUnit() == Period.Unit.YEARS);
ImmutableMap.Builder<String, String> contactsMapBuilder = new ImmutableMap.Builder<>(); ImmutableMap.Builder<String, String> contactsMapBuilder =
new ImmutableMap.Builder<>();
for (DesignatedContact contact : application.getContacts()) { for (DesignatedContact contact : application.getContacts()) {
contactsMapBuilder.put( contactsMapBuilder.put(
Ascii.toLowerCase(contact.getType().toString()), Ascii.toLowerCase(contact.getType().toString()),
ofy().load().key(contact.getContactKey()).now().getForeignKey()); ofy().load().key(contact.getContactKey()).now().getForeignKey());
} }
LaunchNotice launchNotice = application.getLaunchNotice(); LaunchNotice launchNotice = application.getLaunchNotice();
addSoyRecord(application.getCurrentSponsorClientId(), new SoyMapData( addSoyRecord(
application.getCurrentSponsorClientId(),
new SoyMapData(
"name", application.getFullyQualifiedDomainName(), "name", application.getFullyQualifiedDomainName(),
"period", period.getValue(), "period", period.getValue(),
"nameservers", application.loadNameserverFullyQualifiedHostNames(), "nameservers", application.loadNameserverFullyQualifiedHostNames(),
"registrant", ofy().load().key(application.getRegistrant()).now().getForeignKey(), "registrant",
ofy().load().key(application.getRegistrant()).now().getForeignKey(),
"contacts", contactsMapBuilder.build(), "contacts", contactsMapBuilder.build(),
"authInfo", application.getAuthInfo().getPw().getValue(), "authInfo", application.getAuthInfo().getPw().getValue(),
"smdId", application.getEncodedSignedMarks().isEmpty() "smdId",
application.getEncodedSignedMarks().isEmpty()
? null ? null
: unmarshal( : unmarshal(
SignedMark.class, SignedMark.class,
application.getEncodedSignedMarks().get(0).getBytes()).getId(), application.getEncodedSignedMarks().get(0).getBytes())
.getId(),
"applicationRoid", application.getRepoId(), "applicationRoid", application.getRepoId(),
"applicationTime", application.getCreationTime().toString(), "applicationTime", application.getCreationTime().toString(),
"launchNotice", launchNotice == null ? null : ImmutableMap.of( "launchNotice",
launchNotice == null
? null
: ImmutableMap.of(
"noticeId", launchNotice.getNoticeId().getTcnId(), "noticeId", launchNotice.getNoticeId().getTcnId(),
"expirationTime", launchNotice.getExpirationTime().toString(), "expirationTime",
launchNotice.getExpirationTime().toString(),
"acceptedTime", launchNotice.getAcceptedTime().toString()), "acceptedTime", launchNotice.getAcceptedTime().toString()),
"dsRecords", FluentIterable.from(application.getDsData()) "dsRecords",
.transform(new Function<DelegationSignerData, ImmutableMap<String, ?>>() { application
@Override .getDsData()
public ImmutableMap<String, ?> apply(DelegationSignerData dsData) { .stream()
return ImmutableMap.of( .map(
dsData ->
ImmutableMap.of(
"keyTag", dsData.getKeyTag(), "keyTag", dsData.getKeyTag(),
"algorithm", dsData.getAlgorithm(), "algorithm", dsData.getAlgorithm(),
"digestType", dsData.getDigestType(), "digestType", dsData.getDigestType(),
"digest", base16().encode(dsData.getDigest())); "digest", base16().encode(dsData.getDigest())))
}}) .collect(toImmutableList()),
.toList(),
"clTrid", clientTransactionId)); "clTrid", clientTransactionId));
applicationKeys.add(Key.create(application)); applicationKeys.add(Key.create(application));
} catch (EppException e) { } catch (EppException e) {

View file

@ -63,11 +63,7 @@ class AppEngineConnection implements Connection {
* <p>Computing this is expensive since it needs to load {@code ServerSecret} so do it once. * <p>Computing this is expensive since it needs to load {@code ServerSecret} so do it once.
*/ */
private final Supplier<String> xsrfToken = private final Supplier<String> xsrfToken =
memoize(new Supplier<String>() { memoize(() -> xsrfTokenManager.generateToken(getUserId()));
@Override
public String get() {
return xsrfTokenManager.generateToken(getUserId());
}});
@Override @Override
public void prefetchXsrfToken() throws IOException { public void prefetchXsrfToken() throws IOException {

View file

@ -60,28 +60,34 @@ final class AuctionStatusCommand implements RemoteApiCommand {
@Override @Override
public void run() throws Exception { public void run() throws Exception {
final ImmutableSet<String> domains = ImmutableSet.copyOf(mainArguments); final ImmutableSet<String> domains = ImmutableSet.copyOf(mainArguments);
Files.write(output, FluentIterable Files.write(
.from(domains) output,
.transformAndConcat(new Function<String, Iterable<String>>() { FluentIterable.from(domains)
@Override .transformAndConcat(
public Iterable<String> apply(String fullyQualifiedDomainName) { fullyQualifiedDomainName -> {
checkState( checkState(
findTldForName(InternetDomainName.from(fullyQualifiedDomainName)).isPresent(), findTldForName(InternetDomainName.from(fullyQualifiedDomainName)).isPresent(),
"No tld found for %s", fullyQualifiedDomainName); "No tld found for %s",
return ofy().transactNewReadOnly(new Work<Iterable<String>>() { fullyQualifiedDomainName);
return ofy()
.transactNewReadOnly(
new Work<Iterable<String>>() {
@Override @Override
public Iterable<String> run() { public Iterable<String> run() {
ImmutableList.Builder<DomainApplication> applications = ImmutableList.Builder<DomainApplication> applications =
new ImmutableList.Builder<>(); new ImmutableList.Builder<>();
for (String domain : domains) { for (String domain : domains) {
applications.addAll( applications.addAll(
loadActiveApplicationsByDomainName(domain, ofy().getTransactionTime())); loadActiveApplicationsByDomainName(
domain, ofy().getTransactionTime()));
} }
return Lists.transform( return Lists.transform(
FluentIterable.from(applications.build()).toSortedList(ORDERING), ImmutableList.sortedCopyOf(ORDERING, applications.build()),
APPLICATION_FORMATTER); APPLICATION_FORMATTER);
}}); }
}}), UTF_8); });
}),
UTF_8);
} }
private static final Ordering<DomainApplication> ORDERING = new Ordering<DomainApplication>() { private static final Ordering<DomainApplication> ORDERING = new Ordering<DomainApplication>() {
@ -97,11 +103,10 @@ final class AuctionStatusCommand implements RemoteApiCommand {
}}; }};
private static final Function<DomainApplication, String> APPLICATION_FORMATTER = private static final Function<DomainApplication, String> APPLICATION_FORMATTER =
new Function<DomainApplication, String>() { app -> {
@Override
public String apply(DomainApplication app) {
ContactResource registrant = checkNotNull(ofy().load().key(app.getRegistrant()).now()); ContactResource registrant = checkNotNull(ofy().load().key(app.getRegistrant()).now());
Object[] keysAndValues = new Object[] { Object[] keysAndValues =
new Object[] {
"Domain", app.getFullyQualifiedDomainName(), "Domain", app.getFullyQualifiedDomainName(),
"Type", app.getEncodedSignedMarks().isEmpty() ? "Landrush" : "Sunrise", "Type", app.getEncodedSignedMarks().isEmpty() ? "Landrush" : "Sunrise",
"Application Status", app.getApplicationStatus(), "Application Status", app.getApplicationStatus(),
@ -114,5 +119,5 @@ final class AuctionStatusCommand implements RemoteApiCommand {
}; };
return String.format( return String.format(
Strings.repeat("%-25s= %s\n", keysAndValues.length / 2), keysAndValues); Strings.repeat("%-25s= %s\n", keysAndValues.length / 2), keysAndValues);
}}; };
} }

View file

@ -17,6 +17,7 @@ package google.registry.tools;
import static com.google.common.base.CaseFormat.UPPER_CAMEL; import static com.google.common.base.CaseFormat.UPPER_CAMEL;
import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE; import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static google.registry.model.registry.Registries.assertTldExists; import static google.registry.model.registry.Registries.assertTldExists;
import static google.registry.util.PreconditionsUtils.checkArgumentPresent; import static google.registry.util.PreconditionsUtils.checkArgumentPresent;
import static org.joda.time.DateTimeZone.UTC; import static org.joda.time.DateTimeZone.UTC;
@ -25,9 +26,9 @@ import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters; import com.beust.jcommander.Parameters;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Splitter; import com.google.common.base.Splitter;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.collect.Streams;
import com.google.re2j.Matcher; import com.google.re2j.Matcher;
import com.google.re2j.Pattern; import com.google.re2j.Pattern;
import google.registry.model.billing.RegistrarCredit; import google.registry.model.billing.RegistrarCredit;
@ -42,6 +43,7 @@ import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.List; import java.util.List;
import java.util.stream.Stream;
import org.joda.money.BigMoney; import org.joda.money.BigMoney;
import org.joda.money.CurrencyUnit; import org.joda.money.CurrencyUnit;
import org.joda.money.Money; import org.joda.money.Money;
@ -107,31 +109,25 @@ final class CreateAuctionCreditsCommand extends MutatingCommand {
CURRENCY_CODE; CURRENCY_CODE;
public static List<String> getHeaders() { public static List<String> getHeaders() {
return FluentIterable.from(values()) return Stream.of(values())
.transform(new Function<CsvHeader, String>() { .map(header -> UPPER_UNDERSCORE.to(UPPER_CAMEL, header.name()))
@Override .collect(toImmutableList());
public String apply(CsvHeader header) {
// Returns the name of the header as it appears in the CSV file.
return UPPER_UNDERSCORE.to(UPPER_CAMEL, header.name());
}})
.toList();
} }
} }
private static final Pattern QUOTED_STRING = Pattern.compile("\"(.*)\""); private static final Pattern QUOTED_STRING = Pattern.compile("\"(.*)\"");
/** Helper function to unwrap a quoted string, failing if the string is not quoted. */ /** Helper function to unwrap a quoted string, failing if the string is not quoted. */
private static final Function<String, String> UNQUOTER = new Function<String, String>() { private static final Function<String, String> UNQUOTER =
@Override input -> {
public String apply(String input) {
Matcher matcher = QUOTED_STRING.matcher(input); Matcher matcher = QUOTED_STRING.matcher(input);
checkArgument(matcher.matches(), "Input not quoted"); checkArgument(matcher.matches(), "Input not quoted");
return matcher.group(1); return matcher.group(1);
}}; };
/** Returns the input string of quoted CSV values split into the list of unquoted values. */ /** Returns the input string of quoted CSV values split into the list of unquoted values. */
private static List<String> splitCsvLine(String line) { private static List<String> splitCsvLine(String line) {
return FluentIterable.from(Splitter.on(',').split(line)).transform(UNQUOTER).toList(); return Streams.stream(Splitter.on(',').split(line)).map(UNQUOTER).collect(toImmutableList());
} }
@Override @Override

View file

@ -16,6 +16,7 @@ package google.registry.tools;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Strings.isNullOrEmpty; import static com.google.common.base.Strings.isNullOrEmpty;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static com.google.common.collect.Sets.difference; import static com.google.common.collect.Sets.difference;
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.model.registry.Registries.assertTldsExist; import static google.registry.model.registry.Registries.assertTldsExist;
@ -27,9 +28,7 @@ import com.beust.jcommander.Parameters;
import com.google.appengine.tools.remoteapi.RemoteApiException; import com.google.appengine.tools.remoteapi.RemoteApiException;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.CharMatcher; import com.google.common.base.CharMatcher;
import com.google.common.base.Function;
import com.google.common.base.Splitter; import com.google.common.base.Splitter;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
@ -50,7 +49,6 @@ import java.io.StringReader;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.concurrent.Callable;
import javax.inject.Inject; import javax.inject.Inject;
/** /**
@ -164,12 +162,12 @@ public class CreateLrpTokensCommand implements RemoteApiCommand {
} }
final ImmutableSet<LrpTokenEntity> tokensToSave = tokensToSaveBuilder.build(); final ImmutableSet<LrpTokenEntity> tokensToSave = tokensToSaveBuilder.build();
// Wrap in a retrier to deal with transient 404 errors (thrown as RemoteApiExceptions). // Wrap in a retrier to deal with transient 404 errors (thrown as RemoteApiExceptions).
retrier.callWithRetry(new Callable<Void>() { retrier.callWithRetry(
@Override () -> {
public Void call() throws Exception {
saveTokens(tokensToSave); saveTokens(tokensToSave);
return null; return null;
}}, RemoteApiException.class); },
RemoteApiException.class);
} while (line != null); } while (line != null);
} }
@ -196,21 +194,19 @@ public class CreateLrpTokensCommand implements RemoteApiCommand {
private ImmutableSet<String> generateTokens(int count) { private ImmutableSet<String> generateTokens(int count) {
final ImmutableSet<String> candidates = final ImmutableSet<String> candidates =
ImmutableSet.copyOf(TokenUtils.createTokens(LRP, stringGenerator, count)); ImmutableSet.copyOf(TokenUtils.createTokens(LRP, stringGenerator, count));
ImmutableSet<Key<LrpTokenEntity>> existingTokenKeys = FluentIterable.from(candidates) ImmutableSet<Key<LrpTokenEntity>> existingTokenKeys =
.transform(new Function<String, Key<LrpTokenEntity>>() { candidates
@Override .stream()
public Key<LrpTokenEntity> apply(String input) { .map(input -> Key.create(LrpTokenEntity.class, input))
return Key.create(LrpTokenEntity.class, input); .collect(toImmutableSet());
}}) ImmutableSet<String> existingTokenStrings =
.toSet(); ofy()
ImmutableSet<String> existingTokenStrings = FluentIterable .load()
.from(ofy().load().keys(existingTokenKeys).values()) .keys(existingTokenKeys)
.transform(new Function<LrpTokenEntity, String>() { .values()
@Override .stream()
public String apply(LrpTokenEntity input) { .map(LrpTokenEntity::getToken)
return input.getToken(); .collect(toImmutableSet());
}})
.toSet();
return ImmutableSet.copyOf(difference(candidates, existingTokenStrings)); return ImmutableSet.copyOf(difference(candidates, existingTokenStrings));
} }
} }

View file

@ -18,19 +18,17 @@ import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Preconditions.checkState;
import static com.google.common.base.Predicates.isNull; import static com.google.common.base.Predicates.isNull;
import static com.google.common.base.Strings.isNullOrEmpty; import static com.google.common.base.Strings.isNullOrEmpty;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static google.registry.util.DomainNameUtils.canonicalizeDomainName; import static google.registry.util.DomainNameUtils.canonicalizeDomainName;
import static google.registry.util.RegistrarUtils.normalizeRegistrarName; import static google.registry.util.RegistrarUtils.normalizeRegistrarName;
import static java.nio.charset.StandardCharsets.US_ASCII; import static java.nio.charset.StandardCharsets.US_ASCII;
import static org.joda.time.DateTimeZone.UTC; import static org.joda.time.DateTimeZone.UTC;
import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameter;
import com.google.common.base.Function;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import google.registry.model.billing.RegistrarBillingUtils; import google.registry.model.billing.RegistrarBillingUtils;
import google.registry.model.registrar.Registrar; import google.registry.model.registrar.Registrar;
@ -376,8 +374,9 @@ abstract class CreateOrUpdateRegistrarCommand extends MutatingCommand {
builder.setBillingMethod(billingMethod); builder.setBillingMethod(billingMethod);
} }
List<Object> streetAddressFields = Arrays.asList(street, city, state, zip, countryCode); List<Object> streetAddressFields = Arrays.asList(street, city, state, zip, countryCode);
checkArgument(Iterables.any(streetAddressFields, isNull()) checkArgument(
== Iterables.all(streetAddressFields, isNull()), streetAddressFields.stream().anyMatch(isNull())
== streetAddressFields.stream().allMatch(isNull()),
"Must specify all fields of address"); "Must specify all fields of address");
if (street != null) { if (street != null) {
// We always set the localized address for now. That should be safe to do since it supports // We always set the localized address for now. That should be safe to do since it supports
@ -432,15 +431,11 @@ abstract class CreateOrUpdateRegistrarCommand extends MutatingCommand {
// Check if registrar has billing account IDs for the currency of the TLDs that it is // Check if registrar has billing account IDs for the currency of the TLDs that it is
// allowed to register. // allowed to register.
ImmutableSet<CurrencyUnit> tldCurrencies = ImmutableSet<CurrencyUnit> tldCurrencies =
FluentIterable.from(newRegistrar.getAllowedTlds()) newRegistrar
.transform( .getAllowedTlds()
new Function<String, CurrencyUnit>() { .stream()
@Override .map(tld -> Registry.get(tld).getCurrency())
public CurrencyUnit apply(String tld) { .collect(toImmutableSet());
return Registry.get(tld).getCurrency();
}
})
.toSet();
Set<CurrencyUnit> currenciesWithoutBillingAccountId = Set<CurrencyUnit> currenciesWithoutBillingAccountId =
newRegistrar.getBillingAccountMap() == null newRegistrar.getBillingAccountMap() == null
? tldCurrencies ? tldCurrencies

View file

@ -17,22 +17,22 @@ package google.registry.tools;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Preconditions.checkState;
import static com.google.common.base.Strings.emptyToNull; import static com.google.common.base.Strings.emptyToNull;
import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterables.getOnlyElement; import static com.google.common.collect.Iterables.getOnlyElement;
import static com.google.common.collect.Lists.newArrayList;
import static google.registry.model.registrar.Registrar.State.ACTIVE; import static google.registry.model.registrar.Registrar.State.ACTIVE;
import static google.registry.tools.RegistryToolEnvironment.PRODUCTION; import static google.registry.tools.RegistryToolEnvironment.PRODUCTION;
import static google.registry.tools.RegistryToolEnvironment.SANDBOX; import static google.registry.tools.RegistryToolEnvironment.SANDBOX;
import static google.registry.tools.RegistryToolEnvironment.UNITTEST; import static google.registry.tools.RegistryToolEnvironment.UNITTEST;
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull; import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
import static google.registry.util.RegistrarUtils.normalizeClientId; import static google.registry.util.RegistrarUtils.normalizeClientId;
import static java.util.stream.Collectors.toCollection;
import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters; import com.beust.jcommander.Parameters;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Streams;
import google.registry.model.registrar.Registrar; import google.registry.model.registrar.Registrar;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -82,15 +82,9 @@ final class CreateRegistrarCommand extends CreateOrUpdateRegistrarCommand
checkState( checkState(
!Registrar.loadByClientId(clientId).isPresent(), "Registrar %s already exists", clientId); !Registrar.loadByClientId(clientId).isPresent(), "Registrar %s already exists", clientId);
List<Registrar> collisions = List<Registrar> collisions =
newArrayList( Streams.stream(Registrar.loadAll())
filter( .filter(registrar -> normalizeClientId(registrar.getClientId()).equals(clientId))
Registrar.loadAll(), .collect(toCollection(ArrayList::new));
new Predicate<Registrar>() {
@Override
public boolean apply(Registrar registrar) {
return normalizeClientId(registrar.getClientId()).equals(clientId);
}
}));
if (!collisions.isEmpty()) { if (!collisions.isEmpty()) {
throw new IllegalArgumentException(String.format( throw new IllegalArgumentException(String.format(
"The registrar client identifier %s normalizes identically to existing registrar %s", "The registrar client identifier %s normalizes identically to existing registrar %s",

View file

@ -14,13 +14,11 @@
package google.registry.tools; package google.registry.tools;
import static com.google.common.collect.Iterables.transform;
import static google.registry.util.PreconditionsUtils.checkArgumentPresent; import static google.registry.util.PreconditionsUtils.checkArgumentPresent;
import static java.util.stream.Collectors.joining;
import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters; import com.beust.jcommander.Parameters;
import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.net.MediaType; import com.google.common.net.MediaType;
import google.registry.model.registrar.Registrar; import google.registry.model.registrar.Registrar;
@ -64,11 +62,7 @@ public class CreateRegistrarGroupsCommand extends ConfirmingCommand
protected String prompt() { protected String prompt() {
return String.format( return String.format(
"Create registrar contact groups for registrar(s) %s?", "Create registrar contact groups for registrar(s) %s?",
Joiner.on(", ").join(transform(registrars, new Function<Registrar, String>() { registrars.stream().map(Registrar::getRegistrarName).collect(joining(", ")));
@Override
public String apply(Registrar registrar) {
return registrar.getRegistrarName();
}})));
} }
/** Calls the server endpoint to create groups for the specified registrar client id. */ /** Calls the server endpoint to create groups for the specified registrar client id. */

Some files were not shown because too many files have changed in this diff Show more