Search in sources :

Example 46 with Node

use of org.alfresco.web.bean.repository.Node in project acs-community-packaging by Alfresco.

the class RecentSpacesBean method contextUpdated.

// ------------------------------------------------------------------------------
// IContextListener implementation
/**
 * @see org.alfresco.web.app.context.IContextListener#contextUpdated()
 */
public void contextUpdated() {
    // We use this listener handler to refresh the recent spaces list. At the point
    // where this method is called, the current node Id in UI will probably have changed.
    Node node = this.navigator.getCurrentNode();
    // that it appears at the top for us
    for (int i = 0; i < this.recentSpaces.size(); i++) {
        if (node.getId().equals(this.recentSpaces.get(i).getId())) {
            // found same node already in the list - remove it
            this.recentSpaces.remove(i);
            break;
        }
    }
    // remove an item if the list is at the maximum length
    int maxItems = getMaxRecentSpaces();
    if (this.recentSpaces.size() == maxItems) {
        this.recentSpaces.remove(maxItems - 1);
    }
    if (logger.isDebugEnabled())
        logger.debug("Inserting node: " + node.getName() + " at top of recent spaces list.");
    // insert our Node at the top of the list so it's most relevent
    this.recentSpaces.add(0, node);
}
Also used : Node(org.alfresco.web.bean.repository.Node)

Example 47 with Node

use of org.alfresco.web.bean.repository.Node in project acs-community-packaging by Alfresco.

the class ForumsBean method getNodes.

private void getNodes() {
    long startTime = 0;
    if (logger.isDebugEnabled())
        startTime = System.currentTimeMillis();
    UserTransaction tx = null;
    try {
        FacesContext context = FacesContext.getCurrentInstance();
        tx = Repository.getUserTransaction(context, true);
        tx.begin();
        // get the current space from NavigationBean
        String parentNodeId = this.navigator.getCurrentNodeId();
        NodeRef parentRef;
        if (parentNodeId == null) {
            // no specific parent node specified - use the root node
            parentRef = this.getNodeService().getRootNode(Repository.getStoreRef());
        } else {
            // build a NodeRef for the specified Id and our store
            parentRef = new NodeRef(Repository.getStoreRef(), parentNodeId);
        }
        List<ChildAssociationRef> childRefs = this.getNodeService().getChildAssocs(parentRef, ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL);
        this.forums = new ArrayList<Node>(childRefs.size());
        this.topics = new ArrayList<Node>(childRefs.size());
        this.posts = new ArrayList<Node>(childRefs.size());
        for (ChildAssociationRef ref : childRefs) {
            // create our Node representation from the NodeRef
            NodeRef nodeRef = ref.getChildRef();
            if (this.getNodeService().exists(nodeRef)) {
                // find it's type so we can see if it's a node we are interested in
                QName type = this.getNodeService().getType(nodeRef);
                // make sure the type is defined in the data dictionary
                TypeDefinition typeDef = this.getDictionaryService().getType(type);
                if (typeDef != null) {
                    if (this.getDictionaryService().isSubClass(type, ContentModel.TYPE_SYSTEM_FOLDER) == false) {
                        if (this.getDictionaryService().isSubClass(type, ForumModel.TYPE_FORUMS) || this.getDictionaryService().isSubClass(type, ForumModel.TYPE_FORUM)) {
                            // create our Node representation
                            MapNode node = new MapNode(nodeRef, this.getNodeService(), true);
                            node.addPropertyResolver("icon", this.browseBean.resolverSpaceIcon);
                            node.addPropertyResolver("smallIcon", this.browseBean.resolverSmallIcon);
                            this.forums.add(node);
                        }
                        if (this.getDictionaryService().isSubClass(type, ForumModel.TYPE_TOPIC)) {
                            // create our Node representation
                            MapNode node = new MapNode(nodeRef, this.getNodeService(), true);
                            node.addPropertyResolver("icon", this.browseBean.resolverSpaceIcon);
                            node.addPropertyResolver("smallIcon", this.browseBean.resolverSmallIcon);
                            node.addPropertyResolver("replies", this.resolverReplies);
                            this.topics.add(node);
                        } else if (this.getDictionaryService().isSubClass(type, ForumModel.TYPE_POST)) {
                            // create our Node representation
                            MapNode node = new MapNode(nodeRef, this.getNodeService(), true);
                            this.browseBean.setupCommonBindingProperties(node);
                            node.addPropertyResolver("smallIcon", this.browseBean.resolverSmallIcon);
                            node.addPropertyResolver("message", this.resolverContent);
                            node.addPropertyResolver("replyTo", this.resolverReplyTo);
                            this.posts.add(node);
                        }
                    }
                } else {
                    if (logger.isWarnEnabled())
                        logger.warn("Found invalid object in database: id = " + nodeRef + ", type = " + type);
                }
            }
        }
        // commit the transaction
        tx.commit();
    } catch (InvalidNodeRefException refErr) {
        Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_NODEREF), new Object[] { refErr.getNodeRef() }));
        this.forums = Collections.<Node>emptyList();
        this.topics = Collections.<Node>emptyList();
        this.posts = Collections.<Node>emptyList();
        try {
            if (tx != null) {
                tx.rollback();
            }
        } catch (Exception tex) {
        }
    } catch (Throwable err) {
        Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err);
        this.forums = Collections.<Node>emptyList();
        this.topics = Collections.<Node>emptyList();
        this.posts = Collections.<Node>emptyList();
        try {
            if (tx != null) {
                tx.rollback();
            }
        } catch (Exception tex) {
        }
    }
    if (logger.isDebugEnabled()) {
        long endTime = System.currentTimeMillis();
        logger.debug("Time to query and build forums nodes: " + (endTime - startTime) + "ms");
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) FacesContext(javax.faces.context.FacesContext) QName(org.alfresco.service.namespace.QName) Node(org.alfresco.web.bean.repository.Node) MapNode(org.alfresco.web.bean.repository.MapNode) MapNode(org.alfresco.web.bean.repository.MapNode) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) IOException(java.io.IOException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition) NodeRef(org.alfresco.service.cmr.repository.NodeRef) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException)

