mirror of
https://github.com/google/nomulus.git
synced 2025-05-17 17:59:41 +02:00
Run automatic Java 8 conversion over codebase
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=171174380
This commit is contained in:
parent
44df5da771
commit
5edb7935ed
190 changed files with 2312 additions and 3096 deletions
|
@ -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.checkState;
|
||||
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.io.BaseEncoding.base16;
|
||||
import static google.registry.flows.EppXmlTransformer.unmarshal;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.tools.CommandUtilities.addHeader;
|
||||
import static java.util.stream.Collectors.joining;
|
||||
|
||||
import com.beust.jcommander.Parameter;
|
||||
import com.beust.jcommander.Parameters;
|
||||
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.collect.FluentIterable;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.template.soy.data.SoyMapData;
|
||||
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.launch.ApplicationStatus;
|
||||
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.ResourceCommandWrapper;
|
||||
import google.registry.model.reporting.HistoryEntry;
|
||||
|
@ -51,6 +49,7 @@ import google.registry.model.smd.SignedMark;
|
|||
import google.registry.tools.soy.DomainAllocateSoyInfo;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/** Command to allocated a domain from a domain application. */
|
||||
@Parameters(separators = " =", commandDescription = "Allocate a domain application")
|
||||
|
@ -68,20 +67,33 @@ final class AllocateDomainCommand extends MutatingEppToolCommand {
|
|||
protected String postExecute() throws Exception {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
// Check to see that we allocated everything.
|
||||
return builder.append(ofy().transactNewReadOnly(new Work<String>() {
|
||||
@Override
|
||||
public String run() {
|
||||
String failureMessage = FluentIterable
|
||||
.from(ofy().load().keys(applicationKeys).values())
|
||||
.transform(new Function<DomainApplication, String>() {
|
||||
@Override
|
||||
public String apply(DomainApplication application) {
|
||||
return application.getApplicationStatus() == ApplicationStatus.ALLOCATED
|
||||
? null : application.getFullyQualifiedDomainName();
|
||||
}})
|
||||
.join(Joiner.on('\n').skipNulls());
|
||||
return failureMessage.isEmpty() ? "ALL SUCCEEDED" : addHeader("FAILURES", failureMessage);
|
||||
}})).toString();
|
||||
return builder
|
||||
.append(
|
||||
ofy()
|
||||
.transactNewReadOnly(
|
||||
new Work<String>() {
|
||||
@Override
|
||||
public String run() {
|
||||
String failureMessage =
|
||||
ofy()
|
||||
.load()
|
||||
.keys(applicationKeys)
|
||||
.values()
|
||||
.stream()
|
||||
.map(
|
||||
application ->
|
||||
application.getApplicationStatus()
|
||||
== ApplicationStatus.ALLOCATED
|
||||
? 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. */
|
||||
|
@ -96,85 +108,98 @@ final class AllocateDomainCommand extends MutatingEppToolCommand {
|
|||
protected void initMutatingEppToolCommand() {
|
||||
checkArgument(superuser, "This command MUST be run as --superuser.");
|
||||
setSoyTemplate(DomainAllocateSoyInfo.getInstance(), DomainAllocateSoyInfo.CREATE);
|
||||
ofy().transactNewReadOnly(new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
Iterable<Key<DomainApplication>> keys = transform(
|
||||
Splitter.on(',').split(ids),
|
||||
new Function<String, Key<DomainApplication>>() {
|
||||
ofy()
|
||||
.transactNewReadOnly(
|
||||
new VoidWork() {
|
||||
@Override
|
||||
public Key<DomainApplication> apply(String applicationId) {
|
||||
return Key.create(DomainApplication.class, applicationId);
|
||||
}});
|
||||
for (DomainApplication application : ofy().load().keys(keys).values()) {
|
||||
// If the application is already allocated print a warning but do not fail.
|
||||
if (application.getApplicationStatus() == ApplicationStatus.ALLOCATED) {
|
||||
System.err.printf(
|
||||
"Application %s has already been allocated\n", application.getRepoId());
|
||||
continue;
|
||||
}
|
||||
// Ensure domain doesn't already have a final status which it shouldn't be updated from.
|
||||
checkState(
|
||||
!application.getApplicationStatus().isFinalStatus(),
|
||||
"Application has final status %s",
|
||||
application.getApplicationStatus());
|
||||
try {
|
||||
HistoryEntry history = checkNotNull(
|
||||
ofy().load()
|
||||
.type(HistoryEntry.class)
|
||||
.ancestor(checkNotNull(application))
|
||||
.order("modificationTime")
|
||||
.first()
|
||||
.now(),
|
||||
"Could not find any history entries for domain application %s",
|
||||
application.getRepoId());
|
||||
String clientTransactionId =
|
||||
emptyToNull(history.getTrid().getClientTransactionId());
|
||||
Period period = checkNotNull(extractPeriodFromXml(history.getXmlBytes()));
|
||||
checkArgument(period.getUnit() == Period.Unit.YEARS);
|
||||
ImmutableMap.Builder<String, String> contactsMapBuilder = new ImmutableMap.Builder<>();
|
||||
for (DesignatedContact contact : application.getContacts()) {
|
||||
contactsMapBuilder.put(
|
||||
Ascii.toLowerCase(contact.getType().toString()),
|
||||
ofy().load().key(contact.getContactKey()).now().getForeignKey());
|
||||
}
|
||||
LaunchNotice launchNotice = application.getLaunchNotice();
|
||||
addSoyRecord(application.getCurrentSponsorClientId(), new SoyMapData(
|
||||
"name", application.getFullyQualifiedDomainName(),
|
||||
"period", period.getValue(),
|
||||
"nameservers", application.loadNameserverFullyQualifiedHostNames(),
|
||||
"registrant", ofy().load().key(application.getRegistrant()).now().getForeignKey(),
|
||||
"contacts", contactsMapBuilder.build(),
|
||||
"authInfo", application.getAuthInfo().getPw().getValue(),
|
||||
"smdId", application.getEncodedSignedMarks().isEmpty()
|
||||
? null
|
||||
: unmarshal(
|
||||
SignedMark.class,
|
||||
application.getEncodedSignedMarks().get(0).getBytes()).getId(),
|
||||
"applicationRoid", application.getRepoId(),
|
||||
"applicationTime", application.getCreationTime().toString(),
|
||||
"launchNotice", launchNotice == null ? null : ImmutableMap.of(
|
||||
"noticeId", launchNotice.getNoticeId().getTcnId(),
|
||||
"expirationTime", launchNotice.getExpirationTime().toString(),
|
||||
"acceptedTime", launchNotice.getAcceptedTime().toString()),
|
||||
"dsRecords", FluentIterable.from(application.getDsData())
|
||||
.transform(new Function<DelegationSignerData, ImmutableMap<String, ?>>() {
|
||||
@Override
|
||||
public ImmutableMap<String, ?> apply(DelegationSignerData dsData) {
|
||||
return ImmutableMap.of(
|
||||
"keyTag", dsData.getKeyTag(),
|
||||
"algorithm", dsData.getAlgorithm(),
|
||||
"digestType", dsData.getDigestType(),
|
||||
"digest", base16().encode(dsData.getDigest()));
|
||||
}})
|
||||
.toList(),
|
||||
"clTrid", clientTransactionId));
|
||||
applicationKeys.add(Key.create(application));
|
||||
} catch (EppException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
public void vrun() {
|
||||
Iterable<Key<DomainApplication>> keys =
|
||||
transform(
|
||||
Splitter.on(',').split(ids),
|
||||
applicationId -> Key.create(DomainApplication.class, applicationId));
|
||||
for (DomainApplication application : ofy().load().keys(keys).values()) {
|
||||
// If the application is already allocated print a warning but do not fail.
|
||||
if (application.getApplicationStatus() == ApplicationStatus.ALLOCATED) {
|
||||
System.err.printf(
|
||||
"Application %s has already been allocated\n", application.getRepoId());
|
||||
continue;
|
||||
}
|
||||
// Ensure domain doesn't already have a final status which it shouldn't be updated
|
||||
// from.
|
||||
checkState(
|
||||
!application.getApplicationStatus().isFinalStatus(),
|
||||
"Application has final status %s",
|
||||
application.getApplicationStatus());
|
||||
try {
|
||||
HistoryEntry history =
|
||||
checkNotNull(
|
||||
ofy()
|
||||
.load()
|
||||
.type(HistoryEntry.class)
|
||||
.ancestor(checkNotNull(application))
|
||||
.order("modificationTime")
|
||||
.first()
|
||||
.now(),
|
||||
"Could not find any history entries for domain application %s",
|
||||
application.getRepoId());
|
||||
String clientTransactionId =
|
||||
emptyToNull(history.getTrid().getClientTransactionId());
|
||||
Period period = checkNotNull(extractPeriodFromXml(history.getXmlBytes()));
|
||||
checkArgument(period.getUnit() == Period.Unit.YEARS);
|
||||
ImmutableMap.Builder<String, String> contactsMapBuilder =
|
||||
new ImmutableMap.Builder<>();
|
||||
for (DesignatedContact contact : application.getContacts()) {
|
||||
contactsMapBuilder.put(
|
||||
Ascii.toLowerCase(contact.getType().toString()),
|
||||
ofy().load().key(contact.getContactKey()).now().getForeignKey());
|
||||
}
|
||||
LaunchNotice launchNotice = application.getLaunchNotice();
|
||||
addSoyRecord(
|
||||
application.getCurrentSponsorClientId(),
|
||||
new SoyMapData(
|
||||
"name", application.getFullyQualifiedDomainName(),
|
||||
"period", period.getValue(),
|
||||
"nameservers", application.loadNameserverFullyQualifiedHostNames(),
|
||||
"registrant",
|
||||
ofy().load().key(application.getRegistrant()).now().getForeignKey(),
|
||||
"contacts", contactsMapBuilder.build(),
|
||||
"authInfo", application.getAuthInfo().getPw().getValue(),
|
||||
"smdId",
|
||||
application.getEncodedSignedMarks().isEmpty()
|
||||
? null
|
||||
: unmarshal(
|
||||
SignedMark.class,
|
||||
application.getEncodedSignedMarks().get(0).getBytes())
|
||||
.getId(),
|
||||
"applicationRoid", application.getRepoId(),
|
||||
"applicationTime", application.getCreationTime().toString(),
|
||||
"launchNotice",
|
||||
launchNotice == null
|
||||
? null
|
||||
: ImmutableMap.of(
|
||||
"noticeId", launchNotice.getNoticeId().getTcnId(),
|
||||
"expirationTime",
|
||||
launchNotice.getExpirationTime().toString(),
|
||||
"acceptedTime", launchNotice.getAcceptedTime().toString()),
|
||||
"dsRecords",
|
||||
application
|
||||
.getDsData()
|
||||
.stream()
|
||||
.map(
|
||||
dsData ->
|
||||
ImmutableMap.of(
|
||||
"keyTag", dsData.getKeyTag(),
|
||||
"algorithm", dsData.getAlgorithm(),
|
||||
"digestType", dsData.getDigestType(),
|
||||
"digest", base16().encode(dsData.getDigest())))
|
||||
.collect(toImmutableList()),
|
||||
"clTrid", clientTransactionId));
|
||||
applicationKeys.add(Key.create(application));
|
||||
} catch (EppException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,11 +63,7 @@ class AppEngineConnection implements Connection {
|
|||
* <p>Computing this is expensive since it needs to load {@code ServerSecret} so do it once.
|
||||
*/
|
||||
private final Supplier<String> xsrfToken =
|
||||
memoize(new Supplier<String>() {
|
||||
@Override
|
||||
public String get() {
|
||||
return xsrfTokenManager.generateToken(getUserId());
|
||||
}});
|
||||
memoize(() -> xsrfTokenManager.generateToken(getUserId()));
|
||||
|
||||
@Override
|
||||
public void prefetchXsrfToken() throws IOException {
|
||||
|
|
|
@ -60,28 +60,34 @@ final class AuctionStatusCommand implements RemoteApiCommand {
|
|||
@Override
|
||||
public void run() throws Exception {
|
||||
final ImmutableSet<String> domains = ImmutableSet.copyOf(mainArguments);
|
||||
Files.write(output, FluentIterable
|
||||
.from(domains)
|
||||
.transformAndConcat(new Function<String, Iterable<String>>() {
|
||||
@Override
|
||||
public Iterable<String> apply(String fullyQualifiedDomainName) {
|
||||
checkState(
|
||||
findTldForName(InternetDomainName.from(fullyQualifiedDomainName)).isPresent(),
|
||||
"No tld found for %s", fullyQualifiedDomainName);
|
||||
return ofy().transactNewReadOnly(new Work<Iterable<String>>() {
|
||||
@Override
|
||||
public Iterable<String> run() {
|
||||
ImmutableList.Builder<DomainApplication> applications =
|
||||
new ImmutableList.Builder<>();
|
||||
for (String domain : domains) {
|
||||
applications.addAll(
|
||||
loadActiveApplicationsByDomainName(domain, ofy().getTransactionTime()));
|
||||
}
|
||||
return Lists.transform(
|
||||
FluentIterable.from(applications.build()).toSortedList(ORDERING),
|
||||
APPLICATION_FORMATTER);
|
||||
}});
|
||||
}}), UTF_8);
|
||||
Files.write(
|
||||
output,
|
||||
FluentIterable.from(domains)
|
||||
.transformAndConcat(
|
||||
fullyQualifiedDomainName -> {
|
||||
checkState(
|
||||
findTldForName(InternetDomainName.from(fullyQualifiedDomainName)).isPresent(),
|
||||
"No tld found for %s",
|
||||
fullyQualifiedDomainName);
|
||||
return ofy()
|
||||
.transactNewReadOnly(
|
||||
new Work<Iterable<String>>() {
|
||||
@Override
|
||||
public Iterable<String> run() {
|
||||
ImmutableList.Builder<DomainApplication> applications =
|
||||
new ImmutableList.Builder<>();
|
||||
for (String domain : domains) {
|
||||
applications.addAll(
|
||||
loadActiveApplicationsByDomainName(
|
||||
domain, ofy().getTransactionTime()));
|
||||
}
|
||||
return Lists.transform(
|
||||
ImmutableList.sortedCopyOf(ORDERING, applications.build()),
|
||||
APPLICATION_FORMATTER);
|
||||
}
|
||||
});
|
||||
}),
|
||||
UTF_8);
|
||||
}
|
||||
|
||||
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 =
|
||||
new Function<DomainApplication, String>() {
|
||||
@Override
|
||||
public String apply(DomainApplication app) {
|
||||
ContactResource registrant = checkNotNull(ofy().load().key(app.getRegistrant()).now());
|
||||
Object[] keysAndValues = new Object[] {
|
||||
app -> {
|
||||
ContactResource registrant = checkNotNull(ofy().load().key(app.getRegistrant()).now());
|
||||
Object[] keysAndValues =
|
||||
new Object[] {
|
||||
"Domain", app.getFullyQualifiedDomainName(),
|
||||
"Type", app.getEncodedSignedMarks().isEmpty() ? "Landrush" : "Sunrise",
|
||||
"Application Status", app.getApplicationStatus(),
|
||||
|
@ -111,8 +116,8 @@ final class AuctionStatusCommand implements RemoteApiCommand {
|
|||
"Registrar Name", app.getCurrentSponsorClientId(),
|
||||
"Registrant Email", registrant.getEmailAddress(),
|
||||
"Registrant Phone", registrant.getVoiceNumber().getPhoneNumber()
|
||||
};
|
||||
return String.format(
|
||||
Strings.repeat("%-25s= %s\n", keysAndValues.length / 2), keysAndValues);
|
||||
}};
|
||||
};
|
||||
return String.format(
|
||||
Strings.repeat("%-25s= %s\n", keysAndValues.length / 2), keysAndValues);
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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_UNDERSCORE;
|
||||
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.util.PreconditionsUtils.checkArgumentPresent;
|
||||
import static org.joda.time.DateTimeZone.UTC;
|
||||
|
@ -25,9 +26,9 @@ import com.beust.jcommander.Parameter;
|
|||
import com.beust.jcommander.Parameters;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Streams;
|
||||
import com.google.re2j.Matcher;
|
||||
import com.google.re2j.Pattern;
|
||||
import google.registry.model.billing.RegistrarCredit;
|
||||
|
@ -42,6 +43,7 @@ import java.nio.charset.StandardCharsets;
|
|||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
import org.joda.money.BigMoney;
|
||||
import org.joda.money.CurrencyUnit;
|
||||
import org.joda.money.Money;
|
||||
|
@ -107,31 +109,25 @@ final class CreateAuctionCreditsCommand extends MutatingCommand {
|
|||
CURRENCY_CODE;
|
||||
|
||||
public static List<String> getHeaders() {
|
||||
return FluentIterable.from(values())
|
||||
.transform(new Function<CsvHeader, String>() {
|
||||
@Override
|
||||
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();
|
||||
return Stream.of(values())
|
||||
.map(header -> UPPER_UNDERSCORE.to(UPPER_CAMEL, header.name()))
|
||||
.collect(toImmutableList());
|
||||
}
|
||||
}
|
||||
|
||||
private static final Pattern QUOTED_STRING = Pattern.compile("\"(.*)\"");
|
||||
|
||||
/** 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>() {
|
||||
@Override
|
||||
public String apply(String input) {
|
||||
Matcher matcher = QUOTED_STRING.matcher(input);
|
||||
checkArgument(matcher.matches(), "Input not quoted");
|
||||
return matcher.group(1);
|
||||
}};
|
||||
private static final Function<String, String> UNQUOTER =
|
||||
input -> {
|
||||
Matcher matcher = QUOTED_STRING.matcher(input);
|
||||
checkArgument(matcher.matches(), "Input not quoted");
|
||||
return matcher.group(1);
|
||||
};
|
||||
|
||||
/** Returns the input string of quoted CSV values split into the list of unquoted values. */
|
||||
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
|
||||
|
|
|
@ -16,6 +16,7 @@ package google.registry.tools;
|
|||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
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 google.registry.model.ofy.ObjectifyService.ofy;
|
||||
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.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.CharMatcher;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
@ -50,7 +49,6 @@ import java.io.StringReader;
|
|||
import java.nio.file.Path;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
|
@ -164,12 +162,12 @@ public class CreateLrpTokensCommand implements RemoteApiCommand {
|
|||
}
|
||||
final ImmutableSet<LrpTokenEntity> tokensToSave = tokensToSaveBuilder.build();
|
||||
// Wrap in a retrier to deal with transient 404 errors (thrown as RemoteApiExceptions).
|
||||
retrier.callWithRetry(new Callable<Void>() {
|
||||
@Override
|
||||
public Void call() throws Exception {
|
||||
saveTokens(tokensToSave);
|
||||
return null;
|
||||
}}, RemoteApiException.class);
|
||||
retrier.callWithRetry(
|
||||
() -> {
|
||||
saveTokens(tokensToSave);
|
||||
return null;
|
||||
},
|
||||
RemoteApiException.class);
|
||||
} while (line != null);
|
||||
}
|
||||
|
||||
|
@ -196,21 +194,19 @@ public class CreateLrpTokensCommand implements RemoteApiCommand {
|
|||
private ImmutableSet<String> generateTokens(int count) {
|
||||
final ImmutableSet<String> candidates =
|
||||
ImmutableSet.copyOf(TokenUtils.createTokens(LRP, stringGenerator, count));
|
||||
ImmutableSet<Key<LrpTokenEntity>> existingTokenKeys = FluentIterable.from(candidates)
|
||||
.transform(new Function<String, Key<LrpTokenEntity>>() {
|
||||
@Override
|
||||
public Key<LrpTokenEntity> apply(String input) {
|
||||
return Key.create(LrpTokenEntity.class, input);
|
||||
}})
|
||||
.toSet();
|
||||
ImmutableSet<String> existingTokenStrings = FluentIterable
|
||||
.from(ofy().load().keys(existingTokenKeys).values())
|
||||
.transform(new Function<LrpTokenEntity, String>() {
|
||||
@Override
|
||||
public String apply(LrpTokenEntity input) {
|
||||
return input.getToken();
|
||||
}})
|
||||
.toSet();
|
||||
ImmutableSet<Key<LrpTokenEntity>> existingTokenKeys =
|
||||
candidates
|
||||
.stream()
|
||||
.map(input -> Key.create(LrpTokenEntity.class, input))
|
||||
.collect(toImmutableSet());
|
||||
ImmutableSet<String> existingTokenStrings =
|
||||
ofy()
|
||||
.load()
|
||||
.keys(existingTokenKeys)
|
||||
.values()
|
||||
.stream()
|
||||
.map(LrpTokenEntity::getToken)
|
||||
.collect(toImmutableSet());
|
||||
return ImmutableSet.copyOf(difference(candidates, existingTokenStrings));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.Predicates.isNull;
|
||||
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.RegistrarUtils.normalizeRegistrarName;
|
||||
import static java.nio.charset.StandardCharsets.US_ASCII;
|
||||
import static org.joda.time.DateTimeZone.UTC;
|
||||
|
||||
import com.beust.jcommander.Parameter;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Sets;
|
||||
import google.registry.model.billing.RegistrarBillingUtils;
|
||||
import google.registry.model.registrar.Registrar;
|
||||
|
@ -376,8 +374,9 @@ abstract class CreateOrUpdateRegistrarCommand extends MutatingCommand {
|
|||
builder.setBillingMethod(billingMethod);
|
||||
}
|
||||
List<Object> streetAddressFields = Arrays.asList(street, city, state, zip, countryCode);
|
||||
checkArgument(Iterables.any(streetAddressFields, isNull())
|
||||
== Iterables.all(streetAddressFields, isNull()),
|
||||
checkArgument(
|
||||
streetAddressFields.stream().anyMatch(isNull())
|
||||
== streetAddressFields.stream().allMatch(isNull()),
|
||||
"Must specify all fields of address");
|
||||
if (street != null) {
|
||||
// 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
|
||||
// allowed to register.
|
||||
ImmutableSet<CurrencyUnit> tldCurrencies =
|
||||
FluentIterable.from(newRegistrar.getAllowedTlds())
|
||||
.transform(
|
||||
new Function<String, CurrencyUnit>() {
|
||||
@Override
|
||||
public CurrencyUnit apply(String tld) {
|
||||
return Registry.get(tld).getCurrency();
|
||||
}
|
||||
})
|
||||
.toSet();
|
||||
newRegistrar
|
||||
.getAllowedTlds()
|
||||
.stream()
|
||||
.map(tld -> Registry.get(tld).getCurrency())
|
||||
.collect(toImmutableSet());
|
||||
Set<CurrencyUnit> currenciesWithoutBillingAccountId =
|
||||
newRegistrar.getBillingAccountMap() == null
|
||||
? tldCurrencies
|
||||
|
|
|
@ -17,22 +17,22 @@ package google.registry.tools;
|
|||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
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.Lists.newArrayList;
|
||||
import static google.registry.model.registrar.Registrar.State.ACTIVE;
|
||||
import static google.registry.tools.RegistryToolEnvironment.PRODUCTION;
|
||||
import static google.registry.tools.RegistryToolEnvironment.SANDBOX;
|
||||
import static google.registry.tools.RegistryToolEnvironment.UNITTEST;
|
||||
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
|
||||
import static google.registry.util.RegistrarUtils.normalizeClientId;
|
||||
import static java.util.stream.Collectors.toCollection;
|
||||
|
||||
import com.beust.jcommander.Parameter;
|
||||
import com.beust.jcommander.Parameters;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Streams;
|
||||
import google.registry.model.registrar.Registrar;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
@ -82,15 +82,9 @@ final class CreateRegistrarCommand extends CreateOrUpdateRegistrarCommand
|
|||
checkState(
|
||||
!Registrar.loadByClientId(clientId).isPresent(), "Registrar %s already exists", clientId);
|
||||
List<Registrar> collisions =
|
||||
newArrayList(
|
||||
filter(
|
||||
Registrar.loadAll(),
|
||||
new Predicate<Registrar>() {
|
||||
@Override
|
||||
public boolean apply(Registrar registrar) {
|
||||
return normalizeClientId(registrar.getClientId()).equals(clientId);
|
||||
}
|
||||
}));
|
||||
Streams.stream(Registrar.loadAll())
|
||||
.filter(registrar -> normalizeClientId(registrar.getClientId()).equals(clientId))
|
||||
.collect(toCollection(ArrayList::new));
|
||||
if (!collisions.isEmpty()) {
|
||||
throw new IllegalArgumentException(String.format(
|
||||
"The registrar client identifier %s normalizes identically to existing registrar %s",
|
||||
|
|
|
@ -14,13 +14,11 @@
|
|||
|
||||
package google.registry.tools;
|
||||
|
||||
import static com.google.common.collect.Iterables.transform;
|
||||
import static google.registry.util.PreconditionsUtils.checkArgumentPresent;
|
||||
import static java.util.stream.Collectors.joining;
|
||||
|
||||
import com.beust.jcommander.Parameter;
|
||||
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.net.MediaType;
|
||||
import google.registry.model.registrar.Registrar;
|
||||
|
@ -64,11 +62,7 @@ public class CreateRegistrarGroupsCommand extends ConfirmingCommand
|
|||
protected String prompt() {
|
||||
return String.format(
|
||||
"Create registrar contact groups for registrar(s) %s?",
|
||||
Joiner.on(", ").join(transform(registrars, new Function<Registrar, String>() {
|
||||
@Override
|
||||
public String apply(Registrar registrar) {
|
||||
return registrar.getRegistrarName();
|
||||
}})));
|
||||
registrars.stream().map(Registrar::getRegistrarName).collect(joining(", ")));
|
||||
}
|
||||
|
||||
/** Calls the server endpoint to create groups for the specified registrar client id. */
|
||||
|
|
|
@ -24,6 +24,8 @@ import static google.registry.model.ofy.ObjectifyService.ofy;
|
|||
import static google.registry.model.registry.Registries.assertTldExists;
|
||||
import static google.registry.util.DateTimeUtils.isAtOrAfter;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static java.util.Comparator.comparing;
|
||||
import static java.util.stream.Collectors.joining;
|
||||
import static org.joda.time.DateTimeZone.UTC;
|
||||
|
||||
import com.beust.jcommander.Parameter;
|
||||
|
@ -51,10 +53,10 @@ import java.nio.file.Path;
|
|||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import org.joda.time.DateTime;
|
||||
|
@ -143,12 +145,8 @@ final class GenerateAuctionDataCommand implements RemoteApiCommand {
|
|||
/** Return a map of all fully-qualified domain names mapped to the applications for that name. */
|
||||
private static Multimap<String, DomainApplication> getDomainApplicationMap(final String tld) {
|
||||
DateTime now = DateTime.now(UTC);
|
||||
Multimap<String, DomainApplication> domainApplicationMap = TreeMultimap.create(
|
||||
Ordering.natural(), new Comparator<DomainApplication>() {
|
||||
@Override
|
||||
public int compare(DomainApplication o1, DomainApplication o2) {
|
||||
return o1.getForeignKey().compareTo(o2.getForeignKey());
|
||||
}});
|
||||
Multimap<String, DomainApplication> domainApplicationMap =
|
||||
TreeMultimap.create(Ordering.natural(), comparing(DomainApplication::getForeignKey));
|
||||
Iterable<DomainApplication> domainApplications =
|
||||
ofy().load().type(DomainApplication.class).filter("tld", tld);
|
||||
for (DomainApplication domainApplication : domainApplications) {
|
||||
|
@ -202,25 +200,28 @@ final class GenerateAuctionDataCommand implements RemoteApiCommand {
|
|||
// Registrant Name|Registrant Company|Registrant Address 1|Registrant Address 2|
|
||||
// Registrant City|Registrant Province|Registrant Postal Code|Registrant Country|
|
||||
// Registrant Email|Registrant Telephone|Reserve|Application Type
|
||||
return Joiner.on('|').join(ImmutableList.of(
|
||||
domainApplication.getFullyQualifiedDomainName(),
|
||||
domainApplication.getForeignKey(),
|
||||
formatter.print(domainApplication.getCreationTime()),
|
||||
domainApplication.getLastEppUpdateTime() != null
|
||||
? formatter.print(domainApplication.getLastEppUpdateTime()) : "",
|
||||
domainApplication.getCurrentSponsorClientId(),
|
||||
nullToEmpty(postalInfo.isPresent() ? postalInfo.get().getName() : ""),
|
||||
nullToEmpty(postalInfo.isPresent() ? postalInfo.get().getOrg() : ""),
|
||||
Iterables.getFirst(street, ""),
|
||||
Joiner.on(' ').skipNulls().join(Iterables.skip(street, 1)),
|
||||
nullToEmpty(address.isPresent() ? address.get().getCity() : ""),
|
||||
nullToEmpty(address.isPresent() ? address.get().getState() : ""),
|
||||
nullToEmpty(address.isPresent() ? address.get().getZip() : ""),
|
||||
nullToEmpty(address.isPresent() ? address.get().getCountryCode() : ""),
|
||||
nullToEmpty(registrant.getEmailAddress()),
|
||||
nullToEmpty(phoneNumber.isPresent() ? phoneNumber.get().toPhoneString() : ""),
|
||||
"",
|
||||
domainApplication.getEncodedSignedMarks().isEmpty() ? "Landrush" : "Sunrise"));
|
||||
return Joiner.on('|')
|
||||
.join(
|
||||
ImmutableList.of(
|
||||
domainApplication.getFullyQualifiedDomainName(),
|
||||
domainApplication.getForeignKey(),
|
||||
formatter.print(domainApplication.getCreationTime()),
|
||||
domainApplication.getLastEppUpdateTime() != null
|
||||
? formatter.print(domainApplication.getLastEppUpdateTime())
|
||||
: "",
|
||||
domainApplication.getCurrentSponsorClientId(),
|
||||
nullToEmpty(postalInfo.isPresent() ? postalInfo.get().getName() : ""),
|
||||
nullToEmpty(postalInfo.isPresent() ? postalInfo.get().getOrg() : ""),
|
||||
Iterables.getFirst(street, ""),
|
||||
street.stream().skip(1).filter(Objects::nonNull).collect(joining(" ")),
|
||||
nullToEmpty(address.isPresent() ? address.get().getCity() : ""),
|
||||
nullToEmpty(address.isPresent() ? address.get().getState() : ""),
|
||||
nullToEmpty(address.isPresent() ? address.get().getZip() : ""),
|
||||
nullToEmpty(address.isPresent() ? address.get().getCountryCode() : ""),
|
||||
nullToEmpty(registrant.getEmailAddress()),
|
||||
nullToEmpty(phoneNumber.isPresent() ? phoneNumber.get().toPhoneString() : ""),
|
||||
"",
|
||||
domainApplication.getEncodedSignedMarks().isEmpty() ? "Landrush" : "Sunrise"));
|
||||
}
|
||||
|
||||
/** Return a record line for the given registrar. */
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
package google.registry.tools;
|
||||
|
||||
import static com.google.common.collect.ImmutableList.toImmutableList;
|
||||
import static com.google.common.io.BaseEncoding.base16;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.model.registry.Registries.assertTldExists;
|
||||
|
@ -23,10 +24,8 @@ import static java.nio.charset.StandardCharsets.US_ASCII;
|
|||
import com.beust.jcommander.Parameter;
|
||||
import com.beust.jcommander.Parameters;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Ordering;
|
||||
import google.registry.model.domain.DomainResource;
|
||||
import google.registry.model.domain.secdns.DelegationSignerData;
|
||||
import google.registry.model.host.HostResource;
|
||||
|
@ -98,20 +97,24 @@ final class GenerateDnsReportCommand implements RemoteApiCommand {
|
|||
}
|
||||
|
||||
private void write(DomainResource domain) {
|
||||
ImmutableList<String> nameservers = FluentIterable
|
||||
.from(domain.loadNameserverFullyQualifiedHostNames())
|
||||
.toSortedList(Ordering.natural());
|
||||
ImmutableList<Map<String, ?>> dsData = FluentIterable.from(domain.getDsData())
|
||||
.transform(new Function<DelegationSignerData, Map<String, ?>>() {
|
||||
@Override
|
||||
public Map<String, ?> apply(DelegationSignerData dsData) {
|
||||
return ImmutableMap.of(
|
||||
"keyTag", dsData.getKeyTag(),
|
||||
"algorithm", dsData.getAlgorithm(),
|
||||
"digestType", dsData.getDigestType(),
|
||||
"digest", base16().encode(dsData.getDigest()));
|
||||
}})
|
||||
.toList();
|
||||
ImmutableList<String> nameservers =
|
||||
ImmutableList.sortedCopyOf(domain.loadNameserverFullyQualifiedHostNames());
|
||||
ImmutableList<Map<String, ?>> dsData =
|
||||
domain
|
||||
.getDsData()
|
||||
.stream()
|
||||
.map(
|
||||
new Function<DelegationSignerData, Map<String, ?>>() {
|
||||
@Override
|
||||
public Map<String, ?> apply(DelegationSignerData dsData) {
|
||||
return ImmutableMap.of(
|
||||
"keyTag", dsData.getKeyTag(),
|
||||
"algorithm", dsData.getAlgorithm(),
|
||||
"digestType", dsData.getDigestType(),
|
||||
"digest", base16().encode(dsData.getDigest()));
|
||||
}
|
||||
})
|
||||
.collect(toImmutableList());
|
||||
ImmutableMap.Builder<String, Object> mapBuilder = new ImmutableMap.Builder<>();
|
||||
mapBuilder.put("domain", domain.getFullyQualifiedDomainName());
|
||||
if (!nameservers.isEmpty()) {
|
||||
|
@ -124,13 +127,13 @@ final class GenerateDnsReportCommand implements RemoteApiCommand {
|
|||
}
|
||||
|
||||
private void write(HostResource nameserver) {
|
||||
ImmutableList<String> ipAddresses = FluentIterable.from(nameserver.getInetAddresses())
|
||||
.transform(new Function<InetAddress, String>() {
|
||||
@Override
|
||||
public String apply(InetAddress inetAddress) {
|
||||
return inetAddress.getHostAddress();
|
||||
}})
|
||||
.toSortedList(Ordering.natural());
|
||||
ImmutableList<String> ipAddresses =
|
||||
nameserver
|
||||
.getInetAddresses()
|
||||
.stream()
|
||||
.map(InetAddress::getHostAddress)
|
||||
.sorted()
|
||||
.collect(toImmutableList());
|
||||
ImmutableMap<String, ?> map = ImmutableMap.of(
|
||||
"host", nameserver.getFullyQualifiedHostName(),
|
||||
"ips", ipAddresses);
|
||||
|
|
|
@ -20,7 +20,6 @@ import static com.google.common.util.concurrent.MoreExecutors.directExecutor;
|
|||
|
||||
import com.beust.jcommander.Parameter;
|
||||
import com.beust.jcommander.Parameters;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.util.concurrent.FutureCallback;
|
||||
|
@ -121,7 +120,7 @@ final class LoadSnapshotCommand extends BigqueryCommand {
|
|||
}
|
||||
// Block on the completion of all the load jobs.
|
||||
List<?> results = Futures.successfulAsList(loadJobs.values()).get();
|
||||
int numSucceeded = FluentIterable.from(results).filter(notNull()).size();
|
||||
int numSucceeded = (int) results.stream().filter(notNull()).count();
|
||||
System.err.printf(
|
||||
"All load jobs have terminated: %d/%d successful.\n",
|
||||
numSucceeded, loadJobs.size());
|
||||
|
|
|
@ -24,11 +24,10 @@ import static com.google.common.base.Strings.emptyToNull;
|
|||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.util.DatastoreServiceUtils.getNameOrId;
|
||||
import static google.registry.util.DiffUtils.prettyPrintEntityDeepDiff;
|
||||
import static java.util.stream.Collectors.joining;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
@ -228,8 +227,6 @@ public abstract class MutatingCommand extends ConfirmingCommand implements Remot
|
|||
protected String prompt() {
|
||||
return changedEntitiesMap.isEmpty()
|
||||
? "No entity changes to apply."
|
||||
: Joiner.on("\n").join(FluentIterable
|
||||
.from(changedEntitiesMap.values())
|
||||
.transform(toStringFunction()));
|
||||
: changedEntitiesMap.values().stream().map(toStringFunction()).collect(joining("\n"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,11 +14,11 @@
|
|||
|
||||
package google.registry.tools;
|
||||
|
||||
import static java.util.stream.Collectors.joining;
|
||||
|
||||
import com.beust.jcommander.Parameters;
|
||||
import com.google.common.base.Functions;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.ComparisonChain;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.Ordering;
|
||||
import google.registry.rde.PendingDeposit;
|
||||
import google.registry.rde.PendingDepositChecker;
|
||||
|
@ -45,9 +45,11 @@ final class PendingEscrowCommand implements RemoteApiCommand {
|
|||
|
||||
@Override
|
||||
public void run() throws Exception {
|
||||
System.out.println(FluentIterable
|
||||
.from(SORTER.sortedCopy(checker.getTldsAndWatermarksPendingDepositForRdeAndBrda().values()))
|
||||
.transform(Functions.toStringFunction())
|
||||
.join(Joiner.on('\n')));
|
||||
System.out.println(
|
||||
SORTER
|
||||
.sortedCopy(checker.getTldsAndWatermarksPendingDepositForRdeAndBrda().values())
|
||||
.stream()
|
||||
.map(Functions.toStringFunction())
|
||||
.collect(joining("\n")));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ package google.registry.tools;
|
|||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Strings.isNullOrEmpty;
|
||||
import static com.google.common.collect.Iterables.transform;
|
||||
import static com.google.common.collect.ImmutableSet.toImmutableSet;
|
||||
import static google.registry.util.CollectionUtils.nullToEmpty;
|
||||
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
|
||||
import static google.registry.util.PreconditionsUtils.checkArgumentPresent;
|
||||
|
@ -166,8 +166,11 @@ final class RegistrarContactCommand extends MutatingCommand {
|
|||
|| ((contactTypeNames.size() == 1) && contactTypeNames.get(0).isEmpty())) {
|
||||
contactTypes = ImmutableSet.of();
|
||||
} else {
|
||||
contactTypes = ImmutableSet.copyOf(
|
||||
transform(contactTypeNames, Enums.stringConverter(RegistrarContact.Type.class)));
|
||||
contactTypes =
|
||||
contactTypeNames
|
||||
.stream()
|
||||
.map(Enums.stringConverter(RegistrarContact.Type.class))
|
||||
.collect(toImmutableSet());
|
||||
}
|
||||
ImmutableSet<RegistrarContact> contacts = registrar.getContacts();
|
||||
Map<String, RegistrarContact> contactsMap = new LinkedHashMap<>();
|
||||
|
|
|
@ -15,15 +15,13 @@
|
|||
package google.registry.tools;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.collect.ImmutableSet.toImmutableSet;
|
||||
import static google.registry.model.EppResourceUtils.loadByForeignKey;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static org.joda.time.DateTimeZone.UTC;
|
||||
|
||||
import com.beust.jcommander.Parameter;
|
||||
import com.beust.jcommander.Parameters;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.ImmutableSortedSet;
|
||||
import com.google.common.collect.Sets;
|
||||
|
@ -215,21 +213,11 @@ final class UpdateDomainCommand extends CreateOrUpdateDomainCommand {
|
|||
|
||||
ImmutableSet<String> getContactsOfType(
|
||||
DomainResource domainResource, final DesignatedContact.Type contactType) {
|
||||
return FluentIterable.from(domainResource.getContacts())
|
||||
.filter(
|
||||
new Predicate<DesignatedContact>() {
|
||||
@Override
|
||||
public boolean apply(DesignatedContact contact) {
|
||||
return contact.getType().equals(contactType);
|
||||
}
|
||||
})
|
||||
.transform(
|
||||
new Function<DesignatedContact, String>() {
|
||||
@Override
|
||||
public String apply(DesignatedContact contact) {
|
||||
return ofy().load().key(contact.getContactKey()).now().getContactId();
|
||||
}
|
||||
})
|
||||
.toSet();
|
||||
return domainResource
|
||||
.getContacts()
|
||||
.stream()
|
||||
.filter(contact -> contact.getType().equals(contactType))
|
||||
.map(contact -> ofy().load().key(contact.getContactKey()).now().getContactId())
|
||||
.collect(toImmutableSet());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
package google.registry.tools;
|
||||
|
||||
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.intersection;
|
||||
import static com.google.common.collect.Sets.union;
|
||||
|
@ -23,16 +24,13 @@ import static google.registry.util.CollectionUtils.nullToEmpty;
|
|||
|
||||
import com.beust.jcommander.Parameter;
|
||||
import com.beust.jcommander.Parameters;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.googlecode.objectify.Key;
|
||||
import google.registry.config.RegistryEnvironment;
|
||||
import google.registry.model.registry.Registry;
|
||||
import google.registry.model.registry.Registry.TldState;
|
||||
import google.registry.model.registry.label.ReservedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
@ -115,15 +113,7 @@ class UpdateTldCommand extends CreateOrUpdateTldCommand {
|
|||
ImmutableSet<String> getReservedLists(Registry oldRegistry) {
|
||||
return formUpdatedList(
|
||||
"reserved lists",
|
||||
FluentIterable
|
||||
.from(oldRegistry.getReservedLists())
|
||||
.transform(
|
||||
new Function<Key<ReservedList>, String>() {
|
||||
@Override
|
||||
public String apply(Key<ReservedList> key) {
|
||||
return key.getName();
|
||||
}})
|
||||
.toSet(),
|
||||
oldRegistry.getReservedLists().stream().map(Key::getName).collect(toImmutableSet()),
|
||||
reservedListNames,
|
||||
reservedListsAdd,
|
||||
reservedListsRemove);
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
|
||||
package google.registry.tools;
|
||||
|
||||
import static com.google.common.base.MoreObjects.firstNonNull;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.collect.ImmutableList.copyOf;
|
||||
import static com.google.common.collect.Sets.difference;
|
||||
|
@ -100,7 +99,7 @@ final class ValidateEscrowDepositCommand implements Command {
|
|||
SortedMap<String, Long> counts = new TreeMap<>();
|
||||
for (JAXBElement<?> item : deposit.getContents().getContents()) {
|
||||
String name = item.getDeclaredType().getSimpleName();
|
||||
counts.put(name, firstNonNull(counts.get(name), 0L) + 1L);
|
||||
counts.put(name, counts.getOrDefault(name, 0L) + 1L);
|
||||
if (XjcRdeHost.class.isAssignableFrom(item.getDeclaredType())) {
|
||||
XjcRdeHost host = (XjcRdeHost) item.getValue();
|
||||
hostnames.add(checkNotNull(host.getName()));
|
||||
|
|
|
@ -16,16 +16,16 @@ package google.registry.tools;
|
|||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Predicates.notNull;
|
||||
import static com.google.common.collect.ImmutableSet.toImmutableSet;
|
||||
import static google.registry.model.registrar.Registrar.loadByClientId;
|
||||
import static google.registry.util.PreconditionsUtils.checkArgumentPresent;
|
||||
|
||||
import com.beust.jcommander.Parameter;
|
||||
import com.beust.jcommander.Parameters;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Streams;
|
||||
import google.registry.config.RegistryEnvironment;
|
||||
import google.registry.model.registrar.Registrar;
|
||||
import google.registry.tools.server.VerifyOteAction;
|
||||
|
@ -105,21 +105,20 @@ final class VerifyOteCommand implements ServerSideCommand {
|
|||
* prefixes of those accounts (in this case, regname).
|
||||
*/
|
||||
private ImmutableSet<String> getAllRegistrarNames() {
|
||||
return FluentIterable.from(Registrar.loadAll())
|
||||
.transform(new Function<Registrar, String>() {
|
||||
@Override
|
||||
public String apply(Registrar registrar) {
|
||||
if (!registrar.isLive()) {
|
||||
return null;
|
||||
}
|
||||
String name = registrar.getClientId();
|
||||
// Look for names of the form "regname-1", "regname-2", etc. and strip the -# suffix.
|
||||
String replacedName = name.replaceFirst("^(.*)-[1234]$", "$1");
|
||||
// Check if any replacement happened, and thus whether the name matches the format.
|
||||
// If it matches, provide the shortened name, and otherwise return null.
|
||||
return name.equals(replacedName) ? null : replacedName;
|
||||
}})
|
||||
.filter(notNull())
|
||||
.toSet();
|
||||
return Streams.stream(Registrar.loadAll())
|
||||
.map(
|
||||
registrar -> {
|
||||
if (!registrar.isLive()) {
|
||||
return null;
|
||||
}
|
||||
String name = registrar.getClientId();
|
||||
// Look for names of the form "regname-1", "regname-2", etc. and strip the -# suffix.
|
||||
String replacedName = name.replaceFirst("^(.*)-[1234]$", "$1");
|
||||
// Check if any replacement happened, and thus whether the name matches the format.
|
||||
// If it matches, provide the shortened name, and otherwise return null.
|
||||
return name.equals(replacedName) ? null : replacedName;
|
||||
})
|
||||
.filter(notNull())
|
||||
.collect(toImmutableSet());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,14 +19,12 @@ import static google.registry.request.Action.Method.POST;
|
|||
import static java.util.Arrays.asList;
|
||||
import static javax.servlet.http.HttpServletResponse.SC_OK;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Optional;
|
||||
import google.registry.config.RegistryConfig.Config;
|
||||
import google.registry.groups.GroupsConnection;
|
||||
import google.registry.groups.GroupsConnection.Role;
|
||||
import google.registry.model.registrar.Registrar;
|
||||
import google.registry.model.registrar.RegistrarContact;
|
||||
import google.registry.model.registrar.RegistrarContact.Type;
|
||||
import google.registry.request.Action;
|
||||
import google.registry.request.HttpException.BadRequestException;
|
||||
import google.registry.request.HttpException.InternalServerErrorException;
|
||||
|
@ -70,26 +68,26 @@ public class CreateGroupsAction implements Runnable {
|
|||
List<RegistrarContact.Type> types = asList(RegistrarContact.Type.values());
|
||||
// Concurrently create the groups for each RegistrarContact.Type, collecting the results from
|
||||
// each call (which are either an Exception if it failed, or absent() if it succeeded).
|
||||
List<Optional<Exception>> results = Concurrent.transform(
|
||||
types,
|
||||
NUM_SIMULTANEOUS_CONNECTIONS,
|
||||
new Function<RegistrarContact.Type, Optional<Exception>>() {
|
||||
@Override
|
||||
public Optional<Exception> apply(Type type) {
|
||||
try {
|
||||
String groupKey = getGroupEmailAddressForContactType(
|
||||
registrar.getClientId(), type, gSuiteDomainName);
|
||||
String parentGroup =
|
||||
getGroupEmailAddressForContactType("registrar", type, gSuiteDomainName);
|
||||
// Creates the group, then adds it as a member to the global registrar group for
|
||||
// that type.
|
||||
groupsConnection.createGroup(groupKey);
|
||||
groupsConnection.addMemberToGroup(parentGroup, groupKey, Role.MEMBER);
|
||||
return Optional.<Exception> absent();
|
||||
} catch (Exception e) {
|
||||
return Optional.of(e);
|
||||
}
|
||||
}});
|
||||
List<Optional<Exception>> results =
|
||||
Concurrent.transform(
|
||||
types,
|
||||
NUM_SIMULTANEOUS_CONNECTIONS,
|
||||
type -> {
|
||||
try {
|
||||
String groupKey =
|
||||
getGroupEmailAddressForContactType(
|
||||
registrar.getClientId(), type, gSuiteDomainName);
|
||||
String parentGroup =
|
||||
getGroupEmailAddressForContactType("registrar", type, gSuiteDomainName);
|
||||
// Creates the group, then adds it as a member to the global registrar group for
|
||||
// that type.
|
||||
groupsConnection.createGroup(groupKey);
|
||||
groupsConnection.addMemberToGroup(parentGroup, groupKey, Role.MEMBER);
|
||||
return Optional.<Exception>absent();
|
||||
} catch (Exception e) {
|
||||
return Optional.of(e);
|
||||
}
|
||||
});
|
||||
// Return the correct server response based on the results of the group creations.
|
||||
if (Optional.presentInstances(results).iterator().hasNext()) {
|
||||
StringWriter responseString = new StringWriter();
|
||||
|
|
|
@ -16,6 +16,7 @@ package google.registry.tools.server;
|
|||
|
||||
import static com.google.appengine.tools.cloudstorage.GcsServiceFactory.createGcsService;
|
||||
import static com.google.common.base.Predicates.notNull;
|
||||
import static com.google.common.collect.ImmutableList.toImmutableList;
|
||||
import static com.google.common.collect.Iterators.filter;
|
||||
import static com.google.common.io.BaseEncoding.base16;
|
||||
import static google.registry.mapreduce.inputs.EppResourceInputs.createEntityInput;
|
||||
|
@ -31,8 +32,6 @@ import com.google.appengine.tools.cloudstorage.RetryParams;
|
|||
import com.google.appengine.tools.mapreduce.Mapper;
|
||||
import com.google.appengine.tools.mapreduce.Reducer;
|
||||
import com.google.appengine.tools.mapreduce.ReducerInput;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
@ -144,17 +143,13 @@ public class GenerateZoneFilesAction implements Runnable, JsonActionRunner.JsonA
|
|||
ImmutableList.of(
|
||||
new NullInput<EppResource>(),
|
||||
createEntityInput(DomainResource.class)));
|
||||
ImmutableList<String> filenames = FluentIterable.from(tlds)
|
||||
.transform(
|
||||
new Function<String, String>() {
|
||||
@Override
|
||||
public String apply(String tld) {
|
||||
return String.format(
|
||||
GCS_PATH_FORMAT,
|
||||
bucket,
|
||||
String.format(FILENAME_FORMAT, tld, exportTime));
|
||||
}})
|
||||
.toList();
|
||||
ImmutableList<String> filenames =
|
||||
tlds.stream()
|
||||
.map(
|
||||
tld ->
|
||||
String.format(
|
||||
GCS_PATH_FORMAT, bucket, String.format(FILENAME_FORMAT, tld, exportTime)))
|
||||
.collect(toImmutableList());
|
||||
return ImmutableMap.<String, Object>of(
|
||||
"jobPath", createJobPath(jobId),
|
||||
"filenames", filenames);
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
package google.registry.tools.server;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.collect.ImmutableList.toImmutableList;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.request.Action.Method.POST;
|
||||
import static google.registry.util.PipelineUtils.createJobPath;
|
||||
|
@ -22,7 +23,6 @@ import static google.registry.util.PipelineUtils.createJobPath;
|
|||
import com.google.appengine.tools.mapreduce.Input;
|
||||
import com.google.appengine.tools.mapreduce.Mapper;
|
||||
import com.google.appengine.tools.mapreduce.inputs.InMemoryInput;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.googlecode.objectify.Key;
|
||||
|
@ -33,7 +33,7 @@ import google.registry.model.ofy.CommitLogCheckpointRoot;
|
|||
import google.registry.request.Action;
|
||||
import google.registry.request.Response;
|
||||
import google.registry.request.auth.Auth;
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Stream;
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
|
@ -63,13 +63,14 @@ public class KillAllCommitLogsAction implements Runnable {
|
|||
"DO NOT RUN ANYWHERE ELSE EXCEPT CRASH OR TESTS.");
|
||||
// Create a in-memory input, assigning each bucket to its own shard for maximum parallelization,
|
||||
// with one extra shard for the CommitLogCheckpointRoot.
|
||||
Input<Key<?>> input = new InMemoryInput<>(
|
||||
Lists.partition(
|
||||
FluentIterable
|
||||
.from(Arrays.<Key<?>>asList(CommitLogCheckpointRoot.getKey()))
|
||||
.append(CommitLogBucket.getAllBucketKeys())
|
||||
.toList(),
|
||||
1));
|
||||
Input<Key<?>> input =
|
||||
new InMemoryInput<>(
|
||||
Lists.partition(
|
||||
Stream.concat(
|
||||
Stream.of(CommitLogCheckpointRoot.getKey()),
|
||||
CommitLogBucket.getAllBucketKeys().stream())
|
||||
.collect(toImmutableList()),
|
||||
1));
|
||||
response.sendJavaScriptRedirect(createJobPath(mrRunner
|
||||
.setJobName("Delete all commit logs")
|
||||
.setModuleName("tools")
|
||||
|
|
|
@ -19,6 +19,7 @@ import static google.registry.model.EppResourceUtils.queryNotDeleted;
|
|||
import static google.registry.model.registry.Registries.assertTldsExist;
|
||||
import static google.registry.request.Action.Method.GET;
|
||||
import static google.registry.request.Action.Method.POST;
|
||||
import static java.util.Comparator.comparing;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.ImmutableSortedSet;
|
||||
|
@ -28,7 +29,6 @@ import google.registry.request.Action;
|
|||
import google.registry.request.Parameter;
|
||||
import google.registry.request.auth.Auth;
|
||||
import google.registry.util.Clock;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import javax.inject.Inject;
|
||||
|
||||
|
@ -42,12 +42,6 @@ public final class ListDomainsAction extends ListObjectsAction<DomainResource> {
|
|||
|
||||
/** An App Engine limitation on how many subqueries can be used in a single query. */
|
||||
private static final int MAX_NUM_SUBQUERIES = 30;
|
||||
private static final Comparator<DomainResource> COMPARATOR =
|
||||
new Comparator<DomainResource>() {
|
||||
@Override
|
||||
public int compare(DomainResource a, DomainResource b) {
|
||||
return a.getFullyQualifiedDomainName().compareTo(b.getFullyQualifiedDomainName());
|
||||
}};
|
||||
public static final String PATH = "/_dr/admin/list/domains";
|
||||
|
||||
@Inject @Parameter("tlds") ImmutableSet<String> tlds;
|
||||
|
@ -64,7 +58,8 @@ public final class ListDomainsAction extends ListObjectsAction<DomainResource> {
|
|||
checkArgument(!tlds.isEmpty(), "Must specify TLDs to query");
|
||||
assertTldsExist(tlds);
|
||||
ImmutableSortedSet.Builder<DomainResource> builder =
|
||||
new ImmutableSortedSet.Builder<DomainResource>(COMPARATOR);
|
||||
new ImmutableSortedSet.Builder<DomainResource>(
|
||||
comparing(DomainResource::getFullyQualifiedDomainName));
|
||||
for (List<String> batch : Lists.partition(tlds.asList(), MAX_NUM_SUBQUERIES)) {
|
||||
builder.addAll(queryNotDeleted(DomainResource.class, clock.nowUtc(), "tld in", batch));
|
||||
}
|
||||
|
|
|
@ -14,19 +14,19 @@
|
|||
|
||||
package google.registry.tools.server;
|
||||
|
||||
import static com.google.common.collect.ImmutableSortedSet.toImmutableSortedSet;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.request.Action.Method.GET;
|
||||
import static google.registry.request.Action.Method.POST;
|
||||
import static java.util.Comparator.comparing;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Streams;
|
||||
import google.registry.model.EppResourceUtils;
|
||||
import google.registry.model.host.HostResource;
|
||||
import google.registry.request.Action;
|
||||
import google.registry.request.auth.Auth;
|
||||
import google.registry.util.Clock;
|
||||
import java.util.Comparator;
|
||||
import javax.inject.Inject;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
|
@ -40,14 +40,6 @@ public final class ListHostsAction extends ListObjectsAction<HostResource> {
|
|||
|
||||
public static final String PATH = "/_dr/admin/list/hosts";
|
||||
|
||||
private static final Comparator<HostResource> comparator =
|
||||
new Comparator<HostResource>() {
|
||||
@Override
|
||||
public int compare(HostResource host1, HostResource host2) {
|
||||
return host1.getFullyQualifiedHostName()
|
||||
.compareTo(host2.getFullyQualifiedHostName());
|
||||
}};
|
||||
|
||||
@Inject Clock clock;
|
||||
@Inject ListHostsAction() {}
|
||||
|
||||
|
@ -59,13 +51,8 @@ public final class ListHostsAction extends ListObjectsAction<HostResource> {
|
|||
@Override
|
||||
public ImmutableSet<HostResource> loadObjects() {
|
||||
final DateTime now = clock.nowUtc();
|
||||
return FluentIterable
|
||||
.from(ofy().load().type(HostResource.class))
|
||||
.filter(new Predicate<HostResource>() {
|
||||
@Override
|
||||
public boolean apply(HostResource host) {
|
||||
return EppResourceUtils.isActive(host, now);
|
||||
}})
|
||||
.toSortedSet(comparator);
|
||||
return Streams.stream(ofy().load().type(HostResource.class))
|
||||
.filter(host -> EppResourceUtils.isActive(host, now))
|
||||
.collect(toImmutableSortedSet(comparing(HostResource::getFullyQualifiedHostName)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ package google.registry.tools.server;
|
|||
|
||||
import static com.google.common.base.MoreObjects.firstNonNull;
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.collect.ImmutableSet.toImmutableSet;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Functions;
|
||||
|
@ -29,7 +30,6 @@ import com.google.common.collect.ImmutableMap;
|
|||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.ImmutableSortedSet;
|
||||
import com.google.common.collect.ImmutableTable;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Ordering;
|
||||
import google.registry.model.ImmutableObject;
|
||||
|
@ -42,6 +42,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
|
@ -150,14 +151,9 @@ public abstract class ListObjectsAction<T extends ImmutableObject> implements Ru
|
|||
final ImmutableMap<String, String> nameMapping =
|
||||
((fullFieldNames != null) && fullFieldNames.isPresent() && fullFieldNames.get())
|
||||
? getFieldAliases() : getFieldAliases().inverse();
|
||||
return ImmutableSet.copyOf(Iterables.transform(
|
||||
Iterables.concat(getPrimaryKeyFields(), fieldsToUse),
|
||||
new Function<String, String>() {
|
||||
@Override
|
||||
public String apply(String field) {
|
||||
// Rename fields that are in the map according to the map, and leave the others as is.
|
||||
return nameMapping.containsKey(field) ? nameMapping.get(field) : field;
|
||||
}}));
|
||||
return Stream.concat(getPrimaryKeyFields().stream(), fieldsToUse.stream())
|
||||
.map(field -> nameMapping.getOrDefault(field, field))
|
||||
.collect(toImmutableSet());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -209,22 +205,16 @@ public abstract class ListObjectsAction<T extends ImmutableObject> implements Ru
|
|||
*/
|
||||
private static ImmutableMap<String, Integer> computeColumnWidths(
|
||||
ImmutableTable<?, String, String> data, final boolean includingHeader) {
|
||||
return ImmutableMap.copyOf(Maps.transformEntries(
|
||||
data.columnMap(),
|
||||
new Maps.EntryTransformer<String, Map<?, String>, Integer>() {
|
||||
@Override
|
||||
public Integer transformEntry(String columnName, Map<?, String> columnValues) {
|
||||
// Return the length of the longest string in this column (including the column name).
|
||||
return Ordering.natural().max(Iterables.transform(
|
||||
Iterables.concat(
|
||||
ImmutableList.of(includingHeader ? columnName : ""),
|
||||
columnValues.values()),
|
||||
new Function<String, Integer>() {
|
||||
@Override
|
||||
public Integer apply(String value) {
|
||||
return value.length();
|
||||
}}));
|
||||
}}));
|
||||
return ImmutableMap.copyOf(
|
||||
Maps.transformEntries(
|
||||
data.columnMap(),
|
||||
(columnName, columnValues) ->
|
||||
Stream.concat(
|
||||
Stream.of(includingHeader ? columnName : ""),
|
||||
columnValues.values().stream())
|
||||
.map(String::length)
|
||||
.max(Ordering.natural())
|
||||
.get()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -250,12 +240,8 @@ public abstract class ListObjectsAction<T extends ImmutableObject> implements Ru
|
|||
lines.add(rowFormatter.apply(headerRow));
|
||||
|
||||
// Add a row of separator lines (column names mapping to '-' * column width).
|
||||
Map<String, String> separatorRow = Maps.transformValues(columnWidths,
|
||||
new Function<Integer, String>() {
|
||||
@Override
|
||||
public String apply(Integer width) {
|
||||
return Strings.repeat("-", width);
|
||||
}});
|
||||
Map<String, String> separatorRow =
|
||||
Maps.transformValues(columnWidths, width -> Strings.repeat("-", width));
|
||||
lines.add(rowFormatter.apply(separatorRow));
|
||||
}
|
||||
|
||||
|
@ -275,14 +261,12 @@ public abstract class ListObjectsAction<T extends ImmutableObject> implements Ru
|
|||
*/
|
||||
private static Function<Map<String, String>, String> makeRowFormatter(
|
||||
final Map<String, Integer> columnWidths) {
|
||||
return new Function<Map<String, String>, String>() {
|
||||
@Override
|
||||
public String apply(Map<String, String> rowByColumns) {
|
||||
List<String> paddedFields = new ArrayList<>();
|
||||
for (Map.Entry<String, String> cell : rowByColumns.entrySet()) {
|
||||
paddedFields.add(Strings.padEnd(cell.getValue(), columnWidths.get(cell.getKey()), ' '));
|
||||
}
|
||||
return Joiner.on(" ").join(paddedFields);
|
||||
}};
|
||||
return rowByColumns -> {
|
||||
List<String> paddedFields = new ArrayList<>();
|
||||
for (Map.Entry<String, String> cell : rowByColumns.entrySet()) {
|
||||
paddedFields.add(Strings.padEnd(cell.getValue(), columnWidths.get(cell.getKey()), ' '));
|
||||
}
|
||||
return Joiner.on(" ").join(paddedFields);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,12 +14,11 @@
|
|||
|
||||
package google.registry.tools.server;
|
||||
|
||||
import static com.google.common.collect.ImmutableSet.toImmutableSet;
|
||||
import static google.registry.model.registry.Registries.getTlds;
|
||||
import static google.registry.request.Action.Method.GET;
|
||||
import static google.registry.request.Action.Method.POST;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.ImmutableBiMap;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
@ -50,13 +49,7 @@ public final class ListTldsAction extends ListObjectsAction<Registry> {
|
|||
|
||||
@Override
|
||||
public ImmutableSet<Registry> loadObjects() {
|
||||
return FluentIterable.from(getTlds())
|
||||
.transform(new Function<String, Registry>() {
|
||||
@Override
|
||||
public Registry apply(String tldString) {
|
||||
return Registry.get(tldString);
|
||||
}})
|
||||
.toSet();
|
||||
return getTlds().stream().map(Registry::get).collect(toImmutableSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -16,6 +16,7 @@ package google.registry.tools.server;
|
|||
|
||||
import static com.google.common.base.Predicates.equalTo;
|
||||
import static com.google.common.base.Predicates.not;
|
||||
import static com.google.common.collect.ImmutableList.toImmutableList;
|
||||
import static com.google.common.collect.Maps.toMap;
|
||||
import static google.registry.flows.EppXmlTransformer.unmarshal;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
|
@ -23,7 +24,6 @@ import static google.registry.util.CollectionUtils.isNullOrEmpty;
|
|||
import static google.registry.util.DomainNameUtils.ACE_PREFIX;
|
||||
|
||||
import com.google.common.base.Ascii;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.base.Predicate;
|
||||
|
@ -51,7 +51,7 @@ import java.util.ArrayList;
|
|||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.stream.Stream;
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
|
@ -82,14 +82,7 @@ public class VerifyOteAction implements Runnable, JsonAction {
|
|||
public Map<String, Object> handleJsonRequest(Map<String, ?> json) {
|
||||
final boolean summarize = Boolean.parseBoolean((String) json.get("summarize"));
|
||||
return toMap(
|
||||
(List<String>) json.get("registrars"),
|
||||
new Function<String, Object>() {
|
||||
@Nonnull
|
||||
@Override
|
||||
public Object apply(@Nonnull String registrar) {
|
||||
return checkRegistrar(registrar, summarize);
|
||||
}
|
||||
});
|
||||
(List<String>) json.get("registrars"), registrar -> checkRegistrar(registrar, summarize));
|
||||
}
|
||||
|
||||
/** Checks whether the provided registrar has passed OT&E and returns relevant information. */
|
||||
|
@ -112,66 +105,37 @@ public class VerifyOteAction implements Runnable, JsonAction {
|
|||
}
|
||||
|
||||
private static final Predicate<EppInput> HAS_CLAIMS_NOTICE =
|
||||
new Predicate<EppInput>() {
|
||||
@Override
|
||||
public boolean apply(@Nonnull EppInput eppInput) {
|
||||
LaunchCreateExtension launchCreate =
|
||||
eppInput.getSingleExtension(LaunchCreateExtension.class);
|
||||
return launchCreate != null && launchCreate.getNotice() != null;
|
||||
}
|
||||
};
|
||||
|
||||
private static final Predicate<EppInput> HAS_FEE =
|
||||
new Predicate<EppInput>() {
|
||||
@Override
|
||||
public boolean apply(@Nonnull EppInput eppInput) {
|
||||
return eppInput.getSingleExtension(FeeCreateCommandExtension.class) != null;
|
||||
}
|
||||
eppInput -> {
|
||||
LaunchCreateExtension launchCreate =
|
||||
eppInput.getSingleExtension(LaunchCreateExtension.class);
|
||||
return launchCreate != null && launchCreate.getNotice() != null;
|
||||
};
|
||||
|
||||
private static final Predicate<EppInput> HAS_SEC_DNS =
|
||||
new Predicate<EppInput>() {
|
||||
@Override
|
||||
public boolean apply(@Nonnull EppInput eppInput) {
|
||||
return (eppInput.getSingleExtension(SecDnsCreateExtension.class) != null)
|
||||
eppInput ->
|
||||
(eppInput.getSingleExtension(SecDnsCreateExtension.class) != null)
|
||||
|| (eppInput.getSingleExtension(SecDnsUpdateExtension.class) != null);
|
||||
}
|
||||
};
|
||||
|
||||
private static final Predicate<EppInput> IS_SUNRISE =
|
||||
new Predicate<EppInput>() {
|
||||
@Override
|
||||
public boolean apply(@Nonnull EppInput eppInput) {
|
||||
LaunchCreateExtension launchCreate =
|
||||
eppInput.getSingleExtension(LaunchCreateExtension.class);
|
||||
return launchCreate != null && !isNullOrEmpty(launchCreate.getSignedMarks());
|
||||
}
|
||||
eppInput -> {
|
||||
LaunchCreateExtension launchCreate =
|
||||
eppInput.getSingleExtension(LaunchCreateExtension.class);
|
||||
return launchCreate != null && !isNullOrEmpty(launchCreate.getSignedMarks());
|
||||
};
|
||||
|
||||
private static final Predicate<EppInput> IS_IDN =
|
||||
new Predicate<EppInput>() {
|
||||
@Override
|
||||
public boolean apply(@Nonnull EppInput eppInput) {
|
||||
return ((DomainCommand.Create)
|
||||
eppInput ->
|
||||
((DomainCommand.Create)
|
||||
((ResourceCommandWrapper) eppInput.getCommandWrapper().getCommand())
|
||||
.getResourceCommand())
|
||||
.getFullyQualifiedDomainName()
|
||||
.startsWith(ACE_PREFIX);
|
||||
}
|
||||
};
|
||||
|
||||
private static final Predicate<EppInput> IS_SUBORDINATE =
|
||||
new Predicate<EppInput>() {
|
||||
@Override
|
||||
public boolean apply(@Nonnull EppInput eppInput) {
|
||||
return !isNullOrEmpty(
|
||||
eppInput ->
|
||||
!isNullOrEmpty(
|
||||
((HostCommand.Create)
|
||||
((ResourceCommandWrapper) eppInput.getCommandWrapper().getCommand())
|
||||
.getResourceCommand())
|
||||
.getInetAddresses());
|
||||
}
|
||||
};
|
||||
|
||||
/** Enum defining the distinct statistics (types of registrar actions) to record. */
|
||||
public enum StatType {
|
||||
CONTACT_CREATES(0, equalTo(Type.CONTACT_CREATE)),
|
||||
|
@ -192,7 +156,10 @@ public class VerifyOteAction implements Runnable, JsonAction {
|
|||
DOMAIN_CREATES_ASCII(1, equalTo(Type.DOMAIN_CREATE), not(IS_IDN)),
|
||||
DOMAIN_CREATES_IDN(1, equalTo(Type.DOMAIN_CREATE), IS_IDN),
|
||||
DOMAIN_CREATES_WITH_CLAIMS_NOTICE(1, equalTo(Type.DOMAIN_CREATE), HAS_CLAIMS_NOTICE),
|
||||
DOMAIN_CREATES_WITH_FEE(1, equalTo(Type.DOMAIN_CREATE), HAS_FEE),
|
||||
DOMAIN_CREATES_WITH_FEE(
|
||||
1,
|
||||
equalTo(Type.DOMAIN_CREATE),
|
||||
eppInput -> eppInput.getSingleExtension(FeeCreateCommandExtension.class) != null),
|
||||
DOMAIN_CREATES_WITH_SEC_DNS(1, equalTo(Type.DOMAIN_CREATE), HAS_SEC_DNS),
|
||||
DOMAIN_CREATES_WITHOUT_SEC_DNS(0, equalTo(Type.DOMAIN_CREATE), not(HAS_SEC_DNS)),
|
||||
DOMAIN_DELETES(2, equalTo(Type.DOMAIN_DELETE)),
|
||||
|
@ -214,15 +181,7 @@ public class VerifyOteAction implements Runnable, JsonAction {
|
|||
|
||||
/** The number of StatTypes with a non-zero requirement. */
|
||||
private static final int NUM_REQUIREMENTS =
|
||||
FluentIterable.from(values())
|
||||
.filter(
|
||||
new Predicate<StatType>() {
|
||||
@Override
|
||||
public boolean apply(@Nonnull StatType statType) {
|
||||
return statType.requirement > 0;
|
||||
}
|
||||
})
|
||||
.size();
|
||||
(int) Stream.of(values()).filter(statType -> statType.requirement > 0).count();
|
||||
|
||||
/** Required number of times registrars must complete this action. */
|
||||
final int requirement;
|
||||
|
@ -304,15 +263,10 @@ public class VerifyOteAction implements Runnable, JsonAction {
|
|||
? Optional.<EppInput>absent()
|
||||
: Optional.of(unmarshal(EppInput.class, xmlBytes));
|
||||
if (!statCounts.addAll(
|
||||
FluentIterable.from(EnumSet.allOf(StatType.class))
|
||||
.filter(
|
||||
new Predicate<StatType>() {
|
||||
@Override
|
||||
public boolean apply(@Nonnull StatType statType) {
|
||||
return statType.matches(historyEntry.getType(), eppInput);
|
||||
}
|
||||
})
|
||||
.toList())) {
|
||||
EnumSet.allOf(StatType.class)
|
||||
.stream()
|
||||
.filter(statType -> statType.matches(historyEntry.getType(), eppInput))
|
||||
.collect(toImmutableList()))) {
|
||||
statCounts.add(StatType.UNCLASSIFIED_FLOWS);
|
||||
}
|
||||
}
|
||||
|
@ -339,14 +293,8 @@ public class VerifyOteAction implements Runnable, JsonAction {
|
|||
public String toString() {
|
||||
return FluentIterable.from(EnumSet.allOf(StatType.class))
|
||||
.transform(
|
||||
new Function<StatType, String>() {
|
||||
@Nonnull
|
||||
@Override
|
||||
public String apply(@Nonnull StatType statType) {
|
||||
return String.format(
|
||||
"%s: %d", statType.description(), statCounts.count(statType));
|
||||
}
|
||||
})
|
||||
statType ->
|
||||
String.format("%s: %d", statType.description(), statCounts.count(statType)))
|
||||
.append(String.format("TOTAL: %d", statCounts.size()))
|
||||
.join(Joiner.on("\n"));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue