Update nikiroo-utils, Remote:
authorNiki Roo <niki@nikiroo.be>
Sat, 2 Dec 2017 19:25:21 +0000 (20:25 +0100)
committerNiki Roo <niki@nikiroo.be>
Sat, 2 Dec 2017 19:25:21 +0000 (20:25 +0100)
- nikiroo-utils fix for serialisation of objects within custom objects
- remote change source now works on server (not client + delete + re-upload)
- remote import now works on server (not client + delete + re-upload)

changelog.md
libs/nikiroo-utils-3.1.6-sources.jar [moved from libs/nikiroo-utils-3.1.5-sources.jar with 87% similarity]
src/be/nikiroo/fanfix/Main.java
src/be/nikiroo/fanfix/library/CacheLibrary.java
src/be/nikiroo/fanfix/library/RemoteLibrary.java
src/be/nikiroo/fanfix/library/RemoteLibraryServer.java

index d8204124173095e80de7614f55643f616b380e6f..5b725d1368dea2340436c8c74ef37ce24a2b22b7 100644 (file)
@@ -3,7 +3,10 @@
 # Version WIP
 
 - Bug fixes
-- Remote server/client improvements (progress report, can send large files, detect server state)
+- Remote server/client improvement: progress report
+- Remote server/client improvement: can send large files
+- Remote server/client improvement: detect server state
+- Remote server/client improvement: import and change source on server
 - Better support for some CBZ files (if SUMMARY or URL files are present in it)
 - Fix cover images not deleted on story delete
 - Fix some images not supported because not jpeg-able (now try again in png)
