Fix reporting module parameters and yearMonth usage

This is a final refactor to address Nick's comments in [] where YearMonth really should be injected as a Joda type instead of a raw string, and the HTTP parameters should be separate from the default-provided dependencies.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=173539965
This commit is contained in:
larryruili 2017-10-26 08:17:08 -07:00 committed by jianglai
parent d22986a0a3
commit 4a9b8b918a
14 changed files with 109 additions and 87 deletions

View file

@ -20,13 +20,13 @@ import static google.registry.reporting.IcannReportingModule.ICANN_REPORTING_DAT
import com.google.common.collect.ImmutableMap;
import com.google.common.io.Resources;
import google.registry.config.RegistryConfig.Config;
import google.registry.request.Parameter;
import google.registry.util.ResourceUtils;
import google.registry.util.SqlTemplate;
import java.io.IOException;
import java.net.URL;
import javax.inject.Inject;
import org.joda.time.LocalDate;
import org.joda.time.YearMonth;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
@ -44,7 +44,9 @@ public final class ActivityReportingQueryBuilder implements QueryBuilder {
static final String ACTIVITY_REPORT_AGGREGATION = "activity_report_aggregation";
@Inject @Config("projectId") String projectId;
@Inject @Parameter(IcannReportingModule.PARAM_YEAR_MONTH) String yearMonth;
@Inject YearMonth yearMonth;
@Inject ActivityReportingQueryBuilder() {}
/** Returns the aggregate query which generates the activity report from the saved view. */
@ -60,11 +62,9 @@ public final class ActivityReportingQueryBuilder implements QueryBuilder {
/** Sets the month we're doing activity reporting for, and returns the view query map. */
@Override
public ImmutableMap<String, String> getViewQueryMap() throws IOException {
LocalDate reportDate =
DateTimeFormat.forPattern("yyyy-MM").parseLocalDate(yearMonth).withDayOfMonth(1);
LocalDate firstDayOfMonth = reportDate;
LocalDate firstDayOfMonth = yearMonth.toLocalDate(1);
// The pattern-matching is inclusive, so we subtract 1 day to only report that month's data.
LocalDate lastDayOfMonth = reportDate.plusMonths(1).minusDays(1);
LocalDate lastDayOfMonth = yearMonth.toLocalDate(1).plusMonths(1).minusDays(1);
return createQueryMap(firstDayOfMonth, lastDayOfMonth);
}
@ -135,9 +135,9 @@ public final class ActivityReportingQueryBuilder implements QueryBuilder {
}
/** Returns the table name of the query, suffixed with the yearMonth in _YYYYMM format. */
/** Returns the table name of the query, suffixed with the yearMonth in _yyyyMM format. */
private String getTableName(String queryName) {
return String.format("%s_%s", queryName, yearMonth.replace("-", ""));
return String.format("%s_%s", queryName, DateTimeFormat.forPattern("yyyyMM").print(yearMonth));
}
/** Returns {@link String} for file in {@code reporting/sql/} directory. */