Fix update service in RemoteRecorder
Models now get their site assigned
This commit is contained in:
parent
e45b413a32
commit
1032c9f94a
|
@ -21,6 +21,7 @@ import ctbrec.Recording;
|
||||||
import ctbrec.io.HttpClient;
|
import ctbrec.io.HttpClient;
|
||||||
import ctbrec.io.InstantJsonAdapter;
|
import ctbrec.io.InstantJsonAdapter;
|
||||||
import ctbrec.io.ModelJsonAdapter;
|
import ctbrec.io.ModelJsonAdapter;
|
||||||
|
import ctbrec.sites.Site;
|
||||||
import okhttp3.MediaType;
|
import okhttp3.MediaType;
|
||||||
import okhttp3.Request;
|
import okhttp3.Request;
|
||||||
import okhttp3.Request.Builder;
|
import okhttp3.Request.Builder;
|
||||||
|
@ -41,15 +42,18 @@ public class RemoteRecorder implements Recorder {
|
||||||
private JsonAdapter<ModelRequest> modelRequestAdapter = moshi.adapter(ModelRequest.class);
|
private JsonAdapter<ModelRequest> modelRequestAdapter = moshi.adapter(ModelRequest.class);
|
||||||
|
|
||||||
private List<Model> models = Collections.emptyList();
|
private List<Model> models = Collections.emptyList();
|
||||||
|
private List<Site> sites;
|
||||||
|
|
||||||
private Config config;
|
private Config config;
|
||||||
private HttpClient client;
|
private HttpClient client;
|
||||||
private Instant lastSync = Instant.EPOCH;
|
private Instant lastSync = Instant.EPOCH;
|
||||||
private SyncThread syncThread;
|
private SyncThread syncThread;
|
||||||
|
|
||||||
public RemoteRecorder(Config config, HttpClient client) {
|
|
||||||
|
public RemoteRecorder(Config config, HttpClient client, List<Site> sites) {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.client = client;
|
this.client = client;
|
||||||
|
this.sites = sites;
|
||||||
|
|
||||||
syncThread = new SyncThread();
|
syncThread = new SyncThread();
|
||||||
syncThread.start();
|
syncThread.start();
|
||||||
|
@ -144,6 +148,13 @@ public class RemoteRecorder implements Recorder {
|
||||||
ModelListResponse resp = modelListResponseAdapter.fromJson(json);
|
ModelListResponse resp = modelListResponseAdapter.fromJson(json);
|
||||||
if(resp.status.equals("success")) {
|
if(resp.status.equals("success")) {
|
||||||
models = resp.models;
|
models = resp.models;
|
||||||
|
for (Model model : models) {
|
||||||
|
for (Site site : sites) {
|
||||||
|
if(site.isSiteForModel(model)) {
|
||||||
|
model.setSite(site);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
lastSync = Instant.now();
|
lastSync = Instant.now();
|
||||||
} else {
|
} else {
|
||||||
LOG.error("Server returned error: {} - {}", resp.status, resp.msg);
|
LOG.error("Server returned error: {} - {}", resp.status, resp.msg);
|
||||||
|
|
|
@ -168,7 +168,7 @@ public class CamrecApplication extends Application {
|
||||||
if (config.getSettings().localRecording) {
|
if (config.getSettings().localRecording) {
|
||||||
recorder = new LocalRecorder(config);
|
recorder = new LocalRecorder(config);
|
||||||
} else {
|
} else {
|
||||||
recorder = new RemoteRecorder(config, httpClient);
|
recorder = new RemoteRecorder(config, httpClient, sites);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue