JCLOUDS-651: Swift copy object content metadata

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

View File

@ -237,33 +237,59 @@ 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;
if (options.getUserMetadata().isPresent()) {
userMetadata = options.getUserMetadata().get();
} else {
userMetadata = metadata.getMetadata();
}
// copy existing system metadata
Map<String, String> systemMetadata = Maps.newHashMap(); Map<String, String> systemMetadata = Maps.newHashMap();
ContentMetadata contentMetadata = metadata.getPayload().getContentMetadata(); ContentMetadata contentMetadata = options.getContentMetadata().orNull();
String contentDisposition = contentMetadata.getContentDisposition();
if (contentDisposition != null) { if (contentMetadata != null ||
systemMetadata.put(HttpHeaders.CONTENT_DISPOSITION, contentDisposition); options.getUserMetadata().isPresent()) {
} if (contentMetadata != null) {
String contentEncoding = contentMetadata.getContentEncoding(); String contentDisposition = contentMetadata.getContentDisposition();
if (contentEncoding != null) { if (contentDisposition != null) {
systemMetadata.put(HttpHeaders.CONTENT_ENCODING, contentEncoding); systemMetadata.put(HttpHeaders.CONTENT_DISPOSITION, contentDisposition);
} }
String contentLanguage = contentMetadata.getContentLanguage();
if (contentLanguage != null) { String contentEncoding = contentMetadata.getContentEncoding();
systemMetadata.put(HttpHeaders.CONTENT_LANGUAGE, contentLanguage); if (contentEncoding != null) {
} systemMetadata.put(HttpHeaders.CONTENT_ENCODING, contentEncoding);
String contentType = contentMetadata.getContentType(); }
if (contentType != null) {
systemMetadata.put(HttpHeaders.CONTENT_TYPE, contentType); 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 = Maps.newHashMap();
}
} 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);
}
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);
}
userMetadata = metadata.getMetadata();
} }
boolean copied = objectApi.copy(toName, fromContainer, fromName, userMetadata, systemMetadata); boolean copied = objectApi.copy(toName, fromContainer, fromName, userMetadata, systemMetadata);
@ -271,11 +297,7 @@ public class RegionScopedSwiftBlobStore implements BlobStore {
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");
}
} }