Compare commits

...

11 Commits

  1. 30
      Jenkinsfile
  2. 1
      src/main/java/org/leolo/nrapi/util/MiscUtilAPI.java
  3. 4
      src/main/java/org/leolo/nrapi/v0/api/ScheduleSearchAPI.java
  4. 36
      src/main/java/org/leolo/nrapi/v0/api/ScheduleSearchQueryBuilder.java
  5. 27
      src/main/resources/static/docs/schedule_search.html

30
Jenkinsfile vendored

@ -0,0 +1,30 @@
pipeline{
agent any
tools{
maven '3.8.6'
jdk 'JDK 18'
}
stages {
stage ('Initialize') {
steps {
sh '''
echo "PATH = ${PATH}"
echo "M2_HOME = ${M2_HOME}"
'''
}
}
stage('Build'){
steps{
sh 'mvn -Dmaven.test.failure.ignore=true install test'
}
post{
success{
junit 'target/surefire-reports/**/*.xml'
archiveArtifacts artifacts: 'target/*.jar, *.pom', fingerprint: true, followSymlinks: false, onlyIfSuccessful: true
}
}
}
}
}

1
src/main/java/org/leolo/nrapi/util/MiscUtilAPI.java

@ -153,6 +153,7 @@ public class MiscUtilAPI {
}
}
sb.append("}");
sb.append(",\"api-version\":\"0.1\"");
sb.append("}");
String result = "";
try(

4
src/main/java/org/leolo/nrapi/v0/api/ScheduleSearchAPI.java

@ -66,10 +66,10 @@ public class ScheduleSearchAPI {
queryBuilder.setPlatforms(platform.split(","));
}
if(previous!=null&&previous.length()>0){
queryBuilder.setPrevLocation(previous);
queryBuilder.setPrevLocation(previous.split(","));
}
if(next!=null&&next.length()>0){
queryBuilder.setNextLocation(next);
queryBuilder.setNextLocation(next.split(","));
}
list.addAll(queryBuilder.setTableGroup(TableGroup.LONG_TERM_PLANNING).execute());
list.addAll(queryBuilder.setTableGroup(TableGroup.SHORT_TERM_PLANNING).execute());

36
src/main/java/org/leolo/nrapi/v0/api/ScheduleSearchQueryBuilder.java

@ -32,8 +32,8 @@ class ScheduleSearchQueryBuilder {
private boolean strictMode = false;
private String[] platforms;
private boolean stopOnly = false;
private String prevLocation;
private String nextLocation;
private String[] prevLocation;
private String[] nextLocation;
public ScheduleSearchQueryBuilder setTableGroup(TableGroup tableGroup) {
this.tableGroup = tableGroup;
@ -76,12 +76,12 @@ class ScheduleSearchQueryBuilder {
return this;
}
public ScheduleSearchQueryBuilder setPrevLocation(String prevLocation) {
public ScheduleSearchQueryBuilder setPrevLocation(String... prevLocation) {
this.prevLocation = prevLocation;
return this;
}
public ScheduleSearchQueryBuilder setNextLocation(String nextLocation) {
public ScheduleSearchQueryBuilder setNextLocation(String... nextLocation) {
this.nextLocation = nextLocation;
return this;
}
@ -98,10 +98,10 @@ class ScheduleSearchQueryBuilder {
sql.append("origin_time, get_tiploc_name(destination), destination_time, mt.signal_id, mt.atoc_code ");
sql.append(" from ").append(tableGroup.getMainTable()).append(" mt ")
.append(" JOIN ").append(tableGroup.getDetailTable()).append(" dt ON mt.suid=dt.suid ");
if(prevLocation!=null&&prevLocation.length()!=0){
if(prevLocation!=null){
sql.append(" JOIN ").append(tableGroup.getDetailTable()).append(" pt ON mt.suid=pt.suid AND dt.seq > pt.seq");
}
if(nextLocation!=null&&nextLocation.length()!=0){
if(nextLocation!=null){
sql.append(" JOIN ").append(tableGroup.getDetailTable()).append(" nt ON mt.suid=nt.suid AND dt.seq < nt.seq");
}
sql.append(" where dt.tiploc_code IN (");
@ -136,15 +136,23 @@ class ScheduleSearchQueryBuilder {
}
sql.append(")");
}
if(prevLocation!=null&&prevLocation.length()!=0){
sql.append(" AND pt.tiploc_code IN (");
appendLocationSearch(sql, params, prevLocation);
sql.append(") ");
if(prevLocation!=null){
sql.append(" AND ( 1=0 ");
for(String prev:prevLocation){
sql.append(" OR pt.tiploc_code IN (");
appendLocationSearch(sql, params, prev);
sql.append(")");
}
sql.append(")");
}
if(nextLocation!=null&&nextLocation.length()!=0){
sql.append(" AND nt.tiploc_code IN (");
appendLocationSearch(sql, params, nextLocation);
sql.append(") ");
if(nextLocation!=null){
sql.append(" AND ( 1=0 ");
for(String next:nextLocation){
sql.append(" OR nt.tiploc_code IN (");
appendLocationSearch(sql, params, next);
sql.append(")");
}
sql.append(")");
}
log.info(sql.toString());

27
src/main/resources/static/docs/schedule_search.html

@ -9,7 +9,13 @@
<body>
<h1>Search train schedule by location</h1>
<h2>Syntax</h2>
<div class="syntax">/search/{location}[/{date}[/{time}]]?[range={range}][&amp;strict={strict}][&amp;stopOnly={stopOnly}]</div>
<div class="syntax">/search/{location}[/{date}[/{time}]]?
[range={range}]
[&amp;strict={strict}]
[&amp;stopOnly={stopOnly}]
[&amp;previous={previous}]
[&amp;next={next}]
</div>
<h3>Parameters</h3>
<table class="param">
<tr>
@ -64,6 +70,25 @@
<span style="font-weight: bold">Optional.</span>
Show only stopping trains. Valid valued are <code>true</code> or <code>false</code>. Default value is
<code>false</code>.
This value will also affect the <code>previous</code> and <code>next</code> settings.
</td>
</tr>
<tr>
<th>previous</th>
<td>
<span style="font-weight: bold">Optional.</span>
Only show the train previously calls, or passing though the specified locations. The location is provided
in a comma separated list.
</td>
</tr>
<tr>
<th>previous</th>
<td>
<span style="font-weight: bold">Optional.</span>
Only show the train will also call, or passing though the specified locations. The location is provided
in a comma separated list.
</td>
</tr>
</table>

Loading…
Cancel
Save