Issue 111: set filetype to directory when someone accidentally lists a file as a directory

git-svn-id: http://jclouds.googlecode.com/svn/trunk@2431 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
adrian.f.cole 2009-12-15 05:46:35 +00:00
parent 9c72dc8ada
commit 5f3bee6f2e
6 changed files with 65 additions and 7 deletions

View File

@ -52,6 +52,7 @@ import org.jclouds.atmosonline.saas.options.ListOptions;
import org.jclouds.blobstore.attr.ConsistencyModel; import org.jclouds.blobstore.attr.ConsistencyModel;
import org.jclouds.blobstore.attr.ConsistencyModels; import org.jclouds.blobstore.attr.ConsistencyModels;
import org.jclouds.blobstore.functions.ReturnVoidOnNotFoundOr404; import org.jclouds.blobstore.functions.ReturnVoidOnNotFoundOr404;
import org.jclouds.blobstore.functions.ThrowContainerNotFoundOn404;
import org.jclouds.blobstore.functions.ThrowKeyNotFoundOn404; import org.jclouds.blobstore.functions.ThrowKeyNotFoundOn404;
import org.jclouds.http.functions.ReturnFalseOn404; import org.jclouds.http.functions.ReturnFalseOn404;
import org.jclouds.http.options.GetOptions; import org.jclouds.http.options.GetOptions;
@ -96,6 +97,7 @@ public interface AtmosStorageAsyncClient {
@GET @GET
@Path("/rest/namespace/{directoryName}/") @Path("/rest/namespace/{directoryName}/")
@ResponseParser(ParseDirectoryListFromContentAndHeaders.class) @ResponseParser(ParseDirectoryListFromContentAndHeaders.class)
@ExceptionParser(ThrowContainerNotFoundOn404.class)
@Consumes(MediaType.TEXT_XML) @Consumes(MediaType.TEXT_XML)
Future<? extends BoundedSortedSet<? extends DirectoryEntry>> listDirectory( Future<? extends BoundedSortedSet<? extends DirectoryEntry>> listDirectory(
@PathParam("directoryName") String directoryName, ListOptions... options); @PathParam("directoryName") String directoryName, ListOptions... options);

View File

@ -55,10 +55,13 @@ public interface AtmosStorageClient {
URI createDirectory(String directoryName); URI createDirectory(String directoryName);
@Timeout(duration = 10, timeUnit = TimeUnit.MINUTES)
URI createFile(String parent, AtmosObject object); URI createFile(String parent, AtmosObject object);
@Timeout(duration = 10, timeUnit = TimeUnit.MINUTES)
void updateFile(String parent, AtmosObject object); void updateFile(String parent, AtmosObject object);
@Timeout(duration = 10, timeUnit = TimeUnit.MINUTES)
AtmosObject readFile(String path, GetOptions... options); AtmosObject readFile(String path, GetOptions... options);
AtmosObject headFile(String path); AtmosObject headFile(String path);

View File

@ -45,16 +45,16 @@ public class AtmosStorageResponseException extends HttpResponseException {
public AtmosStorageResponseException(HttpCommand command, HttpResponse response, public AtmosStorageResponseException(HttpCommand command, HttpResponse response,
AtmosStorageError error) { AtmosStorageError error) {
super(String.format("command %s failed with code %s, error: %s", command.toString(), response super(String.format("command %s failed with code %s, error: %s", command.getRequest()
.getStatusCode(), error.toString()), command, response); .getRequestLine(), response.getStatusCode(), error.toString()), command, response);
this.setError(error); this.setError(error);
} }
public AtmosStorageResponseException(HttpCommand command, HttpResponse response, public AtmosStorageResponseException(HttpCommand command, HttpResponse response,
AtmosStorageError error, Throwable cause) { AtmosStorageError error, Throwable cause) {
super(String.format("command %1$s failed with error: %2$s", command.toString(), error super(String.format("command %1$s failed with error: %2$s", command.getRequest()
.toString()), command, response, cause); .getRequestLine(), error.toString()), command, response, cause);
this.setError(error); this.setError(error);
} }

View File

@ -31,6 +31,7 @@ import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.atmosonline.saas.domain.AtmosObject; import org.jclouds.atmosonline.saas.domain.AtmosObject;
import org.jclouds.atmosonline.saas.domain.FileType;
import org.jclouds.atmosonline.saas.functions.AtmosObjectName; import org.jclouds.atmosonline.saas.functions.AtmosObjectName;
import org.jclouds.blobstore.domain.MutableBlobMetadata; import org.jclouds.blobstore.domain.MutableBlobMetadata;
import org.jclouds.blobstore.domain.ResourceType; import org.jclouds.blobstore.domain.ResourceType;
@ -69,7 +70,11 @@ public class ObjectToBlobMetadata implements Function<AtmosObject, MutableBlobMe
to.setContentType(from.getContentMetadata().getContentType()); to.setContentType(from.getContentMetadata().getContentType());
to.setName(objectName.apply(from)); to.setName(objectName.apply(from));
to.setSize(from.getSystemMetadata().getSize()); to.setSize(from.getSystemMetadata().getSize());
to.setType(ResourceType.BLOB); if (from.getSystemMetadata().getType() == FileType.DIRECTORY) {
to.setType(ResourceType.FOLDER);
} else {
to.setType(ResourceType.BLOB);
}
Map<String, String> lowerKeyMetadata = Maps.newHashMap(); Map<String, String> lowerKeyMetadata = Maps.newHashMap();
for (Entry<String, String> entry : from.getUserMetadata().getMetadata().entrySet()) { for (Entry<String, String> entry : from.getUserMetadata().getMetadata().entrySet()) {
String key = entry.getKey().toLowerCase(); String key = entry.getKey().toLowerCase();

View File

@ -45,6 +45,7 @@ import org.jclouds.atmosonline.saas.reference.AtmosStorageConstants;
import org.jclouds.blobstore.binders.BindBlobToMultipartFormTest; import org.jclouds.blobstore.binders.BindBlobToMultipartFormTest;
import org.jclouds.blobstore.config.BlobStoreObjectModule; import org.jclouds.blobstore.config.BlobStoreObjectModule;
import org.jclouds.blobstore.functions.ReturnVoidOnNotFoundOr404; import org.jclouds.blobstore.functions.ReturnVoidOnNotFoundOr404;
import org.jclouds.blobstore.functions.ThrowContainerNotFoundOn404;
import org.jclouds.blobstore.functions.ThrowKeyNotFoundOn404; import org.jclouds.blobstore.functions.ThrowKeyNotFoundOn404;
import org.jclouds.date.TimeStamp; import org.jclouds.date.TimeStamp;
import org.jclouds.encryption.internal.Base64; import org.jclouds.encryption.internal.Base64;
@ -106,7 +107,7 @@ public class AtmosStorageClientTest extends RestClientTest<AtmosStorageAsyncClie
assertResponseParserClassEquals(method, httpMethod, assertResponseParserClassEquals(method, httpMethod,
ParseDirectoryListFromContentAndHeaders.class); ParseDirectoryListFromContentAndHeaders.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, ThrowContainerNotFoundOn404.class);
checkFilters(httpMethod); checkFilters(httpMethod);
} }
@ -148,7 +149,7 @@ public class AtmosStorageClientTest extends RestClientTest<AtmosStorageAsyncClie
assertResponseParserClassEquals(method, httpMethod, assertResponseParserClassEquals(method, httpMethod,
ParseDirectoryListFromContentAndHeaders.class); ParseDirectoryListFromContentAndHeaders.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, ThrowContainerNotFoundOn404.class);
checkFilters(httpMethod); checkFilters(httpMethod);
} }

View File

@ -0,0 +1,47 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* ====================================================================
*/
package org.jclouds.atmosonline.saas.blobstore.functions;
import static org.testng.Assert.assertEquals;
import org.testng.annotations.Test;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
* Tests behavior of {@code ObjectToBlobMetadata}
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "atmossaas.ObjectToBlobMetadataTest")
public class ObjectToBlobMetadataTest {
public void testFromWhenTypeIsDirectory() {
Injector injector = Guice.createInjector();
injector.getInstance(ObjectToBlobMetadata.class);
assertEquals("", "");
}
}