diff --git a/remotesync-api/pom.xml b/remotesync-api/pom.xml
index 4f2ccd1..9e71fac 100644
--- a/remotesync-api/pom.xml
+++ b/remotesync-api/pom.xml
@@ -143,7 +143,7 @@
piwigo
remotesync
- 0.0.13
+ 0.0.14
../remotesync
diff --git a/remotesync-api/src/main/java/org/piwigo/remotesync/api/API.java b/remotesync-api/src/main/java/org/piwigo/remotesync/api/API.java
index 7fb9a77..ede62f4 100644
--- a/remotesync-api/src/main/java/org/piwigo/remotesync/api/API.java
+++ b/remotesync-api/src/main/java/org/piwigo/remotesync/api/API.java
@@ -10,7 +10,6 @@
******************************************************************************/
package org.piwigo.remotesync.api;
-import org.piwigo.remotesync.api.AbstractAPI;
import org.piwigo.remotesync.api.client.AuthenticatedWSClient;
import org.piwigo.remotesync.api.exception.ClientServerException;
import org.piwigo.remotesync.api.request.PwgImagesAddAllChunksRequest;
diff --git a/remotesync-api/src/main/java/org/piwigo/remotesync/api/Constants.java b/remotesync-api/src/main/java/org/piwigo/remotesync/api/Constants.java
index 90bbe1d..9dc706a 100644
--- a/remotesync-api/src/main/java/org/piwigo/remotesync/api/Constants.java
+++ b/remotesync-api/src/main/java/org/piwigo/remotesync/api/Constants.java
@@ -41,6 +41,13 @@ public boolean accept(File file) {
}
}
+
+ /**
+ * Added some constant to define the current version
+ * Used to build the matching user-agent
+ * @since v.0.0.14
+ */
+ public static final String CLIENT_VERSION = "0.0.14";
public static final String DIRECTORY_DEFAULT = ConfigurationUtil.INSTANCE.getUserCurrentDirectory().getAbsolutePath();
diff --git a/remotesync-api/src/main/java/org/piwigo/remotesync/api/client/AuthenticatedWSClient.java b/remotesync-api/src/main/java/org/piwigo/remotesync/api/client/AuthenticatedWSClient.java
index 06427c9..db09542 100644
--- a/remotesync-api/src/main/java/org/piwigo/remotesync/api/client/AuthenticatedWSClient.java
+++ b/remotesync-api/src/main/java/org/piwigo/remotesync/api/client/AuthenticatedWSClient.java
@@ -14,17 +14,23 @@
import org.piwigo.remotesync.api.exception.ClientException;
import org.piwigo.remotesync.api.exception.ClientServerException;
import org.piwigo.remotesync.api.request.AbstractRequest;
+import org.piwigo.remotesync.api.request.PwgGetVersionRequest;
import org.piwigo.remotesync.api.request.PwgSessionGetStatusRequest;
import org.piwigo.remotesync.api.request.PwgSessionLoginRequest;
import org.piwigo.remotesync.api.request.PwgSessionLogoutRequest;
import org.piwigo.remotesync.api.response.BasicResponse;
-import org.piwigo.remotesync.api.response.PwgSessionGetStatusResponse;
+import org.piwigo.remotesync.api.response.PwgGetVersionResponse;
+import org.piwigo.remotesync.legacy.PwgSessionGetStatusRequestLegacy;
+import org.piwigo.remotesync.legacy.PwgSessionGetStatusResponseLegacy;
+import org.piwigo.remotesync.legacy.VersionParser;
//TODO handle session timeout
public class AuthenticatedWSClient extends WSClient {
- private PwgSessionGetStatusResponse sessionGetStatusResponse;
-
+ private PwgSessionGetStatusResponseLegacy sessionGetStatusResponse;
+ private PwgGetVersionResponse piwigoVersion;
+ private VersionParser versionParser;
+
public AuthenticatedWSClient(IClientConfiguration clientConfiguration) {
super(clientConfiguration);
}
@@ -32,6 +38,11 @@ public AuthenticatedWSClient(IClientConfiguration clientConfiguration) {
@Override
protected void checkRequestAuthorization(AbstractRequest request) throws ClientServerException {
if (request.isAdminOnly() || request.isNeedPwgToken()) {
+ if (piwigoVersion == null)
+ getPiwigoVersion();
+ if (versionParser == null)
+ versionParser = new VersionParser();
+ versionParser.parseVersion(piwigoVersion.version);
if (sessionGetStatusResponse == null)
getSessionStatus();
if (request.isAdminOnly() && !sessionGetStatusResponse.isAdmin())
@@ -40,9 +51,16 @@ protected void checkRequestAuthorization(AbstractReque
request.setPwgToken(sessionGetStatusResponse.pwg_token);
}
}
+
+ private void getPiwigoVersion() throws ClientServerException {
+ piwigoVersion = doSendRequest(new PwgGetVersionRequest());
+ }
private void getSessionStatus() throws ClientServerException {
- sessionGetStatusResponse = doSendRequest(new PwgSessionGetStatusRequest());
+ if (versionParser.getMajorVersion() <= 2 && versionParser.getMinorVersion() <= 8)
+ sessionGetStatusResponse = doSendRequest(new PwgSessionGetStatusRequestLegacy());
+ else
+ sessionGetStatusResponse = doSendRequest(new PwgSessionGetStatusRequest());
}
@Override
diff --git a/remotesync-api/src/main/java/org/piwigo/remotesync/api/client/DryRunClient.java b/remotesync-api/src/main/java/org/piwigo/remotesync/api/client/DryRunClient.java
index 5a4f5cc..eb43a27 100644
--- a/remotesync-api/src/main/java/org/piwigo/remotesync/api/client/DryRunClient.java
+++ b/remotesync-api/src/main/java/org/piwigo/remotesync/api/client/DryRunClient.java
@@ -21,6 +21,7 @@ public class DryRunClient extends AbstractClient {
private static Logger logger = LoggerFactory.getLogger(DryRunClient.class);
+ @SuppressWarnings("deprecation")
@Override
public T doSendRequest(AbstractRequest request) throws ClientServerException {
try {
diff --git a/remotesync-api/src/main/java/org/piwigo/remotesync/api/client/WSClient.java b/remotesync-api/src/main/java/org/piwigo/remotesync/api/client/WSClient.java
index c4cb698..46c3af5 100644
--- a/remotesync-api/src/main/java/org/piwigo/remotesync/api/client/WSClient.java
+++ b/remotesync-api/src/main/java/org/piwigo/remotesync/api/client/WSClient.java
@@ -35,6 +35,7 @@
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
+import org.piwigo.remotesync.api.Constants;
import org.piwigo.remotesync.api.IClient;
import org.piwigo.remotesync.api.IClientConfiguration;
import org.piwigo.remotesync.api.exception.ClientException;
@@ -217,6 +218,7 @@ protected CloseableHttpClient getHttpClient() throws Exception {
httpClientBuilder.setSSLSocketFactory(new SSLConnectionSocketFactory(sslContextBuilder.build()));
}
+ httpClientBuilder.setUserAgent("PiwigoRemoteSync " + Constants.CLIENT_VERSION);
httpClient = httpClientBuilder.build();
}
diff --git a/remotesync-api/src/main/java/org/piwigo/remotesync/api/response/PwgSessionGetStatusResponse.java b/remotesync-api/src/main/java/org/piwigo/remotesync/api/response/PwgSessionGetStatusResponse.java
index 1f78aa1..2b596b4 100644
--- a/remotesync-api/src/main/java/org/piwigo/remotesync/api/response/PwgSessionGetStatusResponse.java
+++ b/remotesync-api/src/main/java/org/piwigo/remotesync/api/response/PwgSessionGetStatusResponse.java
@@ -10,49 +10,18 @@
******************************************************************************/
package org.piwigo.remotesync.api.response;
-import org.piwigo.remotesync.api.Constants;
-import org.simpleframework.xml.Element;
+import java.util.List;
-public class PwgSessionGetStatusResponse extends BasicResponse {
- @Element
- public String username;
+import org.piwigo.remotesync.legacy.PwgSessionGetStatusResponseLegacy;
+import org.simpleframework.xml.ElementList;
- @Element
- public String status;
+public class PwgSessionGetStatusResponse extends PwgSessionGetStatusResponseLegacy {
- @Element
- public String theme;
+ /**
+ * Casting our list of available_sizes here as it will not be used by the tool
+ * @since v0.0.14
+ */
+ @ElementList(required=false)
+ public List available_sizes;
- @Element
- public String language;
-
- @Element
- public String pwg_token;
-
- @Element
- public String charset;
-
- @Element
- public String current_datetime;
-
- @Element(required=false)
- public String version;
-
- @Element(required=false)
- public String upload_file_types;
-
- @Element(required=false)
- public String upload_form_chunk_size;
-
- public boolean isAdmin() {
- return Constants.UserType.admin.toString().equals(status) || Constants.UserType.webmaster.toString().equals(status);
- }
-
- public boolean isGuest() {
- return Constants.UserType.guest.toString().equals(status);
- }
-
- public boolean isLogged() {
- return !isGuest();
- }
}
diff --git a/remotesync-api/src/main/java/org/piwigo/remotesync/legacy/PwgSessionGetStatusRequestLegacy.java b/remotesync-api/src/main/java/org/piwigo/remotesync/legacy/PwgSessionGetStatusRequestLegacy.java
new file mode 100644
index 0000000..805f38d
--- /dev/null
+++ b/remotesync-api/src/main/java/org/piwigo/remotesync/legacy/PwgSessionGetStatusRequestLegacy.java
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Matthieu Helleboid.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the GNU Public License v2.0
+ * which accompanies this distribution, and is available at
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ *
+ * Contributors:
+ * Matthieu Helleboid - initial API and implementation
+ ******************************************************************************/
+package org.piwigo.remotesync.legacy;
+
+import org.piwigo.remotesync.api.request.AbstractRequest;
+
+/**
+Gets information about the current session. Also provides a token useable with admin methods.
+**/
+@org.piwigo.remotesync.generator.Generated
+public class PwgSessionGetStatusRequestLegacy extends AbstractRequest {
+
+ public PwgSessionGetStatusRequestLegacy() {
+ }
+
+ public boolean isNeedPwgToken() {
+ return false;
+ }
+
+ public boolean isAdminOnly() {
+ return false;
+ };
+
+ public boolean isPostOnly() {
+ return false;
+ };
+
+ public String getWSMethodName() {
+ return "pwg.session.getStatus";
+ }
+
+ public Class getReturnType() {
+ return PwgSessionGetStatusResponseLegacy.class;
+ }
+}
diff --git a/remotesync-api/src/main/java/org/piwigo/remotesync/legacy/PwgSessionGetStatusResponseLegacy.java b/remotesync-api/src/main/java/org/piwigo/remotesync/legacy/PwgSessionGetStatusResponseLegacy.java
new file mode 100644
index 0000000..3d68eb7
--- /dev/null
+++ b/remotesync-api/src/main/java/org/piwigo/remotesync/legacy/PwgSessionGetStatusResponseLegacy.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Matthieu Helleboid.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the GNU Public License v2.0
+ * which accompanies this distribution, and is available at
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ *
+ * Contributors:
+ * Matthieu Helleboid - initial API and implementation
+ ******************************************************************************/
+package org.piwigo.remotesync.legacy;
+
+
+import org.piwigo.remotesync.api.Constants;
+import org.piwigo.remotesync.api.response.BasicResponse;
+import org.simpleframework.xml.Element;
+
+public class PwgSessionGetStatusResponseLegacy extends BasicResponse {
+ @Element
+ public String username;
+
+ @Element
+ public String status;
+
+ @Element
+ public String theme;
+
+ @Element
+ public String language;
+
+ @Element
+ public String pwg_token;
+
+ @Element
+ public String charset;
+
+ @Element
+ public String current_datetime;
+
+ @Element(required=false)
+ public String version;
+
+ @Element(required=false)
+ public String upload_file_types;
+
+ @Element(required=false)
+ public String upload_form_chunk_size;
+
+ public boolean isAdmin() {
+ return Constants.UserType.admin.toString().equals(status) || Constants.UserType.webmaster.toString().equals(status);
+ }
+
+ public boolean isGuest() {
+ return Constants.UserType.guest.toString().equals(status);
+ }
+
+ public boolean isLogged() {
+ return !isGuest();
+ }
+}
diff --git a/remotesync-api/src/main/java/org/piwigo/remotesync/legacy/VersionParser.java b/remotesync-api/src/main/java/org/piwigo/remotesync/legacy/VersionParser.java
new file mode 100644
index 0000000..18b7e93
--- /dev/null
+++ b/remotesync-api/src/main/java/org/piwigo/remotesync/legacy/VersionParser.java
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Matthieu Helleboid.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the GNU Public License v2.0
+ * which accompanies this distribution, and is available at
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ *
+ * Contributors:
+ * Matthieu Helleboid - initial API and implementation
+ ******************************************************************************/
+package org.piwigo.remotesync.legacy;
+
+import java.util.regex.Pattern;
+
+public class VersionParser
+{
+
+ private int major;
+ private int minor;
+ private int build;
+
+ public void parseVersion(String version)
+ {
+ String[] parts = version.split(Pattern.quote("."));
+
+ major = Integer.parseInt(parts[0]);
+ minor = Integer.parseInt(parts[1]);
+ build = Integer.parseInt(parts[2]);
+ }
+
+ public int getMajorVersion()
+ {
+ return (major);
+ }
+
+ public int getMinorVersion()
+ {
+ return (minor);
+ }
+
+ public int getBuildVersion()
+ {
+ return (build);
+ }
+}
diff --git a/remotesync-api/src/test/java/org/piwigo/remotesync/api/test/AbstractTestCase.java b/remotesync-api/src/test/java/org/piwigo/remotesync/api/test/AbstractTestCase.java
index d73f180..af743f0 100644
--- a/remotesync-api/src/test/java/org/piwigo/remotesync/api/test/AbstractTestCase.java
+++ b/remotesync-api/src/test/java/org/piwigo/remotesync/api/test/AbstractTestCase.java
@@ -23,7 +23,6 @@
import org.piwigo.remotesync.api.util.FileUtil;
import org.slf4j.LoggerFactory;
-import ch.qos.logback.classic.Level;
import junit.framework.TestCase;
public abstract class AbstractTestCase extends TestCase {
diff --git a/remotesync-ui/pom.xml b/remotesync-ui/pom.xml
index 95fc728..a9ed8fc 100644
--- a/remotesync-ui/pom.xml
+++ b/remotesync-ui/pom.xml
@@ -17,7 +17,7 @@
piwigo
remotesync-api
- 0.0.13
+ 0.0.14
org.apache.pivot
@@ -73,7 +73,7 @@
piwigo
remotesync
- 0.0.13
+ 0.0.14
../remotesync
diff --git a/remotesync/pom.xml b/remotesync/pom.xml
index f38ff41..98beaee 100644
--- a/remotesync/pom.xml
+++ b/remotesync/pom.xml
@@ -14,7 +14,7 @@
piwigo
remotesync
Piwigo Remote Sync
- 0.0.13
+ 0.0.14
pom
UTF-8
@@ -46,8 +46,8 @@
maven-compiler-plugin
3.2
-
- 1.6
+
+ 1.7