From 635edd0fb90cbe960989f3ad1254fd089be9dec7 Mon Sep 17 00:00:00 2001 From: mcilwain Date: Fri, 12 Jan 2018 13:08:02 -0800 Subject: [PATCH] Centralize PARAM_YEAR_MONTH into RequestParameters Overall this ends up being nicer. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=181782569 --- java/google/registry/billing/BillingModule.java | 1 - java/google/registry/billing/GenerateInvoicesAction.java | 3 ++- java/google/registry/billing/PublishInvoicesAction.java | 3 ++- java/google/registry/module/backend/BackendModule.java | 3 +-- java/google/registry/request/RequestParameters.java | 7 ++++++- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/java/google/registry/billing/BillingModule.java b/java/google/registry/billing/BillingModule.java index e02701183..3a6810f9a 100644 --- a/java/google/registry/billing/BillingModule.java +++ b/java/google/registry/billing/BillingModule.java @@ -43,7 +43,6 @@ public final class BillingModule { public static final String INVOICES_DIRECTORY = "invoices"; static final String PARAM_JOB_ID = "jobId"; - static final String PARAM_YEAR_MONTH = "yearMonth"; static final String BILLING_QUEUE = "billing"; static final String CRON_QUEUE = "retryable-cron-tasks"; diff --git a/java/google/registry/billing/GenerateInvoicesAction.java b/java/google/registry/billing/GenerateInvoicesAction.java index fa6bb4be2..5e2e44017 100644 --- a/java/google/registry/billing/GenerateInvoicesAction.java +++ b/java/google/registry/billing/GenerateInvoicesAction.java @@ -15,6 +15,7 @@ package google.registry.billing; import static google.registry.request.Action.Method.POST; +import static google.registry.request.RequestParameters.PARAM_YEAR_MONTH; import static javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR; import static javax.servlet.http.HttpServletResponse.SC_OK; @@ -120,7 +121,7 @@ public class GenerateInvoicesAction implements Runnable { .countdownMillis(Duration.standardMinutes(10).getMillis()) .param(BillingModule.PARAM_JOB_ID, jobId) // Need to pass this through to ensure transitive yearMonth dependencies are satisfied. - .param(BillingModule.PARAM_YEAR_MONTH, yearMonth.toString()); + .param(PARAM_YEAR_MONTH, yearMonth.toString()); QueueFactory.getQueue(BillingModule.BILLING_QUEUE).add(publishTask); } } diff --git a/java/google/registry/billing/PublishInvoicesAction.java b/java/google/registry/billing/PublishInvoicesAction.java index 03616d04e..edb71cbcf 100644 --- a/java/google/registry/billing/PublishInvoicesAction.java +++ b/java/google/registry/billing/PublishInvoicesAction.java @@ -15,6 +15,7 @@ package google.registry.billing; import static google.registry.request.Action.Method.POST; +import static google.registry.request.RequestParameters.PARAM_YEAR_MONTH; import static javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR; import static javax.servlet.http.HttpServletResponse.SC_NOT_MODIFIED; import static javax.servlet.http.HttpServletResponse.SC_NO_CONTENT; @@ -112,7 +113,7 @@ public class PublishInvoicesAction implements Runnable { TaskOptions copyDetailTask = TaskOptions.Builder.withUrl(CopyDetailReportsAction.PATH) .method(TaskOptions.Method.POST) - .param(BillingModule.PARAM_YEAR_MONTH, yearMonth.toString()); + .param(PARAM_YEAR_MONTH, yearMonth.toString()); QueueFactory.getQueue(BillingModule.CRON_QUEUE).add(copyDetailTask); } } diff --git a/java/google/registry/module/backend/BackendModule.java b/java/google/registry/module/backend/BackendModule.java index bcd2aa9b0..d9218fa70 100644 --- a/java/google/registry/module/backend/BackendModule.java +++ b/java/google/registry/module/backend/BackendModule.java @@ -16,6 +16,7 @@ package google.registry.module.backend; import static google.registry.model.registry.Registries.assertTldExists; import static google.registry.model.registry.Registries.assertTldsExist; +import static google.registry.request.RequestParameters.PARAM_YEAR_MONTH; import static google.registry.request.RequestParameters.extractOptionalDatetimeParameter; import static google.registry.request.RequestParameters.extractOptionalParameter; import static google.registry.request.RequestParameters.extractRequiredParameter; @@ -42,8 +43,6 @@ import org.joda.time.format.DateTimeFormatter; @Module public class BackendModule { - private static final String PARAM_YEAR_MONTH = "yearMonth"; - @Provides @Parameter(RequestParameters.PARAM_TLD) static String provideTld(HttpServletRequest req) { diff --git a/java/google/registry/request/RequestParameters.java b/java/google/registry/request/RequestParameters.java index 5b8882f6b..9c7d7c29d 100644 --- a/java/google/registry/request/RequestParameters.java +++ b/java/google/registry/request/RequestParameters.java @@ -29,9 +29,14 @@ import org.joda.time.DateTime; /** Utilities for extracting parameters from HTTP requests. */ public final class RequestParameters { - /** The standardized request parameter name used by any servlet that takes a tld parameter. */ + /** The standardized request parameter name used by any action that takes a tld parameter. */ public static final String PARAM_TLD = "tld"; + /** + * The standardized request parameter name used by any action that takes a year/month parameter. + */ + public static final String PARAM_YEAR_MONTH = "yearMonth"; + /** * Returns first GET or POST parameter associated with {@code name}. *