Search in sources :

Example 1 with Node

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

the class BrowseBean method updateUILocation.

/**
 * Refresh the UI after a Space selection change. Adds the selected space to the breadcrumb
 * location path and also updates the list components in the UI.
 *
 * @param ref     NodeRef of the selected space
 */
public void updateUILocation(NodeRef ref) {
    // get the current breadcrumb location and append a new handler to it
    // our handler know the ID of the selected node and the display label for it
    List<IBreadcrumbHandler> location = this.navigator.getLocation();
    if (location.size() != 0) {
        // attempt to find the ID - if it's already in the breadcrumb then we
        // navigate directly to that node - rather than add duplication to the breadcrumb path
        boolean foundNode = false;
        for (int i = 0; i < location.size(); i++) {
            IBreadcrumbHandler element = location.get(i);
            if (element instanceof IRepoBreadcrumbHandler) {
                NodeRef nodeRef = ((IRepoBreadcrumbHandler) element).getNodeRef();
                if (ref.equals(nodeRef) == true) {
                    // TODO: we should be able to do this - but the UIBreadcrumb component modifies
                    // it's own internal value when clicked - then uses that from then on!
                    // the other ops are using the same List object and modding it directly.
                    // List<IBreadcrumbHandler> newLocation = new ArrayList<IBreadcrumbHandler>(i+1);
                    // newLocation.addAll(location.subList(0, i + 1));
                    // this.navigator.setLocation(newLocation);
                    // TODO: but instead for now we do this:
                    int count = location.size();
                    for (int n = i + 1; n < count; n++) {
                        location.remove(i + 1);
                    }
                    foundNode = true;
                    break;
                }
            }
        }
        // add new node to the end of the existing breadcrumb
        if (foundNode == false) {
            FacesContext context = FacesContext.getCurrentInstance();
            String breadcrumbMode = Application.getClientConfig(context).getBreadcrumbMode();
            if (ClientConfigElement.BREADCRUMB_LOCATION.equals(breadcrumbMode)) {
                // if the breadcrumb is in "location" mode set the breadcrumb
                // to the full path to the node
                // TODO: check the end of the current breadcrumb, if the given
                // node is a child then we can shortcut the build of the
                // whole path.
                Repository.setupBreadcrumbLocation(context, this.navigator, location, ref);
            } else {
                // if the breadcrum is in "path" mode just add the given item to the end
                String name = Repository.getNameForNode(this.getNodeService(), ref);
                location.add(new BrowseBreadcrumbHandler(ref, name));
            }
        }
    } else {
        // special case to add first item to the location
        String name = Repository.getNameForNode(this.getNodeService(), ref);
        location.add(new BrowseBreadcrumbHandler(ref, name));
    }
    if (logger.isDebugEnabled())
        logger.debug("Updated breadcrumb: " + location);
    // set the current node Id ready for page refresh
    this.navigator.setCurrentNodeId(ref.getId());
    // set up the dispatch context for the navigation handler
    this.navigator.setupDispatchContext(new Node(ref));
    // inform any listeners that the current space has changed
    UIContextService.getInstance(FacesContext.getCurrentInstance()).spaceChanged();
    navigateBrowseScreen();
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) FacesContext(javax.faces.context.FacesContext) IBreadcrumbHandler(org.alfresco.web.ui.common.component.IBreadcrumbHandler) Node(org.alfresco.web.bean.repository.Node) MapNode(org.alfresco.web.bean.repository.MapNode) IRepoBreadcrumbHandler(org.alfresco.web.ui.repo.component.IRepoBreadcrumbHandler)

Example 2 with Node

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

the class BrowseBean method isSitesSpace.

/**
 * Determines whether the current space is a 'Sites' space
 *
 * @return true if the current space is a 'Sites' space
 */
