From 4968ca6e62fde1768a138d7e295f032573db8088 Mon Sep 17 00:00:00 2001 From: theScrabi Date: Tue, 17 Jul 2018 09:31:39 +0200 Subject: [PATCH] make the new merged changes from bitfire compile --- build.gradle | 1 + dav4android | 2 +- .../android/lib/common/OwnCloudClient.java | 1 + .../common/http/methods/HttpBaseMethod.java | 2 + .../http/methods/webdav/CopyMethod.java | 11 +-- .../common/http/methods/webdav/DavMethod.java | 49 ++++++++----- .../http/methods/webdav/MkColMethod.java | 11 +-- .../http/methods/webdav/MoveMethod.java | 12 ++-- .../http/methods/webdav/PropfindMethod.java | 59 +++++++++++----- .../common/http/methods/webdav/PutMethod.java | 15 ++-- .../files/ReadRemoteFileOperation.java | 5 +- .../files/ReadRemoteFolderOperation.java | 5 +- .../lib/resources/files/RemoteFile.java | 68 +++++++++++-------- .../users/GetRemoteUserQuotaOperation.java | 19 ++++-- 14 files changed, 164 insertions(+), 96 deletions(-) diff --git a/build.gradle b/build.gradle index 0b0263c2..e6a9c02d 100644 --- a/build.gradle +++ b/build.gradle @@ -24,6 +24,7 @@ dependencies { // Used for network and database debuging debugApi 'com.facebook.stetho:stetho:1.5.0' debugApi 'com.facebook.stetho:stetho-okhttp3:1.5.0' + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.2.51" } android { diff --git a/dav4android b/dav4android index c6c06a14..da434d76 160000 --- a/dav4android +++ b/dav4android @@ -1 +1 @@ -Subproject commit c6c06a144a1eaf3a75035dfe8700c42b86b0d223 +Subproject commit da434d7693db7d4cfd434ee22d0d336f37f4b6f8 diff --git a/src/com/owncloud/android/lib/common/OwnCloudClient.java b/src/com/owncloud/android/lib/common/OwnCloudClient.java index 79d45023..d67fee6e 100644 --- a/src/com/owncloud/android/lib/common/OwnCloudClient.java +++ b/src/com/owncloud/android/lib/common/OwnCloudClient.java @@ -36,6 +36,7 @@ import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory import com.owncloud.android.lib.common.http.HttpClient; import com.owncloud.android.lib.common.http.HttpConstants; import com.owncloud.android.lib.common.http.methods.HttpBaseMethod; +import com.owncloud.android.lib.common.http.methods.webdav.CopyMethod; import com.owncloud.android.lib.common.network.RedirectionPath; import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.resources.status.OwnCloudVersion; diff --git a/src/com/owncloud/android/lib/common/http/methods/HttpBaseMethod.java b/src/com/owncloud/android/lib/common/http/methods/HttpBaseMethod.java index 7ea9b3e1..aaadcebf 100644 --- a/src/com/owncloud/android/lib/common/http/methods/HttpBaseMethod.java +++ b/src/com/owncloud/android/lib/common/http/methods/HttpBaseMethod.java @@ -52,9 +52,11 @@ public abstract class HttpBaseMethod { protected RequestBody mRequestBody; protected Response mResponse; protected Call mCall; + protected URL mUrl; protected HttpBaseMethod (URL url) { mOkHttpClient = HttpClient.getOkHttpClient(); + mUrl = url; mRequest = new Request.Builder() .url(HttpUrl.parse(url.toString())) .build(); diff --git a/src/com/owncloud/android/lib/common/http/methods/webdav/CopyMethod.java b/src/com/owncloud/android/lib/common/http/methods/webdav/CopyMethod.java index c1978c52..ea79deaf 100644 --- a/src/com/owncloud/android/lib/common/http/methods/webdav/CopyMethod.java +++ b/src/com/owncloud/android/lib/common/http/methods/webdav/CopyMethod.java @@ -3,7 +3,10 @@ package com.owncloud.android.lib.common.http.methods.webdav; import java.net.URL; import at.bitfire.dav4android.exception.UnauthorizedException; +import kotlin.Unit; +import kotlin.jvm.functions.Function1; import okhttp3.HttpUrl; +import okhttp3.Response; public class CopyMethod extends DavMethod { @@ -19,10 +22,10 @@ public class CopyMethod extends DavMethod { @Override public int onExecute() throws Exception { try { - mDavResource.copy(destinationUrl, forceOverride); - - mRequest = mDavResource.getRequest(); - mResponse = mDavResource.getResponse(); + mDavResource.copy(destinationUrl, forceOverride, response -> { + mResponse = response; + return Unit.INSTANCE; + }); } catch (UnauthorizedException davException) { // Do nothing, we will use the 401 code to handle the situation diff --git a/src/com/owncloud/android/lib/common/http/methods/webdav/DavMethod.java b/src/com/owncloud/android/lib/common/http/methods/webdav/DavMethod.java index f10a7ddb..1c827b88 100644 --- a/src/com/owncloud/android/lib/common/http/methods/webdav/DavMethod.java +++ b/src/com/owncloud/android/lib/common/http/methods/webdav/DavMethod.java @@ -30,6 +30,7 @@ import com.owncloud.android.lib.common.http.methods.HttpBaseMethod; import java.net.URL; import java.util.concurrent.TimeUnit; +import at.bitfire.dav4android.Constants; import at.bitfire.dav4android.DavOCResource; import at.bitfire.dav4android.DavResource; import at.bitfire.dav4android.exception.RedirectException; @@ -47,14 +48,14 @@ public abstract class DavMethod extends HttpBaseMethod { super(url); mDavResource = new DavOCResource( mOkHttpClient, - HttpUrl.parse(url.toString())); - mDavResource.setFollowRedirects(false); + HttpUrl.parse(mUrl.toString()), + Constants.INSTANCE.getLog()); } @Override public void abort() { - mDavResource.cancelCall(); + //TODO: abort here } @Override @@ -62,7 +63,6 @@ public abstract class DavMethod extends HttpBaseMethod { try { return onExecute(); } catch(RedirectException e) { - mResponse = getDavResource().getResponse(); return getStatusCode(); } } @@ -74,22 +74,38 @@ public abstract class DavMethod extends HttpBaseMethod { // Connection parameters @Override public void setReadTimeout(long readTimeout, TimeUnit timeUnit) { - mDavResource.setReadTimeout(readTimeout, timeUnit); + super.setReadTimeout(readTimeout, timeUnit); + mDavResource = new DavOCResource( + mOkHttpClient, + HttpUrl.parse(mUrl.toString()), + Constants.INSTANCE.getLog()); } @Override public void setConnectionTimeout(long connectionTimeout, TimeUnit timeUnit) { - mDavResource.setConnectionTimeout(connectionTimeout, timeUnit); + super.setConnectionTimeout(connectionTimeout, timeUnit); + mDavResource = new DavOCResource( + mOkHttpClient, + HttpUrl.parse(mUrl.toString()), + Constants.INSTANCE.getLog()); } @Override public void setFollowRedirects(boolean followRedirects) { - mDavResource.setFollowRedirects(followRedirects); + super.setFollowRedirects(followRedirects); + mDavResource = new DavOCResource( + mOkHttpClient, + HttpUrl.parse(mUrl.toString()), + Constants.INSTANCE.getLog()); } @Override public void setRetryOnConnectionFailure(boolean retryOnConnectionFailure) { - mDavResource.setRetryOnConnectionFailure(retryOnConnectionFailure); + super.setRetryOnConnectionFailure(retryOnConnectionFailure); + mDavResource = new DavOCResource( + mOkHttpClient, + HttpUrl.parse(mUrl.toString()), + Constants.INSTANCE.getLog()); } ////////////////////////////// @@ -98,20 +114,19 @@ public abstract class DavMethod extends HttpBaseMethod { @Override public boolean getRetryOnConnectionFailure() { - return mDavResource.isRetryOnConnectionFailure(); + return false; //TODO: implement me } @Override public boolean isAborted() { - return mDavResource.isCallAborted(); + return true; //TODO: implement me } - - public DavResource getDavResource() { - return mDavResource; - } - - public void setUrl(HttpUrl url) { - mDavResource = new DavOCResource(mOkHttpClient, url); + public void setUrl(URL url) { + mUrl = url; + mDavResource = new DavOCResource( + mOkHttpClient, + HttpUrl.parse(mUrl.toString()), + Constants.INSTANCE.getLog()); } } \ No newline at end of file diff --git a/src/com/owncloud/android/lib/common/http/methods/webdav/MkColMethod.java b/src/com/owncloud/android/lib/common/http/methods/webdav/MkColMethod.java index ace87d67..54a51763 100644 --- a/src/com/owncloud/android/lib/common/http/methods/webdav/MkColMethod.java +++ b/src/com/owncloud/android/lib/common/http/methods/webdav/MkColMethod.java @@ -3,6 +3,9 @@ package com.owncloud.android.lib.common.http.methods.webdav; import java.net.URL; import at.bitfire.dav4android.exception.UnauthorizedException; +import kotlin.Unit; +import kotlin.jvm.functions.Function1; +import okhttp3.Response; public class MkColMethod extends DavMethod { public MkColMethod(URL url) { @@ -12,10 +15,10 @@ public class MkColMethod extends DavMethod { @Override public int onExecute() throws Exception { try { - mDavResource.mkCol(null); - - mRequest = mDavResource.getRequest(); - mResponse = mDavResource.getResponse(); + mDavResource.mkCol(null, response -> { + mResponse = response; + return Unit.INSTANCE; + }); } catch (UnauthorizedException davException) { // Do nothing, we will use the 401 code to handle the situation diff --git a/src/com/owncloud/android/lib/common/http/methods/webdav/MoveMethod.java b/src/com/owncloud/android/lib/common/http/methods/webdav/MoveMethod.java index be4cfa34..9004f8a1 100644 --- a/src/com/owncloud/android/lib/common/http/methods/webdav/MoveMethod.java +++ b/src/com/owncloud/android/lib/common/http/methods/webdav/MoveMethod.java @@ -5,6 +5,9 @@ import com.owncloud.android.lib.common.http.HttpConstants; import java.net.URL; import at.bitfire.dav4android.exception.UnauthorizedException; +import kotlin.Unit; +import kotlin.jvm.functions.Function1; +import okhttp3.Response; public class MoveMethod extends DavMethod { final String destinationUrl; @@ -23,11 +26,10 @@ public class MoveMethod extends DavMethod { destinationUrl, forceOverride, super.getRequestHeader(HttpConstants.OC_TOTAL_LENGTH_HEADER), - super.getRequestHeader(HttpConstants.OC_X_OC_MTIME_HEADER) - ); - - mRequest = mDavResource.getRequest(); - mResponse = mDavResource.getResponse(); + super.getRequestHeader(HttpConstants.OC_X_OC_MTIME_HEADER), response -> { + mResponse = response; + return Unit.INSTANCE; + }); } catch (UnauthorizedException davException) { // Do nothing, we will use the 401 code to handle the situation diff --git a/src/com/owncloud/android/lib/common/http/methods/webdav/PropfindMethod.java b/src/com/owncloud/android/lib/common/http/methods/webdav/PropfindMethod.java index 29560612..7962427b 100644 --- a/src/com/owncloud/android/lib/common/http/methods/webdav/PropfindMethod.java +++ b/src/com/owncloud/android/lib/common/http/methods/webdav/PropfindMethod.java @@ -26,14 +26,13 @@ package com.owncloud.android.lib.common.http.methods.webdav; import java.io.IOException; import java.net.URL; -import java.util.Set; - -import at.bitfire.dav4android.DavResource; +import java.util.ArrayList; +import java.util.List; import at.bitfire.dav4android.Property; +import at.bitfire.dav4android.Response; import at.bitfire.dav4android.exception.DavException; -import at.bitfire.dav4android.exception.HttpException; import at.bitfire.dav4android.exception.UnauthorizedException; -import okhttp3.HttpUrl; +import kotlin.Unit; /** * Propfind calls wrapper @@ -41,28 +40,48 @@ import okhttp3.HttpUrl; */ public class PropfindMethod extends DavMethod { - private int mDepth; - private Property.Name[] mProperties; - private Set mMembers; + // request + private final int mDepth; + private final Property.Name[] mPropertiesToRequest; - public PropfindMethod(URL url, int depth, Property.Name[] properties) { + // response + private final List mMembers; + private Response mRoot; + + public PropfindMethod(URL url, int depth, Property.Name[] propertiesToRequest) { super(url); mDepth = depth; - mProperties = properties; - }; + mPropertiesToRequest = propertiesToRequest; + mMembers = new ArrayList<>(); + mRoot = null; + } @Override - public int onExecute() throws IOException, HttpException, DavException { + public int onExecute() throws IOException, DavException { try { - mDavResource.propfind(mDepth, mProperties); - mMembers = mDavResource.getMembers(); + mDavResource.propfind(mDepth, mPropertiesToRequest, + (Response response, Response.HrefRelation hrefRelation) -> { + switch (hrefRelation) { + case MEMBER: + mMembers.add(response); + break; + case SELF: + mRoot = response; + break; + case OTHER: + default: + } + + return Unit.INSTANCE; + }, response -> { + mResponse = response; + return Unit.INSTANCE; + }); } catch (UnauthorizedException davException) { // Do nothing, we will use the 401 code to handle the situation + return davException.getCode(); } - mRequest = mDavResource.getRequest(); - mResponse = mDavResource.getResponse(); - return super.getStatusCode(); } @@ -70,7 +89,11 @@ public class PropfindMethod extends DavMethod { return mDepth; } - public Set getMembers() { + public List getMembers() { return mMembers; } + + public Response getRoot() { + return mRoot; + } } \ No newline at end of file diff --git a/src/com/owncloud/android/lib/common/http/methods/webdav/PutMethod.java b/src/com/owncloud/android/lib/common/http/methods/webdav/PutMethod.java index 80a48ed1..9de2f324 100644 --- a/src/com/owncloud/android/lib/common/http/methods/webdav/PutMethod.java +++ b/src/com/owncloud/android/lib/common/http/methods/webdav/PutMethod.java @@ -32,8 +32,11 @@ import java.net.URL; import at.bitfire.dav4android.exception.DavException; import at.bitfire.dav4android.exception.HttpException; import at.bitfire.dav4android.exception.UnauthorizedException; +import kotlin.Unit; +import kotlin.jvm.functions.Function1; import okhttp3.HttpUrl; import okhttp3.RequestBody; +import okhttp3.Response; /** * Put calls wrapper @@ -51,16 +54,12 @@ public class PutMethod extends DavMethod { mDavResource.put( mRequestBody, super.getRequestHeader(HttpConstants.IF_MATCH_HEADER), - // Save a file not known to exist, guaranteeing that another upload didn't happen - // before, losing the data of the previous put - true, super.getRequestHeader(HttpConstants.CONTENT_TYPE_HEADER), super.getRequestHeader(HttpConstants.OC_TOTAL_LENGTH_HEADER), - super.getRequestHeader(HttpConstants.OC_X_OC_MTIME_HEADER) - ); - - mRequest = mDavResource.getRequest(); - mResponse = mDavResource.getResponse(); + super.getRequestHeader(HttpConstants.OC_X_OC_MTIME_HEADER), response -> { + mResponse = response; + return Unit.INSTANCE; + }); } catch (UnauthorizedException davException) { // Do nothing, we will use the 401 code to handle the situation diff --git a/src/com/owncloud/android/lib/resources/files/ReadRemoteFileOperation.java b/src/com/owncloud/android/lib/resources/files/ReadRemoteFileOperation.java index 7fe15d75..7985d658 100644 --- a/src/com/owncloud/android/lib/resources/files/ReadRemoteFileOperation.java +++ b/src/com/owncloud/android/lib/resources/files/ReadRemoteFileOperation.java @@ -87,10 +87,9 @@ public class ReadRemoteFileOperation extends RemoteOperation { if (status == HttpConstants.HTTP_MULTI_STATUS || status == HttpConstants.HTTP_OK) { - // Parse response - final DavResource resource = propfind.getDavResource(); - final RemoteFile file = new RemoteFile(resource, client.getAccount().getDisplayName()); + final RemoteFile file = new RemoteFile(propfind.getRoot(), + client.getAccount().getDisplayName()); result = new RemoteOperationResult<>(OK); result.setData(file); diff --git a/src/com/owncloud/android/lib/resources/files/ReadRemoteFolderOperation.java b/src/com/owncloud/android/lib/resources/files/ReadRemoteFolderOperation.java index 0d21d1d0..9265abe5 100644 --- a/src/com/owncloud/android/lib/resources/files/ReadRemoteFolderOperation.java +++ b/src/com/owncloud/android/lib/resources/files/ReadRemoteFolderOperation.java @@ -38,6 +38,7 @@ import java.net.URL; import java.util.ArrayList; import at.bitfire.dav4android.DavResource; +import at.bitfire.dav4android.Response; import static com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode.OK; @@ -88,11 +89,11 @@ public class ReadRemoteFolderOperation extends RemoteOperation properties = davResource.getProperties(); + + for(Property property : properties) { + if(property instanceof CreationDate) + this.setCreationTimestamp( + Long.parseLong(((CreationDate) property).getCreationDate())); + if(property instanceof GetContentLength) + this.setLength(((GetContentLength) property).getContentLength()); + if(property instanceof GetContentType) + this.setMimeType(((GetContentType) property).getType()); + if(property instanceof GetLastModified) + this.setModifiedTimestamp(((GetLastModified) property).getLastModified()); + if(property instanceof GetETag) + this.setEtag(((GetETag) property).getETag()); + if(property instanceof OCPermissions) + this.setPermissions(((OCPermissions) property).getPermission()); + if(property instanceof OCId) + this.setRemoteId(((OCId) property).getId()); + if(property instanceof OCSize) + this.setSize(((OCSize) property).getSize()); + if(property instanceof QuotaUsedBytes) + this.setQuotaUsedBytes( + BigDecimal.valueOf(((QuotaUsedBytes) property).getQuotaUsedBytes())); + if(property instanceof QuotaAvailableBytes) + this.setQuotaAvailableBytes( + BigDecimal.valueOf(((QuotaAvailableBytes) property).getQuotaAvailableBytes())); + if(property instanceof OCPrivatelink) + this.setPrivateLink(((OCPrivatelink) property).getLink()); + } } diff --git a/src/com/owncloud/android/lib/resources/users/GetRemoteUserQuotaOperation.java b/src/com/owncloud/android/lib/resources/users/GetRemoteUserQuotaOperation.java index 27b8330f..2f1b428e 100644 --- a/src/com/owncloud/android/lib/resources/users/GetRemoteUserQuotaOperation.java +++ b/src/com/owncloud/android/lib/resources/users/GetRemoteUserQuotaOperation.java @@ -37,7 +37,9 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.utils.Log_OC; import java.net.URL; +import java.util.List; +import at.bitfire.dav4android.Property; import at.bitfire.dav4android.PropertyCollection; import at.bitfire.dav4android.property.QuotaAvailableBytes; import at.bitfire.dav4android.property.QuotaUsedBytes; @@ -90,13 +92,12 @@ public class GetRemoteUserQuotaOperation extends RemoteOperation(OK); @@ -139,10 +140,16 @@ public class GetRemoteUserQuotaOperation extends RemoteOperation properties) { + long quotaAvailable = 0; + long quotaUsed = 0; - long quotaAvailable = properties.get(QuotaAvailableBytes.class).getQuotaAvailableBytes(); - long quotaUsed = properties.get(QuotaUsedBytes.class).getQuotaUsedBytes(); + for(Property property : properties) { + if(property instanceof QuotaAvailableBytes) + quotaAvailable = ((QuotaAvailableBytes) property).getQuotaAvailableBytes(); + if(property instanceof QuotaUsedBytes) + quotaUsed = ((QuotaUsedBytes) property).getQuotaUsedBytes(); + } // If there's a special case, quota available will contain a negative code // -1, PENDING: Not computed yet, e.g. external storage mounted but folder sizes need scanning