use of com.serotonin.m2m2.vo.role.Role in project ma-core-public by infiniteautomation.
the class PostgresDatabaseTest method test1AutoIncrement.
@Test
public void test1AutoIncrement() throws SQLException {
DSLContext context = Common.getBean(DatabaseProxy.class).getContext();
Roles r = Roles.ROLES;
context.insertInto(r, r.id, r.xid, r.name).values(10, "xid", "name").execute();
context.insertInto(r, r.xid, r.name).values("test", "test").execute();
RoleVO role = Common.getBean(RoleDao.class).getByXid("test");
assertNotEquals(11, role.getId());
assertEquals(4, role.getId());
String sequence = r.getName() + "_" + r.id.getName() + "_seq";
context.alterSequence(sequence).restartWith(20).execute();
context.insertInto(r, r.xid, r.name).values("test2", "test2").execute();
role = Common.getBean(RoleDao.class).getByXid("test2");
assertEquals(20, role.getId());
}
use of com.serotonin.m2m2.vo.role.Role in project ma-core-public by infiniteautomation.
the class SetPointEventHandlerDefinition method handleRoleEvent.
@Override
public void handleRoleEvent(SetPointEventHandlerVO vo, DaoEvent<? extends RoleVO> event) {
// Remove and re-serialize our handler's script roles if it has a role that was deleted
if (vo.getScriptRoles().getRoles().contains(event.getVo().getRole())) {
switch(event.getType()) {
case UPDATE:
break;
case DELETE:
Set<Role> updated = new HashSet<>(vo.getScriptRoles().getRoles());
updated.remove(event.getVo().getRole());
Set<Role> allRoles = new HashSet<>();
for (Role role : updated) {
allRoles.addAll(service.getAllInheritedRoles(role));
}
ScriptPermissions permission = new ScriptPermissions(allRoles, vo.getScriptRoles().getPermissionHolderName());
vo.setScriptRoles(permission);
eventHandlerService.update(vo.getId(), vo);
break;
default:
break;
}
}
}
use of com.serotonin.m2m2.vo.role.Role in project ma-core-public by infiniteautomation.
the class JsonDataVO method jsonRead.
@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
super.jsonRead(reader, jsonObject);
String json = jsonObject.getString("jsonData");
try {
jsonData = JsonDataDao.getInstance().readValueFromString(json);
} catch (Exception e) {
throw new TranslatableJsonException("emport.error.parseError", "jsonData");
}
// Read permission handling in case we need to add the anonymous role
if (jsonObject.containsKey("readPermission")) {
readPermission = reader.read(MangoPermission.class, jsonObject.get("readPermission"));
} else {
readPermission = new MangoPermission();
}
if (jsonObject.containsKey("publicData") && jsonObject.getBoolean("publicData", false)) {
Set<Set<Role>> newRoles = new HashSet<>(readPermission.getRoles());
newRoles.add(Collections.singleton(PermissionHolder.ANONYMOUS_ROLE));
newRoles.add(Collections.singleton(PermissionHolder.USER_ROLE));
readPermission = new MangoPermission(newRoles);
}
}
use of com.serotonin.m2m2.vo.role.Role in project ma-core-public by infiniteautomation.
the class UserEventMulticasterTest method setupRoles.
@Before
public void setupRoles() {
roleService = Common.getBean(RoleService.class);
systemSuperadmin = PermissionHolder.SYSTEM_SUPERADMIN;
// Add some roles
mockRole = new RoleVO(Common.NEW_ID, "MOCK", "Mock test role.");
mockRole = roleService.insert(mockRole);
}
use of com.serotonin.m2m2.vo.role.Role in project ma-core-public by infiniteautomation.
the class RoleDao method addInheritance.
/**
* Recursively add all inherited roles
*/
private void addInheritance(Role role, Set<Role> all) {
Set<Role> inherited = getInherited(role.getId());
for (Role inheritedRole : inherited) {
all.add(inheritedRole);
addInheritance(inheritedRole, all);
}
}
Aggregations