Skip to content
Open
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
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,16 @@ for (RepositorySummary repoSummary : artifactory.storage().getStorageInfo().getR
##### Getting Items
```
ItemHandle fileItem = artifactory.repository("RepoName").file("path/to/file.txt");
ItemHandle folderItem = artifactory.repository("RepoName").folder("path/to/folder");
FolderHandle folderItem = artifactory.repository("RepoName").folder("path/to/folder");
```

##### Getting All Items Under A Folder
```
FolderHandle folder = artifactory.repository("RepoName").folder("path/to/folder");
boolean deep = true;
boolean listFolders = true;
boolean timeStamps = true;
FileList list = folder.list(deep, listFolders, timeStamps);
```

##### Copying Items
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.jfrog.artifactory.client;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.jfrog.artifactory.client.model.FileList;

@JsonIgnoreProperties(ignoreUnknown = true)
public interface FolderHandle extends ItemHandle {
FileList list(boolean deep, boolean listFolders, boolean timestamps);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
@JsonIgnoreProperties(ignoreUnknown = true)
public interface RepositoryHandle {

ItemHandle folder(String folderName);
FolderHandle folder(String folderName);

ItemHandle file(String filePath);

Expand Down
11 changes: 11 additions & 0 deletions api/src/main/java/org/jfrog/artifactory/client/model/FileList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.jfrog.artifactory.client.model;

import java.util.Date;
import java.util.List;

public interface FileList {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really need this new interface (and its implementing class)?
I can see that it is used as the returned value for this new API -

FileList list = folder.list(deep, listFolders, timeStamps);

but the returned value of this API can also be -

List<ListItem>= folder.list(deep, listFolders, timeStamps);

Copy link
Author

Choose a reason for hiding this comment

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

i think i need it for the deserialization because the return data has this structure:
String uri;
Date created;
ListItemImpl[] files;


String getUri();
Date getCreated();
List<ListItem> getFiles();
}
11 changes: 11 additions & 0 deletions api/src/main/java/org/jfrog/artifactory/client/model/ListItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.jfrog.artifactory.client.model;

import java.util.Date;

public interface ListItem {
String getUri();
Long getSize();
Date getLastModified();
Boolean isFolder();
String getSha1();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.jfrog.artifactory.client.impl;

import org.jfrog.artifactory.client.FolderHandle;
import org.jfrog.artifactory.client.model.FileList;
import org.jfrog.artifactory.client.model.impl.FileListImpl;

import java.io.IOException;

public class FolderHandleImpl extends ItemHandleImpl implements FolderHandle {

private final String baseApiPath;

private final ArtifactoryImpl artifactory;
private final String repo;
private final String path;

FolderHandleImpl(ArtifactoryImpl artifactory, String baseApiPath, String repo, String path, Class itemType) {
super(artifactory, baseApiPath, repo, path, itemType);
this.artifactory = artifactory;
this.repo = repo;
this.path = path;
this.baseApiPath = baseApiPath;
}

public FileList list(boolean deep, boolean listFolders, boolean timestamps) {
String deepInt = toInt(deep);
String listFoldersInt = toInt(listFolders);
String timestampsInt = toInt(timestamps);
String url = String.format("%s/storage/%s/%s?list&deep=%s&listFolders=%s&mdTimestamps=%s",
baseApiPath, repo, path, deepInt, listFoldersInt, timestampsInt);

FileListImpl fileListImpl = new FileListImpl();
try {
return artifactory.get(url, fileListImpl.getClass(), null);
} catch (IOException e) {
return null;
}
}

private String toInt(boolean b) {
return b?"1":"0";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,9 @@ class RepositoryHandleImpl implements RepositoryHandle {
this.repoKey = repoKey
}

//TODO: [by yl] Use a FileHandler and a FolderHandler instead or returning Items
@Override
ItemHandle folder(String folderName) {
new ItemHandleImpl(artifactory, baseApiPath, repoKey, folderName, FolderImpl)
FolderHandle folder(String folderName) {
new FolderHandleImpl(artifactory, baseApiPath, repoKey, folderName, FolderImpl)
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.jfrog.artifactory.client.model.impl;

import org.jfrog.artifactory.client.model.FileList;
import org.jfrog.artifactory.client.model.ListItem;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

public class FileListImpl implements FileList {

String uri;
Date created;
ListItemImpl[] files;

FileListImpl(String uri, Date created, ListItemImpl[] files) {
this.uri = uri;
this.created = created;
this.files = files;
}

public FileListImpl() {
}

@Override
public String getUri() {
return uri;
}

@Override
public Date getCreated() {
return created;
}

@Override
public List<ListItem> getFiles() {
return Arrays.asList(files);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.jfrog.artifactory.client.model.impl;

import org.jfrog.artifactory.client.model.File;
import org.jfrog.artifactory.client.model.ListItem;

import java.util.Date;

public class ListItemImpl implements ListItem {
String uri;
Long size;
Date lastModified;
Boolean folder;
String sha1;

ListItemImpl(String uri, Long size, Date lastModified, Boolean folder) {
this.uri = uri;
this.size = size;
this.lastModified = lastModified;
this.folder = folder;
}

ListItemImpl() {
}

@Override
public String getUri() {
return uri;
}

@Override
public Long getSize() {
return size;
}

@Override
public Date getLastModified() {
return lastModified;
}

@Override
public Boolean isFolder() {
return folder;
}

@Override
public String getSha1() {
return sha1;
}

}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=2.9.1
version=2.9.x-SNAPSHOT
19 changes: 19 additions & 0 deletions services/src/test/java/org/jfrog/artifactory/client/ItemTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.jfrog.artifactory.client.impl.ArtifactoryRequestImpl;
import org.jfrog.artifactory.client.impl.CopyMoveException;
import org.jfrog.artifactory.client.model.File;
import org.jfrog.artifactory.client.model.FileList;
import org.jfrog.artifactory.client.model.Folder;
import org.jfrog.artifactory.client.model.Item;
import org.jfrog.artifactory.client.model.LocalRepository;
Expand All @@ -13,10 +14,12 @@

import java.io.IOException;
import java.io.InputStream;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


import static org.testng.Assert.*;

/**
Expand All @@ -29,6 +32,22 @@ public class ItemTests extends ArtifactoryTestsBase {
protected static final String NEW_LOCAL_FROM = "new-local-from";
protected static final String NEW_LOCAL_TO = "new-local-to";

@Test
public void testFolderList() throws IOException {
artifactory.repository(getJCenterRepoName()).download("junit/junit/4.10/junit-4.10-sources.jar").doDownload();

FileList list = artifactory.repository(getJcenterCacheName()).folder("junit").list(true,true,true);
assertNotNull(list);
assertEquals(list.getFiles().size(),3);
assertEquals(list.getFiles().get(2).getSha1(),"6c98d6766e72d5575f96c9479d1c1d3b865c6e25");
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(1317323539000L);
assertEquals(list.getFiles().get(2).getLastModified().getTime(),calendar.getTime().getTime());

FileList list2 = artifactory.repository(getJcenterCacheName()).folder("junit").list(true,false,false);
assertEquals(list2.getFiles().size(),1);
}

@Test
public void testFolderInfo() throws IOException {
// Get the folder to the cache
Expand Down