JCLOUDS-651: Swift copy object content metadata

This commit is contained in:
Andrew Gaul 2015-04-06 17:51:58 -07:00
parent a43dcece16
commit 0c6052f803
2 changed files with 56 additions and 29 deletions

View File

@ -237,18 +237,42 @@ public class RegionScopedSwiftBlobStore implements BlobStore {
public String copyBlob(String fromContainer, String fromName, String toContainer, String toName, public String copyBlob(String fromContainer, String fromName, String toContainer, String toName,
CopyOptions options) { CopyOptions options) {
ObjectApi objectApi = api.getObjectApi(regionId, toContainer); ObjectApi objectApi = api.getObjectApi(regionId, toContainer);
SwiftObject metadata = api.getObjectApi(regionId, fromContainer).getWithoutBody(fromName);
Map<String, String> userMetadata; Map<String, String> userMetadata;
Map<String, String> systemMetadata = Maps.newHashMap();
ContentMetadata contentMetadata = options.getContentMetadata().orNull();
if (contentMetadata != null ||
options.getUserMetadata().isPresent()) {
if (contentMetadata != null) {
String contentDisposition = contentMetadata.getContentDisposition();
if (contentDisposition != null) {
systemMetadata.put(HttpHeaders.CONTENT_DISPOSITION, contentDisposition);
}
String contentEncoding = contentMetadata.getContentEncoding();
if (contentEncoding != null) {
systemMetadata.put(HttpHeaders.CONTENT_ENCODING, contentEncoding);
}
String contentLanguage = contentMetadata.getContentLanguage();
if (contentLanguage != null) {
systemMetadata.put(HttpHeaders.CONTENT_LANGUAGE, contentLanguage);
}
String contentType = contentMetadata.getContentType();
if (contentType != null) {
systemMetadata.put(HttpHeaders.CONTENT_TYPE, contentType);
}
}
if (options.getUserMetadata().isPresent()) { if (options.getUserMetadata().isPresent()) {
userMetadata = options.getUserMetadata().get(); userMetadata = options.getUserMetadata().get();
} else { } else {
userMetadata = metadata.getMetadata(); userMetadata = Maps.newHashMap();
} }
} else {
// copy existing system metadata SwiftObject metadata = api.getObjectApi(regionId, fromContainer).getWithoutBody(fromName);
Map<String, String> systemMetadata = Maps.newHashMap(); contentMetadata = metadata.getPayload().getContentMetadata();
ContentMetadata contentMetadata = metadata.getPayload().getContentMetadata();
String contentDisposition = contentMetadata.getContentDisposition(); String contentDisposition = contentMetadata.getContentDisposition();
if (contentDisposition != null) { if (contentDisposition != null) {
systemMetadata.put(HttpHeaders.CONTENT_DISPOSITION, contentDisposition); systemMetadata.put(HttpHeaders.CONTENT_DISPOSITION, contentDisposition);
@ -265,17 +289,15 @@ public class RegionScopedSwiftBlobStore implements BlobStore {
if (contentType != null) { if (contentType != null) {
systemMetadata.put(HttpHeaders.CONTENT_TYPE, contentType); systemMetadata.put(HttpHeaders.CONTENT_TYPE, contentType);
} }
userMetadata = metadata.getMetadata();
}
boolean copied = objectApi.copy(toName, fromContainer, fromName, userMetadata, systemMetadata); boolean copied = objectApi.copy(toName, fromContainer, fromName, userMetadata, systemMetadata);
if (!copied) { if (!copied) {
throw new RuntimeException("could not copy blob"); throw new RuntimeException("could not copy blob");
} }
// TODO: override content disposition // TODO: Swift copy object *appends* user metadata, does not overwrite
// TODO: override content encoding
// TODO: override content language
// TODO: override content type
return objectApi.getWithoutBody(toName).getETag(); return objectApi.getWithoutBody(toName).getETag();
} }

View File

@ -78,4 +78,9 @@ public class SwiftBlobIntegrationLiveTest extends BaseBlobIntegrationTest {
public void testSetBlobAccess() throws Exception { public void testSetBlobAccess() throws Exception {
throw new SkipException("unsupported in swift"); throw new SkipException("unsupported in swift");
} }
@Override
public void testCopyBlobReplaceMetadata() throws Exception {
throw new SkipException("Swift only supports appending to user metadata, not replacing it");
}
} }