Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add createTime() to BlobInfo and Blob classes #1034

Merged
merged 1 commit into from
Jun 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,12 @@ Builder updateTime(Long updateTime) {
return this;
}

@Override
Builder createTime(Long createTime) {
infoBuilder.createTime(createTime);
return this;
}

@Override
Builder isDirectory(boolean isDirectory) {
infoBuilder.isDirectory(isDirectory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public StorageObject apply(BlobInfo blobInfo) {
private final Long metageneration;
private final Long deleteTime;
private final Long updateTime;
private final Long createTime;
private final String contentType;
private final String contentEncoding;
private final String contentDisposition;
Expand Down Expand Up @@ -188,6 +189,8 @@ public abstract static class Builder {

abstract Builder updateTime(Long updateTime);

abstract Builder createTime(Long createTime);

abstract Builder isDirectory(boolean isDirectory);

/**
Expand Down Expand Up @@ -218,6 +221,7 @@ static final class BuilderImpl extends Builder {
private Long metageneration;
private Long deleteTime;
private Long updateTime;
private Long createTime;
private Boolean isDirectory;

BuilderImpl(BlobId blobId) {
Expand Down Expand Up @@ -245,6 +249,7 @@ static final class BuilderImpl extends Builder {
metageneration = blobInfo.metageneration;
deleteTime = blobInfo.deleteTime;
updateTime = blobInfo.updateTime;
createTime = blobInfo.createTime;
isDirectory = blobInfo.isDirectory;
}

Expand Down Expand Up @@ -369,6 +374,12 @@ Builder updateTime(Long updateTime) {
return this;
}

@Override
Builder createTime(Long createTime) {
this.createTime = createTime;
return this;
}

@Override
Builder isDirectory(boolean isDirectory) {
this.isDirectory = isDirectory;
Expand Down Expand Up @@ -403,6 +414,7 @@ public BlobInfo build() {
metageneration = builder.metageneration;
deleteTime = builder.deleteTime;
updateTime = builder.updateTime;
createTime = builder.createTime;
isDirectory = firstNonNull(builder.isDirectory, Boolean.FALSE);
}

Expand Down Expand Up @@ -600,6 +612,13 @@ public Long updateTime() {
return updateTime;
}

/**
* Returns the creation time of the blob.
*/
public Long createTime() {
return createTime;
}

/**
* Returns {@code true} if the current blob represents a directory. This can only happen if the
* blob is returned by {@link Storage#list(String, Storage.BlobListOption...)} when the
Expand Down Expand Up @@ -660,6 +679,9 @@ public ObjectAccessControl apply(Acl acl) {
if (updateTime != null) {
storageObject.setUpdated(new DateTime(updateTime));
}
if (createTime != null) {
storageObject.setTimeCreated(new DateTime(createTime));
}
if (size != null) {
storageObject.setSize(BigInteger.valueOf(size));
}
Expand Down Expand Up @@ -773,6 +795,9 @@ static BlobInfo fromPb(StorageObject storageObject) {
if (storageObject.getUpdated() != null) {
builder.updateTime(storageObject.getUpdated().getValue());
}
if (storageObject.getTimeCreated() != null) {
builder.createTime(storageObject.getTimeCreated().getValue());
}
if (storageObject.getSize() != null) {
builder.size(storageObject.getSize().longValue());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public class BlobInfoTest {
private static final String SELF_LINK = "http://storage/b/n";
private static final Long SIZE = 1024L;
private static final Long UPDATE_TIME = DELETE_TIME - 1L;
private static final Long CREATE_TIME = UPDATE_TIME - 1L;
private static final BlobInfo BLOB_INFO = BlobInfo.builder("b", "n", GENERATION)
.acl(ACL)
.componentCount(COMPONENT_COUNT)
Expand All @@ -80,6 +81,7 @@ public class BlobInfoTest {
.selfLink(SELF_LINK)
.size(SIZE)
.updateTime(UPDATE_TIME)
.createTime(CREATE_TIME)
.build();
private static final BlobInfo DIRECTORY_INFO = BlobInfo.builder("b", "n/")
.size(0L)
Expand Down Expand Up @@ -127,6 +129,7 @@ public void testBuilder() {
assertEquals(SELF_LINK, BLOB_INFO.selfLink());
assertEquals(SIZE, BLOB_INFO.size());
assertEquals(UPDATE_TIME, BLOB_INFO.updateTime());
assertEquals(CREATE_TIME, BLOB_INFO.createTime());
assertFalse(BLOB_INFO.isDirectory());
assertEquals("b", DIRECTORY_INFO.bucket());
assertEquals("n/", DIRECTORY_INFO.name());
Expand All @@ -138,6 +141,7 @@ public void testBuilder() {
assertNull(DIRECTORY_INFO.contentEncoding());
assertNull(DIRECTORY_INFO.contentLanguage());
assertNull(DIRECTORY_INFO.crc32c());
assertNull(DIRECTORY_INFO.createTime());
assertNull(DIRECTORY_INFO.deleteTime());
assertNull(DIRECTORY_INFO.etag());
assertNull(DIRECTORY_INFO.generation());
Expand Down Expand Up @@ -165,6 +169,7 @@ private void compareBlobs(BlobInfo expected, BlobInfo value) {
assertEquals(expected.contentEncoding(), value.contentEncoding());
assertEquals(expected.contentLanguage(), value.contentLanguage());
assertEquals(expected.crc32c(), value.crc32c());
assertEquals(expected.createTime(), value.createTime());
assertEquals(expected.deleteTime(), value.deleteTime());
assertEquals(expected.etag(), value.etag());
assertEquals(expected.generation(), value.generation());
Expand Down Expand Up @@ -200,6 +205,7 @@ public void testToPbAndFromPb() {
assertNull(blobInfo.contentEncoding());
assertNull(blobInfo.contentLanguage());
assertNull(blobInfo.crc32c());
assertNull(blobInfo.createTime());
assertNull(blobInfo.deleteTime());
assertNull(blobInfo.etag());
assertNull(blobInfo.generation());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public class BlobTest {
private static final String SELF_LINK = "http://storage/b/n";
private static final Long SIZE = 1024L;
private static final Long UPDATE_TIME = DELETE_TIME - 1L;
private static final Long CREATE_TIME = UPDATE_TIME - 1L;
private static final BlobInfo FULL_BLOB_INFO = BlobInfo.builder("b", "n", GENERATION)
.acl(ACL)
.componentCount(COMPONENT_COUNT)
Expand All @@ -93,6 +94,7 @@ public class BlobTest {
.selfLink(SELF_LINK)
.size(SIZE)
.updateTime(UPDATE_TIME)
.createTime(CREATE_TIME)
.build();
private static final BlobInfo BLOB_INFO = BlobInfo.builder("b", "n").metageneration(42L).build();
private static final BlobInfo DIRECTORY_INFO = BlobInfo.builder("b", "n/")
Expand Down Expand Up @@ -347,6 +349,7 @@ public void testBuilder() {
.selfLink(SELF_LINK)
.size(SIZE)
.updateTime(UPDATE_TIME)
.createTime(CREATE_TIME)
.build();
assertEquals("b", blob.bucket());
assertEquals("n", blob.name());
Expand All @@ -358,6 +361,7 @@ public void testBuilder() {
assertEquals(CONTENT_ENCODING, blob.contentEncoding());
assertEquals(CONTENT_LANGUAGE, blob.contentLanguage());
assertEquals(CRC32, blob.crc32c());
assertEquals(CREATE_TIME, blob.createTime());
assertEquals(DELETE_TIME, blob.deleteTime());
assertEquals(ETAG, blob.etag());
assertEquals(GENERATED_ID, blob.generatedId());
Expand Down Expand Up @@ -385,6 +389,7 @@ public void testBuilder() {
assertNull(blob.contentEncoding());
assertNull(blob.contentLanguage());
assertNull(blob.crc32c());
assertNull(blob.createTime());
assertNull(blob.deleteTime());
assertNull(blob.etag());
assertNull(blob.generatedId());
Expand Down