Skip to content

Commit

Permalink
new version 0.0.9:
Browse files Browse the repository at this point in the history
* sync will only connect when needed
* fix get missing derivatives junit test
* better log level management in junit tests
  • Loading branch information
mhelleboid committed Nov 12, 2015
1 parent d32a8fd commit 3831877
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 19 deletions.
2 changes: 1 addition & 1 deletion remotesync-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
<parent>
<groupId>piwigo</groupId>
<artifactId>remotesync</artifactId>
<version>0.0.8</version>
<version>0.0.9</version>
<relativePath>../remotesync</relativePath>
</parent>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
******************************************************************************/
package org.piwigo.remotesync.api.response;

@org.piwigo.remotesync.generator.Generated
import java.util.List;

import org.simpleframework.xml.ElementList;

public class PwgGetMissingDerivativesResponse extends PwgCommonResponse {

@ElementList(required=false)
public List<String> urls;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import org.piwigo.remotesync.api.ISyncConfiguration;
import org.piwigo.remotesync.api.client.AuthenticatedWSClient;
import org.piwigo.remotesync.api.client.WSClient;
import org.piwigo.remotesync.api.exception.ClientServerException;
import org.piwigo.remotesync.api.request.PwgCategoriesAddRequest;
import org.piwigo.remotesync.api.request.PwgImagesAddSimpleRequest;
Expand All @@ -33,6 +34,9 @@ public ConnectedWalker(ISyncConfiguration syncConfiguration) {
}

protected void connect() throws IOException {
if (client != null)
return;

try {
logger.info("Connecting... ");
client = new AuthenticatedWSClient(syncConfiguration).login();
Expand All @@ -45,9 +49,13 @@ protected void connect() throws IOException {
}

protected void disconnect() {
if (client == null)
return;

try {
logger.info("Disconnecting... ");
client.logout();
client = null;
logger.info("Disconnect successful");
} catch (ClientServerException e) {
logger.error("Unable to disconnect : " + e.getMessage());
Expand All @@ -57,8 +65,6 @@ protected void disconnect() {
@Override
protected void handleStart(File startDirectory, Collection<File> results) throws IOException {
super.handleStart(startDirectory, results);
//TODO only connect when needed
connect();
}

@Override
Expand All @@ -67,8 +73,11 @@ protected void handleEnd(Collection<File> results) throws IOException {
disconnect();
}


@Override
protected Integer createAlbum(File directory, Integer parentAlbumId) {
protected Integer createAlbum(File directory, Integer parentAlbumId) throws IOException {
connect();

try {
return client.sendRequest(new PwgCategoriesAddRequest(directory.getName()).setParent(parentAlbumId)).id;
} catch (ClientServerException e) {
Expand All @@ -78,7 +87,9 @@ protected Integer createAlbum(File directory, Integer parentAlbumId) {
}

@Override
protected Integer createImage(File file, Integer albumId) {
protected Integer createImage(File file, Integer albumId) throws IOException {
connect();

try {
PwgImagesAddSimpleRequest request = new PwgImagesAddSimpleRequest(file);
// FIXME should we upload an image without album?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void walk() throws IOException {
walk(startDirectory, null);
}

protected abstract Integer createAlbum(File directory, Integer parentAlbumId);
protected abstract Integer createAlbum(File directory, Integer parentAlbumId) throws IOException;

protected abstract Integer createImage(File file, Integer albumId);
protected abstract Integer createImage(File file, Integer albumId) throws IOException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public static File getFile(Class<?> clazz, String resourceName, boolean checkExi

return file;
} catch (Exception exception) {
logger.error(exception.getMessage(), exception);
logger.debug(exception.getMessage(), exception);
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public void testFakePasswordConverter() throws ParseException {
doTestFakePasswordConverter("a");
doTestFakePasswordConverter("1");
doTestFakePasswordConverter("password");
doTestFakePasswordConverter("1234567890&é(-è_çà)^$ù*,;:!?./§µ%MP");
doTestFakePasswordConverter("1234567890");
}

private void doTestFakePasswordConverter(String password) throws ParseException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
public abstract class AbstractTestCase extends TestCase {

static {
((ch.qos.logback.classic.Logger) LoggerFactory.getLogger("ROOT")).setLevel(Level.INFO);
((ch.qos.logback.classic.Logger) LoggerFactory.getLogger("ROOT")).setLevel(RemotesyncAPIAllTests.TEST_LOG_LEVEL);
}

private static IClient client;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,20 @@
******************************************************************************/
package org.piwigo.remotesync.api.test;

import org.slf4j.LoggerFactory;

import ch.qos.logback.classic.Level;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import ch.qos.logback.classic.Level;

public class RemotesyncAPIAllTests extends TestCase {

//when using mvn
public static Level TEST_LOG_LEVEL = Level.INFO;

public static Test suite() {
((ch.qos.logback.classic.Logger) LoggerFactory.getLogger("ROOT")).setLevel(Level.DEBUG);

//debug only when using suite
TEST_LOG_LEVEL = Level.DEBUG;

TestSuite suite = new TestSuite(RemotesyncAPIAllTests.class.getName());
// $JUnit-BEGIN$
suite.addTestSuite(FileUtilTest.class);
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.8</version>
<version>0.0.9</version>
</dependency>
<dependency>
<groupId>org.apache.pivot</groupId>
Expand Down Expand Up @@ -73,7 +73,7 @@
<parent>
<groupId>piwigo</groupId>
<artifactId>remotesync</artifactId>
<version>0.0.8</version>
<version>0.0.9</version>
<relativePath>../remotesync</relativePath>
</parent>
</project>
5 changes: 4 additions & 1 deletion remotesync/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
<groupId>piwigo</groupId>
<artifactId>remotesync</artifactId>
<name>Piwigo Remote Sync</name>
<version>0.0.8</version>
<version>0.0.9</version>
<packaging>pom</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<modules>
<module>../remotesync-api</module>
<module>../remotesync-ui</module>
Expand Down

0 comments on commit 3831877

Please sign in to comment.