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

View File

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

View File

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

View File

@ -31,6 +31,7 @@ import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.atmosonline.saas.domain.AtmosObject;
import org.jclouds.atmosonline.saas.domain.FileType;
import org.jclouds.atmosonline.saas.functions.AtmosObjectName;
import org.jclouds.blobstore.domain.MutableBlobMetadata;
import org.jclouds.blobstore.domain.ResourceType;
@ -69,7 +70,11 @@ public class ObjectToBlobMetadata implements Function<AtmosObject, MutableBlobMe
to.setContentType(from.getContentMetadata().getContentType());
to.setName(objectName.apply(from));
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();
for (Entry<String, String> entry : from.getUserMetadata().getMetadata().entrySet()) {
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.config.BlobStoreObjectModule;
import org.jclouds.blobstore.functions.ReturnVoidOnNotFoundOr404;
import org.jclouds.blobstore.functions.ThrowContainerNotFoundOn404;
import org.jclouds.blobstore.functions.ThrowKeyNotFoundOn404;
import org.jclouds.date.TimeStamp;
import org.jclouds.encryption.internal.Base64;
@ -106,7 +107,7 @@ public class AtmosStorageClientTest extends RestClientTest<AtmosStorageAsyncClie
assertResponseParserClassEquals(method, httpMethod,
ParseDirectoryListFromContentAndHeaders.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ThrowContainerNotFoundOn404.class);
checkFilters(httpMethod);
}
@ -148,7 +149,7 @@ public class AtmosStorageClientTest extends RestClientTest<AtmosStorageAsyncClie
assertResponseParserClassEquals(method, httpMethod,
ParseDirectoryListFromContentAndHeaders.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ThrowContainerNotFoundOn404.class);
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("", "");
}
}