Search in sources :

Example 1 with QuickSort

use of org.alfresco.web.data.QuickSort 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 2 with QuickSort

use of org.alfresco.web.data.QuickSort in project acs-community-packaging by Alfresco.

the class TemplateSupportBean method selectDictionaryNodes.

/**
 * @param fc         FacesContext
 * @param xpath      XPath to the nodes to select
 * @param noSelectionLabel   Label to add to the list if no items are found in the search
 * @param mimetype   Optional mimetype of items to add, will not add to list if mimetype does not match
 *
 * @return List of SelectItem wrapper objects for the nodes found at the XPath
 */
private List<SelectItem> selectDictionaryNodes(FacesContext fc, String xpath, String noSelectionLabel, String mimetype) {
    List<SelectItem> wrappers = null;
    try {
        NodeRef rootNodeRef = this.getNodeService().getRootNode(Repository.getStoreRef());
        NamespaceService resolver = Repository.getServiceRegistry(fc).getNamespaceService();
        List<NodeRef> results = this.getSearchService().selectNodes(rootNodeRef, xpath, null, resolver, false);
        wrappers = new ArrayList<SelectItem>(results.size() + 1);
        if (results.size() != 0) {
            DictionaryService dd = Repository.getServiceRegistry(fc).getDictionaryService();
            for (NodeRef ref : results) {
                if (this.getNodeService().exists(ref) == true) {
                    Node childNode = new Node(ref);
                    ContentData content = (ContentData) childNode.getProperties().get(ContentModel.PROP_CONTENT);
                    if (dd.isSubClass(childNode.getType(), ContentModel.TYPE_CONTENT) && (mimetype == null || mimetype.equals(content.getMimetype()))) {
                        wrappers.add(new SelectItem(childNode.getId(), childNode.getName()));
                    }
                }
            }
            // make sure the list is sorted by the label
            QuickSort sorter = new QuickSort(wrappers, "label", true, IDataContainer.SORT_CASEINSENSITIVE);
            sorter.sort();
        }
    } catch (AccessDeniedException accessErr) {
    // ignore the result if we cannot access the root
    }
    // add an entry (at the start) to instruct the user to select an item
    if (wrappers == null) {
        wrappers = new ArrayList<SelectItem>(1);
    }
    wrappers.add(0, new SelectItem(NO_SELECTION, Application.getMessage(FacesContext.getCurrentInstance(), noSelectionLabel)));
    return wrappers;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) DictionaryService(org.alfresco.service.cmr.dictionary.DictionaryService) QuickSort(org.alfresco.web.data.QuickSort) AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException) ContentData(org.alfresco.service.cmr.repository.ContentData) NamespaceService(org.alfresco.service.namespace.NamespaceService) SelectItem(javax.faces.model.SelectItem) Node(org.alfresco.web.bean.repository.Node)

Example 3 with QuickSort

use of org.alfresco.web.data.QuickSort in project acs-community-packaging by Alfresco.

the class BaseActionWizard method getTestableAspects.

/**
 * Returns a list of aspects that can be tested i.e. hasAspect
 *
 * @return List of SelectItem objects representing the aspects that can be tested for
 */
public List<SelectItem> getTestableAspects() {
    if ((this.testableAspects == null) || (Application.isDynamicConfig(FacesContext.getCurrentInstance()))) {
        // get the list of common aspects
        this.testableAspects = new ArrayList<SelectItem>();
        this.testableAspects.addAll(getCommonAspects());
        // get those aspects configured to appear only in the remove aspect action
        ConfigService svc = Application.getConfigService(FacesContext.getCurrentInstance());
        Config wizardCfg = svc.getConfig("Action Wizards");
        if (wizardCfg != null) {
            ConfigElement aspectsCfg = wizardCfg.getConfigElement("aspects-test");
            if (aspectsCfg != null) {
                List<SelectItem> aspects = readAspectsConfig(FacesContext.getCurrentInstance(), aspectsCfg);
                this.testableAspects.addAll(aspects);
            } else {
                logger.warn("Could not find 'aspects-test' configuration element");
            }
        } else {
            logger.warn("Could not find 'Action Wizards' configuration section");
        }
        // make sure the list is sorted by the label
        QuickSort sorter = new QuickSort(this.testableAspects, "label", true, IDataContainer.SORT_CASEINSENSITIVE);
        sorter.sort();
    }
    return this.testableAspects;
}
Also used : QuickSort(org.alfresco.web.data.QuickSort) ConfigService(org.springframework.extensions.config.ConfigService) ConfigElement(org.springframework.extensions.config.ConfigElement) SelectItem(javax.faces.model.SelectItem) Config(org.springframework.extensions.config.Config)

