use of com.axelor.meta.db.MetaMenu in project axelor-open-suite by axelor.
the class MetaGroupMenuAssistantService method addMenuRows.
private void addMenuRows(MetaGroupMenuAssistant groupMenuAssistant, List<String[]> rows) {
String[] groupRow = rows.get(0);
rows.remove(0);
Set<String> names = new HashSet<>();
for (String[] line : rows) {
names.add(line[0]);
}
for (MetaMenu metaMenu : groupMenuAssistant.getMenuSet()) {
String name = metaMenu.getName();
if (names.contains(name)) {
continue;
}
String title = metaMenu.getTitle();
String translation = getBundle().getString(title);
if (!Strings.isNullOrEmpty(translation)) {
title = translation;
}
String[] menu = new String[groupRow.length];
menu[0] = name;
menu[1] = title;
rows.add(menu);
}
Collections.sort(rows, (first, second) -> first[0].compareTo(second[0]));
rows.add(0, groupRow);
}
use of com.axelor.meta.db.MetaMenu in project axelor-open-suite by axelor.
the class MetaGroupMenuAssistantService method importMenus.
private void importMenus(String[] row, String[] groupRow, Map<String, Object> groupMap, Group admin) {
List<MetaMenu> menus = menuRepository.all().filter("self.name = ?1", row[0]).order("-priority").fetch();
if (menus.isEmpty()) {
errorLog += "\n" + String.format(I18n.get(IMessage.NO_MENU), row[0]);
return;
}
for (MetaMenu menu : menus) {
boolean noAccess = true;
for (Integer mIndex = 2; mIndex < row.length; mIndex++) {
String code = groupRow[mIndex];
Object object = groupMap.get(code);
Role role = null;
Group group = null;
if (object instanceof Group) {
group = (Group) object;
} else if (object instanceof Role) {
role = (Role) object;
}
if (row[mIndex].equalsIgnoreCase("x")) {
noAccess = false;
if (group != null) {
menu.addGroup(group);
}
if (role != null) {
menu.addRole(role);
}
updatedMenus.add(menu);
} else if (group != null && menu.getGroups().contains(group)) {
menu.removeGroup(group);
updatedMenus.add(menu);
} else if (role != null && menu.getRoles().contains(role)) {
menu.removeRole(role);
updatedMenus.add(menu);
}
}
if (noAccess && admin != null) {
menu.addGroup(admin);
}
}
}
use of com.axelor.meta.db.MetaMenu in project axelor-open-suite by axelor.
the class WkfMenuService method createOrUpdateUserMenu.
@Transactional
public void createOrUpdateUserMenu(WkfTaskConfig wkfTaskConfig) {
String name = USER_MENU_PREFIX + wkfTaskConfig.getId();
MetaMenu metaMenu = findOrCreateMenu(name);
metaMenu.setTitle(wkfTaskConfig.getUserMenuName());
metaMenu.setAction(createOrUpdateAction(metaMenu, wkfTaskConfig, true));
metaMenu.setParent(null);
if (wkfTaskConfig.getUserParentMenuName() != null) {
metaMenu.setParent(metaMenuRepository.findByName(wkfTaskConfig.getUserParentMenuName()));
}
metaMenu.setTagCount(wkfTaskConfig.getUserDisplayTagCount());
if (wkfTaskConfig.getUserPositionMenuName() != null) {
MetaMenu positionMenu = metaMenuRepository.findByName(wkfTaskConfig.getUserPositionMenuName());
if (positionMenu != null) {
if (wkfTaskConfig.getUserMenuPosition().equals("before")) {
metaMenu.setOrder(positionMenu.getOrder() - 1);
} else {
metaMenu.setOrder(positionMenu.getOrder() + 1);
}
}
}
metaMenuRepository.save(metaMenu);
}
use of com.axelor.meta.db.MetaMenu in project axelor-open-suite by axelor.
the class WkfMenuService method removeUserMenu.
@Transactional
public void removeUserMenu(WkfTaskConfig wkfTaskConfig) {
String name = USER_MENU_PREFIX + wkfTaskConfig.getId();
MetaMenu metaMenu = metaMenuRepository.findByName(name);
if (metaMenu != null) {
metaMenuRepository.remove(metaMenu);
}
removeAction(name);
}
use of com.axelor.meta.db.MetaMenu in project axelor-open-suite by axelor.
the class WkfMenuService method removeMenu.
@Transactional
public void removeMenu(WkfTaskConfig wkfTaskConfig) {
String name = MENU_PREFIX + wkfTaskConfig.getId();
MetaMenu metaMenu = metaMenuRepository.findByName(name);
if (metaMenu != null) {
metaMenuRepository.remove(metaMenu);
}
removeAction(name);
}
Aggregations