Search in sources :

Example 1 with MetaMenu

use of com.axelor.meta.db.MetaMenu in project axelor-open-suite by axelor.

the class CalendarConfigurationService method deleteEntryMenu.

@Transactional
public void deleteEntryMenu(CalendarConfiguration calendarConfiguration) {
    MetaAction metaAction = calendarConfiguration.getMetaAction();
    Role role = calendarConfiguration.getRole();
    Group group = calendarConfiguration.getCalendarGroup();
    calendarConfiguration.setMetaAction(null);
    calendarConfiguration.setRole(null);
    calendarConfiguration.getCalendarUser().removeRole(role);
    if (group != null) {
        group.removeRole(role);
    }
    String menuName = NAME + calendarConfiguration.getName().toLowerCase() + "-" + calendarConfiguration.getId();
    MetaMenuRepository metaMenuRepository = Beans.get(MetaMenuRepository.class);
    MetaMenu metaMenu = metaMenuRepository.findByName(menuName);
    metaMenuRepository.remove(metaMenu);
    MetaActionRepository metaActionRepository = Beans.get(MetaActionRepository.class);
    metaActionRepository.remove(metaAction);
    RoleRepository roleRepository = Beans.get(RoleRepository.class);
    roleRepository.remove(role);
}
Also used : Role(com.axelor.auth.db.Role) Group(com.axelor.auth.db.Group) MetaMenuRepository(com.axelor.meta.db.repo.MetaMenuRepository) MetaActionRepository(com.axelor.meta.db.repo.MetaActionRepository) MetaMenu(com.axelor.meta.db.MetaMenu) MetaAction(com.axelor.meta.db.MetaAction) RoleRepository(com.axelor.auth.db.repo.RoleRepository) Transactional(com.google.inject.persist.Transactional)

Example 2 with MetaMenu

use of com.axelor.meta.db.MetaMenu in project axelor-open-suite by axelor.

the class CalendarConfigurationService method createEntryMenu.

@Transactional
public void createEntryMenu(CalendarConfiguration calendarConfiguration) {
    String menuName = NAME + calendarConfiguration.getName().toLowerCase() + "-" + calendarConfiguration.getId();
    String subName = menuName.replaceAll("[-\\s]", ".");
    String title = calendarConfiguration.getName();
    User user = calendarConfiguration.getCalendarUser();
    Group group = calendarConfiguration.getCalendarGroup();
    MetaAction metaAction = this.createMetaAction("action." + subName, title);
    MetaMenu metaMenu = this.createMetaMenu(menuName, title, metaAction, calendarConfiguration.getParentMetaMenu());
    Beans.get(MetaMenuRepository.class).save(metaMenu);
    Role role = new Role();
    role.setName("role." + subName);
    role.addMenu(metaMenu);
    Beans.get(RoleRepository.class).save(role);
    user.addRole(role);
    Beans.get(UserRepository.class).save(user);
    if (group != null) {
        group.addRole(role);
        Beans.get(GroupRepository.class).save(group);
    }
    calendarConfiguration.setRole(role);
    calendarConfiguration.setMetaAction(metaAction);
    calendarConfigurationRepo.save(calendarConfiguration);
}
Also used : Role(com.axelor.auth.db.Role) Group(com.axelor.auth.db.Group) MetaMenuRepository(com.axelor.meta.db.repo.MetaMenuRepository) User(com.axelor.auth.db.User) UserRepository(com.axelor.auth.db.repo.UserRepository) MetaMenu(com.axelor.meta.db.MetaMenu) MetaAction(com.axelor.meta.db.MetaAction) GroupRepository(com.axelor.auth.db.repo.GroupRepository) RoleRepository(com.axelor.auth.db.repo.RoleRepository) Transactional(com.google.inject.persist.Transactional)

Example 3 with MetaMenu

use of com.axelor.meta.db.MetaMenu in project axelor-open-suite by axelor.

the class StudioMetaService method removeMetaMenu.

