mirror of
https://github.com/google/nomulus.git
synced 2025-05-14 16:37:13 +02:00
Replace FluentIterable with streams
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=180005797
This commit is contained in:
parent
552ab12314
commit
3f7cd00882
13 changed files with 121 additions and 104 deletions
|
@ -17,6 +17,7 @@ package google.registry.export;
|
||||||
import static com.google.appengine.api.datastore.DatastoreServiceFactory.getDatastoreService;
|
import static com.google.appengine.api.datastore.DatastoreServiceFactory.getDatastoreService;
|
||||||
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 static com.google.common.collect.ImmutableList.toImmutableList;
|
||||||
|
|
||||||
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;
|
||||||
|
@ -24,9 +25,9 @@ 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.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;
|
||||||
|
import com.google.common.collect.Streams;
|
||||||
import google.registry.util.NonFinalForTesting;
|
import google.registry.util.NonFinalForTesting;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
|
|
||||||
|
@ -88,10 +89,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.from(
|
return Streams.stream(getDatastoreService().prepare(new Query(BACKUP_INFO_KIND)).asIterable())
|
||||||
getDatastoreService().prepare(new Query(BACKUP_INFO_KIND)).asIterable())
|
|
||||||
.filter(entity -> nullToEmpty((String) entity.getProperty("name")).startsWith(namePrefix))
|
.filter(entity -> nullToEmpty((String) entity.getProperty("name")).startsWith(namePrefix))
|
||||||
.transform(DatastoreBackupInfo::new);
|
.map(DatastoreBackupInfo::new)
|
||||||
|
.collect(toImmutableList());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -21,7 +21,6 @@ import static java.nio.charset.StandardCharsets.UTF_8;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.google.common.base.Throwables;
|
import com.google.common.base.Throwables;
|
||||||
import com.google.common.collect.FluentIterable;
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import google.registry.flows.EppException.ParameterValueRangeErrorException;
|
import google.registry.flows.EppException.ParameterValueRangeErrorException;
|
||||||
import google.registry.flows.EppException.ParameterValueSyntaxErrorException;
|
import google.registry.flows.EppException.ParameterValueSyntaxErrorException;
|
||||||
|
@ -40,6 +39,7 @@ import google.registry.xml.XmlException;
|
||||||
import google.registry.xml.XmlTransformer;
|
import google.registry.xml.XmlTransformer;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/** {@link XmlTransformer} for marshalling to and from the Epp model classes. */
|
/** {@link XmlTransformer} for marshalling to and from the Epp model classes. */
|
||||||
public class EppXmlTransformer {
|
public class EppXmlTransformer {
|
||||||
|
@ -87,17 +87,17 @@ public class EppXmlTransformer {
|
||||||
return INPUT_TRANSFORMER.unmarshal(clazz, new ByteArrayInputStream(bytes));
|
return INPUT_TRANSFORMER.unmarshal(clazz, new ByteArrayInputStream(bytes));
|
||||||
} catch (XmlException e) {
|
} catch (XmlException e) {
|
||||||
// If this XmlException is wrapping a known type find it. If not, it's a syntax error.
|
// If this XmlException is wrapping a known type find it. If not, it's a syntax error.
|
||||||
FluentIterable<Throwable> causalChain = FluentIterable.from(Throwables.getCausalChain(e));
|
List<Throwable> causalChain = Throwables.getCausalChain(e);
|
||||||
if (!(causalChain.filter(IpVersionMismatchException.class).isEmpty())) {
|
if (causalChain.stream().anyMatch(IpVersionMismatchException.class::isInstance)) {
|
||||||
throw new IpAddressVersionMismatchException();
|
throw new IpAddressVersionMismatchException();
|
||||||
}
|
}
|
||||||
if (!(causalChain.filter(WrongProtocolVersionException.class).isEmpty())) {
|
if (causalChain.stream().anyMatch(WrongProtocolVersionException.class::isInstance)) {
|
||||||
throw new UnimplementedProtocolVersionException();
|
throw new UnimplementedProtocolVersionException();
|
||||||
}
|
}
|
||||||
if (!(causalChain.filter(InvalidRepoIdException.class).isEmpty())) {
|
if (causalChain.stream().anyMatch(InvalidRepoIdException.class::isInstance)) {
|
||||||
throw new InvalidRepoIdEppException();
|
throw new InvalidRepoIdEppException();
|
||||||
}
|
}
|
||||||
if (!(causalChain.filter(UnknownCurrencyException.class).isEmpty())) {
|
if (causalChain.stream().anyMatch(UnknownCurrencyException.class::isInstance)) {
|
||||||
throw new UnknownCurrencyEppException();
|
throw new UnknownCurrencyEppException();
|
||||||
}
|
}
|
||||||
throw new GenericSyntaxErrorException(e.getMessage());
|
throw new GenericSyntaxErrorException(e.getMessage());
|
||||||
|
|
|
@ -22,16 +22,13 @@ import static java.util.stream.Collectors.toCollection;
|
||||||
import static java.util.stream.Collectors.toList;
|
import static java.util.stream.Collectors.toList;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.google.common.base.Joiner;
|
|
||||||
import com.google.common.base.Predicate;
|
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.ImmutableMap;
|
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.Streams;
|
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;
|
||||||
|
@ -44,6 +41,7 @@ import java.lang.reflect.ParameterizedType;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.util.AbstractList;
|
import java.util.AbstractList;
|
||||||
import java.util.ArrayDeque;
|
import java.util.ArrayDeque;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Deque;
|
import java.util.Deque;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
@ -52,6 +50,7 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
/** A collection of static methods that deal with reflection on model classes. */
|
/** A collection of static methods that deal with reflection on model classes. */
|
||||||
|
@ -94,17 +93,19 @@ public class ModelUtils {
|
||||||
/** Return a string representing the persisted schema of a type or enum. */
|
/** Return a string representing the persisted schema of a type or enum. */
|
||||||
static String getSchema(Class<?> clazz) {
|
static String getSchema(Class<?> clazz) {
|
||||||
StringBuilder stringBuilder = new StringBuilder();
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
Iterable<?> body;
|
Stream<?> body;
|
||||||
if (clazz.isEnum()) {
|
if (clazz.isEnum()) {
|
||||||
stringBuilder.append("enum ");
|
stringBuilder.append("enum ");
|
||||||
body = FluentIterable.from(clazz.getEnumConstants());
|
body = Arrays.stream(clazz.getEnumConstants());
|
||||||
} else {
|
} else {
|
||||||
stringBuilder.append("class ");
|
stringBuilder.append("class ");
|
||||||
body =
|
body =
|
||||||
FluentIterable.from(getAllFields(clazz).values())
|
getAllFields(clazz)
|
||||||
.filter((Field field) -> !field.isAnnotationPresent(Ignore.class))
|
.values()
|
||||||
.transform(
|
.stream()
|
||||||
(Field field) -> {
|
.filter(field -> !field.isAnnotationPresent(Ignore.class))
|
||||||
|
.map(
|
||||||
|
field -> {
|
||||||
String annotation =
|
String annotation =
|
||||||
field.isAnnotationPresent(Id.class)
|
field.isAnnotationPresent(Id.class)
|
||||||
? "@Id "
|
? "@Id "
|
||||||
|
@ -117,8 +118,9 @@ public class ModelUtils {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return stringBuilder
|
return stringBuilder
|
||||||
.append(clazz.getName()).append(" {\n ")
|
.append(clazz.getName())
|
||||||
.append(Joiner.on(";\n ").join(Ordering.usingToString().sortedCopy(body)))
|
.append(" {\n ")
|
||||||
|
.append(body.map(Object::toString).sorted().collect(Collectors.joining(";\n ")))
|
||||||
.append(";\n}")
|
.append(";\n}")
|
||||||
.toString();
|
.toString();
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
package google.registry.model.common;
|
package google.registry.model.common;
|
||||||
|
|
||||||
import static com.google.common.collect.DiscreteDomain.integers;
|
import static com.google.common.collect.DiscreteDomain.integers;
|
||||||
|
import static com.google.common.collect.ImmutableList.toImmutableList;
|
||||||
import static google.registry.util.DateTimeUtils.END_OF_TIME;
|
import static google.registry.util.DateTimeUtils.END_OF_TIME;
|
||||||
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
||||||
import static google.registry.util.DateTimeUtils.isAtOrAfter;
|
import static google.registry.util.DateTimeUtils.isAtOrAfter;
|
||||||
|
@ -23,7 +24,6 @@ import static org.joda.time.DateTimeZone.UTC;
|
||||||
|
|
||||||
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.Range;
|
import com.google.common.collect.Range;
|
||||||
import com.googlecode.objectify.annotation.Embed;
|
import com.googlecode.objectify.annotation.Embed;
|
||||||
import com.googlecode.objectify.annotation.Index;
|
import com.googlecode.objectify.annotation.Index;
|
||||||
|
@ -83,9 +83,11 @@ public class TimeOfYear extends ImmutableObject {
|
||||||
Range<Integer> yearRange = Range.closed(
|
Range<Integer> yearRange = Range.closed(
|
||||||
normalizedRange.lowerEndpoint().getYear(),
|
normalizedRange.lowerEndpoint().getYear(),
|
||||||
normalizedRange.upperEndpoint().getYear());
|
normalizedRange.upperEndpoint().getYear());
|
||||||
return FluentIterable.from(ContiguousSet.create(yearRange, integers()))
|
return ContiguousSet.create(yearRange, integers())
|
||||||
.transform(this::getDateTimeWithYear)
|
.stream()
|
||||||
.filter(normalizedRange);
|
.map(this::getDateTimeWithYear)
|
||||||
|
.filter(normalizedRange)
|
||||||
|
.collect(toImmutableList());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get the first {@link DateTime} with this month/day/millis that is at or after the start. */
|
/** Get the first {@link DateTime} with this month/day/millis that is at or after the start. */
|
||||||
|
|
|
@ -14,16 +14,17 @@
|
||||||
|
|
||||||
package google.registry.model.ofy;
|
package google.registry.model.ofy;
|
||||||
|
|
||||||
|
import static com.google.common.collect.ImmutableList.toImmutableList;
|
||||||
import static com.googlecode.objectify.ObjectifyService.ofy;
|
import static com.googlecode.objectify.ObjectifyService.ofy;
|
||||||
|
|
||||||
import com.google.common.collect.FluentIterable;
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
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.Result;
|
import com.googlecode.objectify.Result;
|
||||||
import com.googlecode.objectify.cmd.DeleteType;
|
import com.googlecode.objectify.cmd.DeleteType;
|
||||||
import com.googlecode.objectify.cmd.Deleter;
|
import com.googlecode.objectify.cmd.Deleter;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Deleter that forwards to {@code ofy().delete()}, but can be augmented via subclassing to
|
* A Deleter that forwards to {@code ofy().delete()}, but can be augmented via subclassing to
|
||||||
|
@ -35,21 +36,25 @@ abstract class AugmentedDeleter implements Deleter {
|
||||||
/** Extension method to allow this Deleter to do extra work prior to the actual delete. */
|
/** Extension method to allow this Deleter to do extra work prior to the actual delete. */
|
||||||
protected abstract void handleDeletion(Iterable<Key<?>> keys);
|
protected abstract void handleDeletion(Iterable<Key<?>> keys);
|
||||||
|
|
||||||
|
private void handleDeletionStream(Stream<?> entityStream) {
|
||||||
|
handleDeletion(entityStream.map(Key::create).collect(toImmutableList()));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result<Void> entities(Iterable<?> entities) {
|
public Result<Void> entities(Iterable<?> entities) {
|
||||||
handleDeletion(Iterables.transform(entities, Key::create));
|
handleDeletionStream(Streams.stream(entities));
|
||||||
return delegate.entities(entities);
|
return delegate.entities(entities);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result<Void> entities(Object... entities) {
|
public Result<Void> entities(Object... entities) {
|
||||||
handleDeletion(FluentIterable.from(entities).transform(Key::create));
|
handleDeletionStream(Arrays.stream(entities));
|
||||||
return delegate.entities(entities);
|
return delegate.entities(entities);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result<Void> entity(Object entity) {
|
public Result<Void> entity(Object entity) {
|
||||||
handleDeletion(Arrays.asList(Key.create(entity)));
|
handleDeletionStream(Stream.of(entity));
|
||||||
return delegate.entity(entity);
|
return delegate.entity(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,11 +14,10 @@
|
||||||
|
|
||||||
package google.registry.model.ofy;
|
package google.registry.model.ofy;
|
||||||
|
|
||||||
import com.google.common.base.Joiner;
|
|
||||||
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;
|
||||||
import google.registry.model.BackupGroupRoot;
|
import google.registry.model.BackupGroupRoot;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
|
|
||||||
|
@ -43,19 +42,19 @@ class TimestampInversionException extends RuntimeException {
|
||||||
|
|
||||||
private TimestampInversionException(DateTime transactionTime, String problem) {
|
private TimestampInversionException(DateTime transactionTime, String problem) {
|
||||||
super(
|
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\n%s",
|
||||||
transactionTime, problem),
|
transactionTime,
|
||||||
|
problem,
|
||||||
getFileAndLine(
|
getFileAndLine(
|
||||||
FluentIterable.from(new Exception().getStackTrace())
|
Arrays.stream(new Exception().getStackTrace())
|
||||||
.firstMatch(
|
.filter(
|
||||||
(StackTraceElement element) ->
|
element ->
|
||||||
!element
|
!element
|
||||||
.getClassName()
|
.getClassName()
|
||||||
.startsWith(Objectify.class.getPackage().getName())
|
.startsWith(Objectify.class.getPackage().getName())
|
||||||
&& !element.getClassName().startsWith(Ofy.class.getName()))
|
&& !element.getClassName().startsWith(Ofy.class.getName()))
|
||||||
|
.findFirst()
|
||||||
.get())));
|
.get())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,9 +21,7 @@ import static google.registry.util.DateTimeUtils.END_OF_TIME;
|
||||||
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
|
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
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;
|
||||||
|
@ -31,6 +29,7 @@ import com.googlecode.objectify.annotation.Id;
|
||||||
import com.googlecode.objectify.annotation.Index;
|
import com.googlecode.objectify.annotation.Index;
|
||||||
import com.googlecode.objectify.annotation.Parent;
|
import com.googlecode.objectify.annotation.Parent;
|
||||||
import google.registry.model.Buildable;
|
import google.registry.model.Buildable;
|
||||||
|
import google.registry.model.EppResource;
|
||||||
import google.registry.model.ImmutableObject;
|
import google.registry.model.ImmutableObject;
|
||||||
import google.registry.model.annotations.ExternalMessagingName;
|
import google.registry.model.annotations.ExternalMessagingName;
|
||||||
import google.registry.model.domain.DomainRenewData;
|
import google.registry.model.domain.DomainRenewData;
|
||||||
|
@ -232,34 +231,38 @@ 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);
|
|
||||||
getInstance().contactPendingActionNotificationResponses =
|
getInstance().contactPendingActionNotificationResponses =
|
||||||
forceEmptyToNull(
|
forceEmptyToNull(
|
||||||
Streams.stream(iterable)
|
responseData
|
||||||
|
.stream()
|
||||||
.filter(ContactPendingActionNotificationResponse.class::isInstance)
|
.filter(ContactPendingActionNotificationResponse.class::isInstance)
|
||||||
.map(ContactPendingActionNotificationResponse.class::cast)
|
.map(ContactPendingActionNotificationResponse.class::cast)
|
||||||
.collect(toImmutableList()));
|
.collect(toImmutableList()));
|
||||||
getInstance().contactTransferResponses =
|
getInstance().contactTransferResponses =
|
||||||
forceEmptyToNull(
|
forceEmptyToNull(
|
||||||
Streams.stream(iterable)
|
responseData
|
||||||
|
.stream()
|
||||||
.filter(ContactTransferResponse.class::isInstance)
|
.filter(ContactTransferResponse.class::isInstance)
|
||||||
.map(ContactTransferResponse.class::cast)
|
.map(ContactTransferResponse.class::cast)
|
||||||
.collect(toImmutableList()));
|
.collect(toImmutableList()));
|
||||||
getInstance().domainPendingActionNotificationResponses =
|
getInstance().domainPendingActionNotificationResponses =
|
||||||
forceEmptyToNull(
|
forceEmptyToNull(
|
||||||
Streams.stream(iterable)
|
responseData
|
||||||
|
.stream()
|
||||||
.filter(DomainPendingActionNotificationResponse.class::isInstance)
|
.filter(DomainPendingActionNotificationResponse.class::isInstance)
|
||||||
.map(DomainPendingActionNotificationResponse.class::cast)
|
.map(DomainPendingActionNotificationResponse.class::cast)
|
||||||
.collect(toImmutableList()));
|
.collect(toImmutableList()));
|
||||||
getInstance().domainTransferResponses =
|
getInstance().domainTransferResponses =
|
||||||
forceEmptyToNull(
|
forceEmptyToNull(
|
||||||
Streams.stream(iterable)
|
responseData
|
||||||
|
.stream()
|
||||||
.filter(DomainTransferResponse.class::isInstance)
|
.filter(DomainTransferResponse.class::isInstance)
|
||||||
.map(DomainTransferResponse.class::cast)
|
.map(DomainTransferResponse.class::cast)
|
||||||
.collect(toImmutableList()));
|
.collect(toImmutableList()));
|
||||||
getInstance().hostPendingActionNotificationResponses =
|
getInstance().hostPendingActionNotificationResponses =
|
||||||
forceEmptyToNull(
|
forceEmptyToNull(
|
||||||
Streams.stream(iterable)
|
responseData
|
||||||
|
.stream()
|
||||||
.filter(HostPendingActionNotificationResponse.class::isInstance)
|
.filter(HostPendingActionNotificationResponse.class::isInstance)
|
||||||
.map(HostPendingActionNotificationResponse.class::cast)
|
.map(HostPendingActionNotificationResponse.class::cast)
|
||||||
.collect(toImmutableList()));
|
.collect(toImmutableList()));
|
||||||
|
|
|
@ -16,6 +16,7 @@ package google.registry.model.smd;
|
||||||
|
|
||||||
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.collect.Iterables.isEmpty;
|
import static com.google.common.collect.Iterables.isEmpty;
|
||||||
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;
|
||||||
|
@ -26,7 +27,6 @@ import static google.registry.util.DateTimeUtils.isBeforeOrAt;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
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.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.googlecode.objectify.Key;
|
import com.googlecode.objectify.Key;
|
||||||
|
@ -164,15 +164,17 @@ public class SignedMarkRevocationList extends ImmutableObject {
|
||||||
ofy()
|
ofy()
|
||||||
.saveWithoutBackup()
|
.saveWithoutBackup()
|
||||||
.entities(
|
.entities(
|
||||||
FluentIterable.from(CollectionUtils.partitionMap(revokes, SHARD_SIZE))
|
CollectionUtils.partitionMap(revokes, SHARD_SIZE)
|
||||||
.transform(
|
.stream()
|
||||||
(ImmutableMap<String, DateTime> shardRevokes) -> {
|
.map(
|
||||||
|
shardRevokes -> {
|
||||||
SignedMarkRevocationList shard = create(creationTime, shardRevokes);
|
SignedMarkRevocationList shard = create(creationTime, shardRevokes);
|
||||||
shard.id = allocateId();
|
shard.id = allocateId();
|
||||||
shard.isShard =
|
shard.isShard =
|
||||||
true; // Avoid the exception in disallowUnshardedSaves().
|
true; // Avoid the exception in disallowUnshardedSaves().
|
||||||
return shard;
|
return shard;
|
||||||
}));
|
})
|
||||||
|
.collect(toImmutableList()));
|
||||||
});
|
});
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,18 +15,19 @@
|
||||||
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.ImmutableList.toImmutableList;
|
||||||
import static com.google.common.collect.ImmutableSortedSet.toImmutableSortedSet;
|
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.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.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;
|
||||||
|
@ -522,23 +523,24 @@ public class RdapJsonFormatter {
|
||||||
if (displayContacts) {
|
if (displayContacts) {
|
||||||
Map<Key<ContactResource>, ContactResource> loadedContacts =
|
Map<Key<ContactResource>, ContactResource> loadedContacts =
|
||||||
ofy().load().keys(domainResource.getReferencedContacts());
|
ofy().load().keys(domainResource.getReferencedContacts());
|
||||||
ImmutableList.Builder<Object> entitiesBuilder = new ImmutableList.Builder<>();
|
ImmutableList<ImmutableMap<String, Object>> entities =
|
||||||
for (DesignatedContact designatedContact :
|
Streams.concat(
|
||||||
FluentIterable.from(domainResource.getContacts())
|
domainResource.getContacts().stream(),
|
||||||
.append(DesignatedContact.create(Type.REGISTRANT, domainResource.getRegistrant()))
|
Stream.of(
|
||||||
.toSortedList(DESIGNATED_CONTACT_ORDERING)) {
|
DesignatedContact.create(Type.REGISTRANT, domainResource.getRegistrant())))
|
||||||
ContactResource loadedContact = loadedContacts.get(designatedContact.getContactKey());
|
.sorted(DESIGNATED_CONTACT_ORDERING)
|
||||||
entitiesBuilder.add(makeRdapJsonForContact(
|
.map(
|
||||||
loadedContact,
|
designatedContact ->
|
||||||
|
makeRdapJsonForContact(
|
||||||
|
loadedContacts.get(designatedContact.getContactKey()),
|
||||||
false,
|
false,
|
||||||
Optional.of(designatedContact.getType()),
|
Optional.of(designatedContact.getType()),
|
||||||
linkBase,
|
linkBase,
|
||||||
null,
|
null,
|
||||||
now,
|
now,
|
||||||
outputDataType,
|
outputDataType,
|
||||||
authorization));
|
authorization))
|
||||||
}
|
.collect(toImmutableList());
|
||||||
ImmutableList<Object> entities = entitiesBuilder.build();
|
|
||||||
if (!entities.isEmpty()) {
|
if (!entities.isEmpty()) {
|
||||||
jsonBuilder.put("entities", entities);
|
jsonBuilder.put("entities", entities);
|
||||||
}
|
}
|
||||||
|
@ -845,14 +847,13 @@ public class RdapJsonFormatter {
|
||||||
jsonBuilder.put("events", events);
|
jsonBuilder.put("events", events);
|
||||||
}
|
}
|
||||||
// include the registrar contacts as subentities
|
// include the registrar contacts as subentities
|
||||||
ImmutableList.Builder<Map<String, Object>> registrarContactsBuilder =
|
ImmutableList<ImmutableMap<String, Object>> registrarContacts =
|
||||||
new ImmutableList.Builder<>();
|
registrar
|
||||||
for (RegistrarContact registrarContact : registrar.getContacts()) {
|
.getContacts()
|
||||||
if (isVisible(registrarContact)) {
|
.stream()
|
||||||
registrarContactsBuilder.add(makeRdapJsonForRegistrarContact(registrarContact, null));
|
.filter(RdapJsonFormatter::isVisible)
|
||||||
}
|
.map(registrarContact -> makeRdapJsonForRegistrarContact(registrarContact, null))
|
||||||
}
|
.collect(toImmutableList());
|
||||||
ImmutableList<Map<String, Object>> registrarContacts = registrarContactsBuilder.build();
|
|
||||||
if (!registrarContacts.isEmpty()) {
|
if (!registrarContacts.isEmpty()) {
|
||||||
jsonBuilder.put("entities", registrarContacts);
|
jsonBuilder.put("entities", registrarContacts);
|
||||||
}
|
}
|
||||||
|
@ -1096,7 +1097,7 @@ public class RdapJsonFormatter {
|
||||||
.map(status -> statusToRdapStatusMap.getOrDefault(status, RdapStatus.OBSCURED));
|
.map(status -> statusToRdapStatusMap.getOrDefault(status, RdapStatus.OBSCURED));
|
||||||
if (isDeleted) {
|
if (isDeleted) {
|
||||||
stream =
|
stream =
|
||||||
Stream.concat(
|
Streams.concat(
|
||||||
stream.filter(rdapStatus -> !Objects.equals(rdapStatus, RdapStatus.ACTIVE)),
|
stream.filter(rdapStatus -> !Objects.equals(rdapStatus, RdapStatus.ACTIVE)),
|
||||||
Stream.of(RdapStatus.REMOVED));
|
Stream.of(RdapStatus.REMOVED));
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,6 @@ import static google.registry.util.DomainNameUtils.ACE_PREFIX;
|
||||||
import com.google.common.base.Ascii;
|
import com.google.common.base.Ascii;
|
||||||
import com.google.common.base.Joiner;
|
import com.google.common.base.Joiner;
|
||||||
import com.google.common.base.Predicates;
|
import com.google.common.base.Predicates;
|
||||||
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.Multiset;
|
import com.google.common.collect.Multiset;
|
||||||
|
@ -50,6 +49,7 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
@ -290,12 +290,13 @@ public class VerifyOteAction implements Runnable, JsonAction {
|
||||||
/** Returns a string showing all possible actions and how many times each was performed. */
|
/** Returns a string showing all possible actions and how many times each was performed. */
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return FluentIterable.from(EnumSet.allOf(StatType.class))
|
return String.format(
|
||||||
.transform(
|
"%s\nTOTAL: %d",
|
||||||
statType ->
|
EnumSet.allOf(StatType.class)
|
||||||
String.format("%s: %d", statType.description(), statCounts.count(statType)))
|
.stream()
|
||||||
.append(String.format("TOTAL: %d", statCounts.size()))
|
.map(stat -> String.format("%s: %d", stat.description(), statCounts.count(stat)))
|
||||||
.join(Joiner.on("\n"));
|
.collect(Collectors.joining("\n")),
|
||||||
|
statCounts.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
package google.registry.util;
|
package google.registry.util;
|
||||||
|
|
||||||
import com.google.common.collect.FluentIterable;
|
import java.util.Arrays;
|
||||||
import java.util.logging.Handler;
|
import java.util.logging.Handler;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
@ -44,8 +44,9 @@ public class FormattingLogger {
|
||||||
|
|
||||||
private void log(Level level, @Nullable Throwable cause, String msg) {
|
private void log(Level level, @Nullable Throwable cause, String msg) {
|
||||||
StackTraceElement callerFrame =
|
StackTraceElement callerFrame =
|
||||||
FluentIterable.from(new Exception().getStackTrace())
|
Arrays.stream(new Exception().getStackTrace())
|
||||||
.firstMatch(frame -> !frame.getClassName().equals(FormattingLogger.class.getName()))
|
.filter(frame -> !frame.getClassName().equals(FormattingLogger.class.getName()))
|
||||||
|
.findFirst()
|
||||||
.get();
|
.get();
|
||||||
if (cause == null) {
|
if (cause == null) {
|
||||||
logger.logp(level, callerFrame.getClassName(), callerFrame.getMethodName(), msg);
|
logger.logp(level, callerFrame.getClassName(), callerFrame.getMethodName(), msg);
|
||||||
|
|
|
@ -15,10 +15,10 @@
|
||||||
package google.registry.rde;
|
package google.registry.rde;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
import static com.google.common.truth.Truth8.assertThat;
|
||||||
import static google.registry.testing.DatastoreHelper.createTld;
|
import static google.registry.testing.DatastoreHelper.createTld;
|
||||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||||
|
|
||||||
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.contact.ContactAddress;
|
import google.registry.model.contact.ContactAddress;
|
||||||
|
@ -87,7 +87,7 @@ public class ContactResourceToXjcConverterTest {
|
||||||
|
|
||||||
// o One or more <status> elements that describe the status of the
|
// o One or more <status> elements that describe the status of the
|
||||||
// contact object.
|
// contact object.
|
||||||
assertThat(FluentIterable.from(bean.getStatuses()).transform(XjcContactStatusType::getS))
|
assertThat(bean.getStatuses().stream().map(XjcContactStatusType::getS))
|
||||||
.containsExactly(
|
.containsExactly(
|
||||||
XjcContactStatusValueType.CLIENT_DELETE_PROHIBITED,
|
XjcContactStatusValueType.CLIENT_DELETE_PROHIBITED,
|
||||||
XjcContactStatusValueType.SERVER_UPDATE_PROHIBITED);
|
XjcContactStatusValueType.SERVER_UPDATE_PROHIBITED);
|
||||||
|
|
|
@ -16,6 +16,7 @@ package google.registry.rde;
|
||||||
|
|
||||||
import static com.google.common.io.BaseEncoding.base16;
|
import static com.google.common.io.BaseEncoding.base16;
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
import static com.google.common.truth.Truth8.assertThat;
|
||||||
import static google.registry.testing.DatastoreHelper.createTld;
|
import static google.registry.testing.DatastoreHelper.createTld;
|
||||||
import static google.registry.testing.DatastoreHelper.newDomainResource;
|
import static google.registry.testing.DatastoreHelper.newDomainResource;
|
||||||
import static google.registry.testing.DatastoreHelper.persistEppResource;
|
import static google.registry.testing.DatastoreHelper.persistEppResource;
|
||||||
|
@ -26,7 +27,6 @@ import static google.registry.xjc.rgp.XjcRgpStatusValueType.TRANSFER_PERIOD;
|
||||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||||
import static org.joda.money.CurrencyUnit.USD;
|
import static org.joda.money.CurrencyUnit.USD;
|
||||||
|
|
||||||
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.InetAddresses;
|
import com.google.common.net.InetAddresses;
|
||||||
|
@ -106,9 +106,9 @@ public class DomainResourceToXjcConverterTest {
|
||||||
assertThat(bean.getClID()).isEqualTo("GetTheeBack");
|
assertThat(bean.getClID()).isEqualTo("GetTheeBack");
|
||||||
|
|
||||||
assertThat(
|
assertThat(
|
||||||
FluentIterable.from(bean.getContacts())
|
bean.getContacts()
|
||||||
.transform(
|
.stream()
|
||||||
input -> String.format("%s %s", input.getType().toString(), input.getValue())))
|
.map(input -> String.format("%s %s", input.getType().toString(), input.getValue())))
|
||||||
.containsExactly("ADMIN 5372808-IRL", "TECH 5372808-TRL");
|
.containsExactly("ADMIN 5372808-IRL", "TECH 5372808-TRL");
|
||||||
|
|
||||||
assertThat(bean.getCrDate()).isEqualTo(DateTime.parse("1900-01-01T00:00:00Z"));
|
assertThat(bean.getCrDate()).isEqualTo(DateTime.parse("1900-01-01T00:00:00Z"));
|
||||||
|
@ -144,7 +144,7 @@ public class DomainResourceToXjcConverterTest {
|
||||||
// "pendingDelete" sub-statuses, including "redemptionPeriod",
|
// "pendingDelete" sub-statuses, including "redemptionPeriod",
|
||||||
// "pendingRestore", and "pendingDelete", that a domain name can be
|
// "pendingRestore", and "pendingDelete", that a domain name can be
|
||||||
// in as a result of grace period processing as specified in [RFC3915].
|
// in as a result of grace period processing as specified in [RFC3915].
|
||||||
assertThat(FluentIterable.from(bean.getRgpStatuses()).transform(XjcRgpStatusType::getS))
|
assertThat(bean.getRgpStatuses().stream().map(XjcRgpStatusType::getS))
|
||||||
.containsExactly(TRANSFER_PERIOD, RENEW_PERIOD);
|
.containsExactly(TRANSFER_PERIOD, RENEW_PERIOD);
|
||||||
|
|
||||||
assertThat(bean.getSecDNS()).named("secdns").isNotNull();
|
assertThat(bean.getSecDNS()).named("secdns").isNotNull();
|
||||||
|
@ -159,7 +159,7 @@ public class DomainResourceToXjcConverterTest {
|
||||||
|
|
||||||
assertThat(bean.getRoid()).isEqualTo("2-Q9JYB4C");
|
assertThat(bean.getRoid()).isEqualTo("2-Q9JYB4C");
|
||||||
|
|
||||||
assertThat(FluentIterable.from(bean.getStatuses()).transform(XjcDomainStatusType::getS))
|
assertThat(bean.getStatuses().stream().map(XjcDomainStatusType::getS))
|
||||||
.containsExactly(
|
.containsExactly(
|
||||||
XjcDomainStatusValueType.CLIENT_DELETE_PROHIBITED,
|
XjcDomainStatusValueType.CLIENT_DELETE_PROHIBITED,
|
||||||
XjcDomainStatusValueType.CLIENT_RENEW_PROHIBITED,
|
XjcDomainStatusValueType.CLIENT_RENEW_PROHIBITED,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue