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

View File

@ -78,4 +78,9 @@ public class SwiftBlobIntegrationLiveTest extends BaseBlobIntegrationTest {
public void testSetBlobAccess() throws Exception {
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");
}
}