diff --git a/java/google/registry/beam/invoicing/InvoicingPipeline.java b/java/google/registry/beam/invoicing/InvoicingPipeline.java index 6e3bfe632..0f70ff631 100644 --- a/java/google/registry/beam/invoicing/InvoicingPipeline.java +++ b/java/google/registry/beam/invoicing/InvoicingPipeline.java @@ -75,6 +75,10 @@ public class InvoicingPipeline implements Serializable { @Config("billingBucketUrl") String billingBucketUrl; + @Inject + @Config("invoiceFilePrefix") + String invoiceFilePrefix; + @Inject InvoicingPipeline() {} @@ -164,7 +168,7 @@ public class InvoicingPipeline implements Serializable { billingBucketUrl, BillingModule.INVOICES_DIRECTORY, yearMonth, - BillingModule.OVERALL_INVOICE_PREFIX, + invoiceFilePrefix, yearMonth))) .withHeader(InvoiceGroupingKey.invoiceHeader()) .withoutSharding() diff --git a/java/google/registry/config/RegistryConfig.java b/java/google/registry/config/RegistryConfig.java index f4515107e..f2fe2d2ce 100644 --- a/java/google/registry/config/RegistryConfig.java +++ b/java/google/registry/config/RegistryConfig.java @@ -692,6 +692,18 @@ public final class RegistryConfig { return ImmutableList.copyOf(config.billing.invoiceEmailRecipients); } + /** + * Returns the file prefix for the invoice CSV file. + * + * @see google.registry.beam.invoicing.InvoicingPipeline + * @see google.registry.reporting.billing.BillingEmailUtils + */ + @Provides + @Config("invoiceFilePrefix") + public static String provideInvoiceFilePrefix(RegistryConfigSettings config) { + return config.billing.invoiceFilePrefix; + } + /** * Returns the Google Cloud Storage bucket for staging escrow deposits pending upload. * diff --git a/java/google/registry/config/RegistryConfigSettings.java b/java/google/registry/config/RegistryConfigSettings.java index 95289073c..5a39013e1 100644 --- a/java/google/registry/config/RegistryConfigSettings.java +++ b/java/google/registry/config/RegistryConfigSettings.java @@ -131,6 +131,7 @@ public class RegistryConfigSettings { /** Configuration for monthly invoices. */ public static class Billing { public List invoiceEmailRecipients; + public String invoiceFilePrefix; } /** Configuration for Registry Data Escrow (RDE). */ diff --git a/java/google/registry/config/files/default-config.yaml b/java/google/registry/config/files/default-config.yaml index 25323259d..2e329cad7 100644 --- a/java/google/registry/config/files/default-config.yaml +++ b/java/google/registry/config/files/default-config.yaml @@ -293,6 +293,7 @@ icannReporting: billing: invoiceEmailRecipients: [] + invoiceFilePrefix: REG-INV rde: # URL prefix of ICANN's server to upload RDE reports to. Nomulus adds /TLD/ID diff --git a/java/google/registry/reporting/billing/BillingEmailUtils.java b/java/google/registry/reporting/billing/BillingEmailUtils.java index 918074949..e15c26a72 100644 --- a/java/google/registry/reporting/billing/BillingEmailUtils.java +++ b/java/google/registry/reporting/billing/BillingEmailUtils.java @@ -48,6 +48,7 @@ class BillingEmailUtils { private final String alertRecipientAddress; private final ImmutableList invoiceEmailRecipients; private final String billingBucket; + private final String invoiceFilePrefix; private final String invoiceDirectoryPrefix; private final GcsUtils gcsUtils; private final Retrier retrier; @@ -60,6 +61,7 @@ class BillingEmailUtils { @Config("alertRecipientEmailAddress") String alertRecipientAddress, @Config("invoiceEmailRecipients") ImmutableList invoiceEmailRecipients, @Config("billingBucket") String billingBucket, + @Config("invoiceFilePrefix") String invoiceFilePrefix, @InvoiceDirectoryPrefix String invoiceDirectoryPrefix, GcsUtils gcsUtils, Retrier retrier) { @@ -69,6 +71,7 @@ class BillingEmailUtils { this.alertRecipientAddress = alertRecipientAddress; this.invoiceEmailRecipients = invoiceEmailRecipients; this.billingBucket = billingBucket; + this.invoiceFilePrefix = invoiceFilePrefix; this.invoiceDirectoryPrefix = invoiceDirectoryPrefix; this.gcsUtils = gcsUtils; this.retrier = retrier; @@ -80,8 +83,7 @@ class BillingEmailUtils { retrier.callWithRetry( () -> { String invoiceFile = - String.format( - "%s-%s.csv", BillingModule.OVERALL_INVOICE_PREFIX, yearMonth.toString()); + String.format("%s-%s.csv", invoiceFilePrefix, yearMonth); GcsFilename invoiceFilename = new GcsFilename(billingBucket, invoiceDirectoryPrefix + invoiceFile); try (InputStream in = gcsUtils.openInputStream(invoiceFilename)) { @@ -91,12 +93,12 @@ class BillingEmailUtils { msg.addRecipient(RecipientType.TO, new InternetAddress(recipient)); } msg.setSubject( - String.format("Domain Registry invoice data %s", yearMonth.toString())); + String.format("Domain Registry invoice data %s", yearMonth)); Multipart multipart = new MimeMultipart(); BodyPart textPart = new MimeBodyPart(); textPart.setText( String.format( - "Attached is the %s invoice for the domain registry.", yearMonth.toString())); + "Attached is the %s invoice for the domain registry.", yearMonth)); multipart.addBodyPart(textPart); BodyPart invoicePart = new MimeBodyPart(); String invoiceData = CharStreams.toString(new InputStreamReader(in, UTF_8)); @@ -128,7 +130,7 @@ class BillingEmailUtils { Message msg = emailService.createMessage(); msg.setFrom(new InternetAddress(outgoingEmailAddress)); msg.addRecipient(RecipientType.TO, new InternetAddress(alertRecipientAddress)); - msg.setSubject(String.format("Billing Pipeline Alert: %s", yearMonth.toString())); + msg.setSubject(String.format("Billing Pipeline Alert: %s", yearMonth)); msg.setText(body); emailService.sendMessage(msg); return null; diff --git a/java/google/registry/reporting/billing/BillingModule.java b/java/google/registry/reporting/billing/BillingModule.java index e1bba7225..b8fa95d0f 100644 --- a/java/google/registry/reporting/billing/BillingModule.java +++ b/java/google/registry/reporting/billing/BillingModule.java @@ -32,8 +32,6 @@ import org.joda.time.YearMonth; public final class BillingModule { public static final String DETAIL_REPORT_PREFIX = "invoice_details"; - // TODO(b/119551360): This should be configurable, not hard-coded to Charleston Road Registry. - public static final String OVERALL_INVOICE_PREFIX = "CRR-INV"; public static final String INVOICES_DIRECTORY = "invoices"; static final String PARAM_SHOULD_PUBLISH = "shouldPublish"; diff --git a/javatests/google/registry/beam/invoicing/InvoicingPipelineTest.java b/javatests/google/registry/beam/invoicing/InvoicingPipelineTest.java index 538dae227..b2994a3f2 100644 --- a/javatests/google/registry/beam/invoicing/InvoicingPipelineTest.java +++ b/javatests/google/registry/beam/invoicing/InvoicingPipelineTest.java @@ -62,6 +62,7 @@ public class InvoicingPipelineTest { invoicingPipeline.projectId = "test-project"; File beamTempFolder = tempFolder.newFolder(); invoicingPipeline.beamBucketUrl = beamTempFolder.getAbsolutePath(); + invoicingPipeline.invoiceFilePrefix = "REG-INV"; invoicingPipeline.beamStagingUrl = beamTempFolder.getAbsolutePath() + "/staging"; invoicingPipeline.invoiceTemplateUrl = beamTempFolder.getAbsolutePath() + "/templates/invoicing"; @@ -196,7 +197,7 @@ public class InvoicingPipelineTest { .containsExactlyElementsIn(entry.getValue()); } - ImmutableList overallInvoice = resultFileContents("CRR-INV-2017-10.csv"); + ImmutableList overallInvoice = resultFileContents("REG-INV-2017-10.csv"); assertThat(overallInvoice.get(0)) .isEqualTo( "StartDate,EndDate,ProductAccountKey,Amount,AmountCurrency,BillingProductCode," diff --git a/javatests/google/registry/reporting/billing/BillingEmailUtilsTest.java b/javatests/google/registry/reporting/billing/BillingEmailUtilsTest.java index 405367ce6..147a0f9c5 100644 --- a/javatests/google/registry/reporting/billing/BillingEmailUtilsTest.java +++ b/javatests/google/registry/reporting/billing/BillingEmailUtilsTest.java @@ -67,7 +67,7 @@ public class BillingEmailUtilsTest { when(emailService.createMessage()) .thenReturn(new MimeMessage(Session.getDefaultInstance(new Properties(), null))); gcsUtils = mock(GcsUtils.class); - when(gcsUtils.openInputStream(new GcsFilename("test-bucket", "results/CRR-INV-2017-10.csv"))) + when(gcsUtils.openInputStream(new GcsFilename("test-bucket", "results/REG-INV-2017-10.csv"))) .thenReturn( new ByteArrayInputStream("test,data\nhello,world".getBytes(StandardCharsets.UTF_8))); msgCaptor = ArgumentCaptor.forClass(Message.class); @@ -80,6 +80,7 @@ public class BillingEmailUtilsTest { "my-receiver@test.com", ImmutableList.of("hello@world.com", "hola@mundo.com"), "test-bucket", + "REG-INV", "results/", gcsUtils, new Retrier(new FakeSleeper(new FakeClock()), RETRY_COUNT)); @@ -109,7 +110,7 @@ public class BillingEmailUtilsTest { .isEqualTo("Attached is the 2017-10 invoice for the domain registry."); assertThat(contents.getBodyPart(1)).isInstanceOf(BodyPart.class); BodyPart attachmentPart = contents.getBodyPart(1); - assertThat(attachmentPart.getContentType()).endsWith("name=CRR-INV-2017-10.csv"); + assertThat(attachmentPart.getContentType()).endsWith("name=REG-INV-2017-10.csv"); assertThat(attachmentPart.getContent().toString()).isEqualTo("test,data\nhello,world"); }