@Override
    public Set<PermissionBean> getPermissions(String userId) throws StorageException {
        Set<PermissionBean> permissions = new HashSet<>();
        beginTx();
        try {
            EntityManager entityManager = getActiveEntityManager();
            CriteriaBuilder builder = entityManager.getCriteriaBuilder();
            CriteriaQuery<RoleMembershipBean> criteriaQuery = builder.createQuery(RoleMembershipBean.class);
            Root<RoleMembershipBean> from = criteriaQuery.from(RoleMembershipBean.class);
            criteriaQuery.where(builder.equal(from.get("userId"), userId));
            TypedQuery<RoleMembershipBean> typedQuery = entityManager.createQuery(criteriaQuery);
            typedQuery.setMaxResults(500);
            List<RoleMembershipBean> resultList = typedQuery.getResultList();
            for (RoleMembershipBean membership : resultList) {
                RoleBean role = getRoleInternal(membership.getRoleId());
                String qualifier = membership.getOrganizationId();
                for (PermissionType permission : role.getPermissions()) {
                    PermissionBean p = new PermissionBean();
                    p.setName(permission);
                    p.setOrganizationId(qualifier);
                    permissions.add(p);
                }
            }
            return permissions;
        } catch (Throwable t) {
            logger.error(t.getMessage(), t);
            throw new StorageException(t);
        } finally {
            rollbackTx();
        }
    }
@ Override public Set < PermissionBean > getPermissions ( String userId ) throws StorageException { Set < PermissionBean > permissions = new HashSet < > ( ) ; beginTx ( ) ; try { EntityManager entityManager = getActiveEntityManager ( ) ; CriteriaBuilder builder = entityManager . getCriteriaBuilder ( ) ; CriteriaQuery < RoleMembershipBean > criteriaQuery = builder . createQuery ( RoleMembershipBean . class ) ; Root < RoleMembershipBean > from = criteriaQuery . from ( RoleMembershipBean . class ) ; criteriaQuery . where ( builder . equal ( from . get ( "userId" ) , userId ) ) ; TypedQuery < RoleMembershipBean > typedQuery = entityManager . createQuery ( criteriaQuery ) ; typedQuery . setMaxResults ( 500 ) ; List < RoleMembershipBean > resultList = typedQuery . getResultList ( ) ; for ( RoleMembershipBean membership : resultList ) { RoleBean role = getRoleInternal ( membership . getRoleId ( ) ) ; String qualifier = membership . getOrganizationId ( ) ; for ( PermissionType permission : role . getPermissions ( ) ) { PermissionBean p = new PermissionBean ( ) ; p . setName ( permission ) ; p . setOrganizationId ( qualifier ) ; permissions . add ( p ) ; } } return permissions ; } catch ( Throwable t ) { logger . error ( t . getMessage ( ) , t ) ; throw new StorageException ( t ) ; } finally { rollbackTx ( ) ; } }
@see io.apiman.manager.api.core.IStorageQuery#getPermissions(java.lang.String)