Search in sources :

Example 21 with PathRef

use of org.nuxeo.ecm.core.api.PathRef in project nuxeo-filesystem-connectors by nuxeo.

the class WebDavClientTest method testDeleteFile.

@Test
public void testDeleteFile() throws Exception {
    String name = "test.txt";
    HttpDelete request = new HttpDelete(ROOT_URI + name);
    int status;
    try (CloseableHttpResponse response = client.execute(request, context)) {
        status = response.getStatusLine().getStatusCode();
    }
    assertEquals(HttpStatus.SC_NO_CONTENT, status);
    // check using Nuxeo Core APIs
    // process invalidations
    session.save();
    PathRef pathRef = new PathRef("/workspaces/workspace/" + name);
    // in the trash with different name
    assertFalse(session.exists(pathRef));
    // recreate it, for other tests using the same repo
    byte[] bytes = "Hello, world!".getBytes("UTF-8");
    doTestPutFile(name, bytes, "text/plain", "Note");
}
Also used : HttpDelete(org.apache.http.client.methods.HttpDelete) PathRef(org.nuxeo.ecm.core.api.PathRef) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) Test(org.junit.Test)

Example 22 with PathRef

use of org.nuxeo.ecm.core.api.PathRef in project nuxeo-filesystem-connectors by nuxeo.

the class WebDavClientTest method testCreateFolder.

@Test
public void testCreateFolder() throws Exception {
    String name = "newfolder";
    HttpMkcol request = new HttpMkcol(ROOT_URI + name);
    int status;
    try (CloseableHttpResponse response = client.execute(request, context)) {
        status = response.getStatusLine().getStatusCode();
    }
    assertEquals(HttpStatus.SC_CREATED, status);
    // check using Nuxeo Core APIs
    // process invalidations
    session.save();
    PathRef pathRef = new PathRef("/workspaces/workspace/" + name);
    assertTrue(session.exists(pathRef));
    DocumentModel doc = session.getDocument(pathRef);
    assertEquals("Folder", doc.getType());
    assertEquals(name, doc.getTitle());
}
Also used : HttpMkcol(org.apache.jackrabbit.webdav.client.methods.HttpMkcol) PathRef(org.nuxeo.ecm.core.api.PathRef) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) Test(org.junit.Test)

Example 23 with PathRef

use of org.nuxeo.ecm.core.api.PathRef in project nuxeo-filesystem-connectors by nuxeo.

the class SimpleBackend method cleanTrashPath.

protected boolean cleanTrashPath(DocumentModel parent, String name) {
    Path checkedPath = new Path(parent.getPathAsString()).append(name);
    if (getSession().exists(new PathRef(checkedPath.toString()))) {
        DocumentModel model = getSession().getDocument(new PathRef(checkedPath.toString()));
        if (model != null && model.isTrashed()) {
            name = name + "." + System.currentTimeMillis();
            getSession().move(model.getRef(), parent.getRef(), name);
            return true;
        }
    }
    return false;
}
Also used : Path(org.nuxeo.common.utils.Path) PathRef(org.nuxeo.ecm.core.api.PathRef) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel)

Example 24 with PathRef

use of org.nuxeo.ecm.core.api.PathRef in project nuxeo-filesystem-connectors by nuxeo.

the class SimpleBackend method resolveLocation.

