diff --git a/java/google/registry/tools/RegistryTool.java b/java/google/registry/tools/RegistryTool.java index 6751ba65a..a93217aa8 100644 --- a/java/google/registry/tools/RegistryTool.java +++ b/java/google/registry/tools/RegistryTool.java @@ -15,6 +15,7 @@ package google.registry.tools; import com.google.common.collect.ImmutableMap; +import google.registry.tools.javascrap.PopulateNullRegistrarFieldsCommand; import google.registry.tools.javascrap.RemoveDomainTransferDataCommand; import google.registry.tools.javascrap.RemoveIpAddressCommand; @@ -97,6 +98,7 @@ public final class RegistryTool { .put("logout", LogoutCommand.class) .put("make_billing_tables", MakeBillingTablesCommand.class) .put("pending_escrow", PendingEscrowCommand.class) + .put("populate_null_registrar_fields", PopulateNullRegistrarFieldsCommand.class) .put("publish_detail_report", PublishDetailReportCommand.class) .put("registrar_activity_report", RegistrarActivityReportCommand.class) .put("registrar_contact", RegistrarContactCommand.class) diff --git a/java/google/registry/tools/javascrap/PopulateNullRegistrarFieldsCommand.java b/java/google/registry/tools/javascrap/PopulateNullRegistrarFieldsCommand.java new file mode 100644 index 000000000..8cc216c3b --- /dev/null +++ b/java/google/registry/tools/javascrap/PopulateNullRegistrarFieldsCommand.java @@ -0,0 +1,73 @@ +// Copyright 2017 The Nomulus Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package google.registry.tools.javascrap; + +import static com.google.common.base.MoreObjects.firstNonNull; +import static google.registry.model.common.EntityGroupRoot.getCrossTldKey; +import static google.registry.model.ofy.ObjectifyService.ofy; + +import com.beust.jcommander.Parameters; +import com.google.common.collect.ImmutableList; +import google.registry.model.registrar.Registrar; +import google.registry.model.registrar.Registrar.Builder; +import google.registry.model.registrar.RegistrarAddress; +import google.registry.tools.MutatingCommand; +import java.util.Objects; + +/** + * Scrap tool to update Registrars with null registrarName or localizedAddress fields. + * + *

This sets a null registrarName to the key name, and null localizedAddress fields to fake data. + */ +@Parameters( + separators = " =", + commandDescription = "Populate previously null required registrar fields." +) +public class PopulateNullRegistrarFieldsCommand extends MutatingCommand { + + @Override + protected void init() throws Exception { + for (Registrar registrar : ofy().load().type(Registrar.class).ancestor(getCrossTldKey())) { + Builder changeBuilder = registrar.asBuilder(); + changeBuilder.setRegistrarName( + firstNonNull(registrar.getRegistrarName(), registrar.getClientId())); + + RegistrarAddress address = registrar.getLocalizedAddress(); + if (address == null) { + changeBuilder.setLocalizedAddress( + new RegistrarAddress.Builder() + .setCity("Fakington") + .setCountryCode("US") + .setState("FL") + .setZip("12345") + .setStreet(ImmutableList.of("123 Fake Street")) + .build()); + } else { + changeBuilder.setLocalizedAddress( + new RegistrarAddress.Builder() + .setCity(firstNonNull(address.getCity(), "Fakington")) + .setCountryCode(firstNonNull(address.getCountryCode(), "US")) + .setState(firstNonNull(address.getState(), "FL")) + .setZip(firstNonNull(address.getZip(), "12345")) + .setStreet(firstNonNull(address.getStreet(), ImmutableList.of("123 Fake Street"))) + .build()); + } + Registrar changedRegistrar = changeBuilder.build(); + if (!Objects.equals(registrar, changedRegistrar)) { + stageEntityChange(registrar, changedRegistrar); + } + } + } +}