@Transactional
public void removeMetaMenu(MetaMenu metaMenu) {
    Preconditions.checkNotNull(metaMenu, "metaMenu cannot be null.");
    List<MetaMenu> subMenus = metaMenuRepo.all().filter("self.parent = ?1", metaMenu).fetch();
    for (MetaMenu subMenu : subMenus) {
        subMenu.setParent(null);
    }
    List<MenuBuilder> subBuilders = menuBuilderRepo.all().filter("self.parentMenu = ?1", metaMenu).fetch();
    for (MenuBuilder subBuilder : subBuilders) {
        subBuilder.setParentMenu(null);
        menuBuilderRepo.save(subBuilder);
    }
    metaMenuRepo.remove(metaMenu);
}
Also used : MetaMenu(com.axelor.meta.db.MetaMenu) MenuBuilder(com.axelor.studio.db.MenuBuilder) Transactional(com.google.inject.persist.Transactional)

Example 4 with MetaMenu

use of com.axelor.meta.db.MetaMenu in project axelor-open-suite by axelor.

the class MenuBuilderService method build.

@Transactional
public MetaMenu build(MenuBuilder builder) {
    MetaMenu menu = metaService.createMenu(builder);
    ActionBuilder actionBuilder = builder.getActionBuilder();
    if (actionBuilder != null) {
        if (actionBuilder.getName() == null) {
            actionBuilder.setName(menu.getName());
        }
        actionBuilder.setXmlId(builder.getXmlId());
        actionBuilder.setTitle(menu.getTitle());
        actionBuilder.setAppBuilder(builder.getAppBuilder());
        menu.setAction(actionBuilderService.build(actionBuilder));
    }
    MetaStore.clear();
    return menu;
}
Also used : ActionBuilder(com.axelor.studio.db.ActionBuilder) MetaMenu(com.axelor.meta.db.MetaMenu) Transactional(com.google.inject.persist.Transactional)

Example 5 with MetaMenu

use of com.axelor.meta.db.MetaMenu in project axelor-open-suite by axelor.

the class MenuBuilderRepo method remove.

@Override
public void remove(MenuBuilder menuBuilder) {
    MetaMenu metaMenu = menuBuilder.getMetaMenu();
    menuBuilder.setMetaMenu(null);
    if (metaMenu != null) {
        metaService.removeMetaMenu(metaMenu);
    }
    ActionBuilder actionBuilder = menuBuilder.getActionBuilder();
    menuBuilder.setActionBuilder(null);
    if (actionBuilder != null) {
        try {
            actionBuilderRepo.remove(actionBuilder);
        } catch (RuntimeException e) {
            TraceBackService.trace(e);
            throw e;
        }
    }
    MetaStore.clear();
    super.remove(menuBuilder);
}
Also used : ActionBuilder(com.axelor.studio.db.ActionBuilder) MetaMenu(com.axelor.meta.db.MetaMenu)

Aggregations

MetaMenu (com.axelor.meta.db.MetaMenu)19 Transactional (com.google.inject.persist.Transactional)10 Role (com.axelor.auth.db.Role)6 Group (com.axelor.auth.db.Group)5 MetaAction (com.axelor.meta.db.MetaAction)4 MetaMenuRepository (com.axelor.meta.db.repo.MetaMenuRepository)3 RoleRepository (com.axelor.auth.db.repo.RoleRepository)2 ActionBuilder (com.axelor.studio.db.ActionBuilder)2 HashSet (java.util.HashSet)2 App (com.axelor.apps.base.db.App)1 AppRepository (com.axelor.apps.base.db.repo.AppRepository)1 User (com.axelor.auth.db.User)1 GroupRepository (com.axelor.auth.db.repo.GroupRepository)1 UserRepository (com.axelor.auth.db.repo.UserRepository)1 MetaActionRepository (com.axelor.meta.db.repo.MetaActionRepository)1 MenuBuilder (com.axelor.studio.db.MenuBuilder)1