Add mtime support to Atmos directory listing

This commit is contained in:
Andrew Gaul 2017-10-29 17:26:34 -07:00
parent 28a70b7fb4
commit b95809046a
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()); .get(), null, null, null, null, ImmutableMap.<String, String>of());
else { else {
BlobMetadataImpl metadata = new BlobMetadataImpl(from.getObjectID(), from.getObjectName(), defaultLocation.get(), 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()); null, new BaseMutableContentMetadata());
MutableBlobMetadataImpl mutable = new MutableBlobMetadataImpl(metadata); MutableBlobMetadataImpl mutable = new MutableBlobMetadataImpl(metadata);
mutable.setSize(from.getSize()); mutable.setSize(from.getSize());

View File

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

View File

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