feat(S3): cleanup S3CloudContentRepository
- use proper signature - add TODO for error handling
This commit is contained in:
parent
4afd6bc703
commit
7d9c20d137
@ -2,10 +2,8 @@ package org.cryptomator.data.cloud.s3;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import com.pcloud.sdk.ApiError;
|
|
||||||
|
|
||||||
import org.cryptomator.data.cloud.InterceptingCloudContentRepository;
|
import org.cryptomator.data.cloud.InterceptingCloudContentRepository;
|
||||||
import org.cryptomator.domain.PCloud;
|
import org.cryptomator.domain.S3Cloud;
|
||||||
import org.cryptomator.domain.exception.BackendException;
|
import org.cryptomator.domain.exception.BackendException;
|
||||||
import org.cryptomator.domain.exception.FatalBackendException;
|
import org.cryptomator.domain.exception.FatalBackendException;
|
||||||
import org.cryptomator.domain.exception.NetworkConnectionException;
|
import org.cryptomator.domain.exception.NetworkConnectionException;
|
||||||
@ -24,56 +22,54 @@ import java.util.List;
|
|||||||
|
|
||||||
import static org.cryptomator.util.ExceptionUtil.contains;
|
import static org.cryptomator.util.ExceptionUtil.contains;
|
||||||
|
|
||||||
class S3CloudContentRepository extends InterceptingCloudContentRepository<PCloud, S3Node, S3Folder, S3File> {
|
class S3CloudContentRepository extends InterceptingCloudContentRepository<S3Cloud, S3Node, S3Folder, S3File> {
|
||||||
|
|
||||||
private final PCloud cloud;
|
private final S3Cloud cloud;
|
||||||
|
|
||||||
public S3CloudContentRepository(PCloud cloud, Context context) {
|
public S3CloudContentRepository(S3Cloud cloud, Context context) {
|
||||||
super(new Intercepted(cloud, context));
|
super(new Intercepted(cloud, context));
|
||||||
this.cloud = cloud;
|
this.cloud = cloud;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: add proper error handling
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void throwWrappedIfRequired(Exception e) throws BackendException {
|
protected void throwWrappedIfRequired(Exception e) throws BackendException {
|
||||||
throwConnectionErrorIfRequired(e);
|
// throwConnectionErrorIfRequired(e);
|
||||||
throwWrongCredentialsExceptionIfRequired(e);
|
// throwWrongCredentialsExceptionIfRequired(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void throwConnectionErrorIfRequired(Exception e) throws NetworkConnectionException {
|
// private void throwConnectionErrorIfRequired(Exception e) throws NetworkConnectionException {
|
||||||
if (contains(e, IOException.class)) {
|
// if (contains(e, IOException.class)) {
|
||||||
throw new NetworkConnectionException(e);
|
// throw new NetworkConnectionException(e);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
// private void throwWrongCredentialsExceptionIfRequired(Exception e) {
|
||||||
|
// if (e instanceof ApiError) {
|
||||||
|
// int errorCode = ((ApiError) e).errorCode();
|
||||||
|
// if (errorCode == PCloudApiError.PCloudApiErrorCodes.INVALID_ACCESS_TOKEN.getValue() //
|
||||||
|
// || errorCode == PCloudApiError.PCloudApiErrorCodes.ACCESS_TOKEN_REVOKED.getValue()) {
|
||||||
|
// throw new WrongCredentialsException(cloud);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
private void throwWrongCredentialsExceptionIfRequired(Exception e) {
|
private static class Intercepted implements CloudContentRepository<S3Cloud, S3Node, S3Folder, S3File> {
|
||||||
if (e instanceof ApiError) {
|
|
||||||
int errorCode = ((ApiError) e).errorCode();
|
|
||||||
if (errorCode == PCloudApiError.PCloudApiErrorCodes.INVALID_ACCESS_TOKEN.getValue() //
|
|
||||||
|| errorCode == PCloudApiError.PCloudApiErrorCodes.ACCESS_TOKEN_REVOKED.getValue()) {
|
|
||||||
throw new WrongCredentialsException(cloud);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class Intercepted implements CloudContentRepository<PCloud, S3Node, S3Folder, S3File> {
|
|
||||||
|
|
||||||
private final S3Impl cloud;
|
private final S3Impl cloud;
|
||||||
|
|
||||||
public Intercepted(PCloud cloud, Context context) {
|
public Intercepted(S3Cloud cloud, Context context) {
|
||||||
this.cloud = new S3Impl(context, cloud);
|
this.cloud = new S3Impl(context, cloud);
|
||||||
}
|
}
|
||||||
|
|
||||||
public S3Folder root(PCloud cloud) {
|
public S3Folder root(S3Cloud cloud) {
|
||||||
return this.cloud.root();
|
return this.cloud.root();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public S3Folder resolve(PCloud cloud, String path) throws BackendException {
|
public S3Folder resolve(S3Cloud cloud, String path) throws BackendException {
|
||||||
try {
|
|
||||||
return this.cloud.resolve(path);
|
return this.cloud.resolve(path);
|
||||||
} catch (IOException ex) {
|
|
||||||
throw new FatalBackendException(ex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -96,20 +92,12 @@ class S3CloudContentRepository extends InterceptingCloudContentRepository<PCloud
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public S3Folder folder(S3Folder parent, String name) throws BackendException {
|
public S3Folder folder(S3Folder parent, String name) throws BackendException {
|
||||||
try {
|
return cloud.folder(parent, name);
|
||||||
return cloud.folder(parent, name);
|
|
||||||
} catch (IOException ex) {
|
|
||||||
throw new FatalBackendException(ex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean exists(S3Node node) throws BackendException {
|
public boolean exists(S3Node node) throws BackendException {
|
||||||
try {
|
|
||||||
return cloud.exists(node);
|
return cloud.exists(node);
|
||||||
} catch (IOException e) {
|
|
||||||
throw new FatalBackendException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -176,16 +164,12 @@ class S3CloudContentRepository extends InterceptingCloudContentRepository<PCloud
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String checkAuthenticationAndRetrieveCurrentAccount(PCloud cloud) throws BackendException {
|
public String checkAuthenticationAndRetrieveCurrentAccount(S3Cloud cloud) throws BackendException {
|
||||||
try {
|
return this.cloud.currentAccount();
|
||||||
return this.cloud.currentAccount();
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new FatalBackendException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void logout(PCloud cloud) throws BackendException {
|
public void logout(S3Cloud cloud) throws BackendException {
|
||||||
// empty
|
// empty
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user