// 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 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 java.util.Arrays.asList; import static org.joda.time.DateTimeZone.UTC; import com.google.common.base.Function; import com.google.common.base.Splitter; import com.google.common.collect.FluentIterable; import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.Iterables; 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 google.registry.model.registry.Registry; import org.joda.money.BigMoney; import org.joda.money.CurrencyUnit; import org.joda.money.Money; import org.joda.time.DateTime; 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.regex.Matcher; import java.util.regex.Pattern; /** * Command for creating new auction credits based on a CSV file from Pool. *
* 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. *
* TODO(b/16009815): Switch this file to using a real CSV parser. *
* Example file format: *
* "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" ** 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. */ @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