OneBusAway / onebusaway-gtfs-modules

A Java-based library for reading, writing, and transforming public transit data in the GTFS format, including database support.
Other
129 stars 106 forks source link

GtfsWriter not ignoring FareAttribute's optional columns #72

Open russellhoff opened 8 years ago

russellhoff commented 8 years ago

I've been able to ignore extra columns for Agency, for instance, as follows:

` private Agency agency;

// ...

List<Object> agenciesObjects = new ArrayList<Object>();

agenciesObjects.add(agency);

writer.excludeOptionalAndMissingFields(Agency.class, agenciesObjects);

writer.handleEntity(agency);

`

But, when it comes to ignore optional columns for FareAttributes, there are two columns which aren't ignored when generating TXTs. This is the piece of code regarding Fares:

` private List fares; // ...
// Fares logHelper.logMessage("\t[11.5] Construyendo fare_attributes.txt y fare_rules.txt...");

    List<Object> faresObjects = new ArrayList<Object>();
    List<Object> faresAttributesObjects = new ArrayList<Object>();
    for(FareRule fr : fares){
        faresObjects.add(fr);
        faresAttributesObjects.add(fr.getFare());
    }
    writer.excludeOptionalAndMissingFields(FareAttribute.class, faresAttributesObjects);
    writer.excludeOptionalAndMissingFields(FareRule.class, faresObjects);

    fares.forEach((fare)->{
        writer.handleEntity(fare.getFare());
        writer.handleEntity(fare);
    });
    `

Is that a bug or not?

russellhoff commented 8 years ago

Anybody?

russellhoff commented 6 years ago

Still undergoing that issue.

russellhoff commented 6 years ago

New attribute eligibilityRestricted is not being ignored.

sheldonabrown commented 6 years ago

Hi Russell,

can you attach a sample GTFS that demonstrates the issue, and tell us a bit more about your use case? Are you using the GTFS Transformer CLI?

And sorry for the delay in responding ...

Sheldon

russellhoff commented 6 years ago

Hi @sheldonabrown,

No worries, I understand the delay. In the latest version of onebusaway-gtfs-modules, 1.3.48, attribute eligibilityRestricted isn't only being ignored, but I never set it to any value.

For instance, when it comes to the creation of Routes, I create them that way:

public class GtfsDataBuilderWS extends GTFSDataBuilder {
    // ...
    private List<Route> routes;
    // ...
@Override
    public void buildAll(String pCodigoOperador) throws Throwable {
        // ...
        routesBuilder();
        // ...
        buildFile();
    }
    // ...
    @Override
    protected void routesBuilder() throws Exception {
        logHelper.logMessage("\t[4] Construyendo Route...");

        LineasDTO lineas = imp.importarLineas(codigoOperador);
        routes = new ArrayList<Route>();
        shapes = new HashMap<String, ShapePointArray>();

        Route aRoute = null;
        AgencyAndId theId = null;
        for(LineaDTO linea : lineas.getListaLineas()){
            aRoute = new Route();
            theId = new AgencyAndId(codigoOperador, linea.getCodigoLinea());
            aRoute.setAgency(agency);
            aRoute.setId(theId);
            aRoute.setShortName(linea.getDescripcionCorta());
            aRoute.setLongName(linea.getDescripcionLarga());
            aRoute.setType(3); 
            tripsBuilder(linea.getCodigoLinea(), aRoute);
            aRoute = maestrosSobrescribir.sobrescribirRoute(codigoOperador, aRoute);
            routes.add(aRoute);
        }

        logHelper.logMessage("\t[4] Route construido.");
    }

    private void buildFile() throws SecurityException, IOException {
        GtfsWriter writer = new GtfsWriter();
        PropertiesConfiguration config = GenerarGtfs.getPropConfig();
        String path = config.getRoot_export_dir() + File.separator + config.getFolder(codigoOperador);
        File outputDir = new File(path);
        if(outputDir.exists()){
            if(outputDir.isDirectory()){
                FileUtils.deleteDirectory(outputDir);
            }
        }else{
            outputDir.mkdirs();
        }
        writer.setOutputLocation(outputDir);
        // ...
        // Routes
        List<Object> routesObjects = new ArrayList<Object>();
        routesObjects.addAll(routes);
        writer.excludeOptionalAndMissingFields(Route.class, routesObjects);
        routes.forEach((route)->{
            writer.handleEntity(route);
        });
        // ...
        writer.close();

        // Comprimimos
        ZipHelper.compressAgencyGtfsFiles(codigoOperador);
    }

Finally, the routes.txt file contains rows with the column eligibilityRestricted valued -999.

russellhoff commented 6 years ago

Anything on this issue?