Skip to content

Commit

Permalink
New version 0.0.14
Browse files Browse the repository at this point in the history
  • Loading branch information
Valentin BAIZEAU authored and Valentin BAIZEAU committed Jul 4, 2019
1 parent 04cd43c commit 6753db1
Show file tree
Hide file tree
Showing 13 changed files with 196 additions and 53 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.13</version>
<version>0.0.14</version>
<relativePath>../remotesync</relativePath>
</parent>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,35 @@
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);
}

@Override
protected <T extends BasicResponse> void checkRequestAuthorization(AbstractRequest<T> 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())
Expand All @@ -40,9 +51,16 @@ protected <T extends BasicResponse> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class DryRunClient extends AbstractClient {

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

@SuppressWarnings("deprecation")
@Override
public <T extends BasicResponse> T doSendRequest(AbstractRequest<T> request) throws ClientServerException {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -217,6 +218,7 @@ protected CloseableHttpClient getHttpClient() throws Exception {
httpClientBuilder.setSSLSocketFactory(new SSLConnectionSocketFactory(sslContextBuilder.build()));
}

httpClientBuilder.setUserAgent("PiwigoRemoteSync " + Constants.CLIENT_VERSION);
httpClient = httpClientBuilder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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();
}
}
Original file line number Diff line number Diff line change
@@ -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<PwgSessionGetStatusResponseLegacy> {

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<PwgSessionGetStatusResponseLegacy> getReturnType() {
return PwgSessionGetStatusResponseLegacy.class;
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
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.13</version>
<version>0.0.14</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.13</version>
<version>0.0.14</version>
<relativePath>../remotesync</relativePath>
</parent>
</project>
6 changes: 3 additions & 3 deletions 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.13</version>
<version>0.0.14</version>
<packaging>pom</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -46,8 +46,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
Expand Down

0 comments on commit 6753db1

Please sign in to comment.