Search in sources :

Example 21 with ChildAssociationRef

use of org.alfresco.service.cmr.repository.ChildAssociationRef 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 22 with ChildAssociationRef

use of org.alfresco.service.cmr.repository.ChildAssociationRef in project acs-community-packaging by Alfresco.

the class AdminNodeBrowseBean method selectResultNode.

/**
 * Action to select search result node
 *
 * @return next action
 */
public String selectResultNode() {
    ChildAssociationRef assocRef = (ChildAssociationRef) searchResults.getRows().getRowData();
    NodeRef childRef = assocRef.getChildRef();
    setNodeRef(childRef);
    return "success";
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 23 with ChildAssociationRef

use of org.alfresco.service.cmr.repository.ChildAssociationRef in project acs-community-packaging by Alfresco.

the class AdminNodeBrowseBean method getChildren.

/**
 * Gets the current node children
 *
 * @return node children
 */
public DataModel getChildren() {
    if (children == null) {
        List<ChildAssociationRef> assocRefs = getNodeService().getChildAssocs(getNodeRef());
        children = new ListDataModel(assocRefs);
    }
    return children;
}
Also used : ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) ListDataModel(javax.faces.model.ListDataModel)

Example 24 with ChildAssociationRef

use of org.alfresco.service.cmr.repository.ChildAssociationRef in project acs-community-packaging by Alfresco.

the class CategoryBrowserPluginBean method retrieveChildren.

/**
 * Retrieves the child folders for the noderef given in the 'noderef' parameter and caches the nodes against the area
 * in the 'area' parameter.
 */
public void retrieveChildren() throws IOException {
    FacesContext context = FacesContext.getCurrentInstance();
    ResponseWriter out = context.getResponseWriter();
    UserTransaction tx = null;
    try {
        tx = Repository.getUserTransaction(context, true);
        tx.begin();
        Map params = context.getExternalContext().getRequestParameterMap();
        String nodeRefStr = (String) params.get("nodeRef");
        // work out which list to cache the nodes in
        Map<String, TreeNode> currentNodes = getNodesMap();
        if (nodeRefStr != null && currentNodes != null) {
            // get the given node's details
            NodeRef parentNodeRef = new NodeRef(nodeRefStr);
            TreeNode parentNode = currentNodes.get(parentNodeRef.toString());
            parentNode.setExpanded(true);
            if (logger.isDebugEnabled())
                logger.debug("retrieving children for noderef: " + parentNodeRef);
            // remove any existing children as the latest ones will be added
            // below
            parentNode.removeChildren();
            // get all the child folder objects for the parent
            List<ChildAssociationRef> childRefs = this.getNodeService().getChildAssocs(parentNodeRef, ContentModel.ASSOC_SUBCATEGORIES, RegexQNamePattern.MATCH_ALL);
            List<TreeNode> sortedNodes = new ArrayList<TreeNode>();
            for (ChildAssociationRef ref : childRefs) {
                NodeRef nodeRef = ref.getChildRef();
                logger.debug("retrieving child : " + nodeRef);
                // build the XML representation of the child node
                TreeNode childNode = createTreeNode(nodeRef);
                parentNode.addChild(childNode);
                currentNodes.put(childNode.getNodeRef(), childNode);
                sortedNodes.add(childNode);
            }
            // order the tree nodes by the tree label
            if (sortedNodes.size() > 1) {
                QuickSort sorter = new QuickSort(sortedNodes, "name", true, IDataContainer.SORT_CASEINSENSITIVE);
                sorter.sort();
            }
            // generate the XML representation
            StringBuilder xml = new StringBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?><nodes>");
            for (TreeNode childNode : sortedNodes) {
                xml.append(childNode.toXML());
            }
            xml.append("</nodes>");
            // send the generated XML back to the tree
            out.write(xml.toString());
            if (logger.isDebugEnabled())
                logger.debug("returning XML: " + xml.toString());
        }
        // commit the transaction
        tx.commit();
    } catch (Throwable err) {
        try {
            if (tx != null) {
                tx.rollback();
            }
        } catch (Exception tex) {
        }
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) FacesContext(javax.faces.context.FacesContext) ArrayList(java.util.ArrayList) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) IOException(java.io.IOException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) QuickSort(org.alfresco.web.data.QuickSort) ResponseWriter(javax.faces.context.ResponseWriter) TreeNode(org.alfresco.web.ui.repo.component.UITree.TreeNode) HashMap(java.util.HashMap) Map(java.util.Map)

Example 25 with ChildAssociationRef

use of org.alfresco.service.cmr.repository.ChildAssociationRef in project acs-community-packaging by Alfresco.

the class CategoryBrowserPluginBean method getCategoryRootNodes.

public List<TreeNode> getCategoryRootNodes() {
    if (this.categoryRootNodes == null) {
        this.categoryRootNodes = new ArrayList<TreeNode>();
        this.categoryNodes = new HashMap<String, TreeNode>();
        UserTransaction tx = null;
        try {
            tx = Repository.getUserTransaction(FacesContext.getCurrentInstance(), true);
            tx.begin();
            Collection<ChildAssociationRef> childRefs = this.getCategoryService().getRootCategories(Repository.getStoreRef(), ContentModel.ASPECT_GEN_CLASSIFIABLE);
            for (ChildAssociationRef ref : childRefs) {
                NodeRef child = ref.getChildRef();
                TreeNode node = createTreeNode(child);
                this.categoryRootNodes.add(node);
                this.categoryNodes.put(node.getNodeRef(), node);
            }
            tx.commit();
        } catch (Throwable err) {
            Utils.addErrorMessage("NavigatorPluginBean exception in getCompanyHomeRootNodes()", err);
            try {
                if (tx != null) {
                    tx.rollback();
                }
            } catch (Exception tex) {
            }
        }
    }
    return this.categoryRootNodes;
}
Also used : UserTransaction(javax.transaction.UserTransaction) NodeRef(org.alfresco.service.cmr.repository.NodeRef) TreeNode(org.alfresco.web.ui.repo.component.UITree.TreeNode) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) IOException(java.io.IOException)

Aggregations

ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)258 NodeRef (org.alfresco.service.cmr.repository.NodeRef)202 QName (org.alfresco.service.namespace.QName)109 Test (org.junit.Test)56 HashMap (java.util.HashMap)54 BaseUnitTest (org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest)53 ArrayList (java.util.ArrayList)52 Serializable (java.io.Serializable)42 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)25 FacesContext (javax.faces.context.FacesContext)22 Map (java.util.Map)19 UserTransaction (javax.transaction.UserTransaction)18 Node (org.alfresco.web.bean.repository.Node)17 Date (java.util.Date)15 StoreRef (org.alfresco.service.cmr.repository.StoreRef)13 NodeService (org.alfresco.service.cmr.repository.NodeService)12 SiteInfo (org.alfresco.service.cmr.site.SiteInfo)12 List (java.util.List)11 StringPropertyValue (org.alfresco.solr.client.StringPropertyValue)11 IOException (java.io.IOException)10