fix: change signatures, remove unneccessary methods
- Change signatures of PCloudImpl, PCloudFile and PCloudFolder to match Google Drive implementation - Remove unneccessary file() and folder() methods (read path directly)
This commit is contained in:
parent
615fe5558e
commit
c958558f50
@ -59,7 +59,7 @@ class PCloudCloudContentRepository extends InterceptingCloudContentRepository<PC
|
||||
private final PCloudImpl cloud;
|
||||
|
||||
public Intercepted(PCloudCloud cloud, Context context, PCloudIdCache idCache) {
|
||||
this.cloud = new PCloudImpl(cloud, context, idCache);
|
||||
this.cloud = new PCloudImpl(context, cloud, idCache);
|
||||
}
|
||||
|
||||
public PCloudFolder root(PCloudCloud cloud) {
|
||||
|
@ -1,54 +1,49 @@
|
||||
package org.cryptomator.data.cloud.pcloud;
|
||||
|
||||
import com.google.api.services.drive.model.File;
|
||||
import com.pcloud.sdk.RemoteEntry;
|
||||
import com.pcloud.sdk.RemoteFile;
|
||||
import com.pcloud.sdk.RemoteFolder;
|
||||
|
||||
import org.cryptomator.util.Optional;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
class PCloudCloudNodeFactory {
|
||||
|
||||
public static PCloudFile file(PCloudFolder parent, RemoteFile metadata) {
|
||||
return new PCloudFile(parent, metadata.fileId(), metadata.name(), getNodePath(parent, metadata.name()), Optional.ofNullable(metadata.size()), Optional.ofNullable(metadata.lastModified()));
|
||||
}
|
||||
|
||||
public static PCloudFile file(PCloudFolder parent, String name, Optional<Long> size, String path) {
|
||||
return new PCloudFile(parent, null, name, path, size, Optional.empty());
|
||||
public static PCloudFile file(PCloudFolder parent, RemoteFile file) {
|
||||
return new PCloudFile(parent, file.name(), getNodePath(parent, file.name()), file.fileId(), Optional.ofNullable(file.size()), Optional.ofNullable(file.lastModified()));
|
||||
}
|
||||
|
||||
public static PCloudFile file(PCloudFolder parent, String name, Optional<Long> size) {
|
||||
return new PCloudFile(parent, null, name, getNodePath(parent, name), size, Optional.empty());
|
||||
return new PCloudFile(parent, name, getNodePath(parent, name), null, size, Optional.empty());
|
||||
}
|
||||
|
||||
public static PCloudFile file(PCloudFolder folder, String name, Optional<Long> size, String path, Long fileId) {
|
||||
return new PCloudFile(folder, fileId, name, path, size, Optional.empty());
|
||||
return new PCloudFile(folder, name, path, fileId, size, Optional.empty());
|
||||
}
|
||||
|
||||
public static PCloudFolder folder(PCloudFolder parent, RemoteFolder metadata) {
|
||||
return new PCloudFolder(parent, metadata.folderId(), metadata.name(), getNodePath(parent, metadata.name()));
|
||||
}
|
||||
|
||||
public static PCloudFolder folder(PCloudFolder parent, String name, String path) {
|
||||
return new PCloudFolder(parent, null, name, path);
|
||||
public static PCloudFolder folder(PCloudFolder parent, RemoteFolder folder) {
|
||||
return new PCloudFolder(parent, folder.name(), getNodePath(parent, folder.name()), folder.folderId());
|
||||
}
|
||||
|
||||
public static PCloudFolder folder(PCloudFolder parent, String name) {
|
||||
return new PCloudFolder(parent, null, name, getNodePath(parent, name));
|
||||
return new PCloudFolder(parent, name, getNodePath(parent, name), null);
|
||||
}
|
||||
|
||||
public static PCloudFolder folder(PCloudFolder parent, String name, String path, Long folderId) {
|
||||
return new PCloudFolder(parent, folderId, name, path);
|
||||
return new PCloudFolder(parent, name, path, folderId);
|
||||
}
|
||||
|
||||
public static String getNodePath(PCloudFolder parent, String name) {
|
||||
return parent.getPath() + "/" + name;
|
||||
}
|
||||
|
||||
public static PCloudNode from(PCloudFolder parent, RemoteEntry metadata) {
|
||||
if (metadata instanceof RemoteFile) {
|
||||
return file(parent, metadata.asFile());
|
||||
public static PCloudNode from(PCloudFolder parent, RemoteEntry remoteEntry) {
|
||||
if (remoteEntry instanceof RemoteFile) {
|
||||
return file(parent, remoteEntry.asFile());
|
||||
} else {
|
||||
return folder(parent, metadata.asFolder());
|
||||
return folder(parent, remoteEntry.asFolder());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,17 +9,17 @@ import java.util.Date;
|
||||
class PCloudFile implements CloudFile, PCloudNode {
|
||||
|
||||
private final PCloudFolder parent;
|
||||
private final Long fileid;
|
||||
private final String name;
|
||||
private final String path;
|
||||
private final Long fileId;
|
||||
private final Optional<Long> size;
|
||||
private final Optional<Date> modified;
|
||||
|
||||
public PCloudFile(PCloudFolder parent, Long fileid, String name, String path, Optional<Long> size, Optional<Date> modified) {
|
||||
public PCloudFile(PCloudFolder parent, String name, String path, Long fileId, Optional<Long> size, Optional<Date> modified) {
|
||||
this.parent = parent;
|
||||
this.fileid = fileid;
|
||||
this.name = name;
|
||||
this.path = path;
|
||||
this.fileId = fileId;
|
||||
this.size = size;
|
||||
this.modified = modified;
|
||||
}
|
||||
@ -29,11 +29,6 @@ class PCloudFile implements CloudFile, PCloudNode {
|
||||
return parent.getCloud();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getId() {
|
||||
return fileid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
@ -44,6 +39,11 @@ class PCloudFile implements CloudFile, PCloudNode {
|
||||
return path;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getId() {
|
||||
return fileId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PCloudFolder getParent() {
|
||||
return parent;
|
||||
|
@ -6,13 +6,13 @@ import org.cryptomator.domain.CloudFolder;
|
||||
class PCloudFolder implements CloudFolder, PCloudNode {
|
||||
|
||||
private final PCloudFolder parent;
|
||||
private final Long folderid;
|
||||
private final String name;
|
||||
private final String path;
|
||||
private final Long folderId;
|
||||
|
||||
public PCloudFolder(PCloudFolder parent, Long folderid, String name, String path) {
|
||||
public PCloudFolder(PCloudFolder parent, String name, String path, Long folderId) {
|
||||
this.parent = parent;
|
||||
this.folderid = folderid;
|
||||
this.folderId = folderId;
|
||||
this.name = name;
|
||||
this.path = path;
|
||||
}
|
||||
@ -22,11 +22,6 @@ class PCloudFolder implements CloudFolder, PCloudNode {
|
||||
return parent.getCloud();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getId() {
|
||||
return folderid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
@ -37,6 +32,11 @@ class PCloudFolder implements CloudFolder, PCloudNode {
|
||||
return path;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getId() {
|
||||
return folderId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PCloudFolder getParent() {
|
||||
return parent;
|
||||
@ -44,6 +44,6 @@ class PCloudFolder implements CloudFolder, PCloudNode {
|
||||
|
||||
@Override
|
||||
public PCloudFolder withCloud(Cloud cloud) {
|
||||
return new PCloudFolder(parent.withCloud(cloud), folderid, name, path);
|
||||
return new PCloudFolder(parent.withCloud(cloud), name, path, folderId);
|
||||
}
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ class PCloudImpl {
|
||||
private final RootPCloudFolder root;
|
||||
private final Context context;
|
||||
|
||||
PCloudImpl(PCloudCloud cloud, Context context, PCloudIdCache idCache) {
|
||||
PCloudImpl(Context context, PCloudCloud cloud, PCloudIdCache idCache) {
|
||||
if (cloud.accessToken() == null) {
|
||||
throw new NoAuthenticationProvidedException(cloud);
|
||||
}
|
||||
@ -129,7 +129,7 @@ class PCloudImpl {
|
||||
return idCache.cache(PCloudCloudNodeFactory.file(parent, file.get().asFile()));
|
||||
}
|
||||
|
||||
return PCloudCloudNodeFactory.file(parent, name, size, parent.getPath() + '/' + name);
|
||||
return PCloudCloudNodeFactory.file(parent, name, size);
|
||||
}
|
||||
|
||||
public PCloudFolder folder(PCloudFolder parent, String name) {
|
||||
@ -147,7 +147,7 @@ class PCloudImpl {
|
||||
if (folder.isPresent()) {
|
||||
return idCache.cache(PCloudCloudNodeFactory.folder(parent, folder.get().asFolder()));
|
||||
}
|
||||
return PCloudCloudNodeFactory.folder(parent, name, parent.getPath() + '/' + name);
|
||||
return PCloudCloudNodeFactory.folder(parent, name);
|
||||
}
|
||||
|
||||
public boolean exists(PCloudNode node) throws ApiError, IOException {
|
||||
@ -195,9 +195,9 @@ class PCloudImpl {
|
||||
if (folder.getParent().getId() == null) {
|
||||
folder = new PCloudFolder( //
|
||||
create(folder.getParent()), //
|
||||
folder.getId(), //
|
||||
folder.getName(), //
|
||||
folder.getPath());
|
||||
folder.getName(), folder.getPath(), folder.getId() //
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
RemoteFolder createdFolder = client() //
|
||||
|
@ -9,7 +9,7 @@ class RootPCloudFolder extends PCloudFolder {
|
||||
private static final long rootFolderId = 0L;
|
||||
|
||||
public RootPCloudFolder(PCloudCloud cloud) {
|
||||
super(null, rootFolderId, "", "");
|
||||
super(null, "", "", rootFolderId);
|
||||
this.cloud = cloud;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user