Skip to content

Commit 6753db1

Browse files
Valentin BAIZEAUValentin BAIZEAU
authored andcommitted
New version 0.0.14
1 parent 04cd43c commit 6753db1

13 files changed

Lines changed: 196 additions & 53 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.13</version>
146+
<version>0.0.14</version>
147147
<relativePath>../remotesync</relativePath>
148148
</parent>
149149
</project>

remotesync-api/src/main/java/org/piwigo/remotesync/api/API.java

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

13-
import org.piwigo.remotesync.api.AbstractAPI;
1413
import org.piwigo.remotesync.api.client.AuthenticatedWSClient;
1514
import org.piwigo.remotesync.api.exception.ClientServerException;
1615
import org.piwigo.remotesync.api.request.PwgImagesAddAllChunksRequest;

remotesync-api/src/main/java/org/piwigo/remotesync/api/Constants.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ public boolean accept(File file) {
4141
}
4242

4343
}
44+
45+
/**
46+
* Added some constant to define the current version
47+
* Used to build the matching user-agent
48+
* @since v.0.0.14
49+
*/
50+
public static final String CLIENT_VERSION = "0.0.14";
4451

4552
public static final String DIRECTORY_DEFAULT = ConfigurationUtil.INSTANCE.getUserCurrentDirectory().getAbsolutePath();
4653

remotesync-api/src/main/java/org/piwigo/remotesync/api/client/AuthenticatedWSClient.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,35 @@
1414
import org.piwigo.remotesync.api.exception.ClientException;
1515
import org.piwigo.remotesync.api.exception.ClientServerException;
1616
import org.piwigo.remotesync.api.request.AbstractRequest;
17+
import org.piwigo.remotesync.api.request.PwgGetVersionRequest;
1718
import org.piwigo.remotesync.api.request.PwgSessionGetStatusRequest;
1819
import org.piwigo.remotesync.api.request.PwgSessionLoginRequest;
1920
import org.piwigo.remotesync.api.request.PwgSessionLogoutRequest;
2021
import org.piwigo.remotesync.api.response.BasicResponse;
21-
import org.piwigo.remotesync.api.response.PwgSessionGetStatusResponse;
22+
import org.piwigo.remotesync.api.response.PwgGetVersionResponse;
23+
import org.piwigo.remotesync.legacy.PwgSessionGetStatusRequestLegacy;
24+
import org.piwigo.remotesync.legacy.PwgSessionGetStatusResponseLegacy;
25+
import org.piwigo.remotesync.legacy.VersionParser;
2226

