Run automatic Java 8 conversion over codebase

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

View file

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

View file

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

View file

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

View file

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