Skip to content
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 @@ -50,7 +50,6 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -648,7 +647,7 @@ PagedFlux<ShareFileItem> listFilesAndDirectoriesWithOptionalTimeout(
final ShareListFilesAndDirectoriesOptions modifiedOptions = options == null
? new ShareListFilesAndDirectoriesOptions() : options;

List<ListFilesIncludeType> includeTypes = new LinkedList<>();
List<ListFilesIncludeType> includeTypes = new ArrayList<>();
if (modifiedOptions.includeAttributes()) {
includeTypes.add(ListFilesIncludeType.ATTRIBUTES);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.storage.file.share.implementation.models;

import com.azure.storage.file.share.models.ShareFileItemProperties;

import java.time.OffsetDateTime;

public class InternalShareFileItemProperties implements ShareFileItemProperties {
private final OffsetDateTime createdOn;
private final OffsetDateTime lastAccessedOn;
private final OffsetDateTime lastWrittenOn;
private final OffsetDateTime changedOn;
private final OffsetDateTime lastModified;
private final String eTag;

/**
* Creates an instance of share item properties.
*
* @param createdOn Datetime the item was created.
* @param lastAccessedOn Datetime the item was last accessed.
* @param lastWrittenOn Datetime the item was last written.
* @param changedOn Datetime the item was last changed.
* @param lastModified Datetime the item was last modified.
* @param eTag ETag of the item.
*/
public InternalShareFileItemProperties(OffsetDateTime createdOn, OffsetDateTime lastAccessedOn,
OffsetDateTime lastWrittenOn, OffsetDateTime changedOn, OffsetDateTime lastModified, String eTag) {
this.createdOn = createdOn;
this.lastAccessedOn = lastAccessedOn;
this.lastWrittenOn = lastWrittenOn;
this.changedOn = changedOn;
this.lastModified = lastModified;
this.eTag = eTag;
}

/**
* @return Datetime this item was created.
*/
public OffsetDateTime getCreatedOn() {
return createdOn;
}

/**
* @return Datetime this item was last accessed.
*/
public OffsetDateTime getLastAccessedOn() {
return lastAccessedOn;
}

/**
* @return Datetime this item was last written.
*/
public OffsetDateTime getLastWrittenOn() {
return lastWrittenOn;
}

/**
* @return Datetime this item was last changed.
*/
public OffsetDateTime getChangedOn() {
return changedOn;
}

/**
* @return Datetime this item was last modified.
*/
public OffsetDateTime getLastModified() {
return lastModified;
}

/**
* @return ETag of this item.
*/
public String getETag() {
return eTag;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.azure.storage.common.implementation.StorageImplUtils;
import com.azure.storage.file.share.implementation.models.DeleteSnapshotsOptionType;
import com.azure.storage.file.share.implementation.models.FileProperty;
import com.azure.storage.file.share.implementation.models.InternalShareFileItemProperties;
import com.azure.storage.file.share.implementation.models.ServicesListSharesSegmentHeaders;
import com.azure.storage.file.share.implementation.models.ShareItemInternal;
import com.azure.storage.file.share.implementation.models.SharePropertiesInternal;
Expand Down Expand Up @@ -195,7 +196,7 @@ public static ShareFileItemProperties transformFileProperty(FileProperty propert
if (property == null) {
return null;
}
return new ShareFileItemProperties(property.getCreationTime(), property.getLastAccessTime(),
return new InternalShareFileItemProperties(property.getCreationTime(), property.getLastAccessTime(),
property.getLastWriteTime(), property.getChangeTime(), property.getLastModified(), property.getEtag());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,73 +8,35 @@
/**
* Share item properties for items on a listing operation.
*/
public class ShareFileItemProperties {
private final OffsetDateTime createdOn;
private final OffsetDateTime lastAccessedOn;
private final OffsetDateTime lastWrittenOn;
private final OffsetDateTime changedOn;
private final OffsetDateTime lastModified;
private final String eTag;

/**
* Creates an instance of share item properties.
*
* @param createdOn Datetime the item was created.
* @param lastAccessedOn Datetime the item was last accessed.
* @param lastWrittenOn Datetime the item was last written.
* @param changedOn Datetime the item was last changed.
* @param lastModified Datetime the item was last modified.
* @param eTag ETag of the item.
*/
public ShareFileItemProperties(OffsetDateTime createdOn, OffsetDateTime lastAccessedOn,
OffsetDateTime lastWrittenOn, OffsetDateTime changedOn, OffsetDateTime lastModified, String eTag) {
this.createdOn = createdOn;
this.lastAccessedOn = lastAccessedOn;
this.lastWrittenOn = lastWrittenOn;
this.changedOn = changedOn;
this.lastModified = lastModified;
this.eTag = eTag;
}
public interface ShareFileItemProperties {

/**
* @return Datetime this item was created.
*/
public OffsetDateTime getCreatedOn() {
return createdOn;
}
OffsetDateTime getCreatedOn();

/**
* @return Datetime this item was last accessed.
*/
public OffsetDateTime getLastAccessedOn() {
return lastAccessedOn;
}
OffsetDateTime getLastAccessedOn();

/**
* @return Datetime this item was last written.
*/
public OffsetDateTime getLastWrittenOn() {
return lastWrittenOn;
}
OffsetDateTime getLastWrittenOn();

/**
* @return Datetime this item was last changed.
*/
public OffsetDateTime getChangedOn() {
return changedOn;
}
OffsetDateTime getChangedOn();

/**
* @return Datetime this item was last modified.
*/
public OffsetDateTime getLastModified() {
return lastModified;
}
OffsetDateTime getLastModified();

/**
* @return ETag of this item.
*/
public String getETag() {
return eTag;
}
String getETag();
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ public Boolean includeExtendedInfo() {
* @throws IllegalStateException Throws when attempting to set null when other parameters require it to be true.
*/
public ShareListFilesAndDirectoriesOptions setIncludeExtendedInfo(Boolean includeExtendedInfo) {
if (includeTimestamps || includeETag || includeAttributes || includePermissionKey) {
throw logger.logExceptionAsError(
new IllegalStateException("includeExtendedInfo must be true in the current state."));
}
this.includeExtendedInfo = includeExtendedInfo;
return this;
}
Expand All @@ -103,9 +99,6 @@ public boolean includeTimestamps() {
*/
public ShareListFilesAndDirectoriesOptions setIncludeTimestamps(boolean includeTimestamps) {
this.includeTimestamps = includeTimestamps;
if (includeTimestamps) {
this.includeExtendedInfo = true;
}
return this;
}

Expand All @@ -122,9 +115,6 @@ public boolean includeETag() {
*/
public ShareListFilesAndDirectoriesOptions setIncludeETag(boolean includeETag) {
this.includeETag = includeETag;
if (includeETag) {
this.includeExtendedInfo = true;
}
return this;
}

Expand All @@ -141,9 +131,6 @@ public boolean includeAttributes() {
*/
public ShareListFilesAndDirectoriesOptions setIncludeAttributes(boolean includeAttributes) {
this.includeAttributes = includeAttributes;
if (includeAttributes) {
this.includeExtendedInfo = true;
}
return this;
}

Expand All @@ -160,9 +147,6 @@ public boolean includePermissionKey() {
*/
public ShareListFilesAndDirectoriesOptions setIncludePermissionKey(boolean includePermissionKey) {
this.includePermissionKey = includePermissionKey;
if (includePermissionKey) {
this.includeExtendedInfo = true;
}
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,42 @@ class DirectoryAPITests extends APISpec {
*/
@Unroll
def "List files and directories args"() {
given:
primaryDirectoryClient.create()
def nameList = new LinkedList()
def dirPrefix = namer.getRandomName(60)
for (int i = 0; i < 2; i++) {
def subDirClient = primaryDirectoryClient.getSubdirectoryClient(dirPrefix + i)
subDirClient.create()
for (int j = 0; j < 2; j++) {
def num = i * 2 + j + 3
subDirClient.createFile(dirPrefix + num, 1024)
}
}
primaryDirectoryClient.createFile(dirPrefix + 2, 1024)
for (int i = 0; i < 3; i++) {
nameList.add(dirPrefix + i)
}

when:
def fileRefIter = primaryDirectoryClient.listFilesAndDirectories(namer.getResourcePrefix() + extraPrefix, maxResults, null, null).iterator()

then:
for (int i = 0; i < numOfResults; i++) {
Objects.equals(nameList.pop(), fileRefIter.next().getName())
}
!fileRefIter.hasNext()

where:
extraPrefix | maxResults | numOfResults
"" | null | 3
"" | 1 | 3
"noOp" | 3 | 0
}
Comment on lines +385 to +416

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a reversion to the old test, keeping old and new service version functionality tested separately.


@Unroll
@RequiredServiceVersion(clazz = ShareServiceVersion.class, min = "V2020_10_02")
def "List files and directories extended info args"() {
given:
primaryDirectoryClient.create()
def nameList = [] as List<String>
Expand All @@ -401,37 +437,28 @@ class DirectoryAPITests extends APISpec {

when:
def options = new ShareListFilesAndDirectoriesOptions()
.setPrefix(namer.getResourcePrefix() + extraPrefix)
.setMaxResultsPerPage(maxResults)
.setIncludeExtendedInfo(includeExtendedInfo) // set FIRST since subsequent can autoset this one
.setPrefix(namer.getResourcePrefix())
.setIncludeExtendedInfo(true)
.setIncludeTimestamps(timestamps)
.setIncludeETag(etag)
.setIncludeAttributes(attributes)
.setIncludePermissionKey(permissionKey)
def returnedFileList = primaryDirectoryClient.listFilesAndDirectories(options, null, null).collect()

then:
options.includeExtendedInfo() == includeExtendedInfoIsTrue
if (expectingResults) {
assert nameList == returnedFileList*.getName()
}
else {
assert returnedFileList.size() == 0
}
nameList == returnedFileList*.getName()

where:
extraPrefix | maxResults | timestamps | etag | attributes | permissionKey | includeExtendedInfo || includeExtendedInfoIsTrue | expectingResults
"" | null | false | false | false | false | null || null | true
"" | 1 | false | false | false | false | null || null | true
"noOp" | 3 | false | false | false | false | null || null | false
"" | null | true | false | false | false | null || true | true
"" | null | false | true | false | false | null || true | true
"" | null | false | false | true | false | null || true | true
"" | null | false | false | false | true | null || true | true
"" | null | true | true | true | true | null || true | true
"" | null | false | false | false | false | true || true | true
timestamps | etag | attributes | permissionKey
false | false | false | false
true | false | false | false
false | true | false | false
false | false | true | false
false | false | false | true
true | true | true | true
}

@RequiredServiceVersion(clazz = ShareServiceVersion.class, min = "V2020_10_02")
def "List files and directories extended info results"() {
given:
def parentDir = primaryDirectoryClient
Expand Down
Loading