Search in sources :

Example 6 with FileExistsException

use of org.alfresco.service.cmr.model.FileExistsException in project acs-community-packaging by Alfresco.

the class EditContentPropertiesDialog method formatErrorMessage.

/**
 * Formats the error message to display if an error occurs during finish processing
 *
 * @param exception The exception
 * @return The formatted message
 */
@Override
protected String formatErrorMessage(Throwable exception) {
    if (editableNode != null) {
        // special case for Mimetype - since this is a sub-property of the ContentData object
        // we must extract it so it can be edited in the client, then we check for it later
        // and create a new ContentData object to wrap it and it's associated URL
        ContentData content = (ContentData) this.editableNode.getProperties().get(ContentModel.PROP_CONTENT);
        if (content != null) {
            this.editableNode.getProperties().put(TEMP_PROP_MIMETYPE, content.getMimetype());
            this.editableNode.getProperties().put(TEMP_PROP_ENCODING, content.getEncoding());
        }
    }
    if (exception instanceof FileExistsException) {
        return MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_EXISTS), ((FileExistsException) exception).getName());
    } else if (exception instanceof InvalidNodeRefException) {
        return MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_NODEREF), new Object[] { this.browseBean.getDocument().getId() });
    } else {
        return super.formatErrorMessage(exception);
    }
}
Also used : ContentData(org.alfresco.service.cmr.repository.ContentData) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) FileExistsException(org.alfresco.service.cmr.model.FileExistsException)

Example 7 with FileExistsException

use of org.alfresco.service.cmr.model.FileExistsException in project alfresco-remote-api by Alfresco.

the class NodesImpl method makeFolders.

private NodeRef makeFolders(NodeRef parentNodeRef, List<String> pathElements) {
    NodeRef currentParentRef = parentNodeRef;
    // just loop and create if necessary
    for (final String element : pathElements) {
        final NodeRef contextNodeRef = currentParentRef;
        // does it exist?
        // Navigation should not check permissions
        NodeRef nodeRef = AuthenticationUtil.runAs(new RunAsWork<NodeRef>() {

            @Override
            public NodeRef doWork() throws Exception {
                return nodeService.getChildByName(contextNodeRef, ContentModel.ASSOC_CONTAINS, element);
            }
        }, AuthenticationUtil.getSystemUserName());
        if (nodeRef == null) {
            try {
                // Checks for create permissions as the fileFolderService is a public service.
                FileInfo createdFileInfo = fileFolderService.create(currentParentRef, element, ContentModel.TYPE_FOLDER);
                currentParentRef = createdFileInfo.getNodeRef();
            } catch (AccessDeniedException ade) {
                throw new PermissionDeniedException(ade.getMessage());
            } catch (FileExistsException fex) {
                // Assume concurrency failure, so retry
                throw new ConcurrencyFailureException(fex.getMessage());
            }
        } else if (!isSubClass(nodeRef, ContentModel.TYPE_FOLDER, false)) {
            String parentName = (String) nodeService.getProperty(contextNodeRef, ContentModel.PROP_NAME);
            throw new ConstraintViolatedException("Name [" + element + "] already exists in the target parent: " + parentName);
        } else {
            // it exists
            currentParentRef = nodeRef;
        }
    }
    return currentParentRef;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException) FileInfo(org.alfresco.service.cmr.model.FileInfo) ConcurrencyFailureException(org.springframework.dao.ConcurrencyFailureException) PermissionDeniedException(org.alfresco.rest.framework.core.exceptions.PermissionDeniedException) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException) FileExistsException(org.alfresco.service.cmr.model.FileExistsException) PermissionDeniedException(org.alfresco.rest.framework.core.exceptions.PermissionDeniedException) AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException) DuplicateChildNodeNameException(org.alfresco.service.cmr.repository.DuplicateChildNodeNameException) NotFoundException(org.alfresco.rest.framework.core.exceptions.NotFoundException) ConcurrencyFailureException(org.springframework.dao.ConcurrencyFailureException) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException) ApiException(org.alfresco.rest.framework.core.exceptions.ApiException) IntegrityException(org.alfresco.repo.node.integrity.IntegrityException) IOException(java.io.IOException) RequestEntityTooLargeException(org.alfresco.rest.framework.core.exceptions.RequestEntityTooLargeException) DisabledServiceException(org.alfresco.rest.framework.core.exceptions.DisabledServiceException) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) FileNotFoundException(org.alfresco.service.cmr.model.FileNotFoundException) ContentQuotaException(org.alfresco.service.cmr.usage.ContentQuotaException) UnsupportedMediaTypeException(org.alfresco.rest.framework.core.exceptions.UnsupportedMediaTypeException) AssociationExistsException(org.alfresco.service.cmr.repository.AssociationExistsException) InsufficientStorageException(org.alfresco.rest.framework.core.exceptions.InsufficientStorageException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) NodeLockedException(org.alfresco.service.cmr.lock.NodeLockedException) ContentIOException(org.alfresco.service.cmr.repository.ContentIOException) ContentLimitViolationException(org.alfresco.repo.content.ContentLimitViolationException) FileExistsException(org.alfresco.service.cmr.model.FileExistsException)

