Fix remote saving
authorNiki Roo <niki@nikiroo.be>
Sat, 2 Dec 2017 16:53:47 +0000 (17:53 +0100)
committerNiki Roo <niki@nikiroo.be>
Sat, 2 Dec 2017 16:53:47 +0000 (17:53 +0100)
src/be/nikiroo/fanfix/library/CacheLibrary.java
src/be/nikiroo/fanfix/library/RemoteLibrary.java
src/be/nikiroo/fanfix/library/RemoteLibraryServer.java

index 62ac9fa77bb4f3f7efd4a463863896961ce7abce..28f568210bbcf137a1690989cad15fac50ae72e7 100644 (file)
@@ -143,7 +143,7 @@ public class CacheLibrary extends BasicLibrary {
                pg.addProgress(pgCacheLib, 1);
 
                story = lib.save(story, luid, pgLib);
-               story = cacheLib.save(story, luid, pgCacheLib);
+               story = cacheLib.save(story, story.getMeta().getLuid(), pgCacheLib);
 
                clearCache();
 
index 06370320fb94a6709f543e859841d4e176e4f8de..f3104135f2977b689a222ea68242c8bc5be75d27 100644 (file)
@@ -191,16 +191,23 @@ public class RemoteLibrary extends BasicLibrary {
        @Override
        public synchronized Story save(final Story story, final String luid,
                        Progress pg) throws IOException {
-               final Progress pgF = pg;
+               final String[] luidSaved = new String[1];
+               Progress pgSave = new Progress();
+               Progress pgRefresh = new Progress();
+               if (pg == null) {
+                       pg = new Progress();
+               }
+
+               pg.setMinMax(0, 10);
+               pg.addProgress(pgSave, 9);
+               pg.addProgress(pgRefresh, 1);
+
+               final Progress pgF = pgSave;
 
                new ConnectActionClientObject(host, port, true) {
                        @Override
                        public void action(Version serverVersion) throws Exception {
                                Progress pg = pgF;
-                               if (pg == null) {
-                                       pg = new Progress();
-                               }
-
                                if (story.getMeta().getWords() <= Integer.MAX_VALUE) {
                                        pg.setMinMax(0, (int) story.getMeta().getWords());
                                }
@@ -213,7 +220,9 @@ public class RemoteLibrary extends BasicLibrary {
                                        pg.add(1);
                                }
 
-                               send(null);
+                               send(null); // done sending the story
+                               luidSaved[0] = (String) send(null); // get LUID
+
                                pg.done();
                        }
 
@@ -225,7 +234,10 @@ public class RemoteLibrary extends BasicLibrary {
 
                // because the meta changed:
                clearCache();
-               story.setMeta(getInfo(luid));
+               refresh(pgRefresh);
+               story.setMeta(getInfo(luidSaved[0]));
+
+               pg.done();
 
                return story;
        }
index 245e6fd9b3fc7184c9178e557bb5efe4ba638b89..c93f0f35c600b90a05ded37322da4751f90a0d4e 100644 (file)
@@ -32,7 +32,7 @@ import be.nikiroo.utils.serial.server.ServerObject;
  * <li>[md5] GET_STORY [luid]: will return the given story if it exists (or NULL
  * if not)</li>
  * <li>[md5] SAVE_STORY [luid]: save the story (that must be sent just after the
- * command) with the given LUID</li>
+ * command) with the given LUID, then return the LUID</li>
  * <li>[md5] DELETE_STORY [luid]: delete the story of LUID luid</li>
  * <li>[md5] GET_COVER [luid]: return the cover of the story</li>
  * <li>[md5] GET_SOURCE_COVER [source]: return the cover for this source</li>
@@ -132,6 +132,7 @@ public class RemoteLibraryServer extends ServerObject {
 
                        Story story = rebuildStory(list);
                        Instance.getLibrary().save(story, (String) args[0], null);
+                       return story.getMeta().getLuid();
                } else if ("DELETE_STORY".equals(command)) {
                        Instance.getLibrary().delete((String) args[0]);
                } else if ("GET_COVER".equals(command)) {