Skip to content

Commit

Permalink
Merge branch 'feature/SG-194'
Browse files Browse the repository at this point in the history
  • Loading branch information
dkocher committed Sep 22, 2023
2 parents a077530 + a0ab113 commit 4f0207e
Show file tree
Hide file tree
Showing 196 changed files with 10,636 additions and 2,580 deletions.
2 changes: 1 addition & 1 deletion storegate/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>https://ws1-stage.storegate.se/api/v4.0/swagger</inputSpec>
<inputSpec>https://ws1-stage.storegate.se/api/v4.2/swagger</inputSpec>
<language>java</language>
<output>${project.basedir}</output>
<modelPackage>ch.cyberduck.core.storegate.io.swagger.client.model</modelPackage>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,11 @@
import ch.cyberduck.core.storegate.io.swagger.client.ApiException;
import ch.cyberduck.core.storegate.io.swagger.client.api.FilesApi;
import ch.cyberduck.core.storegate.io.swagger.client.model.File;
import ch.cyberduck.core.storegate.io.swagger.client.model.FileMetadata;
import ch.cyberduck.core.storegate.io.swagger.client.model.RootFolder;

import org.apache.commons.lang3.StringUtils;

public class StoregateAttributesFinderFeature implements AttributesFinder, AttributesAdapter<FileMetadata> {
public class StoregateAttributesFinderFeature implements AttributesFinder, AttributesAdapter<File> {

private final StoregateSession session;
private final StoregateIdProvider fileid;
Expand All @@ -59,14 +58,15 @@ public PathAttributes find(final Path file, final ListProgressListener listener)
throw new NotfoundException(file.getAbsolute());
}
final FilesApi files = new FilesApi(session.getClient());
return this.toAttributes(files.filesGet_1(URIEncoder.encode(fileid.getPrefixedPath(file))));
return this.toAttributes(files.filesGet_0(URIEncoder.encode(fileid.getPrefixedPath(file))));
}
catch(ApiException e) {
throw new StoregateExceptionMappingService(fileid).map("Failure to read attributes of {0}", e, file);
}
}