Example 48 with Node

use of org.alfresco.web.bean.repository.Node in project acs-community-packaging by Alfresco.

the class ForumsDetailsDialog method previousItem.

public void previousItem(ActionEvent event) {
    UIActionLink link = (UIActionLink) event.getComponent();
    Map<String, String> params = link.getParameterMap();
    String id = params.get("id");
    if (id != null && id.length() != 0) {
        NodeRef currNodeRef = new NodeRef(Repository.getStoreRef(), id);
        List<Node> nodes = this.browseBean.getParentNodes(currNodeRef);
        Node previous = null;
        if (nodes.size() > 1) {
            String currentSortColumn = this.browseBean.getSpacesRichList().getCurrentSortColumn();
            boolean currentSortDescending = this.browseBean.getSpacesRichList().isCurrentSortDescending();
            Collections.sort(nodes, new NodePropertyComparator(currentSortColumn, !currentSortDescending));
            previous = NodeListUtils.previousItem(nodes, id);
            this.browseBean.setupSpaceAction(previous.getId(), false);
        }
        if (previous == null) {
            Node currNode = new Node(currNodeRef);
            this.navigator.setupDispatchContext(currNode);
        }
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) UIActionLink(org.alfresco.web.ui.common.component.UIActionLink) Node(org.alfresco.web.bean.repository.Node) NodePropertyComparator(org.alfresco.web.ui.common.NodePropertyComparator)

Example 49 with Node

use of org.alfresco.web.bean.repository.Node in project acs-community-packaging by Alfresco.

the class TopicDetailsDialog method previousItem.

public void previousItem(ActionEvent event) {
    UIActionLink link = (UIActionLink) event.getComponent();
    Map<String, String> params = link.getParameterMap();
    String id = params.get("id");
    if (id != null && id.length() != 0) {
        NodeRef currNodeRef = new NodeRef(Repository.getStoreRef(), id);
        List<Node> nodes = this.browseBean.getParentNodes(currNodeRef);
        Node previous = null;
        if (nodes.size() > 1) {
            String currentSortColumn = this.browseBean.getSpacesRichList().getCurrentSortColumn();
            boolean currentSortDescending = this.browseBean.getSpacesRichList().isCurrentSortDescending();
            Collections.sort(nodes, new NodePropertyComparator(currentSortColumn, !currentSortDescending));
            previous = NodeListUtils.previousItem(nodes, id);
            this.browseBean.setupSpaceAction(previous.getId(), false);
        }
        if (previous == null) {
            Node currNode = new Node(currNodeRef);
            this.navigator.setupDispatchContext(currNode);
        }
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) UIActionLink(org.alfresco.web.ui.common.component.UIActionLink) Node(org.alfresco.web.bean.repository.Node) NodePropertyComparator(org.alfresco.web.ui.common.NodePropertyComparator)

Example 50 with Node

use of org.alfresco.web.bean.repository.Node in project acs-community-packaging by Alfresco.

the class EditOfflineDialog method checkoutFile.

/**
 * Checkout document to the same space as original one and then add the
 * OFFLINE_EDITING property.
 */
private void checkoutFile(Node node) {
    UserTransaction tx = null;
    FacesContext context = FacesContext.getCurrentInstance();
    if (node != null) {
        try {
            tx = Repository.getUserTransaction(context, false);
            tx.begin();
            if (logger.isDebugEnabled())
                logger.debug("Trying to checkout content node Id: " + node.getId());
            NodeRef workingCopyRef = null;
            // checkout the content to the current space
            workingCopyRef = property.getVersionOperationsService().checkout(node.getNodeRef());
            getNodeService().setProperty(workingCopyRef, ContentModel.PROP_WORKING_COPY_MODE, OFFLINE_EDITING);
            // set the working copy Node instance
            Node workingCopy = new Node(workingCopyRef);
            property.setWorkingDocument(workingCopy);
            // create content URL to the content download servlet with ID and
            // expected filename
            String url = DownloadContentServlet.generateDownloadURL(workingCopyRef, workingCopy.getName());
            workingCopy.getProperties().put("url", url);
            workingCopy.getProperties().put("fileType32", FileTypeImageUtils.getFileTypeImage(workingCopy.getName(), false));
            // commit the transaction
            tx.commit();
        } catch (Throwable err) {
            try {
                if (tx != null) {
                    tx.rollback();
                }
            } catch (Exception tex) {
            }
            Utils.addErrorMessage(Application.getMessage(FacesContext.getCurrentInstance(), MSG_ERROR_CHECKOUT) + err.getMessage(), err);
        }
    } else {
        logger.warn("WARNING: checkoutFile called without a current Document!");
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) FacesContext(javax.faces.context.FacesContext) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Node(org.alfresco.web.bean.repository.Node)

Aggregations

Node (org.alfresco.web.bean.repository.Node)145 NodeRef (org.alfresco.service.cmr.repository.NodeRef)81 FacesContext (javax.faces.context.FacesContext)44 MapNode (org.alfresco.web.bean.repository.MapNode)38 UIActionLink (org.alfresco.web.ui.common.component.UIActionLink)28 InvalidNodeRefException (org.alfresco.service.cmr.repository.InvalidNodeRefException)26 UserTransaction (javax.transaction.UserTransaction)22 QName (org.alfresco.service.namespace.QName)22 NodePropertyComparator (org.alfresco.web.ui.common.NodePropertyComparator)18 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)17 ArrayList (java.util.ArrayList)10 AccessDeniedException (org.alfresco.repo.security.permissions.AccessDeniedException)8 DictionaryService (org.alfresco.service.cmr.dictionary.DictionaryService)8 TypeDefinition (org.alfresco.service.cmr.dictionary.TypeDefinition)7 TransientNode (org.alfresco.web.bean.repository.TransientNode)7 IOException (java.io.IOException)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6 AbortProcessingException (javax.faces.event.AbortProcessingException)6 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)6