use of com.infiniteautomation.mango.db.tables.MintermsRoles 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);
}
Aggregations