Skip to content

Commit

Permalink
Change arg to harvestMonths
Browse files Browse the repository at this point in the history
  • Loading branch information
rpoet-jh committed Mar 14, 2024
1 parent 9e2623e commit 90cff9c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class NihmsHarvester {

private static final Logger LOG = LoggerFactory.getLogger(NihmsHarvester.class);

static final int DEFAULT_HARVEST_DAYS = -1;
static final int DEFAULT_HARVEST_MONTHS = -1;

private final UrlBuilder urlBuilder;
private final NihmsHarvesterDownloader nihmsHarvesterDownloader;
Expand All @@ -55,19 +55,19 @@ public NihmsHarvester(UrlBuilder urlBuilder,
* Retrieve files from NIHMS based on status list and startDate provided
*
* @param statusesToDownload list of {@code NihmsStatus} types to download from the NIHMS website
* @param harvestPeriodDays number of days of data to query
* @param harvestPeriodMonths number of months of data to query
*/
public void harvest(Set<NihmsStatus> statusesToDownload, int harvestPeriodDays) {
public void harvest(Set<NihmsStatus> statusesToDownload, int harvestPeriodMonths) {
if (CollectionUtils.isEmpty(statusesToDownload)) {
throw new RuntimeException("statusesToDownload list cannot be empty");
}

try {
Map<String, String> params = new HashMap<>();

if (harvestPeriodDays != DEFAULT_HARVEST_DAYS) {
if (harvestPeriodMonths != DEFAULT_HARVEST_MONTHS) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/uuuu");
String startDate = LocalDate.now().minus(Period.ofDays(harvestPeriodDays)).format(formatter);
String startDate = LocalDate.now().minus(Period.ofMonths(harvestPeriodMonths)).format(formatter);
LOG.info("Filtering with Start Date " + startDate);
params.put("pdf", startDate);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ public class NihmsHarvesterCLIRunner implements CommandLineRunner {
private boolean inProcess = false;

/**
* The number of days of data to nihms harvest.
* The number of months of data to nihms harvest.
*/
@Option(name = "-d", aliases = {"-harvestDays", "--harvestDays"},
usage = "Period of time by days to query against NIHMS data. For example, to query for the past 90 days " +
"of nihms data, the argument would be -harvestPeriod=90. This value will override the NIHMS system " +
"default which is one year before the current month.")
private int harvestDays = NihmsHarvester.DEFAULT_HARVEST_DAYS;
@Option(name = "-d", aliases = {"-harvestMonths", "--harvestMonths"},
usage = "Period of time by month to query against NIHMS data. For example, to query for the past 3 " +
"months of nihms data, the argument would be -harvestMonths=3. This value will override the NIHMS " +
"system default which is one year before the current month.")
private int harvestMonths = NihmsHarvester.DEFAULT_HARVEST_MONTHS;

private final NihmsHarvester nihmsHarvester;

Expand All @@ -96,7 +96,7 @@ public void run(String... args) {
}

Set<NihmsStatus> statusesToProcess = new HashSet<>();
int harvestPeriodDays = this.harvestDays;
int harvestPeriodMonths = this.harvestMonths;

//select statuses to process
if (this.compliant) {
Expand All @@ -113,7 +113,7 @@ public void run(String... args) {
}

/* Run the package generation application proper */
nihmsHarvester.harvest(statusesToProcess, harvestPeriodDays);
nihmsHarvester.harvest(statusesToProcess, harvestPeriodMonths);

} catch (CmdLineException e) {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@
/**
* @author Russ Poetker ([email protected])
*/
@SpringBootTest(classes = NihmsHarvesterCLI.class, args = {"--harvestDays=30"})
@SpringBootTest(classes = NihmsHarvesterCLI.class, args = {"--harvestMonths=3"})
@TestPropertySource(
locations = "classpath:test-application.properties",
properties = {
"nihmsetl.api.url.param.pdf=",
"nihmsetl.api.url.param.pdt="
})
public class NihmsHarvesterCLIHarvestDaysTest {
public class NihmsHarvesterCLIHarvestMonthsTest {

@SpyBean NihmsHarvester nihmsHarvester;
@MockBean NihmsHarvesterDownloader nihmsHarvesterDownloader;
Expand All @@ -55,7 +55,7 @@ public void testHarvesterCLI_WithHarvestRange() throws IOException, InterruptedE
// GIVEN/WHEN
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/uuuu");
// 30 days passed in args up top in @SpringBootTest
String expectedPdf = LocalDate.now().minus(Period.ofDays(30)).format(formatter)
String expectedPdf = LocalDate.now().minus(Period.ofMonths(3)).format(formatter)
.replace("/", "%2F");
// THEN
verify(nihmsHarvester).harvest(eq(EnumSet.allOf(NihmsStatus.class)), anyInt());
Expand Down

0 comments on commit 90cff9c

Please sign in to comment.