mirror of
https://github.com/apache/jclouds.git
synced 2025-02-16 23:16:58 +00:00
JCLOUDS-929: Plumb delimiter and prefix to GCS.
This commit is contained in:
parent
efdc715b88
commit
834b3d5d2f
@ -26,18 +26,27 @@ import com.google.common.base.Function;
|
||||
public class BlobStoreListContainerOptionsToListObjectOptions implements
|
||||
Function<ListContainerOptions, ListObjectOptions> {
|
||||
public ListObjectOptions apply(ListContainerOptions from) {
|
||||
if (from.getDir() != null && (from.getPrefix() != null || from.getDelimiter() != null)) {
|
||||
throw new IllegalArgumentException("Cannot pass both directory and prefix/delimiter");
|
||||
}
|
||||
checkNotNull(from, "set options to instance NONE instead of passing null");
|
||||
ListObjectOptions httpOptions = new ListObjectOptions();
|
||||
|
||||
if (!from.isRecursive()) {
|
||||
if (!from.isRecursive() && from.getDelimiter() == null) {
|
||||
httpOptions = httpOptions.delimiter("/");
|
||||
}
|
||||
if (from.getDelimiter() != null) {
|
||||
httpOptions = httpOptions.delimiter(from.getDelimiter());
|
||||
}
|
||||
if (from.getDir() != null) {
|
||||
String path = from.getDir();
|
||||
if (!path.endsWith("/"))
|
||||
path += "/";
|
||||
httpOptions = httpOptions.prefix(path);
|
||||
}
|
||||
if (from.getPrefix() != null) {
|
||||
httpOptions.prefix(from.getPrefix());
|
||||
}
|
||||
if (from.getMarker() != null) {
|
||||
httpOptions = httpOptions.pageToken(from.getMarker());
|
||||
}
|
||||
|
@ -16,22 +16,22 @@
|
||||
*/
|
||||
package org.jclouds.googlecloudstorage.blobstore.functions;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.SortedSet;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.jclouds.blobstore.domain.BlobMetadata;
|
||||
import org.jclouds.blobstore.domain.MutableStorageMetadata;
|
||||
import org.jclouds.blobstore.domain.PageSet;
|
||||
import org.jclouds.blobstore.domain.StorageMetadata;
|
||||
import org.jclouds.blobstore.domain.StorageType;
|
||||
import org.jclouds.blobstore.domain.internal.MutableStorageMetadataImpl;
|
||||
import org.jclouds.blobstore.domain.internal.PageSetImpl;
|
||||
import org.jclouds.blobstore.domain.internal.StorageMetadataImpl;
|
||||
import org.jclouds.googlecloudstorage.domain.GoogleCloudStorageObject;
|
||||
import org.jclouds.googlecloudstorage.domain.ListPageWithPrefixes;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
public class ObjectListToStorageMetadata
|
||||
implements Function<ListPageWithPrefixes<GoogleCloudStorageObject>, PageSet<? extends StorageMetadata>> {
|
||||
@ -46,19 +46,13 @@ public class ObjectListToStorageMetadata
|
||||
from = ListPageWithPrefixes.create(null, null, null);
|
||||
}
|
||||
|
||||
return new PageSetImpl<StorageMetadata>(Iterables.transform(Iterables.transform(from, object2blobMd),
|
||||
new Function<BlobMetadata, StorageMetadata>() {
|
||||
public StorageMetadata apply(BlobMetadata input) {
|
||||
Map<String, String> userMetaData = (input != null && input.getUserMetadata() != null) ? input
|
||||
.getUserMetadata() : ImmutableMap.<String, String> of();
|
||||
if (input.getContentMetadata().getContentType().equals("application/directory")) {
|
||||
return new StorageMetadataImpl(StorageType.RELATIVE_PATH, input.getProviderId(), input
|
||||
.getName(), input.getLocation(), input.getUri(), input.getETag(), input
|
||||
.getCreationDate(), input.getLastModified(), userMetaData,
|
||||
input.getSize());
|
||||
}
|
||||
return input;
|
||||
}
|
||||
}), from.nextPageToken());
|
||||
SortedSet<StorageMetadata> results = Sets.<StorageMetadata> newTreeSet(Iterables.transform(from, object2blobMd));
|
||||
for (String prefix : from.prefixes()) {
|
||||
MutableStorageMetadata metadata = new MutableStorageMetadataImpl();
|
||||
metadata.setType(StorageType.RELATIVE_PATH);
|
||||
metadata.setName(prefix);
|
||||
results.add(metadata);
|
||||
}
|
||||
return new PageSetImpl<StorageMetadata>(results, from.nextPageToken());
|
||||
}
|
||||
}
|
||||
|
@ -105,14 +105,4 @@ public class GoogleCloudStorageContainerIntegrationLiveTest extends BaseContaine
|
||||
public void testListMarkerAfterLastKey() throws Exception {
|
||||
throw new SkipException("cannot specify arbitrary markers");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testContainerListWithPrefix() {
|
||||
throw new SkipException("Prefix option has not been plumbed down to GCS");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testDelimiterList() {
|
||||
throw new SkipException("Prefix option has not been plumbed down to GCS");
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user