Example 4 with QuickSort

use of org.alfresco.web.data.QuickSort in project acs-community-packaging by Alfresco.

the class BaseActionWizard method getUsers.

/**
 * @return the List of users in the system wrapped in SelectItem objects
 */
public List<SelectItem> getUsers() {
    if (this.users == null) {
        List<Node> userNodes = Repository.getUsers(FacesContext.getCurrentInstance(), this.getNodeService(), this.getPersonService());
        this.users = new ArrayList<SelectItem>();
        for (Node user : userNodes) {
            String email = (String) user.getProperties().get("email");
            if (email != null && email.length() > 0) {
                this.users.add(new SelectItem(email, (String) user.getProperties().get("fullName")));
            }
        }
        // make sure the list is sorted by the label
        QuickSort sorter = new QuickSort(this.users, "label", true, IDataContainer.SORT_CASEINSENSITIVE);
        sorter.sort();
    }
    return this.users;
}
Also used : QuickSort(org.alfresco.web.data.QuickSort) SelectItem(javax.faces.model.SelectItem) Node(org.alfresco.web.bean.repository.Node)

Example 5 with QuickSort

use of org.alfresco.web.data.QuickSort in project acs-community-packaging by Alfresco.

the class RunActionWizard method getActions.

@Override
public List<SelectItem> getActions() {
    if (this.actions == null) {
        NodeRef nodeRef = new NodeRef(Repository.getStoreRef(), this.parameters.get("id"));
        List<ActionDefinition> ruleActions = this.getActionService().getActionDefinitions(nodeRef);
        this.actions = new ArrayList<SelectItem>();
        for (ActionDefinition ruleActionDef : ruleActions) {
            String title = ruleActionDef.getTitle();
            if (title == null || title.length() == 0) {
                title = ruleActionDef.getName();
            }
            this.actions.add(new SelectItem(ruleActionDef.getName(), title));
        }
        // make sure the list is sorted by the label
        QuickSort sorter = new QuickSort(this.actions, "label", true, IDataContainer.SORT_CASEINSENSITIVE);
        sorter.sort();
        // add the select an action item at the start of the list
        this.actions.add(0, new SelectItem("null", Application.getMessage(FacesContext.getCurrentInstance(), "select_an_action")));
    }
    return this.actions;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) QuickSort(org.alfresco.web.data.QuickSort) SelectItem(javax.faces.model.SelectItem) ActionDefinition(org.alfresco.service.cmr.action.ActionDefinition)

Aggregations

QuickSort (org.alfresco.web.data.QuickSort)30 SelectItem (javax.faces.model.SelectItem)22 FacesContext (javax.faces.context.FacesContext)11 Config (org.springframework.extensions.config.Config)9 ConfigElement (org.springframework.extensions.config.ConfigElement)9 ConfigService (org.springframework.extensions.config.ConfigService)9 NodeRef (org.alfresco.service.cmr.repository.NodeRef)8 Node (org.alfresco.web.bean.repository.Node)6 ArrayList (java.util.ArrayList)5 QName (org.alfresco.service.namespace.QName)5 TreeNode (org.alfresco.web.ui.repo.component.UITree.TreeNode)5 ResponseWriter (javax.faces.context.ResponseWriter)4 ServiceRegistry (org.alfresco.service.ServiceRegistry)4 DictionaryService (org.alfresco.service.cmr.dictionary.DictionaryService)4 TypeDefinition (org.alfresco.service.cmr.dictionary.TypeDefinition)4 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)4 IOException (java.io.IOException)3 UserTransaction (javax.transaction.UserTransaction)3 MimetypeService (org.alfresco.service.cmr.repository.MimetypeService)3 HashMap (java.util.HashMap)2