Search in sources :

Example 1 with PermissionsMinterms

use of com.infiniteautomation.mango.db.tables.PermissionsMinterms in project ma-core-public by infiniteautomation.

the class DataPointPermissionTest method getMintermIds.

private List<Integer> getMintermIds(int permissionId) {
    DSLContext create = Common.getBean(DatabaseProxy.class).getContext();
    PermissionsMinterms table = PermissionsMinterms.PERMISSIONS_MINTERMS;
    return create.select(table.mintermId).from(table).where(table.permissionId.eq(permissionId)).fetch(table.mintermId);
}
Also used : PermissionsMinterms(com.infiniteautomation.mango.db.tables.PermissionsMinterms) DSLContext(org.jooq.DSLContext) DatabaseProxy(com.serotonin.m2m2.db.DatabaseProxy)

Example 2 with PermissionsMinterms

use of com.infiniteautomation.mango.db.tables.PermissionsMinterms in project ma-core-public by infiniteautomation.

the class PermissionPersistenceTest method getMintermIds.

private List<Integer> getMintermIds(int permissionId) {
    DSLContext create = Common.getBean(DatabaseProxy.class).getContext();
    PermissionsMinterms table = PermissionsMinterms.PERMISSIONS_MINTERMS;
    return create.select(table.mintermId).from(table).where(table.permissionId.eq(permissionId)).fetch(table.mintermId);
}
Also used : PermissionsMinterms(com.infiniteautomation.mango.db.tables.PermissionsMinterms) DSLContext(org.jooq.DSLContext) DatabaseProxy(com.serotonin.m2m2.db.DatabaseProxy)

Example 3 with PermissionsMinterms

use of com.infiniteautomation.mango.db.tables.PermissionsMinterms in project ma-core-public by infiniteautomation.

the class PermissionDao method get.

/**
 * Get a MangoPermission by id
 * @return permission if found or null
 */
public MangoPermission get(Integer id) {
    // TODO Mango 4.0 improve performance
    // Fist check to see if it exists as it may have no minterms
    Integer foundId = create.select(permissions.id).from(permissions).where(permissions.id.equal(id)).fetchOneInto(Integer.class);
    if (foundId == null) {
        return null;
    }
    Map<Integer, Set<Role>> mintermMap = new HashMap<>();
    create.select(roleTable.id, roleTable.xid, permissionsMinterms.mintermId).from(permissionsMinterms).join(mintermsRoles).on(permissionsMinterms.mintermId.eq(mintermsRoles.mintermId)).join(roleTable).on(roleTable.id.eq(mintermsRoles.roleId)).where(permissionsMinterms.permissionId.eq(id)).orderBy(permissionsMinterms.permissionId.asc(), permissionsMinterms.mintermId.asc()).fetch().forEach(record -> {
        Role role = new Role(record.get(roleTable.id), record.get(roleTable.xid));
        Integer mintermId = record.get(permissionsMinterms.mintermId);
        mintermMap.computeIfAbsent(mintermId, m -> new HashSet<>()).add(role);
    });
    if (mintermMap.size() > 0) {
        Set<Set<Role>> roleSet = new HashSet<>(mintermMap.values());
        return new MangoPermission(roleSet).withId(id);
    }
    return new MangoPermission(id);
}
Also used : Role(com.serotonin.m2m2.vo.role.Role) DSL(org.jooq.impl.DSL) Role(com.serotonin.m2m2.vo.role.Role) Minterms(com.infiniteautomation.mango.db.tables.Minterms) TransactionDefinition(org.springframework.transaction.TransactionDefinition) DatabaseProxy(com.serotonin.m2m2.db.DatabaseProxy) Permissions(com.infiniteautomation.mango.db.tables.Permissions) Set(java.util.Set) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) MintermsRoles(com.infiniteautomation.mango.db.tables.MintermsRoles) Collectors(java.util.stream.Collectors) HashSet(java.util.HashSet) Map(java.util.Map) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) MangoPermission(com.infiniteautomation.mango.permission.MangoPermission) Repository(org.springframework.stereotype.Repository) DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) Roles(com.infiniteautomation.mango.db.tables.Roles) PermissionsMinterms(com.infiniteautomation.mango.db.tables.PermissionsMinterms) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) MangoPermission(com.infiniteautomation.mango.permission.MangoPermission) HashSet(java.util.HashSet)

Aggregations

PermissionsMinterms (com.infiniteautomation.mango.db.tables.PermissionsMinterms)3 DatabaseProxy (com.serotonin.m2m2.db.DatabaseProxy)3 DSLContext (org.jooq.DSLContext)2 Minterms (com.infiniteautomation.mango.db.tables.Minterms)1 MintermsRoles (com.infiniteautomation.mango.db.tables.MintermsRoles)1 Permissions (com.infiniteautomation.mango.db.tables.Permissions)1 Roles (com.infiniteautomation.mango.db.tables.Roles)1 MangoPermission (com.infiniteautomation.mango.permission.MangoPermission)1 Role (com.serotonin.m2m2.vo.role.Role)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 DSL (org.jooq.impl.DSL)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Repository (org.springframework.stereotype.Repository)1 TransactionDefinition (org.springframework.transaction.TransactionDefinition)1 DefaultTransactionDefinition (org.springframework.transaction.support.DefaultTransactionDefinition)1 TransactionTemplate (org.springframework.transaction.support.TransactionTemplate)1