mirror of
https://github.com/google/nomulus.git
synced 2025-08-03 16:32:11 +02:00
Delete remnants of registrar-level credits
We never fully used this stuff but definitely no longer use it following our recent billing refactor. It's confusing to retain all of these entities and commands given that none of them are actually used by anything. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=201978094
This commit is contained in:
parent
4cddbdacff
commit
6706b99828
24 changed files with 1 additions and 2545 deletions
|
@ -1,212 +0,0 @@
|
|||
// 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;
|
||||
|
||||
import static com.google.common.base.CaseFormat.UPPER_CAMEL;
|
||||
import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE;
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.collect.ImmutableList.toImmutableList;
|
||||
import static google.registry.model.registry.Registries.assertTldExists;
|
||||
import static google.registry.util.PreconditionsUtils.checkArgumentPresent;
|
||||
import static org.joda.time.DateTimeZone.UTC;
|
||||
|
||||
import com.beust.jcommander.Parameter;
|
||||
import com.beust.jcommander.Parameters;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Streams;
|
||||
import com.google.re2j.Matcher;
|
||||
import com.google.re2j.Pattern;
|
||||
import google.registry.model.billing.RegistrarCredit;
|
||||
import google.registry.model.billing.RegistrarCredit.CreditType;
|
||||
import google.registry.model.billing.RegistrarCreditBalance;
|
||||
import google.registry.model.registrar.Registrar;
|
||||
import google.registry.model.registry.Registry;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Stream;
|
||||
import org.joda.money.BigMoney;
|
||||
import org.joda.money.CurrencyUnit;
|
||||
import org.joda.money.Money;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
/**
|
||||
* Command for creating new auction credits based on a CSV file from Pool.
|
||||
*
|
||||
* <p>The CSV file from the auction provider uses double-quotes around every field, so in order to
|
||||
* extract the raw field value we strip off the quotes after splitting each line by commas. We are
|
||||
* using a simple parsing strategy that does not support embedded quotation marks, commas, or
|
||||
* newlines.
|
||||
*
|
||||
* <p>Example file format:
|
||||
*
|
||||
* <pre>
|
||||
* "Affiliate","DomainName","Email","BidderId","BidderStatus","UpdatedAt",
|
||||
* "SalePrice","Commissions","CurrencyCode"
|
||||
* "reg1","foo.xn--q9jyb4c","email1@example.com","???_300","INACTIVE","4/3/2014 7:13:09 PM",
|
||||
* "1000.0000","0.0000","JPY"
|
||||
* "reg2","foo.xn--q9jyb4c","email2@example.net","???_64","WIN","4/3/2014 7:13:09 PM",
|
||||
* "1000.0000","40.0000","JPY"
|
||||
* </pre>
|
||||
*
|
||||
* <p>We only care about three fields: 1) the "Affiliate" field which corresponds to the registrar
|
||||
* clientId stored in Datastore, and which we use to determine which registrar gets the credit, 2)
|
||||
* the "Commissions" field which contains the amount of the auction credit (as determined by logic
|
||||
* on the auction provider's side, see the Finance Requirements Doc for more information), and 3)
|
||||
* the "CurrencyCode" field, which we validate matches the TLD-wide currency for this TLD.
|
||||
*/
|
||||
// TODO(b/16009815): Switch this file to using a real CSV parser.
|
||||
@Parameters(separators = " =", commandDescription = "Create new auction credits based on CSV")
|
||||
final class CreateAuctionCreditsCommand extends MutatingCommand {
|
||||
|
||||
@Parameter(
|
||||
names = "--input_file",
|
||||
description = "CSV file for the Pool.com commissions report",
|
||||
required = true)
|
||||
private Path inputFile;
|
||||
|
||||
@Parameter(
|
||||
names = {"-t", "--tld"},
|
||||
description = "The TLD corresponding to this commissions report",
|
||||
required = true)
|
||||
private String tld;
|
||||
|
||||
@Parameter(
|
||||
names = "--effective_time",
|
||||
description = "The time at which these auction credits should become effective",
|
||||
required = true)
|
||||
private DateTime effectiveTime;
|
||||
|
||||
/** Enum containing the headers we expect in the Pool.com CSV file, in order. */
|
||||
private enum CsvHeader {
|
||||
AFFILIATE,
|
||||
DOMAIN_NAME,
|
||||
EMAIL,
|
||||
BIDDER_ID,
|
||||
BIDDER_STATUS,
|
||||
UPDATED_AT,
|
||||
SALE_PRICE,
|
||||
COMMISSIONS,
|
||||
CURRENCY_CODE;
|
||||
|
||||
public static List<String> getHeaders() {
|
||||
return Stream.of(values())
|
||||
.map(header -> UPPER_UNDERSCORE.to(UPPER_CAMEL, header.name()))
|
||||
.collect(toImmutableList());
|
||||
}
|
||||
}
|
||||
|
||||
private static final Pattern QUOTED_STRING = Pattern.compile("\"(.*)\"");
|
||||
|
||||
/** Helper function to unwrap a quoted string, failing if the string is not quoted. */
|
||||
private static final Function<String, String> UNQUOTER =
|
||||
input -> {
|
||||
Matcher matcher = QUOTED_STRING.matcher(input);
|
||||
checkArgument(matcher.matches(), "Input not quoted");
|
||||
return matcher.group(1);
|
||||
};
|
||||
|
||||
/** Returns the input string of quoted CSV values split into the list of unquoted values. */
|
||||
private static List<String> splitCsvLine(String line) {
|
||||
return Streams.stream(Splitter.on(',').split(line)).map(UNQUOTER).collect(toImmutableList());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() throws Exception {
|
||||
assertTldExists(tld);
|
||||
ImmutableMultimap<Registrar, BigMoney> creditMap = parseCreditsFromCsv(inputFile, tld);
|
||||
stageCreditCreations(creditMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the provided CSV file of data from the auction provider and returns a multimap mapping
|
||||
* each registrar to the collection of auction credit amounts from this TLD's auctions that should
|
||||
* be awarded to this registrar, and validating that every credit amount's currency is in the
|
||||
* specified TLD-wide currency.
|
||||
*/
|
||||
private static ImmutableMultimap<Registrar, BigMoney> parseCreditsFromCsv(
|
||||
Path csvFile, String tld) throws IOException {
|
||||
List<String> lines = Files.readAllLines(csvFile, StandardCharsets.UTF_8);
|
||||
checkArgument(CsvHeader.getHeaders().equals(splitCsvLine(lines.get(0))),
|
||||
"Expected CSV header line not present");
|
||||
ImmutableMultimap.Builder<Registrar, BigMoney> builder = new ImmutableMultimap.Builder<>();
|
||||
for (String line : Iterables.skip(lines, 1)) {
|
||||
List<String> fields = splitCsvLine(line);
|
||||
checkArgument(CsvHeader.getHeaders().size() == fields.size(), "Wrong number of fields");
|
||||
try {
|
||||
String clientId = fields.get(CsvHeader.AFFILIATE.ordinal());
|
||||
Registrar registrar =
|
||||
checkArgumentPresent(
|
||||
Registrar.loadByClientId(clientId), "Registrar %s not found", clientId);
|
||||
CurrencyUnit tldCurrency = Registry.get(tld).getCurrency();
|
||||
CurrencyUnit currency = CurrencyUnit.of((fields.get(CsvHeader.CURRENCY_CODE.ordinal())));
|
||||
checkArgument(
|
||||
tldCurrency.equals(currency),
|
||||
"Credit in wrong currency (%s should be %s)",
|
||||
currency,
|
||||
tldCurrency);
|
||||
// We use BigDecimal and BigMoney to preserve fractional currency units when computing the
|
||||
// total amount of each credit (since auction credits are percentages of winning bids).
|
||||
BigDecimal creditAmount = new BigDecimal(fields.get(CsvHeader.COMMISSIONS.ordinal()));
|
||||
BigMoney credit = BigMoney.of(currency, creditAmount);
|
||||
builder.put(registrar, credit);
|
||||
} catch (IllegalArgumentException | IndexOutOfBoundsException e) {
|
||||
throw new IllegalArgumentException("Error in line: " + line, e);
|
||||
}
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Stages the creation of RegistrarCredit and RegistrarCreditBalance instances for each
|
||||
* registrar in the provided multimap of credit amounts by registrar. The balance instance
|
||||
* created is the total of all the credit amounts for a given registrar.
|
||||
*/
|
||||
private void stageCreditCreations(ImmutableMultimap<Registrar, BigMoney> creditMap) {
|
||||
DateTime now = DateTime.now(UTC);
|
||||
CurrencyUnit currency = Registry.get(tld).getCurrency();
|
||||
for (Registrar registrar : creditMap.keySet()) {
|
||||
// Use RoundingMode.UP to be nice and give registrars the extra fractional units.
|
||||
Money totalAmount =
|
||||
BigMoney.total(currency, creditMap.get(registrar)).toMoney(RoundingMode.UP);
|
||||
System.out.printf("Total auction credit balance for %s: %s\n",
|
||||
registrar.getClientId(), totalAmount);
|
||||
|
||||
// Create the actual credit and initial credit balance.
|
||||
RegistrarCredit credit = new RegistrarCredit.Builder()
|
||||
.setParent(registrar)
|
||||
.setType(CreditType.AUCTION)
|
||||
.setCreationTime(now)
|
||||
.setCurrency(currency)
|
||||
.setTld(tld)
|
||||
.build();
|
||||
RegistrarCreditBalance creditBalance = new RegistrarCreditBalance.Builder()
|
||||
.setParent(credit)
|
||||
.setEffectiveTime(effectiveTime)
|
||||
.setWrittenTime(now)
|
||||
.setAmount(totalAmount)
|
||||
.build();
|
||||
stageEntityChange(null, credit);
|
||||
stageEntityChange(null, creditBalance);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,77 +0,0 @@
|
|||
// 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;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.util.PreconditionsUtils.checkArgumentPresent;
|
||||
|
||||
import com.beust.jcommander.Parameter;
|
||||
import com.beust.jcommander.Parameters;
|
||||
import google.registry.model.billing.RegistrarCredit;
|
||||
import google.registry.model.billing.RegistrarCreditBalance;
|
||||
import google.registry.model.registrar.Registrar;
|
||||
import google.registry.util.SystemClock;
|
||||
import org.joda.money.Money;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
/** Command for creating a new balance for a registrar credit. */
|
||||
@Parameters(separators = " =", commandDescription = "Create a new registrar credit balance")
|
||||
final class CreateCreditBalanceCommand extends MutatingCommand {
|
||||
|
||||
@Parameter(
|
||||
names = "--registrar",
|
||||
description = "Client ID of the registrar owning the credit to create a new balance for",
|
||||
required = true)
|
||||
private String clientId;
|
||||
|
||||
@Parameter(
|
||||
names = "--credit_id",
|
||||
description = "ID of credit to create a new balance for",
|
||||
required = true)
|
||||
private long creditId;
|
||||
|
||||
@Parameter(
|
||||
names = "--balance",
|
||||
description = "The new balance amount",
|
||||
required = true)
|
||||
private Money balance;
|
||||
|
||||
@Parameter(
|
||||
names = "--effective_time",
|
||||
description = "Point in time at which the new balance amount becomes effective",
|
||||
required = true)
|
||||
private DateTime effectiveTime;
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
Registrar registrar =
|
||||
checkArgumentPresent(
|
||||
Registrar.loadByClientId(clientId), "Registrar %s not found", clientId);
|
||||
RegistrarCredit credit = ofy().load()
|
||||
.type(RegistrarCredit.class)
|
||||
.parent(registrar)
|
||||
.id(creditId)
|
||||
.now();
|
||||
checkNotNull(credit, "Registrar credit for %s with ID %s not found", clientId, creditId);
|
||||
RegistrarCreditBalance newBalance = new RegistrarCreditBalance.Builder()
|
||||
.setParent(credit)
|
||||
.setEffectiveTime(effectiveTime)
|
||||
.setWrittenTime(new SystemClock().nowUtc())
|
||||
.setAmount(balance)
|
||||
.build();
|
||||
stageEntityChange(null, newBalance);
|
||||
}
|
||||
}
|
|
@ -1,93 +0,0 @@
|
|||
// 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;
|
||||
|
||||
import static google.registry.util.PreconditionsUtils.checkArgumentPresent;
|
||||
import static org.joda.time.DateTimeZone.UTC;
|
||||
|
||||
import com.beust.jcommander.Parameter;
|
||||
import com.beust.jcommander.Parameters;
|
||||
import google.registry.model.billing.RegistrarCredit;
|
||||
import google.registry.model.billing.RegistrarCredit.CreditType;
|
||||
import google.registry.model.billing.RegistrarCreditBalance;
|
||||
import google.registry.model.registrar.Registrar;
|
||||
import javax.annotation.Nullable;
|
||||
import org.joda.money.Money;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
/** Command for creating a registrar credit object with an initial balance. */
|
||||
@Parameters(separators = " =", commandDescription = "Create a new registrar credit")
|
||||
final class CreateCreditCommand extends MutatingCommand {
|
||||
|
||||
@Parameter(
|
||||
names = "--registrar",
|
||||
description = "Client ID of the registrar who will be awarded this credit",
|
||||
required = true)
|
||||
private String clientId;
|
||||
|
||||
@Parameter(
|
||||
names = "--type",
|
||||
description = "Type of credit (AUCTION or PROMOTION)",
|
||||
required = true)
|
||||
private CreditType type;
|
||||
|
||||
@Nullable
|
||||
@Parameter(
|
||||
names = "--description",
|
||||
description = "Custom description that will appear on invoice line for this credit")
|
||||
private String description;
|
||||
|
||||
@Parameter(
|
||||
names = "--tld",
|
||||
description = "TLD for which this credit applies",
|
||||
required = true)
|
||||
private String tld;
|
||||
|
||||
@Parameter(
|
||||
names = "--balance",
|
||||
description = "Initial balance of this credit",
|
||||
required = true)
|
||||
private Money balance;
|
||||
|
||||
@Parameter(
|
||||
names = "--effective_time",
|
||||
description = "Point in time at which the initial balance becomes effective",
|
||||
required = true)
|
||||
private DateTime effectiveTime;
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
DateTime now = DateTime.now(UTC);
|
||||
Registrar registrar =
|
||||
checkArgumentPresent(
|
||||
Registrar.loadByClientId(clientId), "Registrar %s not found", clientId);
|
||||
RegistrarCredit credit = new RegistrarCredit.Builder()
|
||||
.setParent(registrar)
|
||||
.setType(type)
|
||||
.setCreationTime(now)
|
||||
.setCurrency(balance.getCurrencyUnit())
|
||||
.setDescription(description)
|
||||
.setTld(tld)
|
||||
.build();
|
||||
RegistrarCreditBalance creditBalance = new RegistrarCreditBalance.Builder()
|
||||
.setParent(credit)
|
||||
.setEffectiveTime(effectiveTime)
|
||||
.setWrittenTime(now)
|
||||
.setAmount(balance)
|
||||
.build();
|
||||
stageEntityChange(null, credit);
|
||||
stageEntityChange(null, creditBalance);
|
||||
}
|
||||
}
|
|
@ -15,7 +15,6 @@
|
|||
package google.registry.tools;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static com.google.common.base.Predicates.isNull;
|
||||
import static com.google.common.base.Strings.isNullOrEmpty;
|
||||
import static com.google.common.collect.ImmutableSet.toImmutableSet;
|
||||
|
@ -29,7 +28,6 @@ import com.google.common.base.Joiner;
|
|||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Sets;
|
||||
import google.registry.model.billing.RegistrarBillingUtils;
|
||||
import google.registry.model.registrar.Registrar;
|
||||
import google.registry.model.registrar.Registrar.BillingMethod;
|
||||
import google.registry.model.registrar.RegistrarAddress;
|
||||
|
@ -51,7 +49,6 @@ import java.util.Optional;
|
|||
import java.util.Set;
|
||||
import javax.annotation.Nullable;
|
||||
import org.joda.money.CurrencyUnit;
|
||||
import org.joda.money.Money;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
/** Shared base class for commands to create or update a {@link Registrar}. */
|
||||
|
@ -370,18 +367,7 @@ abstract class CreateOrUpdateRegistrarCommand extends MutatingCommand {
|
|||
newBillingAccountMap.putAll(billingAccountMap);
|
||||
builder.setBillingAccountMap(newBillingAccountMap);
|
||||
}
|
||||
if (billingMethod != null) {
|
||||
if (oldRegistrar != null && !billingMethod.equals(oldRegistrar.getBillingMethod())) {
|
||||
Map<CurrencyUnit, Money> balances = RegistrarBillingUtils.loadBalance(oldRegistrar);
|
||||
for (Money balance : balances.values()) {
|
||||
checkState(balance.isZero(),
|
||||
"Refusing to change billing method on Registrar '%s' from %s to %s"
|
||||
+ " because current balance is non-zero: %s",
|
||||
clientId, oldRegistrar.getBillingMethod(), billingMethod, balances);
|
||||
}
|
||||
}
|
||||
builder.setBillingMethod(billingMethod);
|
||||
}
|
||||
Optional.ofNullable(billingMethod).ifPresent(builder::setBillingMethod);
|
||||
List<Object> streetAddressFields = Arrays.asList(street, city, state, zip, countryCode);
|
||||
checkArgument(
|
||||
streetAddressFields.stream().anyMatch(isNull())
|
||||
|
|
|
@ -1,61 +0,0 @@
|
|||
// 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;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.util.PreconditionsUtils.checkArgumentPresent;
|
||||
|
||||
import com.beust.jcommander.Parameter;
|
||||
import com.beust.jcommander.Parameters;
|
||||
import google.registry.model.billing.RegistrarCredit;
|
||||
import google.registry.model.billing.RegistrarCreditBalance;
|
||||
import google.registry.model.registrar.Registrar;
|
||||
|
||||
/** Command for deleting a registrar credit object and all of its child balances. */
|
||||
@Parameters(separators = " =", commandDescription = "Delete a registrar credit")
|
||||
final class DeleteCreditCommand extends MutatingCommand {
|
||||
|
||||
@Parameter(
|
||||
names = "--registrar",
|
||||
description = "Client ID of the registrar owning the credit to delete",
|
||||
required = true)
|
||||
private String clientId;
|
||||
|
||||
@Parameter(
|
||||
names = "--credit_id",
|
||||
description = "ID of credit to delete",
|
||||
required = true)
|
||||
private long creditId;
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
Registrar registrar =
|
||||
checkArgumentPresent(
|
||||
Registrar.loadByClientId(clientId), "Registrar %s not found", clientId);
|
||||
RegistrarCredit credit = ofy().load()
|
||||
.type(RegistrarCredit.class)
|
||||
.parent(registrar)
|
||||
.id(creditId)
|
||||
.now();
|
||||
checkNotNull(credit, "Registrar credit for %s with ID %s not found", clientId, creditId);
|
||||
stageEntityChange(credit, null);
|
||||
|
||||
for (RegistrarCreditBalance balance :
|
||||
ofy().load().type(RegistrarCreditBalance.class).ancestor(credit)) {
|
||||
stageEntityChange(balance, null);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,69 +0,0 @@
|
|||
// 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;
|
||||
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
|
||||
import com.beust.jcommander.Parameter;
|
||||
import com.beust.jcommander.Parameters;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import google.registry.model.billing.RegistrarCredit;
|
||||
import google.registry.model.billing.RegistrarCreditBalance.BalanceMap;
|
||||
import google.registry.model.registrar.Registrar;
|
||||
import google.registry.tools.Command.RemoteApiCommand;
|
||||
import java.util.Optional;
|
||||
import org.joda.money.Money;
|
||||
|
||||
/** Command to list registrar credits and balances. */
|
||||
@Parameters(commandDescription = "List registrar credits and balances")
|
||||
final class ListCreditsCommand implements RemoteApiCommand {
|
||||
|
||||
@Parameter(
|
||||
names = {"-a", "--all"},
|
||||
description = "Pass this flag to show all credits, even those with a zero active balance")
|
||||
private boolean showAll;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for (Registrar registrar : Registrar.loadAll()) {
|
||||
ImmutableList<String> creditStrings = createCreditStrings(registrar);
|
||||
if (!creditStrings.isEmpty()) {
|
||||
System.out.println(registrar.getClientId());
|
||||
System.out.print(Joiner.on("").join(creditStrings));
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ImmutableList<String> createCreditStrings(final Registrar registrar) {
|
||||
return ofy()
|
||||
.transactNewReadOnly(
|
||||
() -> {
|
||||
ImmutableList.Builder<String> builder = new ImmutableList.Builder<>();
|
||||
for (RegistrarCredit credit : RegistrarCredit.loadAllForRegistrar(registrar)) {
|
||||
BalanceMap balanceMap = BalanceMap.createForCredit(credit);
|
||||
Optional<Money> activeBalance =
|
||||
balanceMap.getActiveBalanceAtTime(ofy().getTransactionTime());
|
||||
// Unless showAll is true, only show credits with a positive active balance (which
|
||||
// excludes just zero-balance credits since credit balances cannot be negative).
|
||||
if (showAll || (activeBalance.isPresent() && activeBalance.get().isPositive())) {
|
||||
builder.add(credit.getSummary() + "\n" + balanceMap);
|
||||
}
|
||||
}
|
||||
return builder.build();
|
||||
});
|
||||
}
|
||||
}
|
|
@ -37,11 +37,8 @@ public final class RegistryTool {
|
|||
.put("convert_idn", ConvertIdnCommand.class)
|
||||
.put("count_domains", CountDomainsCommand.class)
|
||||
.put("create_anchor_tenant", CreateAnchorTenantCommand.class)
|
||||
.put("create_auction_credits", CreateAuctionCreditsCommand.class)
|
||||
.put("create_cdns_tld", CreateCdnsTld.class)
|
||||
.put("create_contact", CreateContactCommand.class)
|
||||
.put("create_credit", CreateCreditCommand.class)
|
||||
.put("create_credit_balance", CreateCreditBalanceCommand.class)
|
||||
.put("create_domain", CreateDomainCommand.class)
|
||||
.put("create_host", CreateHostCommand.class)
|
||||
.put("create_lrp_tokens", CreateLrpTokensCommand.class)
|
||||
|
@ -50,7 +47,6 @@ public final class RegistryTool {
|
|||
.put("create_registrar_groups", CreateRegistrarGroupsCommand.class)
|
||||
.put("create_reserved_list", CreateReservedListCommand.class)
|
||||
.put("create_tld", CreateTldCommand.class)
|
||||
.put("delete_credit", DeleteCreditCommand.class)
|
||||
.put("delete_domain", DeleteDomainCommand.class)
|
||||
.put("delete_entity", DeleteEntityCommand.class)
|
||||
.put("delete_host", DeleteHostCommand.class)
|
||||
|
@ -86,7 +82,6 @@ public final class RegistryTool {
|
|||
.put("get_tld", GetTldCommand.class)
|
||||
.put("ghostryde", GhostrydeCommand.class)
|
||||
.put("hash_certificate", HashCertificateCommand.class)
|
||||
.put("list_credits", ListCreditsCommand.class)
|
||||
.put("list_cursors", ListCursorsCommand.class)
|
||||
.put("list_domains", ListDomainsCommand.class)
|
||||
.put("list_hosts", ListHostsCommand.class)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue