mirror of
https://github.com/google/nomulus.git
synced 2025-06-27 06:44:51 +02:00
Make Registrar load methods return Optionals instead of Nullables
This makes the code more understandable from callsites, and also forces users of this function to deal with the situation where the registrar with a given client ID might not be present (it was previously silently NPEing from some of the callsites). This also adds a test helper method loadRegistrar(clientId) that retains the old functionality for terseness in tests. It also fixes some instances of using the load method with the wrong cachedness -- some uses in high- traffic situations (WHOIS) that should have caching, but also low-traffic reporting that don't benefit from caching so might as well always be current. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=162990468
This commit is contained in:
parent
84fdeebc2f
commit
d536cef20f
81 changed files with 707 additions and 602 deletions
|
@ -17,8 +17,8 @@ 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.base.Preconditions.checkNotNull;
|
||||
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;
|
||||
|
@ -157,13 +157,17 @@ final class CreateAuctionCreditsCommand extends MutatingCommand {
|
|||
List<String> fields = splitCsvLine(line);
|
||||
checkArgument(CsvHeader.getHeaders().size() == fields.size(), "Wrong number of fields");
|
||||
try {
|
||||
String registrarId = fields.get(CsvHeader.AFFILIATE.ordinal());
|
||||
Registrar registrar = checkNotNull(
|
||||
Registrar.loadByClientId(registrarId), "Registrar %s not found", registrarId);
|
||||
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);
|
||||
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()));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue