google-nomulus/java/google/registry/tools/GenerateLordnCommand.java
Justine Tunney 5012893c1d mv com/google/domain/registry google/registry
This change renames directories in preparation for the great package
rename. The repository is now in a broken state because the code
itself hasn't been updated. However this should ensure that git
correctly preserves history for each file.
2016-05-13 18:55:08 -04:00

91 lines
3.6 KiB
Java

// Copyright 2016 The Domain Registry 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 com.google.domain.registry.tools;
import static com.google.domain.registry.model.ofy.ObjectifyService.ofy;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.joda.time.DateTimeZone.UTC;
import com.google.common.collect.ImmutableList;
import com.google.domain.registry.model.domain.DomainResource;
import com.google.domain.registry.tmch.LordnTask;
import com.google.domain.registry.tools.Command.RemoteApiCommand;
import com.google.domain.registry.tools.params.PathParameter;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import org.joda.time.DateTime;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
/** Command to generate a LORDN CSV file for an entire TLD. */
@Parameters(separators = " =", commandDescription = "Generate LORDN CSV file")
final class GenerateLordnCommand implements RemoteApiCommand {
@Parameter(
names = {"-t", "--tld"},
description = "TLD to generate LORDN for",
required = true)
private String tld;
@Parameter(
names = {"-c", "--claims_file"},
description = "Claims CSV output file.",
validateWith = PathParameter.OutputFile.class,
required = true)
private Path claimsOutputPath;
@Parameter(
names = {"-s", "--sunrise_file"},
description = "Sunrise CSV output file.",
validateWith = PathParameter.OutputFile.class,
required = true)
private Path sunriseOutputPath;
@Override
public void run() throws IOException {
DateTime now = DateTime.now(UTC);
ImmutableList.Builder<String> claimsCsv = new ImmutableList.Builder<>();
ImmutableList.Builder<String> sunriseCsv = new ImmutableList.Builder<>();
for (DomainResource domain : ofy().load().type(DomainResource.class).filter("tld", tld)) {
String status = " ";
if (domain.getLaunchNotice() == null && domain.getSmdId() != null) {
sunriseCsv.add(LordnTask.getCsvLineForSunriseDomain(domain, domain.getCreationTime()));
status = "S";
} else if (domain.getLaunchNotice() != null || domain.getSmdId() != null) {
claimsCsv.add(LordnTask.getCsvLineForClaimsDomain(domain, domain.getCreationTime()));
status = "C";
}
System.out.printf("%s[%s] ", domain.getFullyQualifiedDomainName(), status);
}
ImmutableList<String> claimsRows = claimsCsv.build();
ImmutableList<String> claimsAll = new ImmutableList.Builder<String>()
.add(String.format("1,%s,%d", now, claimsRows.size()))
.add(LordnTask.COLUMNS_CLAIMS)
.addAll(claimsRows)
.build();
ImmutableList<String> sunriseRows = sunriseCsv.build();
ImmutableList<String> sunriseAll = new ImmutableList.Builder<String>()
.add(String.format("1,%s,%d", now.plusMillis(1), sunriseRows.size()))
.add(LordnTask.COLUMNS_SUNRISE)
.addAll(sunriseRows)
.build();
Files.write(claimsOutputPath, claimsAll, UTF_8);
Files.write(sunriseOutputPath, sunriseAll, UTF_8);
}
}