private void populateDefaultEditorValues(Connection connection, String tablePrefix, Table table) throws SQLException {
    """
	Populates editor-specific fields added during GTFS-to-snapshot operation with default values. This method also
	"normalizes" the stop sequences for stop times to zero-based, incremented integers. NOTE: stop time normalization
	can take a significant amount of time (for large feeds up to 5 minutes) if the update is large.
    """
        Statement statement = connection.createStatement();
        if (Table.ROUTES.name.equals(table.name)) {
            // Set default values for route status and publicly visible to "Approved" and "Public", respectively.
            // This prevents unexpected results when users attempt to export a GTFS feed from the editor and no
            // routes are exported due to undefined values for status and publicly visible.
            String updateStatusSql = String.format(
                    "update %sroutes set status = 2, publicly_visible = 1 where status is NULL AND publicly_visible is NULL",
                    tablePrefix);
            int updatedRoutes = statement.executeUpdate(updateStatusSql);
            LOG.info("Updated status for {} routes", updatedRoutes);
        }
        if (Table.CALENDAR.name.equals(table.name)) {
            // Set default values for description field. Basically constructs a description from the days of the week
            // for which the calendar is active.
            LOG.info("Updating calendar descriptions");
            String[] daysOfWeek = new String[]{"monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"};
            String concatenatedDaysOfWeek =  String.join(", ",
                    Arrays.stream(daysOfWeek)
                        .map(d -> String.format(
                                    "case %s when 1 then '%s' else '' end",
                                    d,
                                // Capitalize first letter. Converts days of week from "monday" -> "Mo".
                                d.substring(0, 1).toUpperCase() + d.substring(1, 2))).toArray(String[]::new));
            String updateOtherSql = String.format(
                    "update %scalendar set description = concat(%s) where description is NULL",
                    tablePrefix,
                    concatenatedDaysOfWeek);
            LOG.info(updateOtherSql);
            int calendarsUpdated = statement.executeUpdate(updateOtherSql);
            LOG.info("Updated description for {} calendars", calendarsUpdated);
        }
        if (Table.TRIPS.name.equals(table.name)) {
            // Update use_frequency field for patterns. This sets all patterns that have a frequency trip to use
            // frequencies. NOTE: This is performed after copying the TRIPS table rather than after PATTERNS because
            // both tables (plus, frequencies) need to exist for the successful operation.
            // TODO: How should this handle patterns that have both timetable- and frequency-based trips?
            // NOTE: The below substitution uses argument indexing. All values "%1$s" reference the first argument
            // supplied (i.e., tablePrefix).
            String updatePatternsSql = String.format(
                    "update %1$spatterns set use_frequency = 1 " +
                    "from (select distinct %1$strips.pattern_id from %1$strips, %1$sfrequencies where %1$sfrequencies.trip_id = %1$strips.trip_id) freq " +
                    "where freq.pattern_id = %1$spatterns.pattern_id",
                    tablePrefix);
            LOG.info(updatePatternsSql);
            int patternsUpdated = statement.executeUpdate(updatePatternsSql);
            LOG.info("Updated use_frequency for {} patterns", patternsUpdated);
        }
        // TODO: Add simple conversion from calendar_dates to schedule_exceptions if no exceptions exist? See
        // https://github.com/catalogueglobal/datatools-server/issues/80
    }
private void populateDefaultEditorValues(Connection connection, String tablePrefix, Table table) throws SQLException {
        Statement statement = connection.createStatement();
        if (Table.ROUTES.name.equals(table.name)) {
            // Set default values for route status and publicly visible to "Approved" and "Public", respectively.
            // This prevents unexpected results when users attempt to export a GTFS feed from the editor and no
            // routes are exported due to undefined values for status and publicly visible.
            String updateStatusSql = String.format(
                    "update %sroutes set status = 2, publicly_visible = 1 where status is NULL AND publicly_visible is NULL",
                    tablePrefix);
            int updatedRoutes = statement.executeUpdate(updateStatusSql);
            LOG.info("Updated status for {} routes", updatedRoutes);
        }
        if (Table.CALENDAR.name.equals(table.name)) {
            // Set default values for description field. Basically constructs a description from the days of the week
            // for which the calendar is active.
            LOG.info("Updating calendar descriptions");
            String[] daysOfWeek = new String[]{"monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"};
            String concatenatedDaysOfWeek =  String.join(", ",
                    Arrays.stream(daysOfWeek)
                        .map(d -> String.format(
                                    "case %s when 1 then '%s' else '' end",
                                    d,
                                // Capitalize first letter. Converts days of week from "monday" -> "Mo".
                                d.substring(0, 1).toUpperCase() + d.substring(1, 2))).toArray(String[]::new));
            String updateOtherSql = String.format(
                    "update %scalendar set description = concat(%s) where description is NULL",
                    tablePrefix,
                    concatenatedDaysOfWeek);
            LOG.info(updateOtherSql);
            int calendarsUpdated = statement.executeUpdate(updateOtherSql);
            LOG.info("Updated description for {} calendars", calendarsUpdated);
        }
        if (Table.TRIPS.name.equals(table.name)) {
            // Update use_frequency field for patterns. This sets all patterns that have a frequency trip to use
            // frequencies. NOTE: This is performed after copying the TRIPS table rather than after PATTERNS because
            // both tables (plus, frequencies) need to exist for the successful operation.
            // TODO: How should this handle patterns that have both timetable- and frequency-based trips?
            // NOTE: The below substitution uses argument indexing. All values "%1$s" reference the first argument
            // supplied (i.e., tablePrefix).
            String updatePatternsSql = String.format(
                    "update %1$spatterns set use_frequency = 1 " +
                    "from (select distinct %1$strips.pattern_id from %1$strips, %1$sfrequencies where %1$sfrequencies.trip_id = %1$strips.trip_id) freq " +
                    "where freq.pattern_id = %1$spatterns.pattern_id",
                    tablePrefix);
            LOG.info(updatePatternsSql);
            int patternsUpdated = statement.executeUpdate(updatePatternsSql);
            LOG.info("Updated use_frequency for {} patterns", patternsUpdated);
        }
        // TODO: Add simple conversion from calendar_dates to schedule_exceptions if no exceptions exist? See
        // https://github.com/catalogueglobal/datatools-server/issues/80
    }
