Browse Source

Importing SMART data

develop
LO Kam Tao Leo 3 years ago
parent
commit
7f6dc009ba
  1. 5
      src/main/java/org/leolo/nrdatad/App.java
  2. 21
      src/main/java/org/leolo/nrdatad/cron/ReferenceDataJob.java
  3. 24
      src/main/java/org/leolo/nrdatad/model/Smart.java

5
src/main/java/org/leolo/nrdatad/App.java

@ -127,6 +127,11 @@ public class App {
TriggerBuilder.newTrigger().withIdentity("T-OF-"+Constants.CronJob.REFERENCE_DATA).startAt(DateBuilder.evenSecondDateAfterNow()).build()
);
}
scheduler.scheduleJob(
JobBuilder.newJob(ReferenceDataJob.class).withIdentity("J-CW-"+Constants.CronJob.REFERENCE_DATA).build(),
TriggerBuilder.newTrigger().withIdentity("T-CW-"+Constants.CronJob.REFERENCE_DATA)
.withSchedule(CronScheduleBuilder.cronSchedule("* 10 1 ? * 1")).build()
);
} catch (SchedulerException e) {
log.atFatal().withThrowable(e).log("Unable to create cron jobs");
}

21
src/main/java/org/leolo/nrdatad/cron/ReferenceDataJob.java

@ -8,6 +8,7 @@ import org.leolo.nrdatad.ConfigurationManager;
import org.leolo.nrdatad.Constants;
import org.leolo.nrdatad.db.CorpusDao;
import org.leolo.nrdatad.model.Corpus;
import org.leolo.nrdatad.model.Smart;
import org.leolo.nrdatad.util.HttpUtil;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
@ -17,6 +18,7 @@ import java.io.IOException;
import java.net.URISyntaxException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
public class ReferenceDataJob implements Job {
@ -26,7 +28,7 @@ public class ReferenceDataJob implements Job {
public void execute(JobExecutionContext context) throws JobExecutionException {
log.atInfo().log("Load reference data triggered at {}", context.getFireTime());
//There are 3 different kind of reference data. Create 3 thread and deal with them
// new Thread(()->{processCORPUS();}).start();
new Thread(()->{processCORPUS();}).start();
new Thread(()->{processSMART();}).start();
}
@ -47,6 +49,23 @@ public class ReferenceDataJob implements Job {
JSONObject rootObj = new JSONObject(json);
JSONArray rootArray = rootObj.getJSONArray("BERTHDATA");
log.atInfo().log("{} entries found", rootArray.length());
Collection<Smart> smarts = new ArrayList<>();
for (int i = 0; i < rootArray.length(); i++) {
JSONObject obj = rootArray.getJSONObject(i);
Smart smart = Smart.parseJSON(obj);
if(!smart.checkEnums()){
log.atInfo().log("Improper SMART record: {}", obj);
continue;
}
smarts.add(smart);
}
try {
conf.getDatabaseManager().getSmartDao().truncateTable();
conf.getDatabaseManager().getSmartDao().addAll(smarts);
} catch (SQLException e) {
log.atError().withThrowable(e).log("Unable to insert records");
}
log.atInfo().log("Done inserting SMART");
}
private void processCORPUS(){

24
src/main/java/org/leolo/nrdatad/model/Smart.java

@ -154,5 +154,27 @@ public class Smart {
return smart;
}
public boolean checkEnums(){
return event!=null && stepType!=null;
}
@Override
public String toString() {
return "Smart{" +
"smartId=" + smartId +
", td='" + td + '\'' +
", fromBerth='" + fromBerth + '\'' +
", toBerth='" + toBerth + '\'' +
", fromLine='" + fromLine + '\'' +
", toLine='" + toLine + '\'' +
", berthOffset=" + berthOffset +
", platform='" + platform + '\'' +
", event=" + event +
", route='" + route + '\'' +
", stanox='" + stanox + '\'' +
", stationName='" + stationName + '\'' +
", stepType=" + stepType +
", comment='" + comment + '\'' +
'}';
}
}

Loading…
Cancel
Save