mirror of
https://github.com/google/nomulus.git
synced 2025-06-12 07:24:44 +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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue