mirror of
https://github.com/google/nomulus.git
synced 2025-05-16 09:27:16 +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,15 +18,12 @@ import static com.google.appengine.api.datastore.DatastoreServiceFactory.getData
|
|||
import static com.google.appengine.api.taskqueue.QueueFactory.getQueue;
|
||||
import static com.google.common.base.Strings.nullToEmpty;
|
||||
|
||||
import com.google.appengine.api.datastore.Entity;
|
||||
import com.google.appengine.api.datastore.Query;
|
||||
import com.google.appengine.api.modules.ModulesService;
|
||||
import com.google.appengine.api.modules.ModulesServiceFactory;
|
||||
import com.google.appengine.api.taskqueue.TaskHandle;
|
||||
import com.google.appengine.api.taskqueue.TaskOptions;
|
||||
import com.google.appengine.api.taskqueue.TaskOptions.Method;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
@ -91,18 +88,10 @@ public class DatastoreBackupService {
|
|||
public Iterable<DatastoreBackupInfo> findAllByNamePrefix(final String namePrefix) {
|
||||
// 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.
|
||||
return FluentIterable
|
||||
.from(getDatastoreService().prepare(new Query(BACKUP_INFO_KIND)).asIterable())
|
||||
.filter(new Predicate<Entity>() {
|
||||
@Override
|
||||
public boolean apply(Entity entity) {
|
||||
return nullToEmpty((String) entity.getProperty("name")).startsWith(namePrefix);
|
||||
}})
|
||||
.transform(new Function<Entity, DatastoreBackupInfo>() {
|
||||
@Override
|
||||
public DatastoreBackupInfo apply(Entity entity) {
|
||||
return new DatastoreBackupInfo(entity);
|
||||
}});
|
||||
return FluentIterable.from(
|
||||
getDatastoreService().prepare(new Query(BACKUP_INFO_KIND)).asIterable())
|
||||
.filter(entity -> nullToEmpty((String) entity.getProperty("name")).startsWith(namePrefix))
|
||||
.transform(DatastoreBackupInfo::new);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
|
||||
package google.registry.export;
|
||||
|
||||
import static com.google.common.collect.ImmutableList.toImmutableList;
|
||||
import static com.google.common.collect.ImmutableSet.toImmutableSet;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.request.Action.Method.POST;
|
||||
import static google.registry.util.CollectionUtils.nullToEmpty;
|
||||
|
@ -21,13 +23,11 @@ import static google.registry.util.RegistrarUtils.normalizeClientId;
|
|||
import static javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
|
||||
import static javax.servlet.http.HttpServletResponse.SC_OK;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.common.collect.Streams;
|
||||
import com.googlecode.objectify.VoidWork;
|
||||
import google.registry.config.RegistryConfig.Config;
|
||||
import google.registry.groups.GroupsConnection;
|
||||
|
@ -44,7 +44,6 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Callable;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.inject.Inject;
|
||||
|
||||
|
@ -118,16 +117,14 @@ public final class SyncGroupMembersAction implements Runnable {
|
|||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
List<Registrar> dirtyRegistrars = FluentIterable.from(Registrar.loadAllCached())
|
||||
.filter(new Predicate<Registrar>() {
|
||||
@Override
|
||||
public boolean apply(Registrar registrar) {
|
||||
// Only grab active registrars that require syncing and are of the correct type.
|
||||
return registrar.isLive()
|
||||
&& registrar.getContactsRequireSyncing()
|
||||
&& registrar.getType() == Registrar.Type.REAL;
|
||||
}})
|
||||
.toList();
|
||||
List<Registrar> dirtyRegistrars =
|
||||
Streams.stream(Registrar.loadAllCached())
|
||||
.filter(
|
||||
registrar ->
|
||||
registrar.isLive()
|
||||
&& registrar.getContactsRequireSyncing()
|
||||
&& registrar.getType() == Registrar.Type.REAL)
|
||||
.collect(toImmutableList());
|
||||
if (dirtyRegistrars.isEmpty()) {
|
||||
sendResponse(Result.NOT_MODIFIED, null);
|
||||
return;
|
||||
|
@ -137,12 +134,12 @@ public final class SyncGroupMembersAction implements Runnable {
|
|||
new ImmutableMap.Builder<>();
|
||||
for (final Registrar registrar : dirtyRegistrars) {
|
||||
try {
|
||||
retrier.callWithRetry(new Callable<Void>() {
|
||||
@Override
|
||||
public Void call() throws Exception {
|
||||
syncRegistrarContacts(registrar);
|
||||
return null;
|
||||
}}, RuntimeException.class);
|
||||
retrier.callWithRetry(
|
||||
() -> {
|
||||
syncRegistrarContacts(registrar);
|
||||
return null;
|
||||
},
|
||||
RuntimeException.class);
|
||||
resultsBuilder.put(registrar, Optional.<Throwable>absent());
|
||||
} catch (Throwable e) {
|
||||
logger.severe(e, e.getMessage());
|
||||
|
@ -193,18 +190,12 @@ public final class SyncGroupMembersAction implements Runnable {
|
|||
groupKey = getGroupEmailAddressForContactType(
|
||||
registrar.getClientId(), type, gSuiteDomainName);
|
||||
Set<String> currentMembers = groupsConnection.getMembersOfGroup(groupKey);
|
||||
Set<String> desiredMembers = FluentIterable.from(registrarContacts)
|
||||
.filter(new Predicate<RegistrarContact>() {
|
||||
@Override
|
||||
public boolean apply(RegistrarContact contact) {
|
||||
return contact.getTypes().contains(type);
|
||||
}})
|
||||
.transform(new Function<RegistrarContact, String>() {
|
||||
@Override
|
||||
public String apply(RegistrarContact contact) {
|
||||
return contact.getEmailAddress();
|
||||
}})
|
||||
.toSet();
|
||||
Set<String> desiredMembers =
|
||||
registrarContacts
|
||||
.stream()
|
||||
.filter(contact -> contact.getTypes().contains(type))
|
||||
.map(RegistrarContact::getEmailAddress)
|
||||
.collect(toImmutableSet());
|
||||
for (String email : Sets.difference(desiredMembers, currentMembers)) {
|
||||
groupsConnection.addMemberToGroup(groupKey, email, Role.MEMBER);
|
||||
totalAdded++;
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
package google.registry.export.sheet;
|
||||
|
||||
import static com.google.common.base.MoreObjects.firstNonNull;
|
||||
import static com.google.common.collect.ImmutableList.toImmutableList;
|
||||
import static google.registry.model.common.Cursor.CursorType.SYNC_REGISTRAR_SHEET;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.model.registrar.RegistrarContact.Type.ABUSE;
|
||||
|
@ -26,10 +27,8 @@ import static google.registry.model.registrar.RegistrarContact.Type.TECH;
|
|||
import static google.registry.model.registrar.RegistrarContact.Type.WHOIS;
|
||||
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSortedSet;
|
||||
|
@ -77,104 +76,83 @@ class SyncRegistrarsSheet {
|
|||
final DateTime executionTime = clock.nowUtc();
|
||||
sheetSynchronizer.synchronize(
|
||||
spreadsheetId,
|
||||
FluentIterable.from(
|
||||
new Ordering<Registrar>() {
|
||||
@Override
|
||||
public int compare(Registrar left, Registrar right) {
|
||||
return left.getClientId().compareTo(right.getClientId());
|
||||
}
|
||||
}.immutableSortedCopy(Registrar.loadAllCached()))
|
||||
new Ordering<Registrar>() {
|
||||
@Override
|
||||
public int compare(Registrar left, Registrar right) {
|
||||
return left.getClientId().compareTo(right.getClientId());
|
||||
}
|
||||
}.immutableSortedCopy(Registrar.loadAllCached())
|
||||
.stream()
|
||||
.filter(
|
||||
new Predicate<Registrar>() {
|
||||
@Override
|
||||
public boolean apply(Registrar registrar) {
|
||||
return registrar.getType() == Registrar.Type.REAL
|
||||
|| registrar.getType() == Registrar.Type.OTE;
|
||||
}
|
||||
registrar ->
|
||||
registrar.getType() == Registrar.Type.REAL
|
||||
|| registrar.getType() == Registrar.Type.OTE)
|
||||
.map(
|
||||
registrar -> {
|
||||
ImmutableMap.Builder<String, String> builder = new ImmutableMap.Builder<>();
|
||||
ImmutableSortedSet<RegistrarContact> contacts = registrar.getContacts();
|
||||
RegistrarAddress address =
|
||||
firstNonNull(
|
||||
registrar.getLocalizedAddress(),
|
||||
firstNonNull(
|
||||
registrar.getInternationalizedAddress(),
|
||||
new RegistrarAddress.Builder()
|
||||
.setStreet(ImmutableList.of("UNKNOWN"))
|
||||
.setCity("UNKNOWN")
|
||||
.setCountryCode("US")
|
||||
.build()));
|
||||
//
|
||||
// (╯°□°)╯ WARNING WARNING WARNING
|
||||
//
|
||||
// Do not change these mappings simply because the Registrar model changed. Only
|
||||
// change these mappings if the people who use the spreadsheet requested it be
|
||||
// changed.
|
||||
//
|
||||
// These values are hard-coded because they correspond to actual spreadsheet
|
||||
// columns. If you change this dictionary, then you'll need to manually add new
|
||||
// columns to the registrar spreadsheets for all environments before deployment,
|
||||
// and you'll need to remove deleted columns probably like a week after
|
||||
// deployment.
|
||||
//
|
||||
builder.put("clientIdentifier", convert(registrar.getClientId()));
|
||||
builder.put("registrarName", convert(registrar.getRegistrarName()));
|
||||
builder.put("state", convert(registrar.getState()));
|
||||
builder.put("ianaIdentifier", convert(registrar.getIanaIdentifier()));
|
||||
builder.put("billingIdentifier", convert(registrar.getBillingIdentifier()));
|
||||
builder.put("billingAccountMap", convert(registrar.getBillingAccountMap()));
|
||||
builder.put("primaryContacts", convertContacts(contacts, byType(ADMIN)));
|
||||
builder.put("techContacts", convertContacts(contacts, byType(TECH)));
|
||||
builder.put("marketingContacts", convertContacts(contacts, byType(MARKETING)));
|
||||
builder.put("abuseContacts", convertContacts(contacts, byType(ABUSE)));
|
||||
builder.put("whoisInquiryContacts", convertContacts(contacts, byType(WHOIS)));
|
||||
builder.put("legalContacts", convertContacts(contacts, byType(LEGAL)));
|
||||
builder.put("billingContacts", convertContacts(contacts, byType(BILLING)));
|
||||
builder.put(
|
||||
"contactsMarkedAsWhoisAdmin",
|
||||
convertContacts(contacts, RegistrarContact::getVisibleInWhoisAsAdmin));
|
||||
builder.put(
|
||||
"contactsMarkedAsWhoisTech",
|
||||
convertContacts(contacts, RegistrarContact::getVisibleInWhoisAsTech));
|
||||
builder.put("emailAddress", convert(registrar.getEmailAddress()));
|
||||
builder.put("address.street", convert(address.getStreet()));
|
||||
builder.put("address.city", convert(address.getCity()));
|
||||
builder.put("address.state", convert(address.getState()));
|
||||
builder.put("address.zip", convert(address.getZip()));
|
||||
builder.put("address.countryCode", convert(address.getCountryCode()));
|
||||
builder.put("phoneNumber", convert(registrar.getPhoneNumber()));
|
||||
builder.put("faxNumber", convert(registrar.getFaxNumber()));
|
||||
builder.put("creationTime", convert(registrar.getCreationTime()));
|
||||
builder.put("lastUpdateTime", convert(registrar.getLastUpdateTime()));
|
||||
builder.put("allowedTlds", convert(registrar.getAllowedTlds()));
|
||||
builder.put("whoisServer", convert(registrar.getWhoisServer()));
|
||||
builder.put("blockPremiumNames", convert(registrar.getBlockPremiumNames()));
|
||||
builder.put("ipAddressWhitelist", convert(registrar.getIpAddressWhitelist()));
|
||||
builder.put("url", convert(registrar.getUrl()));
|
||||
builder.put("referralUrl", convert(registrar.getReferralUrl()));
|
||||
builder.put("icannReferralEmail", convert(registrar.getIcannReferralEmail()));
|
||||
return builder.build();
|
||||
})
|
||||
.transform(
|
||||
new Function<Registrar, ImmutableMap<String, String>>() {
|
||||
@Override
|
||||
public ImmutableMap<String, String> apply(Registrar registrar) {
|
||||
ImmutableMap.Builder<String, String> builder = new ImmutableMap.Builder<>();
|
||||
ImmutableSortedSet<RegistrarContact> contacts = registrar.getContacts();
|
||||
RegistrarAddress address =
|
||||
firstNonNull(
|
||||
registrar.getLocalizedAddress(),
|
||||
firstNonNull(
|
||||
registrar.getInternationalizedAddress(),
|
||||
new RegistrarAddress.Builder()
|
||||
.setStreet(ImmutableList.of("UNKNOWN"))
|
||||
.setCity("UNKNOWN")
|
||||
.setCountryCode("US")
|
||||
.build()));
|
||||
//
|
||||
// (╯°□°)╯ WARNING WARNING WARNING
|
||||
//
|
||||
// Do not change these mappings simply because the Registrar model changed. Only
|
||||
// change these mappings if the people who use the spreadsheet requested it be
|
||||
// changed.
|
||||
//
|
||||
// These values are hard-coded because they correspond to actual spreadsheet
|
||||
// columns. If you change this dictionary, then you'll need to manually add new
|
||||
// columns to the registrar spreadsheets for all environments before deployment,
|
||||
// and you'll need to remove deleted columns probably like a week after
|
||||
// deployment.
|
||||
//
|
||||
builder.put("clientIdentifier", convert(registrar.getClientId()));
|
||||
builder.put("registrarName", convert(registrar.getRegistrarName()));
|
||||
builder.put("state", convert(registrar.getState()));
|
||||
builder.put("ianaIdentifier", convert(registrar.getIanaIdentifier()));
|
||||
builder.put("billingIdentifier", convert(registrar.getBillingIdentifier()));
|
||||
builder.put("billingAccountMap", convert(registrar.getBillingAccountMap()));
|
||||
builder.put("primaryContacts", convertContacts(contacts, byType(ADMIN)));
|
||||
builder.put("techContacts", convertContacts(contacts, byType(TECH)));
|
||||
builder.put("marketingContacts", convertContacts(contacts, byType(MARKETING)));
|
||||
builder.put("abuseContacts", convertContacts(contacts, byType(ABUSE)));
|
||||
builder.put("whoisInquiryContacts", convertContacts(contacts, byType(WHOIS)));
|
||||
builder.put("legalContacts", convertContacts(contacts, byType(LEGAL)));
|
||||
builder.put("billingContacts", convertContacts(contacts, byType(BILLING)));
|
||||
builder.put(
|
||||
"contactsMarkedAsWhoisAdmin",
|
||||
convertContacts(
|
||||
contacts,
|
||||
new Predicate<RegistrarContact>() {
|
||||
@Override
|
||||
public boolean apply(RegistrarContact contact) {
|
||||
return contact.getVisibleInWhoisAsAdmin();
|
||||
}
|
||||
}));
|
||||
builder.put(
|
||||
"contactsMarkedAsWhoisTech",
|
||||
convertContacts(
|
||||
contacts,
|
||||
new Predicate<RegistrarContact>() {
|
||||
@Override
|
||||
public boolean apply(RegistrarContact contact) {
|
||||
return contact.getVisibleInWhoisAsTech();
|
||||
}
|
||||
}));
|
||||
builder.put("emailAddress", convert(registrar.getEmailAddress()));
|
||||
builder.put("address.street", convert(address.getStreet()));
|
||||
builder.put("address.city", convert(address.getCity()));
|
||||
builder.put("address.state", convert(address.getState()));
|
||||
builder.put("address.zip", convert(address.getZip()));
|
||||
builder.put("address.countryCode", convert(address.getCountryCode()));
|
||||
builder.put("phoneNumber", convert(registrar.getPhoneNumber()));
|
||||
builder.put("faxNumber", convert(registrar.getFaxNumber()));
|
||||
builder.put("creationTime", convert(registrar.getCreationTime()));
|
||||
builder.put("lastUpdateTime", convert(registrar.getLastUpdateTime()));
|
||||
builder.put("allowedTlds", convert(registrar.getAllowedTlds()));
|
||||
builder.put("whoisServer", convert(registrar.getWhoisServer()));
|
||||
builder.put("blockPremiumNames", convert(registrar.getBlockPremiumNames()));
|
||||
builder.put("ipAddressWhitelist", convert(registrar.getIpAddressWhitelist()));
|
||||
builder.put("url", convert(registrar.getUrl()));
|
||||
builder.put("referralUrl", convert(registrar.getReferralUrl()));
|
||||
builder.put("icannReferralEmail", convert(registrar.getIcannReferralEmail()));
|
||||
return builder.build();
|
||||
}
|
||||
})
|
||||
.toList());
|
||||
.collect(toImmutableList()));
|
||||
ofy().transact(new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
|
@ -201,11 +179,7 @@ class SyncRegistrarsSheet {
|
|||
}
|
||||
|
||||
private static Predicate<RegistrarContact> byType(final RegistrarContact.Type type) {
|
||||
return new Predicate<RegistrarContact>() {
|
||||
@Override
|
||||
public boolean apply(RegistrarContact contact) {
|
||||
return contact.getTypes().contains(type);
|
||||
}};
|
||||
return contact -> contact.getTypes().contains(type);
|
||||
}
|
||||
|
||||
/** Converts a value to a string representation that can be stored in a spreadsheet cell. */
|
||||
|
|
|
@ -134,19 +134,16 @@ public class SyncRegistrarsSheetAction implements Runnable {
|
|||
}
|
||||
|
||||
String sheetLockName = String.format("%s: %s", LOCK_NAME, sheetId.get());
|
||||
Callable<Void> runner = new Callable<Void>() {
|
||||
@Nullable
|
||||
@Override
|
||||
public Void call() throws IOException {
|
||||
try {
|
||||
syncRegistrarsSheet.run(sheetId.get());
|
||||
Result.OK.send(response, null);
|
||||
} catch (IOException e) {
|
||||
Result.FAILED.send(response, e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
Callable<Void> runner =
|
||||
() -> {
|
||||
try {
|
||||
syncRegistrarsSheet.run(sheetId.get());
|
||||
Result.OK.send(response, null);
|
||||
} catch (IOException e) {
|
||||
Result.FAILED.send(response, e);
|
||||
}
|
||||
return null;
|
||||
};
|
||||
if (!lockHandler.executeWithLocks(runner, null, timeout, sheetLockName)) {
|
||||
// If we fail to acquire the lock, it probably means lots of updates are happening at once, in
|
||||
// which case it should be safe to not bother. The task queue definition should *not* specify
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue