1 package org.kuali.common.devops.archive.s3;
2
3 import static com.google.common.collect.Maps.newHashMap;
4 import static java.lang.Long.parseLong;
5
6 import java.util.Map;
7 import java.util.Set;
8
9 import org.kuali.common.devops.archive.ArchivedFileMetadata;
10
11 import com.google.common.base.Converter;
12 import com.google.common.collect.ImmutableMap;
13 import com.google.common.collect.ImmutableSet;
14
15 public final class MetadataConverter extends Converter<ArchivedFileMetadata, Map<String, String>> {
16
17 public static final MetadataConverter INSTANCE = new MetadataConverter();
18
19
20 public static final String SIZE_KEY = "archive.source.size";
21 public static final String LAST_MODIFIED_KEY = "archive.source.lastmodified";
22 public static final String MD5_KEY = "archive.source.md5";
23 public static final Set<String> KEYS = ImmutableSet.of(SIZE_KEY, LAST_MODIFIED_KEY, MD5_KEY);
24
25 @Override
26 protected Map<String, String> doForward(ArchivedFileMetadata a) {
27 Map<String, String> map = newHashMap();
28 map.put(SIZE_KEY, a.getSize() + "");
29 map.put(LAST_MODIFIED_KEY, a.getLastModified() + "");
30 map.put(MD5_KEY, a.getMd5());
31 return ImmutableMap.copyOf(map);
32 }
33
34 @Override
35 protected ArchivedFileMetadata doBackward(Map<String, String> b) {
36 long size = parseLong(b.get(SIZE_KEY));
37 long lastModified = parseLong(b.get(LAST_MODIFIED_KEY));
38 String md5 = b.get(MD5_KEY);
39 return ArchivedFileMetadata.builder().withSize(size).withLastModified(lastModified).withMd5(md5).build();
40 }
41
42 private MetadataConverter() {
43 }
44
45 }