Skip to content

Commit cd13ec2

Browse files
committed
add file list functionality
1 parent de63056 commit cd13ec2

File tree

11 files changed

+195
-9
lines changed

11 files changed

+195
-9
lines changed

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,16 @@ for (RepositorySummary repoSummary : artifactory.storage().getStorageInfo().getR
191191
##### Getting Items
192192
```
193193
ItemHandle fileItem = artifactory.repository("RepoName").file("path/to/file.txt");
194-
ItemHandle folderItem = artifactory.repository("RepoName").folder("path/to/folder");
194+
FolderHandle folderItem = artifactory.repository("RepoName").folder("path/to/folder");
195+
```
196+
197+
##### Getting All Items Under A Folder
198+
```
199+
FolderHandle folder = artifactory.repository("RepoName").folder("path/to/folder");
200+
boolean deep = true;
201+
boolean listFolders = true;
202+
boolean timeStamps = true;
203+
FileList list = folder.list(deep, listFolders, timeStamps);
195204
```
196205

197206
##### Copying Items
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package org.jfrog.artifactory.client;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import org.jfrog.artifactory.client.model.FileList;
5+
6+
@JsonIgnoreProperties(ignoreUnknown = true)
7+
public interface FolderHandle extends ItemHandle {
8+
FileList list(boolean deep, boolean listFolders, boolean timestamps);
9+
}

api/src/main/java/org/jfrog/artifactory/client/RepositoryHandle.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
@JsonIgnoreProperties(ignoreUnknown = true)
1717
public interface RepositoryHandle {
1818

19-
ItemHandle folder(String folderName);
19+
FolderHandle folder(String folderName);
2020

2121
ItemHandle file(String filePath);
2222

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.jfrog.artifactory.client.model;
2+
3+
import java.util.Date;
4+
import java.util.List;
5+
6+
public interface FileList {
7+
8+
String getUri();
9+
Date getCreated();
10+
List<ListItem> getFiles();
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.jfrog.artifactory.client.model;
2+
3+
import java.util.Date;
4+
5+
public interface ListItem {
6+
String getUri();
7+
Long getSize();
8+
Date getLastModified();
9+
Boolean isFolder();
10+
String getSha1();
11+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package org.jfrog.artifactory.client.impl;
2+
3+
import org.jfrog.artifactory.client.FolderHandle;
4+
import org.jfrog.artifactory.client.model.FileList;
5+
import org.jfrog.artifactory.client.model.impl.FileListImpl;
6+
7+
import java.io.IOException;
8+
9+
public class FolderHandleImpl extends ItemHandleImpl implements FolderHandle {
10+
11+
private final String baseApiPath;
12+
13+
private final ArtifactoryImpl artifactory;
14+
private final String repo;
15+
private final String path;
16+
17+
FolderHandleImpl(ArtifactoryImpl artifactory, String baseApiPath, String repo, String path, Class itemType) {
18+
super(artifactory, baseApiPath, repo, path, itemType);
19+
this.artifactory = artifactory;
20+
this.repo = repo;
21+
this.path = path;
22+
this.baseApiPath = baseApiPath;
23+
}
24+
25+
public FileList list(boolean deep, boolean listFolders, boolean timestamps) {
26+
String deepInt = toInt(deep);
27+
String listFoldersInt = toInt(listFolders);
28+
String timestampsInt = toInt(timestamps);
29+
String url = String.format("%s/storage/%s/%s?list&deep=%s&listFolders=%s&mdTimestamps=%s",
30+
baseApiPath, repo, path, deepInt, listFoldersInt, timestampsInt);
31+
32+
FileListImpl fileListImpl = new FileListImpl();
33+
try {
34+
return artifactory.get(url, fileListImpl.getClass(), null);
35+
} catch (IOException e) {
36+
return null;
37+
}
38+
}
39+
40+
private String toInt(boolean b) {
41+
return b?"1":"0";
42+
}
43+
}

services/src/main/groovy/org/jfrog/artifactory/client/impl/RepositoryHandleImpl.groovy

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,9 @@ class RepositoryHandleImpl implements RepositoryHandle {
3838
this.repoKey = repoKey
3939
}
4040

41-
//TODO: [by yl] Use a FileHandler and a FolderHandler instead or returning Items
4241
@Override
43-
ItemHandle folder(String folderName) {
44-
new ItemHandleImpl(artifactory, baseApiPath, repoKey, folderName, FolderImpl)
42+
FolderHandle folder(String folderName) {
43+
new FolderHandleImpl(artifactory, baseApiPath, repoKey, folderName, FolderImpl)
4544
}
4645

4746
@Override
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package org.jfrog.artifactory.client.model.impl;
2+
3+
import org.jfrog.artifactory.client.model.FileList;
4+
import org.jfrog.artifactory.client.model.ListItem;
5+
6+
import java.util.Arrays;
7+
import java.util.Date;
8+
import java.util.List;
9+
10+
public class FileListImpl implements FileList {
11+
12+
String uri;
13+
Date created;
14+
ListItemImpl[] files;
15+
16+
FileListImpl(String uri, Date created, ListItemImpl[] files) {
17+
this.uri = uri;
18+
this.created = created;
19+
this.files = files;
20+
}
21+
22+
public FileListImpl() {
23+
}
24+
25+
@Override
26+
public String getUri() {
27+
return uri;
28+
}
29+
30+
@Override
31+
public Date getCreated() {
32+
return created;
33+
}
34+
35+
@Override
36+
public List<ListItem> getFiles() {
37+
return Arrays.asList(files);
38+
}
39+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package org.jfrog.artifactory.client.model.impl;
2+
3+
import org.jfrog.artifactory.client.model.File;
4+
import org.jfrog.artifactory.client.model.ListItem;
5+
6+
import java.util.Date;
7+
8+
public class ListItemImpl implements ListItem {
9+
String uri;
10+
Long size;
11+
Date lastModified;
12+
Boolean folder;
13+
String sha1;
14+
15+
ListItemImpl(String uri, Long size, Date lastModified, Boolean folder) {
16+
this.uri = uri;
17+
this.size = size;
18+
this.lastModified = lastModified;
19+
this.folder = folder;
20+
}
21+
22+
ListItemImpl() {
23+
}
24+
25+
@Override
26+
public String getUri() {
27+
return uri;
28+
}
29+
30+
@Override
31+
public Long getSize() {
32+
return size;
33+
}
34+
35+
@Override
36+
public Date getLastModified() {
37+
return lastModified;
38+
}
39+
40+
@Override
41+
public Boolean isFolder() {
42+
return folder;
43+
}
44+
45+
@Override
46+
public String getSha1() {
47+
return sha1;
48+
}
49+
50+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version=2.9.1
1+
version=2.9.x-SNAPSHOT

0 commit comments

Comments
 (0)