Search in sources :

Example 1 with GroupRepository

use of com.axelor.auth.db.repo.GroupRepository in project axelor-open-suite by axelor.

the class ImportPermission method importPermission.

@Transactional
public Object importPermission(Object bean, Map<String, Object> values) {
    assert bean instanceof Permission;
    try {
        GroupRepository groupRepository = Beans.get(GroupRepository.class);
        Permission permission = (Permission) bean;
        String groups = (String) values.get("group");
        if (permission.getId() != null) {
            if (groups != null && !groups.isEmpty()) {
                for (Group group : groupRepository.all().filter("code in ?1", Arrays.asList(groups.split("\\|"))).fetch()) {
                    Set<Permission> permissions = group.getPermissions();
                    if (permissions == null)
                        permissions = new HashSet<Permission>();
                    permissions.add(permissionRepo.find(permission.getId()));
                    group.setPermissions(permissions);
                    groupRepository.save(group);
                }
            }
        }
        return permission;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return bean;
}
Also used : Group(com.axelor.auth.db.Group) Permission(com.axelor.auth.db.Permission) GroupRepository(com.axelor.auth.db.repo.GroupRepository) HashSet(java.util.HashSet) Transactional(com.google.inject.persist.Transactional)

Aggregations

Group (com.axelor.auth.db.Group)1 Permission (com.axelor.auth.db.Permission)1 GroupRepository (com.axelor.auth.db.repo.GroupRepository)1 Transactional (com.google.inject.persist.Transactional)1 HashSet (java.util.HashSet)1