Search in sources :

Example 1 with AbortProcessingException

use of javax.faces.event.AbortProcessingException in project acs-community-packaging by Alfresco.

the class BrowseBean method setupContentAction.

/**
 * Public helper to setup action pages with content context
 *
 * @param id     of the content node to setup context for
 */
public void setupContentAction(String id, boolean invalidate) {
    if (id != null && id.length() != 0) {
        if (logger.isDebugEnabled())
            logger.debug("Setup for action, setting current document to: " + id);
        try {
            // create the node ref, then our node representation
            NodeRef ref = new NodeRef(Repository.getStoreRef(), id);
            Node node = new MapNode(ref);
            // store the URL to for downloading the content
            if (ApplicationModel.TYPE_FILELINK.equals(node.getType())) {
                node.addPropertyResolver("url", this.resolverLinkDownload);
                node.addPropertyResolver("downloadUrl", this.resolverLinkDownload);
            } else {
                node.addPropertyResolver("url", this.resolverDownload);
                node.addPropertyResolver("downloadUrl", this.resolverDownload);
            }
            node.addPropertyResolver("webdavUrl", this.resolverWebdavUrl);
            node.addPropertyResolver("cifsPath", this.resolverCifsPath);
            node.addPropertyResolver("fileType32", this.resolverFileType32);
            node.addPropertyResolver("mimetype", this.resolverMimetype);
            node.addPropertyResolver("encoding", this.resolverEncoding);
            node.addPropertyResolver("size", this.resolverSize);
            node.addPropertyResolver("lang", this.resolverLang);
            for (NodeEventListener listener : getNodeEventListeners()) {
                listener.created(node, node.getType());
            }
            // get hold of the DocumentDetailsDialog and reset it
            DocumentDetailsDialog docDetails = (DocumentDetailsDialog) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("DocumentDetailsDialog");
            if (docDetails != null) {
                docDetails.reset();
            }
            // remember the document
            setDocument(node);
            // setup the dispatch context in case it is required
            this.navigator.setupDispatchContext(node);
        } catch (InvalidNodeRefException refErr) {
            Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_NODEREF), new Object[] { id }));
            throw new AbortProcessingException("Invalid node reference");
        }
    } else {
        setDocument(null);
    }
    // clear the UI state in preparation for finishing the next action
    if (invalidate == true) {
        // use the context service to notify all registered beans
        UIContextService.getInstance(FacesContext.getCurrentInstance()).notifyBeans();
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) DocumentDetailsDialog(org.alfresco.web.bean.content.DocumentDetailsDialog) Node(org.alfresco.web.bean.repository.Node) MapNode(org.alfresco.web.bean.repository.MapNode) AbortProcessingException(javax.faces.event.AbortProcessingException) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) MapNode(org.alfresco.web.bean.repository.MapNode)

Example 2 with AbortProcessingException

use of javax.faces.event.AbortProcessingException in project acs-community-packaging by Alfresco.

the class UINavigator method broadcast.

/**
 * @see javax.faces.component.UIInput#broadcast(javax.faces.event.FacesEvent)
 */
public void broadcast(FacesEvent event) throws AbortProcessingException {
    if (event instanceof NavigatorEvent) {
        FacesContext context = FacesContext.getCurrentInstance();
        NavigatorEvent navEvent = (NavigatorEvent) event;
        // node or panel selected?
        switch(navEvent.getMode()) {
            case PANEL_SELECTED:
                {
                    String panelSelected = navEvent.getItem();
                    // a panel was selected, setup the context to make the panel
                    // the focus
                    NavigationBean nb = (NavigationBean) FacesHelper.getManagedBean(context, NavigationBean.BEAN_NAME);
                    if (nb != null) {
                        try {
                            if (logger.isDebugEnabled())
                                logger.debug("Selecting panel: " + panelSelected);
                            nb.processToolbarLocation(panelSelected, true);
                        } catch (InvalidNodeRefException refErr) {
                            Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_NOHOME), Application.getCurrentUser(context).getHomeSpaceId()), refErr);
                        } catch (Exception err) {
                            Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err);
                        }
                    }
                    break;
                }
            case NODE_SELECTED:
                {
                    // a node was clicked in the tree
                    boolean nodeExists = true;
                    NodeRef nodeClicked = new NodeRef(navEvent.getItem());
                    // make sure the node exists still before navigating to it
                    UserTransaction tx = null;
                    try {
                        tx = Repository.getUserTransaction(context, true);
                        tx.begin();
                        NodeService nodeSvc = Repository.getServiceRegistry(context).getNodeService();
                        nodeExists = nodeSvc.exists(nodeClicked);
                        tx.commit();
                    } catch (Throwable err) {
                        try {
                            if (tx != null) {
                                tx.rollback();
                            }
                        } catch (Exception tex) {
                        }
                    }
                    if (nodeExists) {
                        // setup the context to make the node the current node
                        BrowseBean bb = (BrowseBean) FacesHelper.getManagedBean(context, BrowseBean.BEAN_NAME);
                        if (bb != null) {
                            if (logger.isDebugEnabled())
                                logger.debug("Selected node: " + nodeClicked);
                            bb.clickSpace(nodeClicked);
                        }
                    } else {
                        String msg = Application.getMessage(context, "navigator_node_deleted");
                        Utils.addErrorMessage(msg);
                    }
                    break;
                }
        }
    } else {
        super.broadcast(event);
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) FacesContext(javax.faces.context.FacesContext) NodeRef(org.alfresco.service.cmr.repository.NodeRef) NavigationBean(org.alfresco.web.bean.NavigationBean) BrowseBean(org.alfresco.web.bean.BrowseBean) NodeService(org.alfresco.service.cmr.repository.NodeService) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) AbortProcessingException(javax.faces.event.AbortProcessingException) IOException(java.io.IOException)

