Search in sources :

Example 26 with NuxeoException

use of org.nuxeo.ecm.core.api.NuxeoException in project nuxeo-drive-server by nuxeo.

the class FileSystemItemManagerImpl method rename.

@Override
public FileSystemItem rename(String id, String name, Principal principal) {
    FileSystemItem fsItem = getFileSystemItemById(id, principal);
    if (fsItem == null) {
        throw new NuxeoException(String.format("Cannot rename file system item with id %s because it doesn't exist.", id));
    }
    fsItem.rename(name);
    return fsItem;
}
Also used : FileSystemItem(org.nuxeo.drive.adapter.FileSystemItem) NuxeoException(org.nuxeo.ecm.core.api.NuxeoException)

Example 27 with NuxeoException

use of org.nuxeo.ecm.core.api.NuxeoException in project nuxeo-drive-server by nuxeo.

the class NuxeoDriveActions method getDriveEditURL.

/**
 * Returns the Drive edit URL for the given document.
 * <p>
 * {@link #NXDRIVE_PROTOCOL} must be handled by a protocol handler configured on the client side (either on the
 * browser, or on the OS).
 *
 * @since 7.4
 * @return Drive edit URL in the form "{@link #NXDRIVE_PROTOCOL}:// {@link #PROTOCOL_COMMAND_EDIT}
 *         /protocol/server[:port]/webappName/[user/userName/]repo/repoName/nxdocid/docId/filename/fileName[/
 *         downloadUrl/downloadUrl]"
 */
public String getDriveEditURL(@SuppressWarnings("hiding") DocumentModel currentDocument) {
    if (currentDocument == null) {
        return null;
    }
    // TODO NXP-15397: handle Drive not started exception
    BlobHolder bh = currentDocument.getAdapter(BlobHolder.class);
    if (bh == null) {
        throw new NuxeoException(String.format("Document %s (%s) is not a BlobHolder, cannot get Drive Edit URL.", currentDocument.getPathAsString(), currentDocument.getId()));
    }
    Blob blob = bh.getBlob();
    if (blob == null) {
        throw new NuxeoException(String.format("Document %s (%s) has no blob, cannot get Drive Edit URL.", currentDocument.getPathAsString(), currentDocument.getId()));
    }
    String fileName = blob.getFilename();
    ServletRequest servletRequest = (ServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
    String baseURL = VirtualHostHelper.getBaseURL(servletRequest);
    StringBuilder sb = new StringBuilder();
    sb.append(NXDRIVE_PROTOCOL).append("://");
    sb.append(PROTOCOL_COMMAND_EDIT).append("/");
    sb.append(baseURL.replaceFirst("://", "/"));
    sb.append("user/");
    sb.append(documentManager.getPrincipal().getName());
    sb.append("/");
    sb.append("repo/");
    sb.append(documentManager.getRepositoryName());
    sb.append("/nxdocid/");
    sb.append(currentDocument.getId());
    sb.append("/filename/");
    String escapedFilename = fileName.replaceAll("(/|\\\\|\\*|<|>|\\?|\"|:|\\|)", "-");
    sb.append(URIUtils.quoteURIPathComponent(escapedFilename, true));
    sb.append("/downloadUrl/");
    DownloadService downloadService = Framework.getService(DownloadService.class);
    String downloadUrl = downloadService.getDownloadUrl(currentDocument, DownloadService.BLOBHOLDER_0, "");
    sb.append(downloadUrl);
    return sb.toString();
}
Also used : ServletRequest(javax.servlet.ServletRequest) Blob(org.nuxeo.ecm.core.api.Blob) BlobHolder(org.nuxeo.ecm.core.api.blobholder.BlobHolder) NuxeoException(org.nuxeo.ecm.core.api.NuxeoException) DownloadService(org.nuxeo.ecm.core.io.download.DownloadService)

Example 28 with NuxeoException

use of org.nuxeo.ecm.core.api.NuxeoException in project nuxeo-drive-server by nuxeo.

the class NuxeoDriveIntegrationTestsHelper method getDefaultDomainPath.

public static String getDefaultDomainPath(CoreSession session) {
    String query = "SELECT * FROM Document where ecm:primaryType = 'Domain'";
    DocumentModelList results = session.query(query);
    if (results.isEmpty()) {
        throw new NuxeoException(String.format("Found no domains in repository %s", session.getRepositoryName()));
    }
    if (results.size() > 1) {
        if (log.isDebugEnabled()) {
            log.debug(String.format("Found more than one domain in repository %s, using first one.", session.getRepositoryName()));
        }
    }
    DocumentModel defaultDomain = results.get(0);
    String defaultDomainPath = defaultDomain.getPathAsString();
    if (log.isDebugEnabled()) {
        log.debug(String.format("Using default domain %s", defaultDomainPath));
    }
    return defaultDomainPath;
}
Also used : DocumentModelList(org.nuxeo.ecm.core.api.DocumentModelList) NuxeoException(org.nuxeo.ecm.core.api.NuxeoException) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel)

Example 29 with NuxeoException

use of org.nuxeo.ecm.core.api.NuxeoException in project nuxeo-drive-server by nuxeo.

the class NuxeoDriveAttachBlob method run.

@OperationMethod
public Blob run(Blob blob) {
    BlobHolder bh = doc.getAdapter(BlobHolder.class);
    if (bh == null) {
        throw new NuxeoException(String.format("Document %s is not a BlobHolder, no blob can be attached to it.", doc.getId()));
    }
    bh.setBlob(blob);
    session.saveDocument(doc);
    return blob;
}
Also used : BlobHolder(org.nuxeo.ecm.core.api.blobholder.BlobHolder) NuxeoException(org.nuxeo.ecm.core.api.NuxeoException) OperationMethod(org.nuxeo.ecm.automation.core.annotations.OperationMethod)

Example 30 with NuxeoException

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

the class SimpleBackend method removeItem.

@Override
public void removeItem(String location) {
    DocumentModel docToRemove = resolveLocation(location);
    if (docToRemove == null) {
        throw new NuxeoException("Document path not found: " + location);
    }
    removeItem(docToRemove.getRef());
}
Also used : NuxeoException(org.nuxeo.ecm.core.api.NuxeoException) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel)

Aggregations

NuxeoException (org.nuxeo.ecm.core.api.NuxeoException)31 FolderItem (org.nuxeo.drive.adapter.FolderItem)14 DocumentModel (org.nuxeo.ecm.core.api.DocumentModel)11 FileSystemItem (org.nuxeo.drive.adapter.FileSystemItem)9 IOException (java.io.IOException)5 Blob (org.nuxeo.ecm.core.api.Blob)5 CloseableCoreSession (org.nuxeo.ecm.core.api.CloseableCoreSession)5 DocumentModelList (org.nuxeo.ecm.core.api.DocumentModelList)4 Principal (java.security.Principal)3 DefaultSyncRootFolderItem (org.nuxeo.drive.adapter.impl.DefaultSyncRootFolderItem)3 BlobHolder (org.nuxeo.ecm.core.api.blobholder.BlobHolder)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ObjectInputStream (java.io.ObjectInputStream)2 ObjectOutputStream (java.io.ObjectOutputStream)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 Path (org.nuxeo.common.utils.Path)2