From ea91d8cd26f24dbc62fbfe0bbb8894954d125afe Mon Sep 17 00:00:00 2001 From: Matthieu Helleboid Date: Fri, 8 May 2015 09:21:32 +0200 Subject: [PATCH] new version 0.0.6 * do not create album for root directory --- remotesync-api/pom.xml | 2 +- .../java/org/piwigo/remotesync/api/Job.java | 4 +-- .../piwigo/remotesync/api/sync/SyncCache.java | 2 +- .../piwigo/remotesync/api/sync/SyncJob.java | 33 ++++++++++++------- remotesync-ui/pom.xml | 4 +-- remotesync/README.txt | 6 ++-- remotesync/pom.xml | 2 +- 7 files changed, 32 insertions(+), 21 deletions(-) diff --git a/remotesync-api/pom.xml b/remotesync-api/pom.xml index 9f22108..fad5735 100644 --- a/remotesync-api/pom.xml +++ b/remotesync-api/pom.xml @@ -136,7 +136,7 @@ piwigo remotesync - 0.0.5 + 0.0.6 ../remotesync diff --git a/remotesync-api/src/main/java/org/piwigo/remotesync/api/Job.java b/remotesync-api/src/main/java/org/piwigo/remotesync/api/Job.java index 5cdf90a..12d4d4d 100644 --- a/remotesync-api/src/main/java/org/piwigo/remotesync/api/Job.java +++ b/remotesync-api/src/main/java/org/piwigo/remotesync/api/Job.java @@ -29,7 +29,7 @@ public synchronized void execute() { try { doExecute(); } catch (Exception e) { - // FIXME + logger.error("Error in job " + this, e); } finally { running = false; } @@ -44,7 +44,7 @@ public void run() { }).start(); } - protected abstract void doExecute(); + protected abstract void doExecute() throws Exception; public boolean isRunning() { return running; diff --git a/remotesync-api/src/main/java/org/piwigo/remotesync/api/sync/SyncCache.java b/remotesync-api/src/main/java/org/piwigo/remotesync/api/sync/SyncCache.java index 96d274a..48c2566 100644 --- a/remotesync-api/src/main/java/org/piwigo/remotesync/api/sync/SyncCache.java +++ b/remotesync-api/src/main/java/org/piwigo/remotesync/api/sync/SyncCache.java @@ -167,7 +167,7 @@ protected PictureCache addPicture(File file, Integer id) { protected void writeToFile(CacheElement cacheElement) { try { - FileUtils.writeStringToFile(cacheFile, "\n" + cacheElement.toString(), true); + FileUtils.writeStringToFile(cacheFile, cacheElement.toString() + "\n", true); } catch (IOException e) { logger.error("Cannot write " + LEGACY_CACHE_FILE_NAME + " in directory " + cacheFile.getParent(), e); } diff --git a/remotesync-api/src/main/java/org/piwigo/remotesync/api/sync/SyncJob.java b/remotesync-api/src/main/java/org/piwigo/remotesync/api/sync/SyncJob.java index 1c48fc9..759926a 100644 --- a/remotesync-api/src/main/java/org/piwigo/remotesync/api/sync/SyncJob.java +++ b/remotesync-api/src/main/java/org/piwigo/remotesync/api/sync/SyncJob.java @@ -35,18 +35,23 @@ public class SyncJob extends Job { private static abstract class SyncDirectoryWalker extends DirectoryWalker { protected GalleryConfig config; - - protected Map fileCaches = new HashMap(); + protected File startDirectory; + protected Map fileCaches = new HashMap(); private SyncDirectoryWalker(GalleryConfig config) { super(null, Constants.IMAGE_EXTENSIONS_FILTER, -1); this.config = config; + startDirectory = new File(config.getDirectory()); } @Override protected void handleDirectoryStart(File directory, int depth, Collection results) throws IOException { FileCache fileCache = new SyncCache.FileCache(config.getUrl(), SyncCache.getLegacyCacheFile(directory)).parseFile(); fileCaches.put(directory, fileCache); + + //do not create an album for root directory + if (directory.equals(startDirectory)) + return; if (fileCache.albumCache != null) { logger.debug("album already in cache : " + directory); @@ -81,7 +86,7 @@ protected void handleFile(File file, int depth, java.util.Collection resul } public void walk() throws IOException { - walk(new File(config.getDirectory()), null); + walk(startDirectory, null); } protected abstract Integer createAlbum(File directory, Integer parentAlbumId); @@ -117,7 +122,7 @@ public ConnectedWalker(GalleryConfig config) { super(config); } - protected void connect() { + protected void connect() throws IOException { try { logger.info("Connecting... "); client = new AuthenticatedWSClient(config.getUrl()).login(config.getUsername(), config.getPassword()); @@ -125,6 +130,7 @@ protected void connect() { } catch (ClientServerException e) { client = null; logger.error("Unable to connect : " + e.getMessage()); + throw new CancelException("Unable to connect", startDirectory, 0); } } @@ -153,32 +159,37 @@ protected void handleEnd(Collection results) throws IOException { @Override protected Integer createAlbum(File directory, Integer parentAlbumId) { try { - if (client != null) - return client.sendRequest(new PwgCategoriesAddRequest(directory.getName()).setParent(parentAlbumId)).id; + return client.sendRequest(new PwgCategoriesAddRequest(directory.getName()).setParent(parentAlbumId)).id; } catch (ClientServerException e) { logger.error("Cannot create album for " + directory, e); + return null; } - return null; } @Override protected Integer createPicture(File file, Integer albumId) { try { - if (client != null) - return client.sendRequest(new PwgImagesAddSimpleRequest(file).setCategory(albumId)).image_id; + PwgImagesAddSimpleRequest request = new PwgImagesAddSimpleRequest(file); + //FIXME should we upload a picture without album? + if (albumId != null) + request.setCategory(albumId); + return client.sendRequest(request).image_id; } catch (ClientServerException e) { logger.error("Cannot updload image for " + file, e); + return null; } - return null; } } private static final Logger logger = LoggerFactory.getLogger(SyncJob.class); - protected void doExecute() { + protected void doExecute() throws Exception { GalleryConfig config = ConfigUtil.INSTANCE.getUserConfig().getCurrentGalleryConfig(); + //TODO shoud validate config +// GalleryConfigValidator.INSTANCE.validate(config); + logger.info("User {} will sync gallery {} with directory {}", config.getUsername(), config.getUrl(), config.getDirectory()); try { diff --git a/remotesync-ui/pom.xml b/remotesync-ui/pom.xml index f3ded75..034f171 100644 --- a/remotesync-ui/pom.xml +++ b/remotesync-ui/pom.xml @@ -17,7 +17,7 @@ piwigo remotesync-api - 0.0.5 + 0.0.6 org.apache.pivot @@ -66,7 +66,7 @@ piwigo remotesync - 0.0.5 + 0.0.6 ../remotesync diff --git a/remotesync/README.txt b/remotesync/README.txt index 36ebdbb..32abfd3 100644 --- a/remotesync/README.txt +++ b/remotesync/README.txt @@ -21,8 +21,8 @@ cd remotesync mvn -Dmaven.test.skip=true clean package #show help -java -jar ../remotesync-api/target/remotesync-api-0.0.5-jar-with-dependencies.jar -help -java -jar ../remotesync-ui/target/remotesync-ui-0.0.5-jar-with-dependencies.jar -help +java -jar ../remotesync-api/target/remotesync-api-0.0.6-jar-with-dependencies.jar -help +java -jar ../remotesync-ui/target/remotesync-ui-0.0.6-jar-with-dependencies.jar -help #launch remote sync ui -java -jar ../remotesync-ui/target/remotesync-ui-0.0.5-jar-with-dependencies.jar +java -jar ../remotesync-ui/target/remotesync-ui-0.0.6-jar-with-dependencies.jar diff --git a/remotesync/pom.xml b/remotesync/pom.xml index 69abb29..84a6403 100644 --- a/remotesync/pom.xml +++ b/remotesync/pom.xml @@ -14,7 +14,7 @@ piwigo remotesync Piwigo Remote Sync - 0.0.5 + 0.0.6 pom ../remotesync-api