Example 3 with AbortProcessingException

use of javax.faces.event.AbortProcessingException in project acs-community-packaging by Alfresco.

the class CreateDiscussionDialog method createTopic.

// ------------------------------------------------------------------------------
// Helper methods
/**
 * Creates a topic for the node with the given id
 *
 * @param id The id of the node to discuss
 */
protected void createTopic(final String id) {
    RetryingTransactionCallback<NodeRef> createTopicCallback = new RetryingTransactionCallback<NodeRef>() {

        public NodeRef execute() throws Throwable {
            NodeRef forumNodeRef = null;
            discussingNodeRef = new NodeRef(Repository.getStoreRef(), id);
            if (getNodeService().hasAspect(discussingNodeRef, ForumModel.ASPECT_DISCUSSABLE)) {
                throw new AlfrescoRuntimeException("createDiscussion called for an object that already has a discussion!");
            }
            // Add the discussable aspect
            getNodeService().addAspect(discussingNodeRef, ForumModel.ASPECT_DISCUSSABLE, null);
            // The discussion aspect create the necessary child
            List<ChildAssociationRef> destChildren = getNodeService().getChildAssocs(discussingNodeRef, ForumModel.ASSOC_DISCUSSION, RegexQNamePattern.MATCH_ALL);
            // Take the first one
            if (destChildren.size() == 0) {
                // Drop the aspect and recreate it.  This should not happen, but just in case ...
                getNodeService().removeAspect(discussingNodeRef, ForumModel.ASPECT_DISCUSSABLE);
                getNodeService().addAspect(discussingNodeRef, ForumModel.ASPECT_DISCUSSABLE, null);
                // The discussion aspect create the necessary child
                destChildren = getNodeService().getChildAssocs(discussingNodeRef, ForumModel.ASSOC_DISCUSSION, RegexQNamePattern.MATCH_ALL);
            }
            if (destChildren.size() == 0) {
                throw new AlfrescoRuntimeException("The discussable aspect behaviour is not creating a topic");
            } else {
                // We just take the first one
                ChildAssociationRef discussionAssoc = destChildren.get(0);
                forumNodeRef = discussionAssoc.getChildRef();
            }
            if (logger.isDebugEnabled())
                logger.debug("created forum for content: " + discussingNodeRef.toString());
            return forumNodeRef;
        }
    };
    FacesContext context = FacesContext.getCurrentInstance();
    NodeRef forumNodeRef = null;
    try {
        forumNodeRef = getTransactionService().getRetryingTransactionHelper().doInTransaction(createTopicCallback, false);
    } catch (InvalidNodeRefException refErr) {
        Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_NODEREF), new Object[] { id }));
        throw new AbortProcessingException("Invalid node reference");
    } catch (Throwable e) {
        Utils.addErrorMessage(MessageFormat.format(Application.getMessage(context, Repository.ERROR_GENERIC), e.getMessage()), e);
        ReportedException.throwIfNecessary(e);
    }
    // finally setup the context for the forum we just created
    if (forumNodeRef != null) {
        this.browseBean.clickSpace(forumNodeRef);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) FacesContext(javax.faces.context.FacesContext) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) AbortProcessingException(javax.faces.event.AbortProcessingException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 4 with AbortProcessingException

use of javax.faces.event.AbortProcessingException in project acs-community-packaging by Alfresco.

the class StartWorkflowWizard method init.

// ------------------------------------------------------------------------------
// Wizard implementation
@Override
public void init(Map<String, String> parameters) {
    super.init(parameters);
    // reset the selected workflow
    if (this.availableWorkflows != null && this.availableWorkflows.size() > 0) {
        this.selectedWorkflow = (String) this.availableWorkflows.get(0).getValue();
    } else {
        this.selectedWorkflow = null;
    }
    this.previouslySelectedWorkflow = null;
    this.startTaskNode = null;
    this.resources = null;
    this.itemsToAdd = null;
    this.packageItemsToAdd = new ArrayList<String>();
    this.isItemBeingAdded = false;
    resetRichList();
    // add the item the workflow wizard was started on to the list of resources
    String itemToWorkflowId = this.parameters.get("item-to-workflow");
    try {
        if (itemToWorkflowId != null && itemToWorkflowId.length() > 0) {
            // create the node ref for the item and determine its type
            NodeRef itemToWorkflow = new NodeRef(Repository.getStoreRef(), itemToWorkflowId);
            QName type = this.getNodeService().getType(itemToWorkflow);
            if (this.getDictionaryService().isSubClass(type, ContentModel.TYPE_CONTENT) || this.getDictionaryService().isSubClass(type, ApplicationModel.TYPE_FILELINK)) {
                this.packageItemsToAdd.add(itemToWorkflow.toString());
            }
        }
    } catch (InvalidNodeRefException refErr) {
        Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_NODEREF), new Object[] { itemToWorkflowId }));
        throw new AbortProcessingException("Invalid node reference");
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) QName(org.alfresco.service.namespace.QName) AbortProcessingException(javax.faces.event.AbortProcessingException) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException)

