use of com.infiniteautomation.mango.permission.MangoPermission 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);
}
use of com.infiniteautomation.mango.permission.MangoPermission in project ma-core-public by infiniteautomation.
the class SystemPermissionDao method update.
/**
* Update the permission
*/
public void update(String permissionTypeName, MangoPermission existing, MangoPermission permission) {
if (!existing.equals(permission)) {
permissionService.deletePermissions(existing);
}
MangoPermission toUpdate = permissionService.findOrCreate(permission);
this.create.update(SYSTEM_PERMISSIONS).set(SYSTEM_PERMISSIONS.permissionId, toUpdate.getId()).where(SYSTEM_PERMISSIONS.permissionType.eq(permissionTypeName)).execute();
}
use of com.infiniteautomation.mango.permission.MangoPermission in project ma-core-public by infiniteautomation.
the class EventDetectorDao method deletePostRelationalData.
@Override
public void deletePostRelationalData(AbstractEventDetectorVO vo) {
// Clean permissions
MangoPermission readPermission = vo.getReadPermission();
MangoPermission editPermission = vo.getEditPermission();
permissionService.deletePermissions(readPermission, editPermission);
vo.getDefinition().deletePostRelationalData(vo);
}
use of com.infiniteautomation.mango.permission.MangoPermission in project ma-core-public by infiniteautomation.
the class EventDetectorDao method savePreRelationalData.
@Override
public void savePreRelationalData(AbstractEventDetectorVO existing, AbstractEventDetectorVO vo) {
MangoPermission readPermission = permissionService.findOrCreate(vo.getReadPermission());
vo.setReadPermission(readPermission);
MangoPermission editPermission = permissionService.findOrCreate(vo.getEditPermission());
vo.setEditPermission(editPermission);
vo.getDefinition().savePreRelationalData(existing, vo);
}
use of com.infiniteautomation.mango.permission.MangoPermission in project ma-core-public by infiniteautomation.
the class DataSourceDao method mapRecord.
@Override
public DataSourceVO mapRecord(Record record) {
DataSourceVO ds = (DataSourceVO) SerializationHelper.readObjectInContextFromArray(record.get(table.data));
ds.setId(record.get(table.id));
ds.setXid(record.get(table.xid));
ds.setName(record.get(table.name));
ds.setDefinition(ModuleRegistry.getDataSourceDefinition(record.get(table.dataSourceType)));
ds.setData(extractDataFromObject(record.get(table.jsonData)));
ds.setReadPermission(new MangoPermission(record.get(table.readPermissionId)));
ds.setEditPermission(new MangoPermission(record.get(table.editPermissionId)));
return ds;
}
Aggregations