@Override
public DocumentModel resolveLocation(String location) {
    Path resolvedLocation = parseLocation(location);
    DocumentModel doc = null;
    doc = getPathCache().get(resolvedLocation.toString());
    if (doc != null) {
        return doc;
    }
    DocumentRef docRef = new PathRef(resolvedLocation.toString());
    if (exists(docRef)) {
        doc = getSession().getDocument(docRef);
    } else {
        String encodedPath = urlEncode(resolvedLocation.toString());
        if (!resolvedLocation.toString().equals(encodedPath)) {
            DocumentRef encodedPathRef = new PathRef(encodedPath);
            if (exists(encodedPathRef)) {
                doc = getSession().getDocument(encodedPathRef);
            }
        }
        if (doc == null) {
            String filename = resolvedLocation.lastSegment();
            Path parentLocation = resolvedLocation.removeLastSegments(1);
            // first try with spaces (for create New Folder)
            String folderName = filename;
            DocumentRef folderRef = new PathRef(parentLocation.append(folderName).toString());
            if (exists(folderRef)) {
                doc = getSession().getDocument(folderRef);
            }
            // look for a child
            DocumentModel parentDocument = resolveParent(parentLocation.toString());
            if (parentDocument == null) {
                // parent doesn't exist, no use looking for a child
                return null;
            }
            List<DocumentModel> children = getChildren(parentDocument.getRef());
            for (DocumentModel child : children) {
                BlobHolder bh = child.getAdapter(BlobHolder.class);
                if (bh != null) {
                    Blob blob = bh.getBlob();
                    if (blob != null) {
                        try {
                            String blobFilename = blob.getFilename();
                            if (filename.equals(blobFilename)) {
                                doc = child;
                                break;
                            } else if (urlEncode(filename).equals(blobFilename)) {
                                doc = child;
                                break;
                            } else if (URLEncoder.encode(filename, "UTF-8").equals(blobFilename)) {
                                doc = child;
                                break;
                            } else if (encode(blobFilename.getBytes(), "ISO-8859-1").equals(filename)) {
                                doc = child;
                                break;
                            }
                        } catch (UnsupportedEncodingException e) {
                            // cannot happen for UTF-8
                            throw new RuntimeException(e);
                        }
                    }
                }
            }
        }
    }
    getPathCache().put(resolvedLocation.toString(), doc);
    return doc;
}
Also used : Path(org.nuxeo.common.utils.Path) Blob(org.nuxeo.ecm.core.api.Blob) DocumentRef(org.nuxeo.ecm.core.api.DocumentRef) PathRef(org.nuxeo.ecm.core.api.PathRef) BlobHolder(org.nuxeo.ecm.core.api.blobholder.BlobHolder) UnsupportedEncodingException(java.io.UnsupportedEncodingException) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel)

Example 25 with PathRef

use of org.nuxeo.ecm.core.api.PathRef in project nuxeo-filesystem-connectors by nuxeo.

the class SimpleBackend method getVirtualFolderNames.

@Override
public LinkedList<String> getVirtualFolderNames() {
    if (orderedBackendNames == null) {
        List<DocumentModel> children = getChildren(new PathRef(rootPath));
        orderedBackendNames = new LinkedList<String>();
        if (children != null) {
            for (DocumentModel model : children) {
                orderedBackendNames.add(model.getName());
            }
        }
    }
    return orderedBackendNames;
}
Also used : PathRef(org.nuxeo.ecm.core.api.PathRef) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel)

Aggregations

PathRef (org.nuxeo.ecm.core.api.PathRef)26 DocumentModel (org.nuxeo.ecm.core.api.DocumentModel)21 Test (org.junit.Test)14 DocumentRef (org.nuxeo.ecm.core.api.DocumentRef)8 Path (org.nuxeo.common.utils.Path)5 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)4 Blob (org.nuxeo.ecm.core.api.Blob)4 ArrayList (java.util.ArrayList)3 Blob (org.nuxeo.ecm.automation.client.model.Blob)3 IdRef (org.nuxeo.ecm.core.api.IdRef)3 ACE (org.nuxeo.ecm.core.api.security.ACE)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 StringBlob (org.nuxeo.ecm.automation.client.model.StringBlob)2 CollectionManager (org.nuxeo.ecm.collections.api.CollectionManager)2 CoreSession (org.nuxeo.ecm.core.api.CoreSession)2 DocumentModelList (org.nuxeo.ecm.core.api.DocumentModelList)2 NuxeoException (org.nuxeo.ecm.core.api.NuxeoException)2 BlobHolder (org.nuxeo.ecm.core.api.blobholder.BlobHolder)2 StringBlob (org.nuxeo.ecm.core.api.impl.blob.StringBlob)2