Example 8 with FileExistsException

use of org.alfresco.service.cmr.model.FileExistsException in project alfresco-remote-api by Alfresco.

the class ADMRemoteStore method createDocuments.

/**
 * Creates multiple XML documents encapsulated in a single one.
 *
 * @param res       WebScriptResponse
 * @param store       String
 * @param in       XML document containing multiple document contents to write
 */
@Override
protected void createDocuments(WebScriptResponse res, String store, InputStream in) {
    try {
        DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        Document document;
        document = documentBuilder.parse(in);
        Element docEl = document.getDocumentElement();
        Transformer transformer = ADMRemoteStore.this.transformer.get();
        for (Node n = docEl.getFirstChild(); n != null; n = n.getNextSibling()) {
            if (!(n instanceof Element)) {
                continue;
            }
            final String path = ((Element) n).getAttribute("path");
            // Turn the first element child into a document
            Document doc = documentBuilder.newDocument();
            Node child;
            for (child = n.getFirstChild(); child != null; child = child.getNextSibling()) {
                if (child instanceof Element) {
                    doc.appendChild(doc.importNode(child, true));
                    break;
                }
            }
            ByteArrayOutputStream out = new ByteArrayOutputStream(512);
            transformer.transform(new DOMSource(doc), new StreamResult(out));
            out.close();
            writeDocument(path, new ByteArrayInputStream(out.toByteArray()));
        }
    } catch (AccessDeniedException ae) {
        res.setStatus(Status.STATUS_UNAUTHORIZED);
        throw ae;
    } catch (FileExistsException feeErr) {
        res.setStatus(Status.STATUS_CONFLICT);
        throw feeErr;
    } catch (Exception e) {
        // various annoying checked SAX/IO exceptions related to XML processing can be thrown
        // none of them should occur if the XML document is well formed
        logger.error(e);
        res.setStatus(Status.STATUS_INTERNAL_SERVER_ERROR);
        throw new AlfrescoRuntimeException(e.getMessage(), e);
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(org.w3c.dom.Document) FileNotFoundException(org.alfresco.service.cmr.model.FileNotFoundException) FileExistsException(org.alfresco.service.cmr.model.FileExistsException) AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) SocketException(java.net.SocketException) ContentIOException(org.alfresco.service.cmr.repository.ContentIOException) IOException(java.io.IOException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) FileExistsException(org.alfresco.service.cmr.model.FileExistsException)

Example 9 with FileExistsException

use of org.alfresco.service.cmr.model.FileExistsException in project records-management by Alfresco.

the class RM978Test method testCopyDocumentInFolderInRmSite.

public void testCopyDocumentInFolderInRmSite() {
    doBehaviourDrivenTest(new BehaviourDrivenTest(AlfrescoRuntimeException.class, user) {

        private NodeRef folder1;

        private NodeRef document1;

        private String document1Name = GUID.generate();

        private NodeRef rmCategory;

        private NodeRef rmFolder;

        public void given() {
            folder1 = fileFolderService.create(documentLibrary, GUID.generate(), ContentModel.TYPE_FOLDER).getNodeRef();
            document1 = fileFolderService.create(folder1, document1Name, ContentModel.TYPE_CONTENT).getNodeRef();
            runAs(new RunAsWork<Void>() {

                public Void doWork() throws Exception {
                    rmCategory = filePlanService.createRecordCategory(filePlan, GUID.generate());
                    rmFolder = recordFolderService.createRecordFolder(rmCategory, GUID.generate());
                    return null;
                }
            }, getAdminUserName());
        }

        public void when() throws FileExistsException, FileNotFoundException {
            runAs(new RunAsWork<Void>() {

                public Void doWork() throws Exception {
                    filePlanPermissionService.setPermission(rmFolder, user, RMPermissionModel.FILING);
                    return null;
                }
            }, getAdminUserName());
            fileFolderService.copy(document1, rmFolder, null);
        }
    });
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) RunAsWork(org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork) FileNotFoundException(org.alfresco.service.cmr.model.FileNotFoundException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) FileExistsException(org.alfresco.service.cmr.model.FileExistsException)

Example 10 with FileExistsException

use of org.alfresco.service.cmr.model.FileExistsException in project records-management by Alfresco.

the class RM978Test method testMoveFolderInFolderInRmSite.

public void testMoveFolderInFolderInRmSite() {
    doBehaviourDrivenTest(new BehaviourDrivenTest(AlfrescoRuntimeException.class, user) {

        private NodeRef folder1;

        private NodeRef rmCategory;

        private NodeRef rmFolder;

        public void given() {
            folder1 = fileFolderService.create(documentLibrary, GUID.generate(), ContentModel.TYPE_FOLDER).getNodeRef();
            runAs(new RunAsWork<Void>() {

                public Void doWork() throws Exception {
                    rmCategory = filePlanService.createRecordCategory(filePlan, GUID.generate());
                    rmFolder = recordFolderService.createRecordFolder(rmCategory, GUID.generate());
                    return null;
                }
            }, getAdminUserName());
        }

        public void when() throws FileExistsException, FileNotFoundException {
            fileFolderService.move(folder1, rmFolder, GUID.generate());
        }
    });
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) RunAsWork(org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork) FileNotFoundException(org.alfresco.service.cmr.model.FileNotFoundException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) FileExistsException(org.alfresco.service.cmr.model.FileExistsException)

Aggregations

FileExistsException (org.alfresco.service.cmr.model.FileExistsException)12 NodeRef (org.alfresco.service.cmr.repository.NodeRef)10 FileNotFoundException (org.alfresco.service.cmr.model.FileNotFoundException)8 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)4 RunAsWork (org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork)4 FileInfo (org.alfresco.service.cmr.model.FileInfo)4 Serializable (java.io.Serializable)3 HashMap (java.util.HashMap)3 AccessDeniedException (org.alfresco.repo.security.permissions.AccessDeniedException)3 FileFolderService (org.alfresco.service.cmr.model.FileFolderService)3 ContentData (org.alfresco.service.cmr.repository.ContentData)3 InvalidNodeRefException (org.alfresco.service.cmr.repository.InvalidNodeRefException)3 IOException (java.io.IOException)2 Map (java.util.Map)2 IntegrityException (org.alfresco.repo.node.integrity.IntegrityException)2 ContentIOException (org.alfresco.service.cmr.repository.ContentIOException)2 NodeService (org.alfresco.service.cmr.repository.NodeService)2 QName (org.alfresco.service.namespace.QName)2 ConcurrencyFailureException (org.springframework.dao.ConcurrencyFailureException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1