Skip to content

Commit 3831877

Browse files
committed
new version 0.0.9:
* sync will only connect when needed * fix get missing derivatives junit test * better log level management in junit tests
1 parent d32a8fd commit 3831877

10 files changed

Lines changed: 41 additions & 19 deletions

File tree

remotesync-api/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@
143143
<parent>
144144
<groupId>piwigo</groupId>
145145
<artifactId>remotesync</artifactId>
146-
<version>0.0.8</version>
146+
<version>0.0.9</version>
147147
<relativePath>../remotesync</relativePath>
148148
</parent>
149149
</project>

remotesync-api/src/gen/java/org/piwigo/remotesync/api/response/PwgGetMissingDerivativesResponse.java renamed to remotesync-api/src/main/java/org/piwigo/remotesync/api/response/PwgGetMissingDerivativesResponse.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
******************************************************************************/
1111
package org.piwigo.remotesync.api.response;
1212

13-
@org.piwigo.remotesync.generator.Generated
13+
import java.util.List;
14+
15+
import org.simpleframework.xml.ElementList;
16+
1417
public class PwgGetMissingDerivativesResponse extends PwgCommonResponse {
18+
19+
@ElementList(required=false)
20+
public List<String> urls;
1521
}

remotesync-api/src/main/java/org/piwigo/remotesync/api/sync/ConnectedWalker.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import org.piwigo.remotesync.api.ISyncConfiguration;
1818
import org.piwigo.remotesync.api.client.AuthenticatedWSClient;
19+
import org.piwigo.remotesync.api.client.WSClient;
1920
import org.piwigo.remotesync.api.exception.ClientServerException;
2021
import org.piwigo.remotesync.api.request.PwgCategoriesAddRequest;
2122
import org.piwigo.remotesync.api.request.PwgImagesAddSimpleRequest;
@@ -33,6 +34,9 @@ public ConnectedWalker(ISyncConfiguration syncConfiguration) {
3334
}
3435

