Skip to content

Commit

Permalink
new version 0.0.6
Browse files Browse the repository at this point in the history
* do not create album for root directory
  • Loading branch information
mhelleboid committed May 8, 2015
1 parent 5884c60 commit ea91d8c
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 21 deletions.
2 changes: 1 addition & 1 deletion remotesync-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
<parent>
<groupId>piwigo</groupId>
<artifactId>remotesync</artifactId>
<version>0.0.5</version>
<version>0.0.6</version>
<relativePath>../remotesync</relativePath>
</parent>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public synchronized void execute() {
try {
doExecute();
} catch (Exception e) {
// FIXME
logger.error("Error in job " + this, e);
} finally {
running = false;
}
Expand All @@ -44,7 +44,7 @@ public void run() {
}).start();
}

protected abstract void doExecute();
protected abstract void doExecute() throws Exception;

public boolean isRunning() {
return running;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,23 @@ public class SyncJob extends Job {
private static abstract class SyncDirectoryWalker extends DirectoryWalker<File> {

protected GalleryConfig config;

protected Map<File, FileCache> fileCaches = new HashMap<File, FileCache>();
protected File startDirectory;
protected Map<File, FileCache> fileCaches = new HashMap<File, FileCache>();

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<File> 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);
Expand Down Expand Up @@ -81,7 +86,7 @@ protected void handleFile(File file, int depth, java.util.Collection<File> resul
}

public void walk() throws IOException {
walk(new File(config.getDirectory()), null);
walk(startDirectory, null);
}

protected abstract Integer createAlbum(File directory, Integer parentAlbumId);
Expand Down Expand Up @@ -117,14 +122,15 @@ 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());
logger.info("Connect successful");
} catch (ClientServerException e) {
client = null;
logger.error("Unable to connect : " + e.getMessage());
throw new CancelException("Unable to connect", startDirectory, 0);
}
}

Expand Down Expand Up @@ -153,32 +159,37 @@ protected void handleEnd(Collection<File> 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 {
Expand Down
4 changes: 2 additions & 2 deletions remotesync-ui/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<dependency>
<groupId>piwigo</groupId>
<artifactId>remotesync-api</artifactId>
<version>0.0.5</version>
<version>0.0.6</version>
</dependency>
<dependency>
<groupId>org.apache.pivot</groupId>
Expand Down Expand Up @@ -66,7 +66,7 @@
<parent>
<groupId>piwigo</groupId>
<artifactId>remotesync</artifactId>
<version>0.0.5</version>
<version>0.0.6</version>
<relativePath>../remotesync</relativePath>
</parent>
</project>
6 changes: 3 additions & 3 deletions remotesync/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion remotesync/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<groupId>piwigo</groupId>
<artifactId>remotesync</artifactId>
<name>Piwigo Remote Sync</name>
<version>0.0.5</version>
<version>0.0.6</version>
<packaging>pom</packaging>
<modules>
<module>../remotesync-api</module>
Expand Down

0 comments on commit ea91d8c

Please sign in to comment.