@Override
public String index() throws Exception {
final String name = get("name");
final Long menuId = getLong("menu.id");
final Set<Menu> family;
final Menu givenMenu;
if (null != menuId) {
givenMenu = entityDao.get(Menu.class, menuId);
family = HierarchyEntityUtils.getFamily(givenMenu);
} else {
family = null;
givenMenu = null;
}
User user = entityDao.get(User.class, getUserId());
MenuProfile profile = menuService.getProfile(user, getLong("security.menuProfileId"));
List<Menu> menus = Collections.emptyList();
if (null != profile) {
menus = menuService.getMenus(profile, user);
}
CollectionUtils.filter(menus, new Predicate() {
public boolean evaluate(Object object) {
Menu amenu = (Menu) object;
if (null != family && !family.contains(amenu)) return false;
if (StringUtils.isNotEmpty(name)) {
if (!amenu.getChildren().isEmpty()) return false;
StringBuilder searchTarget = new StringBuilder(StrUtils.concat(amenu.getName(),
amenu.getTitle(), amenu.getRemark()));
for (Resource res : amenu.getResources()) {
searchTarget.append(StrUtils.concat(res.getName(), res.getTitle(), res.getRemark()));
}
return searchTarget.toString().contains(name);
} else return true;
}