use of ch.cyberduck.core.eue.io.swagger.client.api.ListResourceApi in project cyberduck by iterate-ch.
the class EueReadFeature method read.
@Override
public InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException {
try {
final String resourceId = fileid.getFileId(file, new DisabledListProgressListener());
final UiFsModel uiFsModel = new ListResourceApi(new EueApiClient(session)).resourceResourceIdGet(resourceId, null, null, null, null, null, null, Collections.singletonList(EueAttributesFinderFeature.OPTION_DOWNLOAD), null);
final HttpUriRequest request = new HttpGet(uiFsModel.getUilink().getDownloadURI());
if (status.isAppend()) {
final HttpRange range = HttpRange.withStatus(status);
final String header;
if (TransferStatus.UNKNOWN_LENGTH == range.getEnd()) {
header = String.format("bytes=%d-", range.getStart());
} else {
header = String.format("bytes=%d-%d", range.getStart(), range.getEnd());
}
if (log.isDebugEnabled()) {
log.debug(String.format("Add range header %s for file %s", header, file));
}
request.addHeader(new BasicHeader(HttpHeaders.RANGE, header));
// Disable compression
request.addHeader(new BasicHeader(HttpHeaders.ACCEPT_ENCODING, "identity"));
}
final HttpResponse response = session.getClient().execute(request);
switch(response.getStatusLine().getStatusCode()) {
case HttpStatus.SC_OK:
case HttpStatus.SC_PARTIAL_CONTENT:
return new HttpMethodReleaseInputStream(response);
default:
throw new DefaultHttpResponseExceptionMappingService().map("Download {0} failed", new HttpResponseException(response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase()), file);
}
} catch (ApiException e) {
throw new EueExceptionMappingService().map("Download {0} failed", e, file);
} catch (IOException e) {
throw new DefaultIOExceptionMappingService().map("Download {0} failed", e, file);
}
}
use of ch.cyberduck.core.eue.io.swagger.client.api.ListResourceApi in project cyberduck by iterate-ch.
the class EueResourceIdProvider method getFileId.
@Override
public String getFileId(final Path file, final ListProgressListener listener) throws BackgroundException {
try {
if (StringUtils.isNotBlank(file.attributes().getFileId())) {
return file.attributes().getFileId();
}
if (cache.contains(new SimplePathPredicate(file))) {
final String cached = cache.get(new SimplePathPredicate(file));
if (log.isDebugEnabled()) {
log.debug(String.format("Return cached fileid %s for file %s", cached, file));
}
return cached;
}
if (file.isRoot()) {
return ROOT;
}
int offset = 0;
UiFsModel fsModel;
final int chunksize = new HostPreferences(session.getHost()).getInteger("eue.listing.chunksize");
do {
final String parentResourceId = this.getFileId(file.getParent(), listener);
switch(parentResourceId) {
case EueResourceIdProvider.ROOT:
case EueResourceIdProvider.TRASH:
fsModel = new ListResourceAliasApi(new EueApiClient(session)).resourceAliasAliasGet(parentResourceId, null, null, null, null, chunksize, offset, null, null);
break;
default:
fsModel = new ListResourceApi(new EueApiClient(session)).resourceResourceIdGet(parentResourceId, null, null, null, null, chunksize, offset, null, null);
}
for (Children child : fsModel.getUifs().getChildren()) {
// Case insensitive
if (child.getUifs().getName().equalsIgnoreCase(file.getName())) {
return getResourceIdFromResourceUri(child.getUifs().getResourceURI());
}
}
offset += chunksize;
} while (fsModel.getUifs().getChildren().size() == chunksize);
throw new NotfoundException(file.getAbsolute());
} catch (ApiException e) {
throw new EueExceptionMappingService().map("Failure to read attributes of {0}", e, file);
}
}
use of ch.cyberduck.core.eue.io.swagger.client.api.ListResourceApi in project cyberduck by iterate-ch.
the class EueAttributesFinderFeature method find.
@Override
public PathAttributes find(final Path file, final ListProgressListener listener) throws BackgroundException {
try {
final EueApiClient client = new EueApiClient(session);
final UiFsModel response;
final String resourceId = fileid.getFileId(file, listener);
switch(resourceId) {
case EueResourceIdProvider.ROOT:
case EueResourceIdProvider.TRASH:
response = new ListResourceAliasApi(client).resourceAliasAliasGet(resourceId, null, file.attributes().getETag(), null, null, null, null, Collections.singletonList(OPTION_WIN_32_PROPS), null);
break;
default:
response = new ListResourceApi(client).resourceResourceIdGet(resourceId, null, file.attributes().getETag(), null, null, null, null, Collections.singletonList(OPTION_WIN_32_PROPS), null);
break;
}
final PathAttributes attr = this.toAttributes(response.getUifs(), response.getUiwin32(), EueShareFeature.findShareForResource(session.userShares(), resourceId));
if (client.getResponseHeaders().containsKey(HttpHeaders.ETAG)) {
attr.setETag(StringUtils.remove(client.getResponseHeaders().get(HttpHeaders.ETAG).stream().findFirst().orElse(null), '"'));
}
return attr;
} catch (ApiException e) {
switch(e.getCode()) {
case HttpStatus.SC_NOT_MODIFIED:
if (log.isDebugEnabled()) {
log.debug(String.format("No changes for file %s with ETag %s", file, file.attributes().getETag()));
}
return file.attributes();
}
throw new EueExceptionMappingService().map("Failure to read attributes of {0}", e, file);
}
}
use of ch.cyberduck.core.eue.io.swagger.client.api.ListResourceApi in project cyberduck by iterate-ch.
the class EueListService method list.
protected AttributedList<Path> list(final Path directory, final ListProgressListener listener, final int chunksize) throws BackgroundException {
final AttributedList<Path> children = new AttributedList<>();
final EueApiClient client = new EueApiClient(session);
try {
int offset = 0;
UiFsModel fsModel;
do {
final String resourceId = fileid.getFileId(directory, listener);
switch(resourceId) {
case EueResourceIdProvider.ROOT:
case EueResourceIdProvider.TRASH:
fsModel = new ListResourceAliasApi(client).resourceAliasAliasGet(resourceId, null, null, null, null, chunksize, offset, Collections.singletonList(EueAttributesFinderFeature.OPTION_WIN_32_PROPS), null);
break;
default:
fsModel = new ListResourceApi(client).resourceResourceIdGet(resourceId, null, null, null, null, chunksize, offset, Collections.singletonList(EueAttributesFinderFeature.OPTION_WIN_32_PROPS), null);
break;
}
for (Children child : fsModel.getUifs().getChildren()) {
final EnumSet<Path.Type> type;
switch(child.getUifs().getResourceType()) {
case "aliascontainer":
type = EnumSet.of(Path.Type.directory, Path.Type.placeholder);
break;
case "container":
type = EnumSet.of(Path.Type.directory);
break;
default:
type = EnumSet.of(Path.Type.file);
}
children.add(new Path(directory, child.getUifs().getName(), type, attributes.toAttributes(child.getUifs(), child.getUiwin32(), EueShareFeature.findShareForResource(session.userShares(), EueResourceIdProvider.getResourceIdFromResourceUri(child.getUifs().getResourceURI())))));
listener.chunk(directory, children);
}
offset += chunksize;
} while (fsModel.getUifs().getChildren().size() == chunksize);
return children;
} catch (ApiException e) {
throw new EueExceptionMappingService().map("Listing directory {0} failed", e, directory);
}
}
Aggregations