3536
protected void connect() throws IOException {
37+
if (client != null)
38+
return;
39+
3640
try {
3741
logger.info("Connecting... ");
3842
client = new AuthenticatedWSClient(syncConfiguration).login();
@@ -45,9 +49,13 @@ protected void connect() throws IOException {
4549
}
4650

4751
protected void disconnect() {
52+
if (client == null)
53+
return;
54+
4855
try {
4956
logger.info("Disconnecting... ");
5057
client.logout();
58+
client = null;
5159
logger.info("Disconnect successful");
5260
} catch (ClientServerException e) {
5361
logger.error("Unable to disconnect : " + e.getMessage());
@@ -57,8 +65,6 @@ protected void disconnect() {
5765
@Override
5866
protected void handleStart(File startDirectory, Collection<File> results) throws IOException {
5967
super.handleStart(startDirectory, results);
60-
//TODO only connect when needed
61-
connect();
6268
}
6369

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

76+
7077
@Override
71-
protected Integer createAlbum(File directory, Integer parentAlbumId) {
78+
protected Integer createAlbum(File directory, Integer parentAlbumId) throws IOException {
79+
connect();
80+
7281
try {
7382
return client.sendRequest(new PwgCategoriesAddRequest(directory.getName()).setParent(parentAlbumId)).id;
7483
} catch (ClientServerException e) {
@@ -78,7 +87,9 @@ protected Integer createAlbum(File directory, Integer parentAlbumId) {
7887
}
7988

8089
@Override
81-
protected Integer createImage(File file, Integer albumId) {
90+
protected Integer createImage(File file, Integer albumId) throws IOException {
91+
connect();
92+
8293
try {
8394
PwgImagesAddSimpleRequest request = new PwgImagesAddSimpleRequest(file);
8495
// FIXME should we upload an image without album?

remotesync-api/src/main/java/org/piwigo/remotesync/api/sync/SyncDirectoryWalker.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public void walk() throws IOException {
8181
walk(startDirectory, null);
8282
}
8383

84-
protected abstract Integer createAlbum(File directory, Integer parentAlbumId);
84+
protected abstract Integer createAlbum(File directory, Integer parentAlbumId) throws IOException;
8585

86-
protected abstract Integer createImage(File file, Integer albumId);
86+
protected abstract Integer createImage(File file, Integer albumId) throws IOException;
8787
}

remotesync-api/src/main/java/org/piwigo/remotesync/api/util/FileUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public static File getFile(Class<?> clazz, String resourceName, boolean checkExi
116116

117117
return file;
118118
} catch (Exception exception) {
119-
logger.error(exception.getMessage(), exception);
119+
logger.debug(exception.getMessage(), exception);
120120
return null;
121121
}
122122
}

remotesync-api/src/test/java/org/piwigo/remotesync/api/test/APITest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public void testFakePasswordConverter() throws ParseException {
119119
doTestFakePasswordConverter("a");
120120
doTestFakePasswordConverter("1");
121121
doTestFakePasswordConverter("password");
122-
doTestFakePasswordConverter("1234567890&é(-è_çà)^$ù*,;:!?./§µ%MP");
122+
doTestFakePasswordConverter("1234567890");
123123
}
124124

125125
private void doTestFakePasswordConverter(String password) throws ParseException {

remotesync-api/src/test/java/org/piwigo/remotesync/api/test/AbstractTestCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
public abstract class AbstractTestCase extends TestCase {
3030

3131
static {
32-
((ch.qos.logback.classic.Logger) LoggerFactory.getLogger("ROOT")).setLevel(Level.INFO);
32+
((ch.qos.logback.classic.Logger) LoggerFactory.getLogger("ROOT")).setLevel(RemotesyncAPIAllTests.TEST_LOG_LEVEL);
3333
}
3434

3535
private static IClient client;

remotesync-api/src/test/java/org/piwigo/remotesync/api/test/RemotesyncAPIAllTests.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,20 @@
1010
******************************************************************************/
1111
package org.piwigo.remotesync.api.test;
1212

13-
import org.slf4j.LoggerFactory;
14-
15-
import ch.qos.logback.classic.Level;
1613
import junit.framework.Test;
1714
import junit.framework.TestCase;
1815
import junit.framework.TestSuite;
16+
import ch.qos.logback.classic.Level;
1917

2018
public class RemotesyncAPIAllTests extends TestCase {
2119

20+
//when using mvn
21+
public static Level TEST_LOG_LEVEL = Level.INFO;
22+
2223
public static Test suite() {
23-
((ch.qos.logback.classic.Logger) LoggerFactory.getLogger("ROOT")).setLevel(Level.DEBUG);
24-
24+
//debug only when using suite
25+
TEST_LOG_LEVEL = Level.DEBUG;
26+
2527
TestSuite suite = new TestSuite(RemotesyncAPIAllTests.class.getName());
2628
// $JUnit-BEGIN$
2729
suite.addTestSuite(FileUtilTest.class);

remotesync-ui/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<dependency>
1818
<groupId>piwigo</groupId>
1919
<artifactId>remotesync-api</artifactId>
20-
<version>0.0.8</version>
20+
<version>0.0.9</version>
2121
</dependency>
2222
<dependency>
2323
<groupId>org.apache.pivot</groupId>
@@ -73,7 +73,7 @@
7373
<parent>
7474
<groupId>piwigo</groupId>
7575
<artifactId>remotesync</artifactId>
76-
<version>0.0.8</version>
76+
<version>0.0.9</version>
7777
<relativePath>../remotesync</relativePath>
7878
</parent>
7979
</project>

remotesync/pom.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@
1414
<groupId>piwigo</groupId>
1515
<artifactId>remotesync</artifactId>
1616
<name>Piwigo Remote Sync</name>
17-
<version>0.0.8</version>
17+
<version>0.0.9</version>
1818
<packaging>pom</packaging>
19+
<properties>
20+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
21+
</properties>
1922
<modules>
2023
<module>../remotesync-api</module>
2124
<module>../remotesync-ui</module>

0 commit comments

Comments
 (0)