diff --git a/java/google/registry/beam/spec11/Spec11Pipeline.java b/java/google/registry/beam/spec11/Spec11Pipeline.java index fb09616d1..ee39720e6 100644 --- a/java/google/registry/beam/spec11/Spec11Pipeline.java +++ b/java/google/registry/beam/spec11/Spec11Pipeline.java @@ -21,8 +21,6 @@ import google.registry.config.RegistryConfig.Config; import google.registry.util.Retrier; import google.registry.util.SqlTemplate; import java.io.Serializable; -import java.time.LocalDate; -import java.time.YearMonth; import javax.inject.Inject; import org.apache.beam.runners.dataflow.DataflowRunner; import org.apache.beam.runners.dataflow.options.DataflowPipelineOptions; @@ -41,6 +39,8 @@ import org.apache.beam.sdk.values.KV; import org.apache.beam.sdk.values.PCollection; import org.apache.beam.sdk.values.TypeDescriptor; import org.apache.beam.sdk.values.TypeDescriptors; +import org.joda.time.LocalDate; +import org.joda.time.YearMonth; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -64,7 +64,7 @@ public class Spec11Pipeline implements Serializable { * @see google.registry.reporting.spec11.Spec11EmailUtils */ public static String getSpec11ReportFilePath(LocalDate localDate) { - YearMonth yearMonth = YearMonth.of(localDate.getYear(), localDate.getMonth()); + YearMonth yearMonth = new YearMonth(localDate); return String.format("icann/spec11/%s/SPEC11_MONTHLY_REPORT_%s", yearMonth, localDate); } diff --git a/java/google/registry/reporting/ReportingModule.java b/java/google/registry/reporting/ReportingModule.java index a295636a9..47890971b 100644 --- a/java/google/registry/reporting/ReportingModule.java +++ b/java/google/registry/reporting/ReportingModule.java @@ -26,14 +26,12 @@ import google.registry.config.RegistryConfig.Config; import google.registry.request.HttpException.BadRequestException; import google.registry.request.Parameter; import google.registry.util.Clock; -import java.time.LocalDate; -import java.time.format.DateTimeParseException; import java.util.Optional; import javax.servlet.http.HttpServletRequest; -import org.joda.time.DateTime; +import org.joda.time.DateTimeZone; +import org.joda.time.LocalDate; import org.joda.time.YearMonth; -import org.joda.time.format.DateTimeFormat; -import org.joda.time.format.DateTimeFormatter; +import org.joda.time.format.ISODateTimeFormat; /** Dagger module for injecting common settings for all reporting tasks. */ @Module @@ -68,10 +66,9 @@ public class ReportingModule { @Provides @Parameter(PARAM_YEAR_MONTH) static Optional provideYearMonthOptional(HttpServletRequest req) { - DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM"); Optional optionalYearMonthStr = extractOptionalParameter(req, PARAM_YEAR_MONTH); try { - return optionalYearMonthStr.map(s -> YearMonth.parse(s, formatter)); + return optionalYearMonthStr.map(s -> YearMonth.parse(s, ISODateTimeFormat.yearMonth())); } catch (IllegalArgumentException e) { throw new BadRequestException( String.format( @@ -87,20 +84,17 @@ public class ReportingModule { @Provides static YearMonth provideYearMonth( @Parameter(PARAM_YEAR_MONTH) Optional yearMonthOptional, LocalDate date) { - return yearMonthOptional.orElseGet( - () -> new YearMonth(date.getYear(), date.getMonthValue() - 1)); + return yearMonthOptional.orElseGet(() -> new YearMonth(date.minusMonths(1))); } /** Extracts an optional date in yyyy-MM-dd format from the request. */ @Provides @Parameter(PARAM_DATE) static Optional provideDateOptional(HttpServletRequest req) { - java.time.format.DateTimeFormatter formatter = - java.time.format.DateTimeFormatter.ISO_LOCAL_DATE; Optional optionalDateString = extractOptionalParameter(req, PARAM_DATE); try { - return optionalDateString.map(s -> LocalDate.parse(s, formatter)); - } catch (DateTimeParseException e) { + return optionalDateString.map(s -> LocalDate.parse(s, ISODateTimeFormat.yearMonthDay())); + } catch (IllegalArgumentException e) { throw new BadRequestException( String.format( "date must be in yyyy-MM-dd format, got %s instead", @@ -116,11 +110,7 @@ public class ReportingModule { @Provides static LocalDate provideDate( @Parameter(PARAM_DATE) Optional dateOptional, Clock clock) { - return dateOptional.orElseGet( - () -> { - DateTime now = clock.nowUtc(); - return LocalDate.of(now.getYear(), now.getMonthOfYear(), now.getDayOfMonth()); - }); + return dateOptional.orElseGet(() -> new LocalDate(clock.nowUtc(), DateTimeZone.UTC)); } /** Constructs a {@link Dataflow} API client with default settings. */ diff --git a/java/google/registry/reporting/spec11/GenerateSpec11ReportAction.java b/java/google/registry/reporting/spec11/GenerateSpec11ReportAction.java index 21b1021bf..57d701519 100644 --- a/java/google/registry/reporting/spec11/GenerateSpec11ReportAction.java +++ b/java/google/registry/reporting/spec11/GenerateSpec11ReportAction.java @@ -33,9 +33,9 @@ import google.registry.request.Action; import google.registry.request.Response; import google.registry.request.auth.Auth; import java.io.IOException; -import java.time.LocalDate; import java.util.Map; import javax.inject.Inject; +import org.joda.time.LocalDate; /** * Invokes the {@code Spec11Pipeline} Beam template via the REST api. diff --git a/java/google/registry/reporting/spec11/PublishSpec11ReportAction.java b/java/google/registry/reporting/spec11/PublishSpec11ReportAction.java index f58ff60a9..82e2ee64b 100644 --- a/java/google/registry/reporting/spec11/PublishSpec11ReportAction.java +++ b/java/google/registry/reporting/spec11/PublishSpec11ReportAction.java @@ -31,8 +31,8 @@ import google.registry.request.Parameter; import google.registry.request.Response; import google.registry.request.auth.Auth; import java.io.IOException; -import java.time.LocalDate; import javax.inject.Inject; +import org.joda.time.LocalDate; /** * Retries until a {@code Dataflow} job with a given {@code jobId} completes, continuing the Spec11 diff --git a/java/google/registry/reporting/spec11/Spec11Module.java b/java/google/registry/reporting/spec11/Spec11Module.java index d9fd5a492..4fee57004 100644 --- a/java/google/registry/reporting/spec11/Spec11Module.java +++ b/java/google/registry/reporting/spec11/Spec11Module.java @@ -21,8 +21,8 @@ import dagger.Provides; import google.registry.beam.spec11.Spec11Pipeline; import java.lang.annotation.Documented; import java.lang.annotation.Retention; -import java.time.LocalDate; import javax.inject.Qualifier; +import org.joda.time.LocalDate; /** Module for dependencies required by Spec11 reporting. */ @Module diff --git a/java/google/registry/reporting/spec11/Spec11RegistrarThreatMatchesParser.java b/java/google/registry/reporting/spec11/Spec11RegistrarThreatMatchesParser.java index 6f09ddc9b..4e16ebc01 100644 --- a/java/google/registry/reporting/spec11/Spec11RegistrarThreatMatchesParser.java +++ b/java/google/registry/reporting/spec11/Spec11RegistrarThreatMatchesParser.java @@ -26,8 +26,8 @@ import google.registry.gcs.GcsUtils; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; -import java.time.LocalDate; import javax.inject.Inject; +import org.joda.time.LocalDate; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; diff --git a/javatests/google/registry/reporting/ReportingModuleTest.java b/javatests/google/registry/reporting/ReportingModuleTest.java index f532e1659..922d54a45 100644 --- a/javatests/google/registry/reporting/ReportingModuleTest.java +++ b/javatests/google/registry/reporting/ReportingModuleTest.java @@ -23,10 +23,10 @@ import com.google.common.truth.Truth8; import google.registry.request.HttpException.BadRequestException; import google.registry.testing.FakeClock; import google.registry.util.Clock; -import java.time.LocalDate; import java.util.Optional; import javax.servlet.http.HttpServletRequest; import org.joda.time.DateTime; +import org.joda.time.LocalDate; import org.joda.time.YearMonth; import org.junit.Before; import org.junit.Test; @@ -71,15 +71,15 @@ public class ReportingModuleTest { @Test public void testEmptyYearMonth_returnsLastMonth() { - assertThat(ReportingModule.provideYearMonth(Optional.empty(), LocalDate.of(2017, 7, 6))) - .isEqualTo(new YearMonth(2017, 6)); + assertThat(ReportingModule.provideYearMonth(Optional.empty(), new LocalDate(2017, 1, 6))) + .isEqualTo(new YearMonth(2016, 12)); } @Test public void testGivenYearMonth_returnsThatMonth() { assertThat( ReportingModule.provideYearMonth( - Optional.of(new YearMonth(2017, 5)), LocalDate.of(2017, 7, 6))) + Optional.of(new YearMonth(2017, 5)), new LocalDate(2017, 7, 6))) .isEqualTo(new YearMonth(2017, 5)); } @@ -93,7 +93,7 @@ public class ReportingModuleTest { public void testValidDateParameter_returnsThatDate() { when(req.getParameter("date")).thenReturn("2017-05-13"); Truth8.assertThat(ReportingModule.provideDateOptional(req)) - .hasValue(LocalDate.of(2017, 5, 13)); + .hasValue(new LocalDate(2017, 5, 13)); } @Test @@ -109,12 +109,12 @@ public class ReportingModuleTest { @Test public void testEmptyDate_returnsToday() { assertThat(ReportingModule.provideDate(Optional.empty(), clock)) - .isEqualTo(LocalDate.of(2017, 7, 1)); + .isEqualTo(new LocalDate(2017, 7, 1)); } @Test public void testGivenDate_returnsThatDate() { - assertThat(ReportingModule.provideDate(Optional.of(LocalDate.of(2017, 7, 2)), clock)) - .isEqualTo(LocalDate.of(2017, 7, 2)); + assertThat(ReportingModule.provideDate(Optional.of(new LocalDate(2017, 7, 2)), clock)) + .isEqualTo(new LocalDate(2017, 7, 2)); } } diff --git a/javatests/google/registry/reporting/spec11/GenerateSpec11ReportActionTest.java b/javatests/google/registry/reporting/spec11/GenerateSpec11ReportActionTest.java index 64a70cc53..b9896e469 100644 --- a/javatests/google/registry/reporting/spec11/GenerateSpec11ReportActionTest.java +++ b/javatests/google/registry/reporting/spec11/GenerateSpec11ReportActionTest.java @@ -35,7 +35,7 @@ import google.registry.testing.AppEngineRule; import google.registry.testing.FakeResponse; import google.registry.testing.TaskQueueHelper.TaskMatcher; import java.io.IOException; -import java.time.LocalDate; +import org.joda.time.LocalDate; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -87,7 +87,7 @@ public class GenerateSpec11ReportActionTest { "gs://template", "us-east1-c", "api_key/a", - LocalDate.parse("2018-06-11"), + new LocalDate(2018, 6, 11), response, dataflow); action.run(); diff --git a/javatests/google/registry/reporting/spec11/PublishSpec11ReportActionTest.java b/javatests/google/registry/reporting/spec11/PublishSpec11ReportActionTest.java index 4a86093c2..b2a7ba5ad 100644 --- a/javatests/google/registry/reporting/spec11/PublishSpec11ReportActionTest.java +++ b/javatests/google/registry/reporting/spec11/PublishSpec11ReportActionTest.java @@ -32,7 +32,7 @@ import com.google.api.services.dataflow.model.Job; import com.google.common.net.MediaType; import google.registry.testing.FakeResponse; import java.io.IOException; -import java.time.LocalDate; +import org.joda.time.LocalDate; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -67,7 +67,7 @@ public class PublishSpec11ReportActionTest { response = new FakeResponse(); publishAction = new PublishSpec11ReportAction( - "test-project", "12345", emailUtils, dataflow, response, LocalDate.of(2018, 6, 5)); + "test-project", "12345", emailUtils, dataflow, response, new LocalDate(2018, 6, 5)); } @Test @@ -75,7 +75,7 @@ public class PublishSpec11ReportActionTest { expectedJob.setCurrentState("JOB_STATE_DONE"); publishAction = new PublishSpec11ReportAction( - "test-project", "12345", emailUtils, dataflow, response, LocalDate.of(2018, 6, 2)); + "test-project", "12345", emailUtils, dataflow, response, new LocalDate(2018, 6, 2)); publishAction.run(); assertThat(response.getStatus()).isEqualTo(SC_OK); verify(emailUtils).emailSpec11Reports(); diff --git a/javatests/google/registry/reporting/spec11/Spec11RegistrarThreatMatchesParserTest.java b/javatests/google/registry/reporting/spec11/Spec11RegistrarThreatMatchesParserTest.java index 6e2b8f506..3492492f1 100644 --- a/javatests/google/registry/reporting/spec11/Spec11RegistrarThreatMatchesParserTest.java +++ b/javatests/google/registry/reporting/spec11/Spec11RegistrarThreatMatchesParserTest.java @@ -26,8 +26,8 @@ import google.registry.gcs.GcsUtils; import google.registry.testing.TestDataHelper; import java.io.ByteArrayInputStream; import java.nio.charset.StandardCharsets; -import java.time.LocalDate; import java.util.List; +import org.joda.time.LocalDate; import org.json.JSONException; import org.json.JSONObject; import org.junit.Before; @@ -41,7 +41,7 @@ public class Spec11RegistrarThreatMatchesParserTest { private final GcsUtils gcsUtils = mock(GcsUtils.class); private final Spec11RegistrarThreatMatchesParser parser = - new Spec11RegistrarThreatMatchesParser(LocalDate.of(2018, 7, 21), gcsUtils, "test-bucket"); + new Spec11RegistrarThreatMatchesParser(new LocalDate(2018, 7, 21), gcsUtils, "test-bucket"); @Before public void setUp() {