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;
}
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();
}
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;
}
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;
}
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());
}
Aggregations