Example 5 with AbortProcessingException

use of javax.faces.event.AbortProcessingException in project acs-community-packaging by Alfresco.

the class CheckinCheckoutDialog method setupContentDocument.

/**
 * Setup a content document node context
 *
 * @param id GUID of the node to setup as the content document context
 * @return The Node
 */
protected Node setupContentDocument(String id) {
    if (logger.isDebugEnabled())
        logger.debug("Setup for action, setting current document to: " + id);
    Node node = null;
    try {
        // create the node ref, then our node representation
        NodeRef ref = new NodeRef(Repository.getStoreRef(), id);
        node = new Node(ref);
        // create content URL to the content download servlet with ID and expected filename
        // the myfile part will be ignored by the servlet but gives the browser a hint
        String url = DownloadContentServlet.generateDownloadURL(ref, node.getName());
        node.getProperties().put("url", url);
        node.getProperties().put("workingCopy", node.hasAspect(ContentModel.ASPECT_WORKING_COPY));
        node.getProperties().put("fileType32", FileTypeImageUtils.getFileTypeImage(node.getName(), false));
        // remember the document
        property.setDocument(node);
        // refresh the UI, calling this method now is fine as it basically makes sure certain
        // beans clear the state - so when we finish here other beans will have been reset
        UIContextService.getInstance(FacesContext.getCurrentInstance()).notifyBeans();
    } catch (InvalidNodeRefException refErr) {
        Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_NODEREF), new Object[] { id }));
        throw new AbortProcessingException("Invalid node reference");
    }
    return node;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Node(org.alfresco.web.bean.repository.Node) AbortProcessingException(javax.faces.event.AbortProcessingException) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException)

Aggregations

AbortProcessingException (javax.faces.event.AbortProcessingException)5 InvalidNodeRefException (org.alfresco.service.cmr.repository.InvalidNodeRefException)5 NodeRef (org.alfresco.service.cmr.repository.NodeRef)5 FacesContext (javax.faces.context.FacesContext)2 Node (org.alfresco.web.bean.repository.Node)2 IOException (java.io.IOException)1 UserTransaction (javax.transaction.UserTransaction)1 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)1 RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)1 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)1 NodeService (org.alfresco.service.cmr.repository.NodeService)1 QName (org.alfresco.service.namespace.QName)1 BrowseBean (org.alfresco.web.bean.BrowseBean)1 NavigationBean (org.alfresco.web.bean.NavigationBean)1 DocumentDetailsDialog (org.alfresco.web.bean.content.DocumentDetailsDialog)1 MapNode (org.alfresco.web.bean.repository.MapNode)1