healthDB;
private final RemotePresenter remotePresenter;
private RemotePreferences remotePreferences;
-
+ private FileController fileController;
+
/**
- * Creates a RemoteController instance by connecting to a broker and setting up properties.
+ * Creates a RemoteController instance by connecting to a broker and setting up
+ * properties.
*
- * You may set a prefix if you want to share a broker with multiple instance groups.
- * The prefix may be a code, where only selected users have access too. It must be set if you want to set up or use
- * a global mqtt server for multiple organizations.
- * A Organization may have different rooms, to split up presentation instances into.
- * Users may have only access to some rooms.
+ * You may set a prefix if you want to share a broker with multiple instance
+ * groups. The prefix may be a code, where only selected users have access too.
+ * It must be set if you want to set up or use a global mqtt server for multiple
+ * organizations. A Organization may have different rooms, to split up
+ * presentation instances into. Users may have only access to some rooms.
*
* A room contains one shared presentation, and multiple playlists.
*
- * All properties are by default without local notify. They can't be used for in program synchronization.
- * Furthermore they are retained.
+ * All properties are by default without local notify. They can't be used for in
+ * program synchronization. Furthermore they are retained.
*
- * @param mainWindow
- * can be null, if headless
+ * @param mainWindow can be null, if headless
*/
public RemoteController(RemotePreferences remotePreferences, MainController mainController, MainWindow mainWindow) {
this.remotePreferences = remotePreferences;
-
+
position = new MqttObject<>(formatTopic(RemoteTopic.POSITION), (s) -> (Position) parseXML(s),
- RemoteController::toXML, RemoteTopic.POSITION_QOS, RemoteTopic.POSITION_RETAINED,
- null);
+ RemoteController::toXML, RemoteTopic.POSITION_QOS, RemoteTopic.POSITION_RETAINED, null);
position.onRemoteChange((p, a) -> updateSongOrPosition(mainController, mainWindow));
-
- song = new MqttObject<>(formatTopic(RemoteTopic.SONG),
- (s) -> (Song) parseXML(s), RemoteController::toXML, RemoteTopic.SONG_QOS, RemoteTopic.SONG_RETAINED,
- null);
+
+ song = new MqttObject<>(formatTopic(RemoteTopic.SONG), (s) -> (Song) parseXML(s), RemoteController::toXML,
+ RemoteTopic.SONG_QOS, RemoteTopic.SONG_RETAINED, null);
song.onRemoteChange((s, a) -> updateSongOrPosition(mainController, mainWindow));
-
+
if (mainWindow != null) {
- playlist = new MqttObject<>(formatTopic(RemoteTopic.PLAYLIST),
- (s) -> (SongsModel) parseXML(s),
- RemoteController::toXML, RemoteTopic.PLAYLIST_QOS, RemoteTopic.PLAYLIST_RETAINED,
- null);
- playlist.onRemoteChange((p, a) -> mainWindow.updatePlaylist(p));
- mainWindow.getPresentModel().addSongsModelListener(() -> playlist.set(new SongsModel(mainWindow.getPresentModel())));
-
+ playlist = new MqttObject<>(formatTopic(RemoteTopic.PLAYLIST), (s) -> (SongsModel) parseXML(s),
+ RemoteController::toXML, RemoteTopic.PLAYLIST_QOS, RemoteTopic.PLAYLIST_RETAINED, null);
+ playlist.onRemoteChange((p, a) -> fileController.downloadFiles(p, () -> mainWindow.updatePlaylist(p)));
+ mainWindow.getPresentModel().addSongsModelListener(() -> playlist.set(new SongsModel(fileController.uploadFiles(mainWindow.getPresentModel()))));
+
latestVersion = new MqttObject<>(formatTopic(RemoteTopic.PATCHES_LATEST_VERSION),
- (s) -> (Version) parseXML(s),
- RemoteController::toXML, RemoteTopic.PATCHES_LATEST_VERSION_QOS, RemoteTopic.PATCHES_LATEST_VERSION_RETAINED,
- (a, b) -> false);
-
+ (s) -> (Version) parseXML(s), RemoteController::toXML, RemoteTopic.PATCHES_LATEST_VERSION_QOS,
+ RemoteTopic.PATCHES_LATEST_VERSION_RETAINED, (a, b) -> false);
+
latestChanges = new MqttObject<>(formatTopic(RemoteTopic.PATCHES_LATEST_CHANGES),
- (s) -> (SongsModel) parseXML(s),
- RemoteController::toXML, RemoteTopic.PATCHES_LATEST_CHANGES_QOS, RemoteTopic.PATCHES_LATEST_CHANEGS_RETAINED,
- (a, b) -> false);
-
+ (s) -> (SongsModel) parseXML(s), RemoteController::toXML, RemoteTopic.PATCHES_LATEST_CHANGES_QOS,
+ RemoteTopic.PATCHES_LATEST_CHANEGS_RETAINED, (a, b) -> false);
+
latestReject = new MqttObject<>(formatTopic(RemoteTopic.PATCHES_LATEST_REJECT),
- (s) -> (ChangeReject) parseXML(s),
- null, RemoteTopic.PATCHES_LATEST_REJECT_QOS, RemoteTopic.PATCHES_LATEST_REJECT_RETAINED,
- (a, b) -> false);
-
- requestGet = new MqttObject<>(formatClientIDTopic(RemoteTopic.PATCHES_REQUEST_GET),
- RemoteController::toXML, RemoteTopic.PATCHES_REQUEST_GET_QOS, RemoteTopic.PATCHES_REQUEST_GET_RETAINED);
-
+ (s) -> (ChangeReject) parseXML(s), null, RemoteTopic.PATCHES_LATEST_REJECT_QOS,
+ RemoteTopic.PATCHES_LATEST_REJECT_RETAINED, (a, b) -> false);
+
+ requestGet = new MqttObject<>(formatClientIDTopic(RemoteTopic.PATCHES_REQUEST_GET), RemoteController::toXML,
+ RemoteTopic.PATCHES_REQUEST_GET_QOS, RemoteTopic.PATCHES_REQUEST_GET_RETAINED);
+
requestPatches = new MqttObject<>(formatClientIDTopic(RemoteTopic.PATCHES_REQUEST_PATCHES),
- (s) -> (Patches) parseXML(s),
- RemoteController::toXML, RemoteTopic.PATCHES_REQUEST_PATCHES_QOS, RemoteTopic.PATCHES_REQUEST_PATCHES_RETAINED,
- (a, b) -> false);
-
- healthDB = new MqttObject<>(formatPrefixTopic(RemoteTopic.HEALTH_DB),
- Health::valueOfBytes, null, RemoteTopic.HEALTH_DB_QOS, RemoteTopic.HEALTH_DB_RETAINED, null);
+ (s) -> (Patches) parseXML(s), RemoteController::toXML, RemoteTopic.PATCHES_REQUEST_PATCHES_QOS,
+ RemoteTopic.PATCHES_REQUEST_PATCHES_RETAINED, (a, b) -> false);
+
+ filesRequestSet = new MqttObject<>(formatClientIDTopic(RemoteTopic.FILES_REQUEST_SET), (b) -> b,
+ RemoteTopic.FILES_REQUEST_SET_QOS, RemoteTopic.FILES_REQUEST_SET_RETAINED);
+
+ filesRequestGet = new MqttObject<>(formatClientIDTopic(RemoteTopic.FILES_REQUEST_GET),
+ RemoteController::toXML, RemoteTopic.FILES_REQUEST_GET_QOS, RemoteTopic.FILES_REQUEST_GET_RETAINED);
+
+ filesRequestFile = new MqttObject<>(formatClientIDTopic(RemoteTopic.FILES_REQUEST_FILE), null, null,
+ RemoteTopic.FILES_REQUEST_FILE_QOS, RemoteTopic.FILES_REQUEST_FILE_RETAINED, (a, b) -> false);
+
+ healthDB = new MqttObject<>(formatPrefixTopic(RemoteTopic.HEALTH_DB), Health::valueOfBytes, null,
+ RemoteTopic.HEALTH_DB_QOS, RemoteTopic.HEALTH_DB_RETAINED, null);
} else {
this.playlist = null;
this.requestPatches = null;
@@ -120,9 +133,10 @@ public RemoteController(RemotePreferences remotePreferences, MainController main
this.healthDB = null;
}
+ fileController = new FileController(this);
remotePresenter = new RemotePresenter(this);
}
-
+
public void connectTo(MQTT mqtt) throws MqttException {
song.connectTo(mqtt);
position.connectTo(mqtt);
@@ -133,8 +147,11 @@ public void connectTo(MQTT mqtt) throws MqttException {
requestPatches.connectTo(mqtt);
latestReject.connectTo(mqtt);
healthDB.connectTo(mqtt);
+ filesRequestFile.connectTo(mqtt);
+ filesRequestGet.connectTo(mqtt);
+ filesRequestSet.connectTo(mqtt);
}
-
+
private void updateSongOrPosition(MainController mainController, MainWindow mainWindow) {
if (position == null || song == null)
return;
@@ -147,50 +164,49 @@ private void updateSongOrPosition(MainController mainController, MainWindow main
if (s == null) {
return;
}
-
+
if (StringTools.equals(s.getUUID(), p.getUUID())) {
if (p.isVisible()) {
+ p = StringTools.isEmpty(s.getImage()) ? p : null;
presentSong(mainController, mainWindow, s, p);
} else {
presentSong(mainController, mainWindow, null, null);
}
}
}
-
+
private void presentSong(MainController mainController, MainWindow mainWindow, Song s, Position p) {
- SongPresentationPosition spp = p != null
- ? new SongPresentationPosition(p.getPart(), p.getLine())
- : null;
+ SongPresentationPosition spp = p != null ? new SongPresentationPosition(p.getPart(), p.getLine()) : null;
if (mainWindow != null) {
mainWindow.present(s, spp);
} else {
mainController.present(new Presentable(s, null), spp);
}
}
-
+
public MqttObject getSong() {
return song;
}
-
+
public MqttObject getPlaylist() {
return playlist;
}
-
+
public MqttObject getPosition() {
return position;
}
-
+
public RemotePresenter getRemotePresenter(Presentable presentable) {
remotePresenter.setContent(presentable, null);
return remotePresenter;
}
-
+
static Persistable parseXML(byte[] xml) {
if (xml.length == 0)
return null;
return XMLConverter.fromXMLToPersistable(new ByteArrayInputStream(xml));
}
-
+
static byte[] toXML(Persistable persistable) {
if (persistable == null)
return new byte[0];
@@ -203,47 +219,62 @@ static byte[] toXML(Persistable persistable) {
}
return null;
}
-
+
private String formatTopic(String topic) {
- return String.format(topic, getRemotePreferences().getPrefix().isBlank() ? "" : getRemotePreferences().getPrefix() + "/",
- getRemotePreferences().getRoom());
+ return String.format(topic,
+ getRemotePreferences().getPrefix().isBlank() ? "" : getRemotePreferences().getPrefix() + "/",
+ getRemotePreferences().getRoom());
}
-
+
private String formatClientIDTopic(String topic) {
- return String.format(topic, getRemotePreferences().getPrefix().isBlank() ? "" : getRemotePreferences().getPrefix() + "/", remotePreferences
- .getClientID());
+ return String.format(topic,
+ getRemotePreferences().getPrefix().isBlank() ? "" : getRemotePreferences().getPrefix() + "/",
+ remotePreferences.getClientID());
}
-
+
private String formatPrefixTopic(String topic) {
- return String.format(topic, getRemotePreferences().getPrefix().isEmpty() ? "" : getRemotePreferences().getPrefix() + "/");
+ return String.format(topic,
+ getRemotePreferences().getPrefix().isEmpty() ? "" : getRemotePreferences().getPrefix() + "/");
}
-
+
public MqttObject getLatestVersion() {
return latestVersion;
}
-
+
public MqttObject getLatestChanges() {
return latestChanges;
}
-
+
public MqttObject getRequestPatches() {
return requestPatches;
}
-
+
public MqttObject getRequestGet() {
return requestGet;
}
-
+
public MqttObject getLatestReject() {
return latestReject;
}
-
+
public MqttObject getHealthDB() {
return healthDB;
}
-
+
public RemotePreferences getRemotePreferences() {
return remotePreferences;
}
-
+
+ public MqttObject getFilesRequestSet() {
+ return filesRequestSet;
+ }
+
+ public MqttObject getFilesRequestGet() {
+ return filesRequestGet;
+ }
+
+ public MqttObject getFilesRequestFile() {
+ return filesRequestFile;
+ }
+
}
diff --git a/src/main/java/org/zephyrsoft/sdb2/remote/RemoteTopic.java b/src/main/java/org/zephyrsoft/sdb2/remote/RemoteTopic.java
index 2b2babbb..140df4dc 100644
--- a/src/main/java/org/zephyrsoft/sdb2/remote/RemoteTopic.java
+++ b/src/main/java/org/zephyrsoft/sdb2/remote/RemoteTopic.java
@@ -64,4 +64,21 @@ public class RemoteTopic {
final static String PATCHES_REQUEST_PATCHES = "%sdb/v1/patches/request/%s/patches";
final static int PATCHES_REQUEST_PATCHES_QOS = 1;
final static boolean PATCHES_REQUEST_PATCHES_RETAINED = false;
+
+ // If client uploads a file: to username/uuid
+ final static String FILES_REQUEST_SET = "%sdb/v1/files/request/%s/set/+";
+ final static int FILES_REQUEST_SET_QOS = 1;
+ final static boolean FILES_REQUEST_SET_RETAINED = false;
+
+ // If client needs a file, it sends a request to get
+ final static String FILES_REQUEST_GET = "%sdb/v1/files/request/%s/get";
+ final static int FILES_REQUEST_GET_QOS = 1;
+ final static boolean FILES_REQUEST_GET_RETAINED = false;
+
+ // And it will recieve the requested file to uuid:
+ final static String FILES_REQUEST_FILE = "%sdb/v1/files/request/%s/file/+";
+ final static int FILES_REQUEST_FILE_QOS = 1;
+ final static boolean FILES_REQUEST_FILE_RETAINED = false;
+ public final static int FILES_REQUEST_FILE_UUID = 0;
+
}
From da07a91a47dca9f5d1a4bbe81d6e64321f516d41 Mon Sep 17 00:00:00 2001
From: Lenard Spiecker <17047770+l-spiecker@users.noreply.github.com>
Date: Wed, 20 Mar 2024 00:36:50 +0100
Subject: [PATCH 2/2] chg: filesync file set response
---
.../zephyrsoft/sdb2/model/XMLConverter.java | 3 +-
.../sdb2/remote/FileController.java | 46 +++++++++++---
.../sdb2/remote/FileSetResponse.java | 60 +++++++++++++++++++
.../sdb2/remote/RemoteController.java | 24 ++++++--
.../zephyrsoft/sdb2/remote/RemoteTopic.java | 5 ++
5 files changed, 123 insertions(+), 15 deletions(-)
create mode 100644 src/main/java/org/zephyrsoft/sdb2/remote/FileSetResponse.java
diff --git a/src/main/java/org/zephyrsoft/sdb2/model/XMLConverter.java b/src/main/java/org/zephyrsoft/sdb2/model/XMLConverter.java
index 3b92ad7c..c308e9fa 100644
--- a/src/main/java/org/zephyrsoft/sdb2/model/XMLConverter.java
+++ b/src/main/java/org/zephyrsoft/sdb2/model/XMLConverter.java
@@ -22,6 +22,7 @@
import org.zephyrsoft.sdb2.model.statistics.StatisticsModel;
import org.zephyrsoft.sdb2.remote.ChangeReject;
import org.zephyrsoft.sdb2.remote.FileRequest;
+import org.zephyrsoft.sdb2.remote.FileSetResponse;
import org.zephyrsoft.sdb2.remote.PatchRequest;
import org.zephyrsoft.sdb2.remote.Patches;
import org.zephyrsoft.sdb2.remote.Position;
@@ -66,7 +67,7 @@ public static T fromXMLToPersistable(InputStream xmlInpu
private static JAXBContext createContext() throws JAXBException {
JAXBContext context = JAXBContext.newInstance(SongsModel.class, SettingsModel.class, StatisticsModel.class, Version.class,
- PatchRequest.class, Song.class, Patches.class, ChangeReject.class, Position.class, FileRequest.class);
+ PatchRequest.class, Song.class, Patches.class, ChangeReject.class, Position.class, FileRequest.class, FileSetResponse.class);
return context;
}
diff --git a/src/main/java/org/zephyrsoft/sdb2/remote/FileController.java b/src/main/java/org/zephyrsoft/sdb2/remote/FileController.java
index 05c7dbbf..b1fcb3d3 100644
--- a/src/main/java/org/zephyrsoft/sdb2/remote/FileController.java
+++ b/src/main/java/org/zephyrsoft/sdb2/remote/FileController.java
@@ -89,7 +89,10 @@ public void onChange(byte[] object, Object... args) {
missingFiles.forEach((fileName) -> remoteController.getFilesRequestGet().set(new FileRequest(fileName)));
}
- public SongsModel uploadFiles(SongsModel songsModel) {
+
+ public void uploadFiles(SongsModel songsModel, Consumer callback) {
+ HashSet localFiles = new HashSet<>();
+
for (Song song: songsModel.getSongs()) {
if(!StringTools.isEmpty(song.getImage()) && URI.create(song.getImage()).getScheme().equals("file")) {
Path path = Paths.get(URI.create(song.getImage()));
@@ -98,6 +101,7 @@ public SongsModel uploadFiles(SongsModel songsModel) {
.filter(f -> f.contains("."))
.map(f -> f.substring(oldFilename.lastIndexOf(".")));
String newFilename = StringTools.createUUID() + fileExtension.get();
+ localFiles.add(newFilename);
Path dbPath = Paths.get(FileAndDirectoryLocations.getDBBlobDir(), newFilename);
try {
Files.createDirectories(Paths.get(FileAndDirectoryLocations.getDBBlobDir()));
@@ -109,16 +113,42 @@ public SongsModel uploadFiles(SongsModel songsModel) {
} catch (IOException e) {
e.printStackTrace();
}
- try {
- byte[] content = Files.readAllBytes(dbPath);
- remoteController.getFilesRequestSet().set(content, newFilename);
- } catch (IOException e) {
- e.printStackTrace();
- }
song.setImage("sdb://"+newFilename);
}
}
- return songsModel;
+ if(localFiles.isEmpty()) {
+ callback.accept(songsModel);
+ return;
+ }
+
+ this.remoteController.getFilesRequestSetResponse().onRemoteChange(new OnChangeListener() {
+ @Override
+ public void onChange(FileSetResponse object, Object... args) {
+ String fileName = object.getUuid();
+ if ( localFiles.contains(fileName) ){
+ if(!object.isOk()) {
+ System.err.println("Could not upload file " + fileName + " Reason: " + object.getReason());
+ remoteController.getFilesRequestSetResponse().removeOnRemoteChangeListener(this);
+ }else {
+ localFiles.remove(fileName);
+ if (localFiles.isEmpty()) {
+ callback.accept(songsModel);
+ remoteController.getFilesRequestSetResponse().removeOnRemoteChangeListener(this);
+ }
+ }
+ }
+ }
+ });
+
+ localFiles.forEach((fileName) -> {
+ Path dbPath = Paths.get(FileAndDirectoryLocations.getDBBlobDir(), fileName);
+ try {
+ byte[] content = Files.readAllBytes(dbPath);
+ remoteController.getFilesRequestSet().set(content, fileName);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ });
}
}
diff --git a/src/main/java/org/zephyrsoft/sdb2/remote/FileSetResponse.java b/src/main/java/org/zephyrsoft/sdb2/remote/FileSetResponse.java
new file mode 100644
index 00000000..fb0f2895
--- /dev/null
+++ b/src/main/java/org/zephyrsoft/sdb2/remote/FileSetResponse.java
@@ -0,0 +1,60 @@
+/*
+ * This file is part of the Song Database (SDB).
+ *
+ * SDB is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License 3.0 as published by
+ * the Free Software Foundation.
+ *
+ * SDB is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License 3.0 for more details.
+ *
+ * You should have received a copy of the GNU General Public License 3.0
+ * along with SDB. If not, see .
+ */
+package org.zephyrsoft.sdb2.remote;
+
+import org.zephyrsoft.sdb2.model.Persistable;
+
+import jakarta.xml.bind.annotation.XmlAccessOrder;
+import jakarta.xml.bind.annotation.XmlAccessType;
+import jakarta.xml.bind.annotation.XmlAccessorOrder;
+import jakarta.xml.bind.annotation.XmlAccessorType;
+import jakarta.xml.bind.annotation.XmlElement;
+import jakarta.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement(name = "fileSetResponse")
+@XmlAccessorType(XmlAccessType.NONE)
+@XmlAccessorOrder(XmlAccessOrder.ALPHABETICAL)
+public class FileSetResponse implements Persistable {
+ private static final long serialVersionUID = 8867365661007188776L;
+
+ @XmlElement(name = "uuid")
+ private String uuid = null;
+ @XmlElement(name = "ok")
+ private boolean ok = true;
+ @XmlElement(name = "reason")
+ private String reason = "";
+
+ public FileSetResponse() {
+ initIfNecessary();
+ }
+
+ @Override
+ public void initIfNecessary() {
+ // Nothing to do
+ }
+
+ public boolean isOk() {
+ return ok;
+ }
+
+ public String getUuid() {
+ return uuid;
+ }
+
+ public String getReason() {
+ return reason;
+ }
+}
diff --git a/src/main/java/org/zephyrsoft/sdb2/remote/RemoteController.java b/src/main/java/org/zephyrsoft/sdb2/remote/RemoteController.java
index 24d5289d..4043d5e4 100644
--- a/src/main/java/org/zephyrsoft/sdb2/remote/RemoteController.java
+++ b/src/main/java/org/zephyrsoft/sdb2/remote/RemoteController.java
@@ -53,6 +53,7 @@ public class RemoteController {
private final MqttObject latestReject;
private MqttObject filesRequestSet;
private MqttObject filesRequestGet;
+ private MqttObject filesRequestSetResponse;
private MqttObject filesRequestFile;
private final MqttObject healthDB;
private final RemotePresenter remotePresenter;
@@ -87,11 +88,17 @@ public RemoteController(RemotePreferences remotePreferences, MainController main
RemoteTopic.SONG_QOS, RemoteTopic.SONG_RETAINED, null);
song.onRemoteChange((s, a) -> updateSongOrPosition(mainController, mainWindow));
+ filesRequestGet = new MqttObject<>(formatClientIDTopic(RemoteTopic.FILES_REQUEST_GET),
+ RemoteController::toXML, RemoteTopic.FILES_REQUEST_GET_QOS, RemoteTopic.FILES_REQUEST_GET_RETAINED);
+
+ filesRequestFile = new MqttObject<>(formatClientIDTopic(RemoteTopic.FILES_REQUEST_FILE), null, null,
+ RemoteTopic.FILES_REQUEST_FILE_QOS, RemoteTopic.FILES_REQUEST_FILE_RETAINED, (a, b) -> false);
+
if (mainWindow != null) {
playlist = new MqttObject<>(formatTopic(RemoteTopic.PLAYLIST), (s) -> (SongsModel) parseXML(s),
RemoteController::toXML, RemoteTopic.PLAYLIST_QOS, RemoteTopic.PLAYLIST_RETAINED, null);
playlist.onRemoteChange((p, a) -> fileController.downloadFiles(p, () -> mainWindow.updatePlaylist(p)));
- mainWindow.getPresentModel().addSongsModelListener(() -> playlist.set(new SongsModel(fileController.uploadFiles(mainWindow.getPresentModel()))));
+ mainWindow.getPresentModel().addSongsModelListener(() -> fileController.uploadFiles(mainWindow.getPresentModel(), (s) -> playlist.set(new SongsModel(s))));
latestVersion = new MqttObject<>(formatTopic(RemoteTopic.PATCHES_LATEST_VERSION),
(s) -> (Version) parseXML(s), RemoteController::toXML, RemoteTopic.PATCHES_LATEST_VERSION_QOS,
@@ -115,11 +122,9 @@ public RemoteController(RemotePreferences remotePreferences, MainController main
filesRequestSet = new MqttObject<>(formatClientIDTopic(RemoteTopic.FILES_REQUEST_SET), (b) -> b,
RemoteTopic.FILES_REQUEST_SET_QOS, RemoteTopic.FILES_REQUEST_SET_RETAINED);
- filesRequestGet = new MqttObject<>(formatClientIDTopic(RemoteTopic.FILES_REQUEST_GET),
- RemoteController::toXML, RemoteTopic.FILES_REQUEST_GET_QOS, RemoteTopic.FILES_REQUEST_GET_RETAINED);
-
- filesRequestFile = new MqttObject<>(formatClientIDTopic(RemoteTopic.FILES_REQUEST_FILE), null, null,
- RemoteTopic.FILES_REQUEST_FILE_QOS, RemoteTopic.FILES_REQUEST_FILE_RETAINED, (a, b) -> false);
+ filesRequestSetResponse = new MqttObject<>(formatClientIDTopic(RemoteTopic.FILES_REQUEST_SET_RESPONSE),
+ (s) -> (FileSetResponse) parseXML(s), null, RemoteTopic.FILES_REQUEST_SET_RESPONSE_QOS,
+ RemoteTopic.FILES_REQUEST_SET_RESPONSE_RETAINED, (a, b) -> false);
healthDB = new MqttObject<>(formatPrefixTopic(RemoteTopic.HEALTH_DB), Health::valueOfBytes, null,
RemoteTopic.HEALTH_DB_QOS, RemoteTopic.HEALTH_DB_RETAINED, null);
@@ -131,6 +136,8 @@ public RemoteController(RemotePreferences remotePreferences, MainController main
this.latestReject = null;
this.latestChanges = null;
this.healthDB = null;
+ this.filesRequestSet = null;
+ this.filesRequestSetResponse = null;
}
fileController = new FileController(this);
@@ -150,6 +157,7 @@ public void connectTo(MQTT mqtt) throws MqttException {
filesRequestFile.connectTo(mqtt);
filesRequestGet.connectTo(mqtt);
filesRequestSet.connectTo(mqtt);
+ filesRequestSetResponse.connectTo(mqtt);
}
private void updateSongOrPosition(MainController mainController, MainWindow mainWindow) {
@@ -277,4 +285,8 @@ public MqttObject getFilesRequestFile() {
return filesRequestFile;
}
+ public MqttObject getFilesRequestSetResponse() {
+ return filesRequestSetResponse;
+ }
+
}
diff --git a/src/main/java/org/zephyrsoft/sdb2/remote/RemoteTopic.java b/src/main/java/org/zephyrsoft/sdb2/remote/RemoteTopic.java
index 140df4dc..38066005 100644
--- a/src/main/java/org/zephyrsoft/sdb2/remote/RemoteTopic.java
+++ b/src/main/java/org/zephyrsoft/sdb2/remote/RemoteTopic.java
@@ -70,6 +70,11 @@ public class RemoteTopic {
final static int FILES_REQUEST_SET_QOS = 1;
final static boolean FILES_REQUEST_SET_RETAINED = false;
+ // If client uploads a file, response: to username
+ final static String FILES_REQUEST_SET_RESPONSE = "%sdb/v1/files/request/%s/set_response";
+ final static int FILES_REQUEST_SET_RESPONSE_QOS = 1;
+ final static boolean FILES_REQUEST_SET_RESPONSE_RETAINED = false;
+
// If client needs a file, it sends a request to get
final static String FILES_REQUEST_GET = "%sdb/v1/files/request/%s/get";
final static int FILES_REQUEST_GET_QOS = 1;