Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add argument to TruncateNewCalendarStatements #240

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.onebusaway.gtfs_transformer.impl;

import org.onebusaway.csv_entities.schema.annotations.CsvField;
import org.onebusaway.gtfs.model.ServiceCalendar;
import org.onebusaway.gtfs.model.ServiceCalendarDate;
import org.onebusaway.gtfs.services.GtfsMutableRelationalDao;
Expand All @@ -35,6 +36,31 @@
public class TruncateNewCalendarStatements implements GtfsTransformStrategy {

private final Logger _log = LoggerFactory.getLogger(TruncateNewCalendarStatements.class);

/*
* add two arguments used in the truncated transformation strategy
* calendarField --> calendar_field (json config file)
* Calendar.YEAR = 1
* Calendar.MONTH = 2
* Calendar.DAY_OF_MONTH = 5
* Calendar.DAY_OF_YEAR = 6
* calendarAmount --> calendar_amount (json config file)
*/
@CsvField(optional = true)
private int calendarField = Calendar.MONTH;

@CsvField(optional = true)
private int calendarAmount = 1;


public void setCalendarField(int calendarField) {
this.calendarField = calendarField;
}

public void setCalendarAmount(int calendarAmount) {
this.calendarAmount = calendarAmount;
}

@Override
public String getName() {
return this.getClass().getSimpleName();
Expand All @@ -43,9 +69,8 @@ public String getName() {
@Override
public void run(TransformContext transformContext, GtfsMutableRelationalDao gtfsMutableRelationalDao) {
RemoveEntityLibrary removeEntityLibrary = new RemoveEntityLibrary();
// TODO make this an argument -- default to one month from now
Calendar c = Calendar.getInstance();
c.roll(Calendar.MONTH, 1);
c.add(calendarField, calendarAmount);
java.util.Date oneMonthFromNow = c.getTime();
Set<ServiceCalendar> serviceCalendarsToRemove = new HashSet<ServiceCalendar>();
for (ServiceCalendar calendar: gtfsMutableRelationalDao.getAllCalendars()) {
Expand Down