mirror of
https://github.com/google/nomulus.git
synced 2025-05-13 07:57:13 +02:00
Switch all added usages of java.time to be joda.time
This is for consistency, mostly the LocalDate fields added in [] ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=224525451
This commit is contained in:
parent
68320ebad8
commit
305b1edc85
10 changed files with 30 additions and 40 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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<YearMonth> provideYearMonthOptional(HttpServletRequest req) {
|
||||
DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM");
|
||||
Optional<String> 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<YearMonth> 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<LocalDate> provideDateOptional(HttpServletRequest req) {
|
||||
java.time.format.DateTimeFormatter formatter =
|
||||
java.time.format.DateTimeFormatter.ISO_LOCAL_DATE;
|
||||
Optional<String> 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<LocalDate> 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. */
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue