mirror of
https://github.com/google/nomulus
synced 2026-09-12 11:06:29 +00:00
Convert GenerateLordnCommand to tm (#1091)
* Convert GenerateLordnCommand to tm This makes use of QueryComposer and adds a `list()` method to it. Since there was no test for GenerateLordnCommand, this also implements one. * Changes requested in review * Add test for list queries * Stream domains instead of listing them * Reformatted
This commit is contained in:
@@ -444,5 +444,10 @@ public class DatastoreTransactionManager implements TransactionManager {
|
||||
public long count() {
|
||||
return buildQuery().count();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<T> list() {
|
||||
return buildQuery().list();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
@@ -737,5 +737,10 @@ public class JpaTransactionManagerImpl implements JpaTransactionManager {
|
||||
CriteriaQueryBuilder<Long> queryBuilder = CriteriaQueryBuilder.createCount(em, entityClass);
|
||||
return addCriteria(queryBuilder).getSingleResult();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<T> list() {
|
||||
return buildQuery().getResultList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,6 +91,9 @@ public abstract class QueryComposer<T> {
|
||||
/** Returns the number of results of the query. */
|
||||
public abstract long count();
|
||||
|
||||
/** Returns the results of the query as a list. */
|
||||
public abstract List<T> list();
|
||||
|
||||
// We have to wrap the CriteriaQueryBuilder predicate factories in our own functions because at
|
||||
// the point where we pass them to the Comparator constructor, the compiler can't determine which
|
||||
// of the overloads to use since there is no "value" object for context.
|
||||
|
||||
@@ -14,9 +14,10 @@
|
||||
|
||||
package google.registry.tools;
|
||||
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.persistence.transaction.QueryComposer.Comparator;
|
||||
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
|
||||
import static google.registry.persistence.transaction.TransactionManagerUtil.transactIfJpaTm;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.joda.time.DateTimeZone.UTC;
|
||||
|
||||
import com.beust.jcommander.Parameter;
|
||||
import com.beust.jcommander.Parameters;
|
||||
@@ -24,9 +25,11 @@ import com.google.common.collect.ImmutableList;
|
||||
import google.registry.model.domain.DomainBase;
|
||||
import google.registry.tmch.LordnTaskUtils;
|
||||
import google.registry.tools.params.PathParameter;
|
||||
import google.registry.util.Clock;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import javax.inject.Inject;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
/** Command to generate a LORDN CSV file for an entire TLD. */
|
||||
@@ -53,22 +56,21 @@ final class GenerateLordnCommand implements CommandWithRemoteApi {
|
||||
required = true)
|
||||
private Path sunriseOutputPath;
|
||||
|
||||
@Inject Clock clock;
|
||||
|
||||
@Override
|
||||
public void run() throws IOException {
|
||||
DateTime now = DateTime.now(UTC);
|
||||
DateTime now = clock.nowUtc();
|
||||
ImmutableList.Builder<String> claimsCsv = new ImmutableList.Builder<>();
|
||||
ImmutableList.Builder<String> sunriseCsv = new ImmutableList.Builder<>();
|
||||
for (DomainBase domain : ofy().load().type(DomainBase.class).filter("tld", tld)) {
|
||||
String status = " ";
|
||||
if (domain.getLaunchNotice() == null && domain.getSmdId() != null) {
|
||||
sunriseCsv.add(LordnTaskUtils.getCsvLineForSunriseDomain(domain, domain.getCreationTime()));
|
||||
status = "S";
|
||||
} else if (domain.getLaunchNotice() != null || domain.getSmdId() != null) {
|
||||
claimsCsv.add(LordnTaskUtils.getCsvLineForClaimsDomain(domain, domain.getCreationTime()));
|
||||
status = "C";
|
||||
}
|
||||
System.out.printf("%s[%s] ", domain.getDomainName(), status);
|
||||
}
|
||||
transactIfJpaTm(
|
||||
() ->
|
||||
tm()
|
||||
.createQueryComposer(DomainBase.class)
|
||||
.where("tld", Comparator.EQ, tld)
|
||||
.orderBy("repoId")
|
||||
.stream()
|
||||
.forEach(domain -> processDomain(claimsCsv, sunriseCsv, domain)));
|
||||
ImmutableList<String> claimsRows = claimsCsv.build();
|
||||
ImmutableList<String> claimsAll =
|
||||
new ImmutableList.Builder<String>()
|
||||
@@ -86,4 +88,19 @@ final class GenerateLordnCommand implements CommandWithRemoteApi {
|
||||
Files.write(claimsOutputPath, claimsAll, UTF_8);
|
||||
Files.write(sunriseOutputPath, sunriseAll, UTF_8);
|
||||
}
|
||||
|
||||
private static void processDomain(
|
||||
ImmutableList.Builder<String> claimsCsv,
|
||||
ImmutableList.Builder<String> sunriseCsv,
|
||||
DomainBase domain) {
|
||||
String status = " ";
|
||||
if (domain.getLaunchNotice() == null && domain.getSmdId() != null) {
|
||||
sunriseCsv.add(LordnTaskUtils.getCsvLineForSunriseDomain(domain, domain.getCreationTime()));
|
||||
status = "S";
|
||||
} else if (domain.getLaunchNotice() != null || domain.getSmdId() != null) {
|
||||
claimsCsv.add(LordnTaskUtils.getCsvLineForClaimsDomain(domain, domain.getCreationTime()));
|
||||
status = "C";
|
||||
}
|
||||
System.out.printf("%s[%s] ", domain.getDomainName(), status);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user