Skip to content

Commit

Permalink
Merge branch 'next' into dependabot/gradle/next/org.json-json-20240303
Browse files Browse the repository at this point in the history
  • Loading branch information
vesavlad authored May 19, 2024
2 parents 26825d7 + 1a6fb8c commit d919059
Show file tree
Hide file tree
Showing 13 changed files with 128 additions and 61 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/close-stale-pr-and-issues.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: 'Close stale issues'

on:
schedule:
- cron: '30 7 * * *'
workflow_dispatch:

permissions:
issues: write

jobs:
stale:
if: github.repository_owner == 'transittrack'
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
id: stale
with:
stale-issue-message: 'This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 30 days'
days-before-stale: 90
days-before-close: 30
operations-per-run: 260
exempt-issue-labels: 'Roadmap'
ascending: true
39 changes: 26 additions & 13 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@ name: Java CI with Gradle

on:
push:
branches: [ "main", "v3" ]
branches: [ "main", "next" ]
pull_request:
branches: [ "main" ]
branches: [ "main", "next" ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
name: Checkout

- name: Set up JDK 17
uses: actions/setup-java@v3
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '17'
java-version: '21'
distribution: 'temurin'
cache: gradle

Expand All @@ -37,33 +37,46 @@ jobs:
run: gradle clean build

container-image:
if: github.repository_owner == 'opentransportro' && github.event_name == 'push' && (github.ref == 'refs/heads/v3')
if: github.repository_owner == 'transittrack' && github.event_name == 'push'
runs-on: ubuntu-latest
needs:
- build
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up JDK 17
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: 17
java-version: 21
distribution: temurin
cache: gradle

- name: Docker setup-buildx
uses: docker/setup-buildx-action@v3
with:
install: true

- name: Docker Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}


- name: Setup Gradle
uses: gradle/gradle-build-action@v3

- name: Build container image with Jib, push to Dockerhub
env:
CONTAINER_REPO: docker.io/otrro/transitclock-server-v3
CONTAINER_REGISTRY_USER: ${{secrets.DOCKER_USER}}
CONTAINER_REGISTRY_PASSWORD: ${{ secrets.DOCKER_AUTH }}
CONTAINER_REPO: "ghcr.io/transittrack/transittrack"
CONTAINER_REGISTRY_USER: ${{ github.repository_owner }}
CONTAINER_REGISTRY_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
run: |
# we give the container two tags
# - "latest"
# - a string like "2.3_2022-12-12T21-38"
# - a string like "3.0_2022-12-12T21-38"
version_with_snapshot=`gradle properties -q | awk '/^version:/ {print $2}'`
version=${version_with_snapshot/-SNAPSHOT/}
Expand Down
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 @@ -217,11 +217,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);
6 changes: 3 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ subprojects {
mavenBom("org.springframework.boot:spring-boot-dependencies:${springVersion}")
}
dependencies{
dependency("org.apache.commons:commons-csv:1.10.0")
dependency("io.hypersistence:hypersistence-utils-hibernate-62:3.7.1")
dependency("com.google.guava:guava:33.0.0-jre")
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
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
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pluginManagement {
kotlin("plugin.allopen") version kotlinVersion

id("org.springframework.boot") version springVersion
id("io.spring.dependency-management") version "1.1.4"
id("io.spring.dependency-management") version "1.1.5"

id("com.google.cloud.tools.jib") version jibPluginVersion
id("com.palantir.git-version") version "0.15.0"
Expand Down

0 comments on commit d919059

Please sign in to comment.