private void populateDefaultEditorValues ( Connection connection , String tablePrefix , Table table ) throws SQLException { Statement statement = connection . createStatement ( ) ; if ( Table . ROUTES . name . equals ( table . name ) ) { // Set default values for route status and publicly visible to "Approved" and "Public", respectively. // This prevents unexpected results when users attempt to export a GTFS feed from the editor and no // routes are exported due to undefined values for status and publicly visible. String updateStatusSql = String . format ( "update %sroutes set status = 2, publicly_visible = 1 where status is NULL AND publicly_visible is NULL" , tablePrefix ) ; int updatedRoutes = statement . executeUpdate ( updateStatusSql ) ; LOG . info ( "Updated status for {} routes" , updatedRoutes ) ; } if ( Table . CALENDAR . name . equals ( table . name ) ) { // Set default values for description field. Basically constructs a description from the days of the week // for which the calendar is active. LOG . info ( "Updating calendar descriptions" ) ; String [ ] daysOfWeek = new String [ ] { "monday" , "tuesday" , "wednesday" , "thursday" , "friday" , "saturday" , "sunday" } ; String concatenatedDaysOfWeek = String . join ( ", " , Arrays . stream ( daysOfWeek ) . map ( d -> String . format ( "case %s when 1 then '%s' else '' end" , d , // Capitalize first letter. Converts days of week from "monday" -> "Mo". d . substring ( 0 , 1 ) . toUpperCase ( ) + d . substring ( 1 , 2 ) ) ) . toArray ( String [ ] :: new ) ) ; String updateOtherSql = String . format ( "update %scalendar set description = concat(%s) where description is NULL" , tablePrefix , concatenatedDaysOfWeek ) ; LOG . info ( updateOtherSql ) ; int calendarsUpdated = statement . executeUpdate ( updateOtherSql ) ; LOG . info ( "Updated description for {} calendars" , calendarsUpdated ) ; } if ( Table . TRIPS . name . equals ( table . name ) ) { // Update use_frequency field for patterns. This sets all patterns that have a frequency trip to use // frequencies. NOTE: This is performed after copying the TRIPS table rather than after PATTERNS because // both tables (plus, frequencies) need to exist for the successful operation. // TODO: How should this handle patterns that have both timetable- and frequency-based trips? // NOTE: The below substitution uses argument indexing. All values "%1$s" reference the first argument // supplied (i.e., tablePrefix). String updatePatternsSql = String . format ( "update %1$spatterns set use_frequency = 1 " + "from (select distinct %1$strips.pattern_id from %1$strips, %1$sfrequencies where %1$sfrequencies.trip_id = %1$strips.trip_id) freq " + "where freq.pattern_id = %1$spatterns.pattern_id" , tablePrefix ) ; LOG . info ( updatePatternsSql ) ; int patternsUpdated = statement . executeUpdate ( updatePatternsSql ) ; LOG . info ( "Updated use_frequency for {} patterns" , patternsUpdated ) ; } // TODO: Add simple conversion from calendar_dates to schedule_exceptions if no exceptions exist? See // https://github.com/catalogueglobal/datatools-server/issues/80 }
Populates editor-specific fields added during GTFS-to-snapshot operation with default values. This method also
"normalizes" the stop sequences for stop times to zero-based, incremented integers. NOTE: stop time normalization
can take a significant amount of time (for large feeds up to 5 minutes) if the update is large.
Populates editor - specific fields added during GTFS - to - snapshot operation with default values . This method also normalizes the stop sequences for stop times to zero - based incremented integers . NOTE : stop time normalization can take a significant amount of time ( for large feeds up to 5 minutes ) if the update is large .