Search in sources :

Example 6 with ListFile

use of org.ow2.proactive_grid_cloud_portal.dataspace.dto.ListFile in project scheduling by ow2-proactive.

the class FileSystem method list.

public static ListFile list(FileObject fo, List<String> includes, List<String> excludes) throws FileSystemException {
    fo.refresh();
    ListFile answer = new ListFile();
    List<String> dirList = Lists.newArrayList();
    List<String> fileList = Lists.newArrayList();
    List<String> fullList = Lists.newArrayList();
    List<FileObject> foundFileObjects = new LinkedList<>();
    if (isNullOrEmpty(includes) && isNullOrEmpty(excludes)) {
        fo.findFiles(Selectors.SELECT_CHILDREN, false, foundFileObjects);
    } else {
        FileSelector selector = new org.objectweb.proactive.extensions.dataspaces.vfs.selector.FileSelector(includes, excludes);
        fo.findFiles(selector, false, foundFileObjects);
    }
    for (FileObject child : foundFileObjects) {
        FileType type = child.getType();
        FileName childName = child.getName();
        switch(type) {
            case FOLDER:
                if (!child.equals(fo)) {
                    // exclude root directory from the list
                    String relativePath = fo.getName().getRelativeName(childName);
                    dirList.add(relativePath);
                    fullList.add(relativePath);
                }
                break;
            case FILE:
                String relativePath = fo.getName().getRelativeName(childName);
                fileList.add(relativePath);
                fullList.add(relativePath);
                break;
            default:
                throw new RuntimeException("Unknown : " + type);
        }
    }
    Collections.sort(dirList);
    Collections.sort(fileList);
    Collections.sort(fullList);
    answer.setDirectoryListing(dirList);
    answer.setFileListing(fileList);
    answer.setFullListing(fullList);
    return answer;
}
Also used : LinkedList(java.util.LinkedList) ListFile(org.ow2.proactive_grid_cloud_portal.dataspace.dto.ListFile)

Example 7 with ListFile

use of org.ow2.proactive_grid_cloud_portal.dataspace.dto.ListFile in project scheduling by ow2-proactive.

the class SchedulerRestClient method list.

public ListFile list(String sessionId, String dataspacePath, String pathname) throws Exception {
    StringBuffer uriTmpl = (new StringBuffer()).append(restEndpointURL).append(addSlashIfMissing(restEndpointURL)).append("data/").append(dataspacePath).append('/');
    ResteasyClient client = new ResteasyClientBuilder().httpEngine(httpEngine).providerFactory(providerFactory).build();
    ResteasyWebTarget target = client.target(uriTmpl.toString()).path(pathname).queryParam("comp", "list");
    Response response = null;
    try {
        response = target.request().header("sessionid", sessionId).get();
        if (response.getStatus() != HttpURLConnection.HTTP_OK) {
            if (response.getStatus() == HttpURLConnection.HTTP_UNAUTHORIZED) {
                throw new NotConnectedRestException("User not authenticated or session timeout.");
            } else {
                throwException(String.format("Cannot list the specified location: %s", pathname), response);
            }
        }
        return response.readEntity(ListFile.class);
    } finally {
        if (response != null) {
            response.close();
        }
    }
}
Also used : Response(javax.ws.rs.core.Response) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) ResteasyClient(org.jboss.resteasy.client.jaxrs.ResteasyClient) ResteasyWebTarget(org.jboss.resteasy.client.jaxrs.ResteasyWebTarget) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException)

Aggregations

ListFile (org.ow2.proactive_grid_cloud_portal.dataspace.dto.ListFile)4 Test (org.junit.Test)3 ResteasyClient (org.jboss.resteasy.client.jaxrs.ResteasyClient)2 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)2 ResteasyWebTarget (org.jboss.resteasy.client.jaxrs.ResteasyWebTarget)2 LinkedList (java.util.LinkedList)1 Response (javax.ws.rs.core.Response)1 FileObject (org.apache.commons.vfs2.FileObject)1 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)1 Session (org.ow2.proactive_grid_cloud_portal.common.Session)1 NotConnectedRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException)1