public boolean isSitesSpace() {
    boolean siteSpace = false;
    Node currentNode = this.navigator.getCurrentNode();
    if (currentNode != null) {
        // check the type of the node to see if it is a 'site' related space
        QName currentNodeType = currentNode.getType();
        if (SiteModel.TYPE_SITES.isMatch(currentNodeType) || SiteModel.TYPE_SITE.isMatch(currentNodeType) || getDictionaryService().isSubClass(currentNodeType, SiteModel.TYPE_SITE)) {
            siteSpace = true;
        }
    }
    return siteSpace;
}
Also used : QName(org.alfresco.service.namespace.QName) Node(org.alfresco.web.bean.repository.Node) MapNode(org.alfresco.web.bean.repository.MapNode)

Example 3 with Node

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

the class BrowseBean method deleteSpace.

/**
 * Handles the deleteSpace action by deciding which delete dialog to display
 */
public void deleteSpace(ActionEvent event) {
    setupDeleteAction(event);
    boolean hasMultipleParents = false;
    boolean showDeleteAssocDialog = false;
    // determine if the node being delete has multiple parents
    Node node = this.getActionSpace();
    List<ChildAssociationRef> parents = this.nodeService.getParentAssocs(node.getNodeRef(), ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL);
    if (parents != null && parents.size() > 1) {
        hasMultipleParents = true;
    }
    // determine which delete dialog to display
    if (this.navigator.getSearchContext() == null && hasMultipleParents) {
        // if we are not in a search and the node has multiple parents
        // see if the current node has the primary parent association
        NodeRef parentSpace = this.navigator.getCurrentNode().getNodeRef();
        ChildAssociationRef assoc = this.nodeService.getPrimaryParent(node.getNodeRef());
        // show delete assoc dialog if the current space is not the primary parent for the node
        showDeleteAssocDialog = !parentSpace.equals(assoc.getParentRef());
    }
    // show the appropriate dialog
    FacesContext fc = FacesContext.getCurrentInstance();
    if (showDeleteAssocDialog) {
        fc.getApplication().getNavigationHandler().handleNavigation(fc, null, "dialog:deleteSpaceAssoc");
    } else {
        final Map<String, String> dialogParams = new HashMap<String, String>(1);
        dialogParams.put("hasMultipleParents", Boolean.toString(hasMultipleParents));
        Application.getDialogManager().setupParameters(dialogParams);
        fc.getApplication().getNavigationHandler().handleNavigation(fc, null, "dialog:deleteSpace");
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) FacesContext(javax.faces.context.FacesContext) HashMap(java.util.HashMap) Node(org.alfresco.web.bean.repository.Node) MapNode(org.alfresco.web.bean.repository.MapNode) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 4 with Node

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

the class BrowseBean method queryBrowseNodes.

// ------------------------------------------------------------------------------
// Helper methods
/**
 * Query a list of nodes for the specified parent node Id
 *
 * @param parentNodeId     Id of the parent node or null for the root node
 */
private void queryBrowseNodes(String parentNodeId) {
    long startTime = 0;
    if (logger.isDebugEnabled())
        startTime = System.currentTimeMillis();
    UserTransaction tx = null;
    try {
        FacesContext context = FacesContext.getCurrentInstance();
        tx = Repository.getUserTransaction(context, true);
        tx.begin();
        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<FileInfo> children = null;
        FileFilterMode.setClient(Client.webclient);
        try {
            children = this.getFileFolderService().list(parentRef);
        } finally {
            FileFilterMode.clearClient();
        }
        this.containerNodes = new ArrayList<Node>(children.size());
        this.contentNodes = new ArrayList<Node>(children.size());
        // in case of dynamic config, only lookup once
        Set<NodeEventListener> nodeEventListeners = getNodeEventListeners();
        for (FileInfo fileInfo : children) {
            // create our Node representation from the NodeRef
            NodeRef nodeRef = fileInfo.getNodeRef();
            // 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) {
                MapNode node = null;
                // look for File content node
                if (this.getDictionaryService().isSubClass(type, ContentModel.TYPE_CONTENT)) {
                    // create our Node representation
                    node = new MapNode(nodeRef, this.getNodeService(), fileInfo.getProperties());
                    setupCommonBindingProperties(node);
                    this.contentNodes.add(node);
                } else // look for Space folder node
                if (this.getDictionaryService().isSubClass(type, ContentModel.TYPE_FOLDER) == true && this.getDictionaryService().isSubClass(type, ContentModel.TYPE_SYSTEM_FOLDER) == false) {
                    // create our Node representation
                    node = new MapNode(nodeRef, this.getNodeService(), fileInfo.getProperties());
                    node.addPropertyResolver("icon", this.resolverSpaceIcon);
                    node.addPropertyResolver("smallIcon", this.resolverSmallIcon);
                    this.containerNodes.add(node);
                } else // look for File Link object node
                if (ApplicationModel.TYPE_FILELINK.equals(type)) {
                    // create our File Link Node representation
                    node = new MapNode(nodeRef, this.getNodeService(), fileInfo.getProperties());
                    // only display the user has the permissions to navigate to the target of the link
                    NodeRef destRef = (NodeRef) node.getProperties().get(ContentModel.PROP_LINK_DESTINATION);
                    if (destRef != null && new Node(destRef).hasPermission(PermissionService.READ) == true) {
                        node.addPropertyResolver("url", this.resolverLinkUrl);
                        node.addPropertyResolver("downloadUrl", this.resolverLinkDownload);
                        node.addPropertyResolver("webdavUrl", this.resolverLinkWebdavUrl);
                        node.addPropertyResolver("cifsPath", this.resolverLinkCifsPath);
                        node.addPropertyResolver("fileType16", this.resolverFileType16);
                        node.addPropertyResolver("fileType32", this.resolverFileType32);
                        node.addPropertyResolver("lang", this.resolverLang);
                        this.contentNodes.add(node);
                    }
                } else if (ApplicationModel.TYPE_FOLDERLINK.equals(type)) {
                    // create our Folder Link Node representation
                    node = new MapNode(nodeRef, this.getNodeService(), fileInfo.getProperties());
                    // only display the user has the permissions to navigate to the target of the link
                    NodeRef destRef = (NodeRef) node.getProperties().get(ContentModel.PROP_LINK_DESTINATION);
                    if (destRef != null && new Node(destRef).hasPermission(PermissionService.READ) == true) {
                        node.addPropertyResolver("icon", this.resolverSpaceIcon);
                        node.addPropertyResolver("smallIcon", this.resolverSmallIcon);
                        this.containerNodes.add(node);
                    }
                }
                // inform any listeners that a Node wrapper has been created
                if (node != null) {
                    for (NodeEventListener listener : nodeEventListeners) {
                        listener.created(node, type);
                    }
                }
            } 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() }), refErr);
        this.containerNodes = Collections.<Node>emptyList();
        this.contentNodes = 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.containerNodes = Collections.<Node>emptyList();
        this.contentNodes = 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 map 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) SearcherException(org.alfresco.repo.search.SearcherException) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) AbortProcessingException(javax.faces.event.AbortProcessingException) IOException(java.io.IOException) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException)

Example 5 with Node

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

the class BrowseBean method setupDeleteAction.

/**
 * Acrtion event called by Delete Space actions. We setup the action space as normal, then prepare
 * any special case message string to be shown to the user if they are trying to delete specific spaces.
 */
public void setupDeleteAction(ActionEvent event) {
    String message = null;
    setupSpaceAction(event);
    Node node = getActionSpace();
    if (node != null) {
        FacesContext fc = FacesContext.getCurrentInstance();
        NodeRef companyRootRef = new NodeRef(Repository.getStoreRef(), Application.getCompanyRootId(fc));
        if (node.getNodeRef().equals(companyRootRef)) {
            message = Application.getMessage(fc, MSG_DELETE_COMPANYROOT);
        }
    }
    setDeleteMessage(message);
}
Also used : FacesContext(javax.faces.context.FacesContext) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Node(org.alfresco.web.bean.repository.Node) MapNode(org.alfresco.web.bean.repository.MapNode)

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