Add mtime support to Atmos directory listing

This commit is contained in:
Andrew Gaul 2017-10-29 17:26:34 -07:00
parent 4b10bcc054
commit 0960ea4969
3 changed files with 31 additions and 2 deletions

View File

@ -59,7 +59,7 @@ public class DirectoryEntryListToResourceMetadataList implements
.get(), null, null, null, null, ImmutableMap.<String, String>of());
else {
BlobMetadataImpl metadata = new BlobMetadataImpl(from.getObjectID(), from.getObjectName(), defaultLocation.get(),
null, null, null, null, ImmutableMap.<String, String>of(), null,
null, null, null, from.getModifiedTime(), ImmutableMap.<String, String>of(), null,
null, new BaseMutableContentMetadata());
MutableBlobMetadataImpl mutable = new MutableBlobMetadataImpl(metadata);
mutable.setSize(from.getSize());

View File

@ -16,6 +16,10 @@
*/
package org.jclouds.atmos.domain;
import java.util.Date;
import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.Objects;
/**
@ -26,12 +30,19 @@ public class DirectoryEntry implements Comparable<DirectoryEntry> {
private final FileType type;
private final String objname;
private final long size;
@Nullable private final Date modifiedTime;
@Deprecated
public DirectoryEntry(String objectid, FileType type, String objname, long size) {
this(objectid, type, objname, size, null);
}
public DirectoryEntry(String objectid, FileType type, String objname, long size, Date modifiedTime) {
this.objectid = objectid;
this.objname = objname;
this.type = type;
this.size = size;
this.modifiedTime = modifiedTime != null ? (Date) modifiedTime.clone() : null;
}
public String getObjectID() {
@ -50,6 +61,10 @@ public class DirectoryEntry implements Comparable<DirectoryEntry> {
return size;
}
public Date getModifiedTime() {
return modifiedTime != null ? (Date) modifiedTime.clone() : null;
}
public int compareTo(DirectoryEntry o) {
if (getObjectName() == null)
return -1;

View File

@ -16,10 +16,14 @@
*/
package org.jclouds.atmos.xml;
import java.util.Date;
import java.util.Set;
import javax.inject.Inject;
import org.jclouds.atmos.domain.DirectoryEntry;
import org.jclouds.atmos.domain.FileType;
import org.jclouds.date.DateService;
import org.jclouds.http.functions.ParseSax;
import com.google.common.collect.Sets;
@ -37,12 +41,20 @@ public class ListDirectoryResponseHandler extends ParseSax.HandlerWithResult<Set
private FileType currentType;
private String currentFileName;
private long currentSize;
private Date currentModificationTime;
// metadata parsing
private String currentName;
private StringBuilder currentText = new StringBuilder();
private final DateService dateService;
@Inject
ListDirectoryResponseHandler(DateService dateService) {
this.dateService = dateService;
}
public Set<DirectoryEntry> getResult() {
return entries;
}
@ -61,9 +73,11 @@ public class ListDirectoryResponseHandler extends ParseSax.HandlerWithResult<Set
} else if (qName.equals("Value")) {
if (currentName.equals("size")) {
currentSize = Long.parseLong(currentText.toString().trim());
} else if (currentName.equals("mtime")) {
currentModificationTime = dateService.iso8601DateOrSecondsDateParse(currentText.toString().trim());
}
} else if (qName.equals("DirectoryEntry")) {
entries.add(new DirectoryEntry(currentObjectId, currentType, currentFileName, currentSize));
entries.add(new DirectoryEntry(currentObjectId, currentType, currentFileName, currentSize, currentModificationTime));
}
currentText.setLength(0);
}