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) {
}
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations