Search in sources :

Example 1 with ListResourceApi

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);
    }
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) DefaultHttpResponseExceptionMappingService(ch.cyberduck.core.http.DefaultHttpResponseExceptionMappingService) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) HttpResponseException(org.apache.http.client.HttpResponseException) IOException(java.io.IOException) HttpMethodReleaseInputStream(ch.cyberduck.core.http.HttpMethodReleaseInputStream) ListResourceApi(ch.cyberduck.core.eue.io.swagger.client.api.ListResourceApi) DefaultIOExceptionMappingService(ch.cyberduck.core.DefaultIOExceptionMappingService) UiFsModel(ch.cyberduck.core.eue.io.swagger.client.model.UiFsModel) BasicHeader(org.apache.http.message.BasicHeader) HttpRange(ch.cyberduck.core.http.HttpRange) ApiException(ch.cyberduck.core.eue.io.swagger.client.ApiException)

Example 2 with ListResourceApi

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);
    }
}
Also used : NotfoundException(ch.cyberduck.core.exception.NotfoundException) ListResourceAliasApi(ch.cyberduck.core.eue.io.swagger.client.api.ListResourceAliasApi) SimplePathPredicate(ch.cyberduck.core.SimplePathPredicate) ListResourceApi(ch.cyberduck.core.eue.io.swagger.client.api.ListResourceApi) Children(ch.cyberduck.core.eue.io.swagger.client.model.Children) UiFsModel(ch.cyberduck.core.eue.io.swagger.client.model.UiFsModel) HostPreferences(ch.cyberduck.core.preferences.HostPreferences) ApiException(ch.cyberduck.core.eue.io.swagger.client.ApiException)

Example 3 with ListResourceApi

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);
    }
}
Also used : PathAttributes(ch.cyberduck.core.PathAttributes) ListResourceAliasApi(ch.cyberduck.core.eue.io.swagger.client.api.ListResourceAliasApi) ListResourceApi(ch.cyberduck.core.eue.io.swagger.client.api.ListResourceApi) UiFsModel(ch.cyberduck.core.eue.io.swagger.client.model.UiFsModel) ApiException(ch.cyberduck.core.eue.io.swagger.client.ApiException)

Example 4 with ListResourceApi

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);
    }
}
Also used : Path(ch.cyberduck.core.Path) ListResourceAliasApi(ch.cyberduck.core.eue.io.swagger.client.api.ListResourceAliasApi) AttributedList(ch.cyberduck.core.AttributedList) ListResourceApi(ch.cyberduck.core.eue.io.swagger.client.api.ListResourceApi) Children(ch.cyberduck.core.eue.io.swagger.client.model.Children) UiFsModel(ch.cyberduck.core.eue.io.swagger.client.model.UiFsModel) ApiException(ch.cyberduck.core.eue.io.swagger.client.ApiException)

Aggregations

ApiException (ch.cyberduck.core.eue.io.swagger.client.ApiException)4 ListResourceApi (ch.cyberduck.core.eue.io.swagger.client.api.ListResourceApi)4 UiFsModel (ch.cyberduck.core.eue.io.swagger.client.model.UiFsModel)4 ListResourceAliasApi (ch.cyberduck.core.eue.io.swagger.client.api.ListResourceAliasApi)3 Children (ch.cyberduck.core.eue.io.swagger.client.model.Children)2 AttributedList (ch.cyberduck.core.AttributedList)1 DefaultIOExceptionMappingService (ch.cyberduck.core.DefaultIOExceptionMappingService)1 DisabledListProgressListener (ch.cyberduck.core.DisabledListProgressListener)1 Path (ch.cyberduck.core.Path)1 PathAttributes (ch.cyberduck.core.PathAttributes)1 SimplePathPredicate (ch.cyberduck.core.SimplePathPredicate)1 NotfoundException (ch.cyberduck.core.exception.NotfoundException)1 DefaultHttpResponseExceptionMappingService (ch.cyberduck.core.http.DefaultHttpResponseExceptionMappingService)1 HttpMethodReleaseInputStream (ch.cyberduck.core.http.HttpMethodReleaseInputStream)1 HttpRange (ch.cyberduck.core.http.HttpRange)1 HostPreferences (ch.cyberduck.core.preferences.HostPreferences)1 IOException (java.io.IOException)1 HttpResponse (org.apache.http.HttpResponse)1 HttpResponseException (org.apache.http.client.HttpResponseException)1 HttpGet (org.apache.http.client.methods.HttpGet)1