similarity index 87%
rename from libs/nikiroo-utils-3.1.5-sources.jar
rename to libs/nikiroo-utils-3.1.6-sources.jar
index 38d88a67c60d68239a1824f121b6d04679560471..5f2dbae17e1ec5c599c565d6a1e040b0db80cfbc 100644 (file)
Binary files a/libs/nikiroo-utils-3.1.5-sources.jar and b/libs/nikiroo-utils-3.1.6-sources.jar differ
index f18e03ca5dcefed8b616fae27e280d062da299ef..0da6bbab3dc7344e2df04f7e7bf6de6cdce5ead4 100644 (file)
@@ -333,7 +333,7 @@ public class Main {
                                try {
                                        ServerObject server = new RemoteLibraryServer(key, port);
                                        server.setTraceHandler(Instance.getTraceHandler());
-                                       server.start();
+                                       server.run();
                                } catch (IOException e) {
                                        Instance.getTraceHandler().error(e);
                                }
index 28f568210bbcf137a1690989cad15fac50ae72e7..14113e4a583be24b5ea2a5ba71b04810220255c6 100644 (file)
@@ -3,6 +3,7 @@ package be.nikiroo.fanfix.library;
 import java.awt.image.BufferedImage;
 import java.io.File;
 import java.io.IOException;
+import java.net.URL;
 import java.util.List;
 
 import be.nikiroo.fanfix.Instance;
@@ -101,6 +102,7 @@ public class CacheLibrary extends BasicLibrary {
 
        @Override
        public BufferedImage getCover(final String luid) {
+               // TODO: cache doesn't seem to work
                if (isCached(luid)) {
                        return cacheLib.getCover(luid);
                }
@@ -211,6 +213,25 @@ public class CacheLibrary extends BasicLibrary {
                }
        }
 
+       @Override
+       public Story imprt(URL url, Progress pg) throws IOException {
+               if (pg == null) {
+                       pg = new Progress();
+               }
+
+               Progress pgImprt = new Progress();
+               Progress pgCache = new Progress();
+               pg.setMinMax(0, 10);
+               pg.addProgress(pgImprt, 7);
+               pg.addProgress(pgCache, 3);
+
+               Story story = lib.imprt(url, pgImprt);
+               cacheLib.save(story, story.getMeta().getLuid(), pgCache);
+
+               pg.done();
+               return story;
+       }
+
        // All the following methods are only used by Save and Delete in
        // BasicLibrary:
 
index f3104135f2977b689a222ea68242c8bc5be75d27..7b52fe3639e9683517b8af88de0f436eb515a451 100644 (file)
@@ -3,6 +3,7 @@ package be.nikiroo.fanfix.library;
 import java.awt.image.BufferedImage;
 import java.io.File;
 import java.io.IOException;
+import java.net.URL;
 import java.net.UnknownHostException;
 import java.util.ArrayList;
 import java.util.List;
@@ -220,8 +221,7 @@ public class RemoteLibrary extends BasicLibrary {
                                        pg.add(1);
                                }
 
-                               send(null); // done sending the story
-                               luidSaved[0] = (String) send(null); // get LUID
+                               luidSaved[0] = (String) send(null);
 
                                pg.done();
                        }
@@ -235,7 +235,10 @@ public class RemoteLibrary extends BasicLibrary {
                // because the meta changed:
                clearCache();
                refresh(pgRefresh);
-               story.setMeta(getInfo(luidSaved[0]));
+
+               MetaData meta = getInfo(luidSaved[0]);
+               meta.setCover(story.getMeta().getCover());
+               story.setMeta(meta);
 
                pg.done();
 
@@ -276,6 +279,96 @@ public class RemoteLibrary extends BasicLibrary {
                }
        }
 
+       @Override
+       // Could work (more slowly) without it
+       public Story imprt(final URL url, Progress pg) throws IOException {
+               if (pg == null) {
+                       pg = new Progress();
+               }
+
+               pg.setMinMax(0, 2);
+               Progress pgImprt = new Progress();
+               Progress pgGet = new Progress();
+               pg.addProgress(pgImprt, 1);
+               pg.addProgress(pgGet, 1);
+
+               final Progress pgF = pgImprt;
+               final String[] luid = new String[1];
+
+               try {
+                       new ConnectActionClientObject(host, port, true) {
+                               @Override
+                               public void action(Version serverVersion) throws Exception {
+                                       Progress pg = pgF;
+
+                                       Object rep = send(new Object[] { md5, "IMPORT",
+                                                       url.toString() });
+
+                                       while (true) {
+                                               if (!RemoteLibraryServer.updateProgress(pg, rep)) {
+                                                       break;
+                                               }
+
+                                               rep = send(null);
+                                       }
+
+                                       pg.done();
+                                       luid[0] = (String) rep;
+                               }
+
+                               @Override
+                               protected void onError(Exception e) {
+                                       Instance.getTraceHandler().error(e);
+                               }
+                       }.connect();
+               } catch (IOException e) {
+                       Instance.getTraceHandler().error(e);
+               }
+
+               if (luid[0] == null) {
+                       throw new IOException("Remote failure");
+               }
+
+               Story story = getStory(luid[0], pgGet);
+               pgGet.done();
+
+               pg.done();
+               return story;
+       }
+
+       @Override
+       // Could work (more slowly) without it
+       public synchronized void changeSource(final String luid,
+                       final String newSource, Progress pg) throws IOException {
+               final Progress pgF = pg == null ? new Progress() : pg;
+
+               try {
+                       new ConnectActionClientObject(host, port, true) {
+                               @Override
+                               public void action(Version serverVersion) throws Exception {
+                                       Progress pg = pgF;
+
+                                       Object rep = send(new Object[] { md5, "CHANGE_SOURCE",
+                                                       luid, newSource });
+                                       while (true) {
+                                               if (!RemoteLibraryServer.updateProgress(pg, rep)) {
+                                                       break;
+                                               }
+
+                                               rep = send(null);
+                                       }
+                               }
+
+                               @Override
+                               protected void onError(Exception e) {
+                                       Instance.getTraceHandler().error(e);
+                               }
+                       }.connect();
+               } catch (IOException e) {
+                       Instance.getTraceHandler().error(e);
+               }
+       }
+
        @Override
        public synchronized File getFile(final String luid, Progress pg) {
                throw new java.lang.InternalError(
index c93f0f35c600b90a05ded37322da4751f90a0d4e..adef7edea06e5ca7f9d0bbc0ff1323252f8f7ff5 100644 (file)
@@ -1,6 +1,7 @@
 package be.nikiroo.fanfix.library;
 
 import java.io.IOException;
+import java.net.URL;
 import java.security.InvalidParameterException;
 import java.util.ArrayList;
 import java.util.List;
@@ -33,11 +34,15 @@ import be.nikiroo.utils.serial.server.ServerObject;
  * if not)</li>
  * <li>[md5] SAVE_STORY [luid]: save the story (that must be sent just after the
  * command) with the given LUID, then return the LUID</li>
+ * <li>[md5] IMPORT [url]: save the story found at the given URL, 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>
  * <li>[md5] SET_SOURCE_COVER [source], [luid]: set the default cover for the
  * given source to the cover of the story denoted by luid</li>
+ * <li>[md5] CHANGE_SOURCE [luid] [new source]: change the source of the story
+ * of LUID luid</li>
  * <li>[md5] EXIT: stop the server</li>
  * </ul>
  * 
@@ -74,13 +79,13 @@ public class RemoteLibraryServer extends ServerObject {
                if (data instanceof Object[]) {
                        Object[] dataArray = (Object[]) data;
                        if (dataArray.length >= 2) {
+                               md5 = "" + dataArray[0];
+                               command = "" + dataArray[1];
+
                                args = new Object[dataArray.length - 2];
                                for (int i = 2; i < dataArray.length; i++) {
                                        args[i - 2] = dataArray[i];
                                }
-
-                               md5 = "" + dataArray[0];
-                               command = "" + dataArray[1];
                        }
                }
 
@@ -133,6 +138,10 @@ public class RemoteLibraryServer extends ServerObject {
                        Story story = rebuildStory(list);
                        Instance.getLibrary().save(story, (String) args[0], null);
                        return story.getMeta().getLuid();
+               } else if ("IMPORT".equals(command)) {
+                       Story story = Instance.getLibrary().imprt(
+                                       new URL((String) args[0]), createPgForwarder(action));
+                       return story.getMeta().getLuid();
                } else if ("DELETE_STORY".equals(command)) {
                        Instance.getLibrary().delete((String) args[0]);
                } else if ("GET_COVER".equals(command)) {
@@ -142,6 +151,9 @@ public class RemoteLibraryServer extends ServerObject {
                } else if ("SET_SOURCE_COVER".equals(command)) {
                        Instance.getLibrary().setSourceCover((String) args[0],
                                        (String) args[1]);
+               } else if ("CHANGE_SOURCE".equals(command)) {
+                       Instance.getLibrary().changeSource((String) args[0],
+                                       (String) args[1], createPgForwarder(action));
                } else if ("EXIT".equals(command)) {
                        stop(0, false);
                }