use of com.agiletec.apsadmin.system.TreeNodeWrapper in project entando-core by entando.
the class CategoryAction method getAvailableNodesForMoveTreeAjax.
public List<TreeNodeWrapper> getAvailableNodesForMoveTreeAjax() {
List<TreeNodeWrapper> result = new ArrayList<TreeNodeWrapper>();
try {
String startCategoryCode = this.getSelectedNode();
if (StringUtils.isBlank(startCategoryCode)) {
_logger.warn("required parameter 'selectedNode' missing");
return result;
}
Category nodeToMove = this.getCategory(startCategoryCode);
if (null == nodeToMove) {
_logger.warn("category {} is null", startCategoryCode);
return result;
}
// XXX FIX JS
this.setCategoryCodeToken(super.getParameter("categoryCodeToken"));
List<Category> searchResult = this.getCategoryManager().searchCategories(this.getCategoryCodeToken());
if (null == searchResult || searchResult.isEmpty()) {
return result;
}
BeanComparator comparator = new BeanComparator("code");
Collections.sort(result, comparator);
int maxIndex = 30;
String maxParam = super.getParameter("max");
if (StringUtils.isNotBlank(maxParam) && StringUtils.isNumeric(maxParam)) {
maxIndex = new Integer(maxParam).intValue();
}
Iterator<Category> it = searchResult.iterator();
while (result.size() < maxIndex && it.hasNext()) {
ITreeNode candidate = it.next();
if (!candidate.isChildOf(nodeToMove.getCode()) && !candidate.getCode().equals(nodeToMove.getParentCode())) {
result.add(new TreeNodeWrapper(candidate, this.getCurrentLang().getCode()));
}
}
} catch (Throwable t) {
_logger.error("Error on searching categories ajax", t);
throw new RuntimeException("Error on searching categories ajax", t);
}
return result;
}
use of com.agiletec.apsadmin.system.TreeNodeWrapper in project entando-core by entando.
the class TestPageTreeAction method checkTestViewTree_3_4.
private void checkTestViewTree_3_4() throws Throwable {
ITreeNode showableRoot = ((PageTreeAction) this.getAction()).getShowableTree();
assertEquals("homepage", showableRoot.getCode());
assertTrue(showableRoot instanceof TreeNodeWrapper);
ITreeNode[] children = ((TreeNodeWrapper) showableRoot).getChildren();
assertEquals(7, children.length);
boolean check = false;
for (int i = 0; i < children.length; i++) {
TreeNodeWrapper child = (TreeNodeWrapper) children[i];
if (child.getCode().equals("pagina_1")) {
assertEquals(2, child.getChildrenCodes().length);
assertEquals("pagina_11", child.getChildrenCodes()[0]);
assertEquals("pagina_12", child.getChildrenCodes()[1]);
check = true;
} else {
assertEquals(0, child.getChildrenCodes().length);
}
}
if (!check) {
fail();
}
}
Aggregations