protected PathAttributes toAttributes(final File f) {
@Override
public PathAttributes toAttributes(final File f) {
final PathAttributes attrs = new PathAttributes();
if(0 != f.getModified().getMillis()) {
attrs.setModificationDate(f.getModified().getMillis());
Expand All @@ -80,53 +80,37 @@ protected PathAttributes toAttributes(final File f) {
else {
attrs.setCreationDate(f.getUploaded().getMillis());
}
attrs.setSize(f.getSize());
if((f.getFlags() & 4) == 4) {
// This item is locked by some user
attrs.setLockId(Boolean.TRUE.toString());
}
if((f.getFlags() & 512) == 512) {
// This item is hidden
attrs.setHidden(true);
}
// NoAccess 0
// ReadOnly 1
// ReadWrite 2
// Synchronize 4 Read, write access and permission to syncronize using desktop client.
// FullControl 99
final Permission permission;
if((f.getPermission() & 2) == 2 || (f.getPermission() & 4) == 4) {
permission = new Permission(Permission.Action.read_write, Permission.Action.none, Permission.Action.none);
}
else {
permission = new Permission(Permission.Action.read, Permission.Action.none, Permission.Action.none);
}
if((f.getFlags() & 1) == 1) {
// This item is a folder
permission.setUser(permission.getUser().or(Permission.Action.execute));
}
attrs.setPermission(permission);
attrs.setFileId(f.getId());
return attrs;
}

@Override
public PathAttributes toAttributes(final FileMetadata f) {
final PathAttributes attrs = new PathAttributes();
if(0 != f.getModified().getMillis()) {
attrs.setModificationDate(f.getModified().getMillis());
}
if(0 != f.getCreated().getMillis()) {
attrs.setCreationDate(f.getCreated().getMillis());
if(f.getSize() != null) {
attrs.setSize(f.getSize());
}
attrs.setSize(f.getFileSize());
if((f.getFlags() & 4) == 4) {
// This item is locked by some user
attrs.setLockId(Boolean.TRUE.toString());
if(f.getFlags() != null) {
if((f.getFlags() & 4) == 4) {
// This item is locked by some user
attrs.setLockId(Boolean.TRUE.toString());
}
if((f.getFlags() & 512) == 512) {
// This item is hidden
attrs.setHidden(true);
}
}
if((f.getFlags() & 512) == 512) {
// This item is hidden
attrs.setHidden(true);
if(f.getPermission() != null) {
// NoAccess 0
// ReadOnly 1
// ReadWrite 2
// Synchronize 4 Read, write access and permission to syncronize using desktop client.
// FullControl 99
final Permission permission;
if((f.getPermission() & 2) == 2 || (f.getPermission() & 4) == 4) {
permission = new Permission(Permission.Action.read_write, Permission.Action.none, Permission.Action.none);
}
else {
permission = new Permission(Permission.Action.read, Permission.Action.none, Permission.Action.none);
}
if((f.getFlags() & 1) == 1) {
// This item is a folder
permission.setUser(permission.getUser().or(Permission.Action.execute));
}
attrs.setPermission(permission);
}
attrs.setFileId(f.getId());
return attrs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void delete(final Map<Path, TransferStatus> files, final PasswordCallback
callback.delete(file.getKey());
final StoregateApiClient client = session.getClient();
final HttpRequestBase request;
request = new HttpDelete(String.format("%s/v4/files/%s", client.getBasePath(), fileid.getFileId(file.getKey())));
request = new HttpDelete(String.format("%s/v4.2/files/%s", client.getBasePath(), fileid.getFileId(file.getKey())));
if(file.getValue().getLockId() != null) {
request.addHeader("X-Lock-Id", file.getValue().getLockId().toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public String getFileId(final Path file) throws BackgroundException {
}
return cached;
}
final String id = new FilesApi(session.getClient()).filesGet_1(URIEncoder.encode(this.getPrefixedPath(file))).getId();
final String id = new FilesApi(session.getClient()).filesGet_0(URIEncoder.encode(this.getPrefixedPath(file))).getId();
this.cache(file, id);
return id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public AttributedList<Path> list(final Path directory, final ListProgressListene
int fileCount = 0;
FileContents files;
do {
files = new FilesApi(this.session.getClient()).filesGet(URIEncoder.encode(fileid.getPrefixedPath(directory)),
files = new FilesApi(this.session.getClient()).filesGetById(URIEncoder.encode(fileid.getFileId(directory)),
pageIndex,
chunksize,
"Name asc",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public Path move(final Path file, final Path renamed, final TransferStatus statu
.parentID(fileid.getFileId(renamed.getParent()))
.mode(1); // Overwrite
final HttpEntityEnclosingRequestBase request;
request = new HttpPost(String.format("%s/v4/files/%s/move", client.getBasePath(), fileid.getFileId(file)));
request = new HttpPost(String.format("%s/v4.2/files/%s/move", client.getBasePath(), fileid.getFileId(file)));
if(status.getLockId() != null) {
request.addHeader("X-Lock-Id", status.getLockId().toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import ch.cyberduck.core.preferences.HostPreferences;
import ch.cyberduck.core.storegate.io.swagger.client.ApiException;
import ch.cyberduck.core.storegate.io.swagger.client.JSON;
import ch.cyberduck.core.storegate.io.swagger.client.model.FileMetadata;
import ch.cyberduck.core.storegate.io.swagger.client.model.File;
import ch.cyberduck.core.threading.BackgroundActionState;
import ch.cyberduck.core.threading.BackgroundExceptionCallable;
import ch.cyberduck.core.threading.DefaultRetryCallable;
Expand All @@ -52,7 +52,7 @@
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;

public class StoregateMultipartWriteFeature implements MultipartWrite<FileMetadata> {
public class StoregateMultipartWriteFeature implements MultipartWrite<File> {
private static final Logger log = LogManager.getLogger(StoregateMultipartWriteFeature.class);

private final StoregateSession session;
Expand All @@ -69,14 +69,14 @@ public Append append(final Path file, final TransferStatus status) throws Backgr
}

@Override
public HttpResponseOutputStream<FileMetadata> write(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException {
public HttpResponseOutputStream<File> write(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException {
final String location = new StoregateWriteFeature(session, fileid).start(file, status);
final MultipartOutputStream proxy = new MultipartOutputStream(location, file, status);
return new HttpResponseOutputStream<FileMetadata>(new MemorySegementingOutputStream(proxy,
return new HttpResponseOutputStream<File>(new MemorySegementingOutputStream(proxy,
new HostPreferences(session.getHost()).getInteger("storegate.upload.multipart.chunksize")),
new StoregateAttributesFinderFeature(session, fileid), status) {
@Override
public FileMetadata getStatus() {
public File getStatus() {
return proxy.getResult();
}
};
Expand All @@ -88,7 +88,7 @@ private final class MultipartOutputStream extends OutputStream {
private final TransferStatus overall;
private final AtomicBoolean close = new AtomicBoolean();
private final AtomicReference<BackgroundException> canceled = new AtomicReference<>();
private final AtomicReference<FileMetadata> result = new AtomicReference<>();
private final AtomicReference<File> result = new AtomicReference<>();

private Long offset = 0L;
private final Long length;
Expand Down Expand Up @@ -136,15 +136,17 @@ public Void call() throws BackgroundException {
switch(response.getStatusLine().getStatusCode()) {
case HttpStatus.SC_OK:
case HttpStatus.SC_CREATED:
final FileMetadata metadata = new JSON().getContext(FileMetadata.class).readValue(new InputStreamReader(response.getEntity().getContent(), StandardCharsets.UTF_8), FileMetadata.class);
final File metadata = new JSON().getContext(File.class).readValue(
new InputStreamReader(response.getEntity().getContent(), StandardCharsets.UTF_8), File.class);
result.set(metadata);
fileid.cache(file, metadata.getId());
case HttpStatus.SC_NO_CONTENT:
// Upload complete
offset += content.length;
break;
default:
final ApiException failure = new ApiException(response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase(), Collections.emptyMap(),
final ApiException failure = new ApiException(response.getStatusLine().getStatusCode(),
response.getStatusLine().getReasonPhrase(), Collections.emptyMap(),
EntityUtils.toString(response.getEntity()));
throw new StoregateExceptionMappingService(fileid).map("Upload {0} failed", failure, file);
}
Expand Down Expand Up @@ -199,14 +201,16 @@ public void close() throws IOException {
switch(response.getStatusLine().getStatusCode()) {
case HttpStatus.SC_OK:
case HttpStatus.SC_CREATED:
final FileMetadata metadata = new JSON().getContext(FileMetadata.class).readValue(new InputStreamReader(response.getEntity().getContent(), StandardCharsets.UTF_8),
FileMetadata.class);
final File metadata = new JSON().getContext(File.class).readValue(
new InputStreamReader(response.getEntity().getContent(), StandardCharsets.UTF_8),
File.class);
result.set(metadata);
fileid.cache(file, metadata.getId());
case HttpStatus.SC_NO_CONTENT:
break;
default:
final ApiException failure = new ApiException(response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase(), Collections.emptyMap(),
final ApiException failure = new ApiException(response.getStatusLine().getStatusCode(),
response.getStatusLine().getReasonPhrase(), Collections.emptyMap(),
EntityUtils.toString(response.getEntity()));
throw new StoregateExceptionMappingService(fileid).map("Upload {0} failed", failure, file);
}
Expand All @@ -233,7 +237,7 @@ public String toString() {
return sb.toString();
}

public FileMetadata getResult() {
public File getResult() {
return result.get();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public StoregateReadFeature(final StoregateSession session, final StoregateIdPro
public InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException {
try {
final StoregateApiClient client = session.getClient();
final HttpUriRequest request = new HttpGet(String.format("%s/v4/download/files/%s?stream=true", client.getBasePath(),
final HttpUriRequest request = new HttpGet(String.format("%s/v4.2/download/files/%s?stream=true", client.getBasePath(),
fileid.getFileId(file)));
if(status.isAppend()) {
final HttpRange range = HttpRange.withStatus(status);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public DescriptiveUrl toDownloadUrl(final Path file, final Sharee sharee, final
MessageFormat.format(LocaleFactory.localizedString("Create a passphrase required to access {0}", "Credentials"), file.getName()),
new LoginOptions().anonymous(true).keychain(false).icon(bookmark.getProtocol().disk())).getPassword());
return new DescriptiveUrl(URI.create(
new FileSharesApi(session.getClient()).fileSharesPost(request).getUrl()), DescriptiveUrl.Type.signed);
new FileSharesApi(session.getClient()).fileSharesPost_0(request).getUrl()), DescriptiveUrl.Type.signed);
}
catch(ApiException e) {
throw new StoregateExceptionMappingService(fileid).map(e);
Expand All @@ -79,7 +79,7 @@ public DescriptiveUrl toUploadUrl(final Path file, final Sharee sharee, final Vo
MessageFormat.format(LocaleFactory.localizedString("Create a passphrase required to access {0}", "Credentials"), file.getName()),
new LoginOptions().anonymous(true).keychain(false).icon(bookmark.getProtocol().disk())).getPassword());
return new DescriptiveUrl(URI.create(
new FileSharesApi(session.getClient()).fileSharesPost(request).getUrl()), DescriptiveUrl.Type.signed);
new FileSharesApi(session.getClient()).fileSharesPost_0(request).getUrl()), DescriptiveUrl.Type.signed);
}
catch(ApiException e) {
throw new StoregateExceptionMappingService(fileid).map(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

import ch.cyberduck.core.Path;
import ch.cyberduck.core.shared.DefaultTouchFeature;
import ch.cyberduck.core.storegate.io.swagger.client.model.FileMetadata;
import ch.cyberduck.core.storegate.io.swagger.client.model.File;

public class StoregateTouchFeature extends DefaultTouchFeature<FileMetadata> {
public class StoregateTouchFeature extends DefaultTouchFeature<File> {

public StoregateTouchFeature(final StoregateSession session, final StoregateIdProvider fileid) {
super(new StoregateWriteFeature(session, fileid));
Expand Down
Loading

0 comments on commit 4f0207e

Please sign in to comment.