2327
//TODO handle session timeout
2428
public class AuthenticatedWSClient extends WSClient {
2529

26-
private PwgSessionGetStatusResponse sessionGetStatusResponse;
27-
30+
private PwgSessionGetStatusResponseLegacy sessionGetStatusResponse;
31+
private PwgGetVersionResponse piwigoVersion;
32+
private VersionParser versionParser;
33+
2834
public AuthenticatedWSClient(IClientConfiguration clientConfiguration) {
2935
super(clientConfiguration);
3036
}
3137

3238
@Override
3339
protected <T extends BasicResponse> void checkRequestAuthorization(AbstractRequest<T> request) throws ClientServerException {
3440
if (request.isAdminOnly() || request.isNeedPwgToken()) {
41+
if (piwigoVersion == null)
42+
getPiwigoVersion();
43+
if (versionParser == null)
44+
versionParser = new VersionParser();
45+
versionParser.parseVersion(piwigoVersion.version);
3546
if (sessionGetStatusResponse == null)
3647
getSessionStatus();
3748
if (request.isAdminOnly() && !sessionGetStatusResponse.isAdmin())
@@ -40,9 +51,16 @@ protected <T extends BasicResponse> void checkRequestAuthorization(AbstractReque
4051
request.setPwgToken(sessionGetStatusResponse.pwg_token);
4152
}
4253
}
54+
55+
private void getPiwigoVersion() throws ClientServerException {
56+
piwigoVersion = doSendRequest(new PwgGetVersionRequest());
57+
}
4358

4459
private void getSessionStatus() throws ClientServerException {
45-
sessionGetStatusResponse = doSendRequest(new PwgSessionGetStatusRequest());
60+
if (versionParser.getMajorVersion() <= 2 && versionParser.getMinorVersion() <= 8)
61+
sessionGetStatusResponse = doSendRequest(new PwgSessionGetStatusRequestLegacy());
62+
else
63+
sessionGetStatusResponse = doSendRequest(new PwgSessionGetStatusRequest());
4664
}
4765

4866
@Override

remotesync-api/src/main/java/org/piwigo/remotesync/api/client/DryRunClient.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public class DryRunClient extends AbstractClient {
2121

2222
private static Logger logger = LoggerFactory.getLogger(DryRunClient.class);
2323

24+
@SuppressWarnings("deprecation")
2425
@Override
2526
public <T extends BasicResponse> T doSendRequest(AbstractRequest<T> request) throws ClientServerException {
2627
try {

remotesync-api/src/main/java/org/piwigo/remotesync/api/client/WSClient.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.apache.http.impl.client.BasicCredentialsProvider;
3636
import org.apache.http.impl.client.CloseableHttpClient;
3737
import org.apache.http.impl.client.HttpClientBuilder;
38+
import org.piwigo.remotesync.api.Constants;
3839
import org.piwigo.remotesync.api.IClient;
3940
import org.piwigo.remotesync.api.IClientConfiguration;
4041
import org.piwigo.remotesync.api.exception.ClientException;
@@ -217,6 +218,7 @@ protected CloseableHttpClient getHttpClient() throws Exception {
217218
httpClientBuilder.setSSLSocketFactory(new SSLConnectionSocketFactory(sslContextBuilder.build()));
218219
}
219220

221+
httpClientBuilder.setUserAgent("PiwigoRemoteSync " + Constants.CLIENT_VERSION);
220222
httpClient = httpClientBuilder.build();
221223
}
222224

remotesync-api/src/main/java/org/piwigo/remotesync/api/response/PwgSessionGetStatusResponse.java

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

13-
import org.piwigo.remotesync.api.Constants;
14-
import org.simpleframework.xml.Element;
13+
import java.util.List;
1514

16-
public class PwgSessionGetStatusResponse extends BasicResponse {
17-
@Element
18-
public String username;
15+
import org.piwigo.remotesync.legacy.PwgSessionGetStatusResponseLegacy;
16+
import org.simpleframework.xml.ElementList;
1917

20-
@Element
21-
public String status;
18+
public class PwgSessionGetStatusResponse extends PwgSessionGetStatusResponseLegacy {
2219

23-
@Element
24-
public String theme;
20+
/**
21+
* Casting our list of available_sizes here as it will not be used by the tool
22+
* @since v0.0.14
23+
*/
24+
@ElementList(required=false)
25+
public List<String> available_sizes;
2526

26-
@Element
27-
public String language;
28-
29-
@Element
30-
public String pwg_token;
31-
32-
@Element
33-
public String charset;
34-
35-
@Element
36-
public String current_datetime;
37-
38-
@Element(required=false)
39-
public String version;
40-
41-
@Element(required=false)
42-
public String upload_file_types;
43-
44-
@Element(required=false)
45-
public String upload_form_chunk_size;
46-
47-
public boolean isAdmin() {
48-
return Constants.UserType.admin.toString().equals(status) || Constants.UserType.webmaster.toString().equals(status);
49-
}
50-
51-
public boolean isGuest() {
52-
return Constants.UserType.guest.toString().equals(status);
53-
}
54-
55-
public boolean isLogged() {
56-
return !isGuest();
57-
}
5827
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2014 Matthieu Helleboid.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the GNU Public License v2.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
7+
*
8+
* Contributors:
9+
* Matthieu Helleboid - initial API and implementation
10+
******************************************************************************/
11+
package org.piwigo.remotesync.legacy;
12+
13+
import org.piwigo.remotesync.api.request.AbstractRequest;
14+
15+
/**
16+
Gets information about the current session. Also provides a token useable with admin methods.
17+
**/
18+
@org.piwigo.remotesync.generator.Generated
19+
public class PwgSessionGetStatusRequestLegacy extends AbstractRequest<PwgSessionGetStatusResponseLegacy> {
20+
21+
public PwgSessionGetStatusRequestLegacy() {
22+
}
23+
24+
public boolean isNeedPwgToken() {
25+
return false;
26+
}
27+
28+
public boolean isAdminOnly() {
29+
return false;
30+
};
31+
32+
public boolean isPostOnly() {
33+
return false;
34+
};
35+
36+
public String getWSMethodName() {
37+
return "pwg.session.getStatus";
38+
}
39+
40+
public Class<PwgSessionGetStatusResponseLegacy> getReturnType() {
41+
return PwgSessionGetStatusResponseLegacy.class;
42+
}
43+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2014 Matthieu Helleboid.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the GNU Public License v2.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
7+
*
8+
* Contributors:
9+
* Matthieu Helleboid - initial API and implementation
10+
******************************************************************************/
11+
package org.piwigo.remotesync.legacy;
12+
13+
14+
import org.piwigo.remotesync.api.Constants;
15+
import org.piwigo.remotesync.api.response.BasicResponse;
16+
import org.simpleframework.xml.Element;
17+
18+
public class PwgSessionGetStatusResponseLegacy extends BasicResponse {
19+
@Element
20+
public String username;
21+
22+
@Element
23+
public String status;
24+
25+
@Element
26+
public String theme;
27+
28+
@Element
29+
public String language;
30+
31+
@Element
32+
public String pwg_token;
33+
34+
@Element
35+
public String charset;
36+
37+
@Element
38+
public String current_datetime;
39+
40+
@Element(required=false)
41+
public String version;
42+
43+
@Element(required=false)
44+
public String upload_file_types;
45+
46+
@Element(required=false)
47+
public String upload_form_chunk_size;
48+
49+
public boolean isAdmin() {
50+
return Constants.UserType.admin.toString().equals(status) || Constants.UserType.webmaster.toString().equals(status);
51+
}
52+
53+
public boolean isGuest() {
54+
return Constants.UserType.guest.toString().equals(status);
55+
}
56+
57+
public boolean isLogged() {
58+
return !isGuest();
59+
}
60+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2014 Matthieu Helleboid.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the GNU Public License v2.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
7+
*
8+
* Contributors:
9+
* Matthieu Helleboid - initial API and implementation
10+
******************************************************************************/
11+
package org.piwigo.remotesync.legacy;
12+
13+
import java.util.regex.Pattern;
14+
15+
public class VersionParser
16+
{
17+
18+
private int major;
19+
private int minor;
20+
private int build;
21+
22+
public void parseVersion(String version)
23+
{
24+
String[] parts = version.split(Pattern.quote("."));
25+
26+
major = Integer.parseInt(parts[0]);
27+
minor = Integer.parseInt(parts[1]);
28+
build = Integer.parseInt(parts[2]);
29+
}
30+
31+
public int getMajorVersion()
32+
{
33+
return (major);
34+
}
35+
36+
public int getMinorVersion()
37+
{
38+
return (minor);
39+
}
40+
41+
public int getBuildVersion()
42+
{
43+
return (build);
44+
}
45+
}

0 commit comments

Comments
 (0)