Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/next' into goeuropa/features/sto…
Browse files Browse the repository at this point in the history
…p_reports_adh
  • Loading branch information
TsimurSh committed May 20, 2024
2 parents bd51058 + 6a5b8ec commit b7132bc
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ ResponseEntity<String> getTripsWithTravelTimes(
ResponseEntity<String> getAvlReport(
StandardParameters stdParameters,
@Parameter(description = "Vehicle id") @RequestParam(value = "v") String vehicleId,
@Parameter(description = "Begin date(MM-DD-YYYY.") @RequestParam(value = "beginDate") String beginDate,
@Parameter(description = "Num days.", required = false) @RequestParam(value = "numDays", required = false) int numDays,
@Parameter(description = "Begin date(MM-DD-YYYY or YYYY-MM-DD") @RequestParam(value = "beginDate") String beginDate,
@Parameter(description = "Num days.") @RequestParam(value = "numDays", defaultValue = "1", required = false) int numDays,
@Parameter(description = "Begin time(HH:MM)") @RequestParam(value = "beginTime", required = false) String beginTime,
@Parameter(description = "End time(HH:MM)") @RequestParam(value = "endTime", required = false) String endTime);

Expand Down Expand Up @@ -104,8 +104,8 @@ ResponseEntity<String> getTrips(
ResponseEntity<String> scheduleAdhReport(
StandardParameters stdParameters,
@Parameter(description = "Route id") @RequestParam(value = "r") String routeId,
@Parameter(description = "Begin date(MM-DD-YYYY.") @RequestParam(value = "beginDate") String beginDate,
@Parameter(description = "Num days.", required = false) @RequestParam(value = "numDays", required = false) int numDays,
@Parameter(description = "Begin date(MM-DD-YYYY or YYYY-MM-DD") @RequestParam(value = "beginDate") String beginDate,
@Parameter(description = "Num days.") @RequestParam(value = "numDays", defaultValue = "1", required = false) int numDays,
@Parameter(description = "Begin time(HH:MM)") @RequestParam(value = "beginTime") String beginTime,
@Parameter(description = "End time(HH:MM)") @RequestParam(value = "endTime") String endTime,
@Parameter(description = "Allowable early in mins(default 1.0)")
Expand Down
20 changes: 20 additions & 0 deletions app/src/main/java/org/transitclock/config/WebConfiguration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.transitclock.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@EnableWebMvc
public class WebConfiguration implements WebMvcConfigurer {

@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/api/**")
.allowedOriginPatterns("http://**", "https://**")
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
.allowedHeaders("*")
.allowCredentials(true);
}
}
20 changes: 11 additions & 9 deletions app/src/main/java/org/transitclock/core/reports/Reports.java
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,8 @@ public static String getScheduleAdhByStops(
// + " abs(((ad.time / 1000) - (ad.scheduled_time / 1000))) AS
// difference_in_seconds, \n"
+ " s.id AS stop_id, \n"
+ " ad.stop_order AS stop_order \n"
+ " ad.stop_order AS stop_order, \n"
+ " ad.vehicle_id AS v_id \n"
+ " FROM arrivals_departures ad, stops s \n"
+ "WHERE "
// To get stop name
Expand All @@ -276,7 +277,8 @@ public static String getScheduleAdhByStops(
// + " ((ad.time / 1000) - (ad.scheduled_time / 1000)) AS
// difference_in_seconds, \n"
+ " s.id AS stop_id, \n"
+ " ad.stop_order AS stop_order \n"
+ " ad.stop_order AS stop_order, \n"
+ " ad.vehicle_id AS v_id \n"
+ " FROM arrivals_departures ad, Stops s \n"
+ "WHERE "
// To get stop name
Expand All @@ -294,18 +296,18 @@ public static String getScheduleAdhByStops(
+ " \n"
+ " ORDER BY direction_id, ad.stop_order, s.name \n"
+ "), \n"
+ "trips_late_query_v2 AS ( SELECT"
+ " array_to_string(array_agg(trips_late::text || ' (' ||"
+ " difference_in_seconds::text || ')' order by trips_late::text), '; ') AS"
+ " trips_late, \n"
+ "trips_late_query_v2 AS ( SELECT \n"
+ " array_to_string(array_agg('trip: ' || trips_late::text || ' (' ||"
+ " difference_in_seconds::text || '), vehicle: ' || v_id::text order by trips_late::text), '; ')"
+ " AS trips_late, \n"
+ " stop_id, \n"
+ " stop_order \n"
+ " FROM trips_late_query_with_time \n"
+ " GROUP BY stop_id, stop_order \n"
+ " ), \n"
+ " trips_early_query_v2 AS ( \n"
+ " SELECT array_to_string(array_agg(trips_early::text || ' (' ||"
+ " difference_in_seconds::text || ')' order by trips_early::text), '; ')"
+ " trips_early_query_v2 AS ( SELECT \n"
+ " array_to_string(array_agg('trip: ' || trips_early::text || ' (' ||"
+ " difference_in_seconds::text || '), vehicle: ' || v_id::text order by trips_early::text), '; ')"
+ " AS trips_early, \n"
+ " stop_id, \n"
+ " stop_order \n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,17 @@ public static String timeRangeClause(

SimpleDateFormat currentFormat = new SimpleDateFormat("MM-dd-yyyy");
SimpleDateFormat requiredFormat = new SimpleDateFormat("yyyy-MM-dd");

try {
beginDate = requiredFormat.format(currentFormat.parse(beginDate));
if (beginDate.charAt(4) != '-') { // for two patterns MM-dd-yyyy & yyyy-MM-dd
beginDate = requiredFormat.format(currentFormat.parse(beginDate));
} else {
requiredFormat.parse(beginDate);
}
} catch (ParseException e) {
logger.error("Exception happened while processing time-range clause", e);
}

return " AND %s BETWEEN '%s' AND TIMESTAMP '%s' + INTERVAL '%d day' %s "
.formatted(timeColumnName, beginDate, beginDate, numDays, timeSql);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE export_table RENAME COLUMN first_name TO file_name;
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-- removing faulty constraints definitions
ALTER TABLE travel_times_for_trip_to_travel_times_for_path
DROP CONSTRAINT fk_tratimfortritotratimforpat_on_travel_times_for_stop_path;

ALTER TABLE travel_times_for_trip_to_travel_times_for_path
DROP CONSTRAINT fk_tratimfortritotratimforpat_on_travel_times_for_trip;

-- recreating new constraints
ALTER TABLE travel_times_for_trip_to_travel_times_for_path
ADD CONSTRAINT fk_tratimfortritotratimforpat_on_travel_times_for_stop_path FOREIGN KEY (for_path_id) REFERENCES travel_times_for_stop_paths (id);

ALTER TABLE travel_times_for_trip_to_travel_times_for_path
ADD CONSTRAINT fk_tratimfortritotratimforpat_on_travel_times_for_trip FOREIGN KEY (for_trip_id) REFERENCES travel_times_for_trips (id);
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ subprojects {
mavenBom("org.springframework.boot:spring-boot-dependencies:${springVersion}")
}
dependencies{
dependency("org.apache.commons:commons-csv:1.10.0")
dependency("org.apache.commons:commons-csv:1.11.0")
dependency("io.hypersistence:hypersistence-utils-hibernate-62:3.7.5")
dependency("com.google.guava:guava:33.2.0-jre")
}
Expand Down
2 changes: 1 addition & 1 deletion libs/core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ dependencies {

implementation("com.google.guava:guava")

api("org.json:json:20231013")
api("org.json:json:20240303")
implementation("org.jasypt:jasypt:1.9.3")

api(group = "org.ehcache", name = "ehcache", classifier = "jakarta") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class ExportTable implements Serializable {
@Column(name = "export_status")
private int exportStatus;

@Column(name = "first_name")
@Column(name = "file_name")
private String fileName;

@Column(name = "file")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@

import com.querydsl.jpa.impl.JPAQuery;
import jakarta.persistence.*;
import lombok.*;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.DynamicUpdate;
import org.transitclock.domain.structs.QTravelTimesForTrip;

import java.io.Serializable;
import java.util.*;
Expand All @@ -24,7 +23,7 @@
@Entity
@Slf4j
@DynamicUpdate
@Getter @Setter @ToString
@Data
@Table(
name = "travel_times_for_trips",
indexes = {
Expand Down Expand Up @@ -72,15 +71,13 @@ public class TravelTimesForTrip implements Serializable {
private final String tripCreatedForId;

@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(
name = "travel_times_for_trip_to_travel_times_for_path",
joinColumns = {
@JoinColumn(name = "for_path_id", referencedColumnName = "id")
},
inverseJoinColumns = {
@JoinColumn(name = "for_trip_id", referencedColumnName = "id")
}
)
@JoinTable(name = "travel_times_for_trip_to_travel_times_for_path",
joinColumns = {
@JoinColumn(name = "for_trip_id", referencedColumnName = "id")
},
inverseJoinColumns = {
@JoinColumn(name = "for_path_id", referencedColumnName = "id")
})
@Cascade({CascadeType.SAVE_UPDATE})
@OrderColumn(name = "list_index")
private final List<TravelTimesForStopPath> travelTimesForStopPaths = new ArrayList<>();
Expand Down Expand Up @@ -273,16 +270,4 @@ public TravelTimesForStopPath getTravelTimesForStopPath(int index) {
public int numberOfStopPaths() {
return travelTimesForStopPaths.size();
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof TravelTimesForTrip that)) return false;
return configRev == that.configRev && travelTimesRev == that.travelTimesRev && Objects.equals(id, that.id) && Objects.equals(tripPatternId, that.tripPatternId) && Objects.equals(tripCreatedForId, that.tripCreatedForId) && Objects.equals(travelTimesForStopPaths, that.travelTimesForStopPaths);
}

@Override
public int hashCode() {
return Objects.hash(id, configRev, travelTimesRev, tripPatternId, tripCreatedForId, travelTimesForStopPaths);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -528,9 +528,9 @@ public boolean isStopAtOrAfterStop(String stopId1, String stopId2) {
* @return
*/
public List<String> getStopIds() {
List<String> list = new ArrayList<String>(stopPaths.size());
for (StopPath stopPath : stopPaths) list.add(stopPath.getStopId());
return list;
return stopPaths.stream()
.map(StopPath::getStopId)
.collect(Collectors.toList());
}

/**
Expand All @@ -539,7 +539,9 @@ public List<String> getStopIds() {
* @return ID of last stop
*/
public String getLastStopIdForTrip() {
return stopPaths.get(stopPaths.size() - 1).getStopId();
return Optional.ofNullable(getStopPath(stopPaths.size() - 1))
.map(StopPath::getStopId)
.orElse(null);
}

/**
Expand All @@ -560,7 +562,8 @@ public double getLength() {
* @return The specified StopPath or null if index out of range
*/
public StopPath getStopPath(int index) {
if (index < 0 || index >= stopPaths.size()) return null;
if (index < 0 || index >= stopPaths.size())
return null;

return stopPaths.get(index);
}
Expand Down

0 comments on commit b7132bc

Please sign in to comment.