public class ResourceToObjectInfo implements Function<StorageMetadata, MutableObjectInfoWithMetadata> {
public MutableObjectInfoWithMetadata apply(StorageMetadata from) {
if (from == null)
return null;
MutableObjectInfoWithMetadata to = new MutableObjectInfoWithMetadataImpl();
if (from.getType() == StorageType.BLOB) {
to.setContentType(((BlobMetadata) from).getContentMetadata().getContentType());
to.setBytes(((BlobMetadata) from).getContentMetadata().getContentLength());
to.setHash(((BlobMetadata) from).getContentMetadata().getContentMD5());
} else if (from.getType() == StorageType.RELATIVE_PATH) {
to.setContentType("application/directory");
}
if (from.getETag() != null && to.getHash() == null)
to.setHash(ETagUtils.convertHexETagToByteArray(from.getETag()));
to.setName(from.getName());
to.setLastModified(from.getLastModified());
if (from.getUserMetadata() != null) {
for (Entry<String, String> entry : from.getUserMetadata().entrySet())
to.getMetadata().put(entry.getKey().toLowerCase(), entry.getValue());
}
return to;
}