use of com.infiniteautomation.mango.spring.service.PermissionService in project ma-modules-public by infiniteautomation.
the class EmailEventHandlerModel method readInto.
@Override
public void readInto(EmailEventHandlerVO vo) {
super.readInto(vo);
if (activeRecipients != null) {
List<MailingListRecipient> beans = new ArrayList<>();
for (EmailRecipientModel model : activeRecipients) beans.add(model.fromModel());
vo.setActiveRecipients(beans);
}
vo.setSendEscalation(sendEscalation);
vo.setRepeatEscalations(repeatEscalations);
vo.setEscalationDelayType(Common.TIME_PERIOD_CODES.getId(escalationDelayType));
vo.setEscalationDelay(escalationDelay);
if (escalationRecipients != null) {
List<MailingListRecipient> beans = new ArrayList<>();
for (EmailRecipientModel model : escalationRecipients) beans.add(model.fromModel());
vo.setEscalationRecipients(beans);
}
vo.setSendInactive(sendInactive);
vo.setInactiveOverride(inactiveOverride);
if (inactiveRecipients != null) {
List<MailingListRecipient> beans = new ArrayList<>();
for (EmailRecipientModel model : inactiveRecipients) beans.add(model.fromModel());
vo.setInactiveRecipients(beans);
}
vo.setIncludeSystemInfo(includeSystemInfo);
if (includePointValueCount != null)
vo.setIncludePointValueCount(includePointValueCount);
vo.setIncludeLogfile(includeLogfile);
vo.setCustomTemplate(customTemplate);
vo.setScript(script);
PermissionService service = Common.getBean(PermissionService.class);
vo.setScriptRoles(new ScriptPermissions(service.explodeLegacyPermissionGroupsToRoles(scriptPermissions)));
if (scriptContext != null) {
List<IntStringPair> additionalContext = new ArrayList<>();
for (ScriptContextVariableModel var : scriptContext) {
Integer id = DataPointDao.getInstance().getIdByXid(var.getXid());
if (id != null) {
additionalContext.add(new IntStringPair(id, var.getVariableName()));
} else {
additionalContext.add(new IntStringPair(Common.NEW_ID, var.getVariableName()));
}
}
vo.setAdditionalContext(additionalContext);
}
vo.setSubject(EmailEventHandlerVO.SUBJECT_INCLUDE_CODES.getId(subject));
}
use of com.infiniteautomation.mango.spring.service.PermissionService in project ma-modules-public by infiniteautomation.
the class MangoJavaScriptModel method toVO.
public MangoJavaScript toVO() {
MangoJavaScript vo = new MangoJavaScript();
vo.setWrapInFunction(wrapInFunction);
vo.setContext(convertContext());
vo.setLogLevel(logLevel);
PermissionService service = Common.getBean(PermissionService.class);
vo.setPermissions(new ScriptPermissions(service.explodeLegacyPermissionGroupsToRoles(permissions)));
if (resultDataType != null)
vo.setResultDataType(DataType.fromName(resultDataType));
vo.setScript(script);
vo.setAdditionalContext(additionalContext);
return vo;
}
use of com.infiniteautomation.mango.spring.service.PermissionService in project ma-core-public by infiniteautomation.
the class DataSourceDaoDeadlockDetection method detectDeadlockFromDataSourceDeleteDataPointInsert.
/**
* See the deadlock when you insert data source, then point,
* then then delete source (which deletes the point inside a transaction)
*/
@Test
public void detectDeadlockFromDataSourceDeleteDataPointInsert() {
// 25;
int numThreads = 5;
// 100;
int numDataSources = 10;
PermissionService permissionService = Common.getBean(PermissionService.class);
DataSourceService dataSourceService = Common.getBean(DataSourceService.class);
AtomicInteger failures = new AtomicInteger();
AtomicInteger successes = new AtomicInteger();
AtomicInteger running = new AtomicInteger(numThreads);
MutableObject<Exception> failure = new MutableObject<>(null);
for (int i = 0; i < numThreads; i++) {
new Thread() {
@Override
public void run() {
try {
for (int i = 0; i < numDataSources; i++) {
// Create data source
MockDataSourceVO ds = new MockDataSourceVO();
ds.setName(Common.generateXid("Mock "));
dataSourceService.insert(ds);
// Create and save point
createMockDataPoint(ds, new MockPointLocatorVO());
// Delete data source
dataSourceService.delete(ds.getId());
successes.getAndIncrement();
}
} catch (Exception e) {
e.printStackTrace();
failure.setValue(e);
failures.getAndIncrement();
} finally {
running.decrementAndGet();
}
}
}.start();
}
while (running.get() > 0) {
try {
Thread.sleep(100);
} catch (Exception e) {
}
}
if (failures.get() > 0) {
fail("Ran " + successes.get() + " queries: " + failure.getValue().getMessage());
}
}
use of com.infiniteautomation.mango.spring.service.PermissionService in project ma-core-public by infiniteautomation.
the class LazyFieldJsonTest method testLazyPermissionInObject.
@Test
public void testLazyPermissionInObject() {
RoleService roleService = Common.getBean(RoleService.class);
PermissionService permissionService = Common.getBean(PermissionService.class);
Role role1 = roleService.insert(new RoleVO(Common.NEW_ID, "XID-1", "Role 1")).getRole();
Role role2 = roleService.insert(new RoleVO(Common.NEW_ID, "XID-2", "Role 2")).getRole();
LazyContainer container = new LazyContainer();
container.supplyPermission(() -> MangoPermission.builder().minterm(role1, role2).build());
try (StringWriter stringWriter = new StringWriter()) {
JsonWriter writer = new JsonWriter(Common.JSON_CONTEXT, stringWriter);
JsonTypeWriter typeWriter = new JsonTypeWriter(Common.JSON_CONTEXT);
JsonValue value = typeWriter.writeObject(container);
writer.setPrettyIndent(0);
writer.setPrettyOutput(true);
writer.writeObject(value);
String json = stringWriter.toString();
JsonTypeReader typeReader = new JsonTypeReader(json);
JsonValue read = typeReader.read();
JsonObject root = read.toJsonObject();
JsonReader reader = new JsonReader(Common.JSON_CONTEXT, root);
ImportContext context = new ImportContext(reader, new ProcessResult(), Common.getTranslations());
LazyContainer readContainer = new LazyContainer();
context.getReader().readInto(readContainer, root);
assertEquals(container.getPermission(), readContainer.getPermission());
} catch (IOException | JsonException e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of com.infiniteautomation.mango.spring.service.PermissionService in project ma-core-public by infiniteautomation.
the class PermissionPersistenceTest method testComplexPermission.
@Test
public void testComplexPermission() {
PermissionService service = Common.getBean(PermissionService.class);
// Create some roles
Set<Role> minterm1 = this.createRoles(1).stream().map(r -> r.getRole()).collect(Collectors.toSet());
Set<Role> minterm2 = this.createRoles(2).stream().map(r -> r.getRole()).collect(Collectors.toSet());
Set<Role> minterm3 = this.createRoles(3).stream().map(r -> r.getRole()).collect(Collectors.toSet());
// insert the permission
Set<Set<Role>> minterms = new HashSet<>();
minterms.add(minterm1);
minterms.add(minterm2);
minterms.add(minterm3);
MangoPermission permission = service.findOrCreate(new MangoPermission(minterms));
MangoPermission read = service.get(permission.getId());
assertEquals(3, read.getRoles().size());
Iterator<Set<Role>> it = read.getRoles().iterator();
while (it.hasNext()) {
Set<Role> minterm = it.next();
switch(minterm.size()) {
case 1:
assertEquals(1, minterm.size());
Role minterm1Role1 = minterm.iterator().next();
assertTrue(minterm1.contains(minterm1Role1));
break;
case 2:
assertEquals(2, minterm.size());
Iterator<Role> it2 = minterm.iterator();
Role minterm2Role1 = it2.next();
Role minterm2Role2 = it2.next();
assertTrue(minterm2.contains(minterm2Role1));
assertTrue(minterm2.contains(minterm2Role2));
break;
case 3:
assertEquals(3, minterm.size());
Iterator<Role> it3 = minterm.iterator();
Role minterm3Role1 = it3.next();
Role minterm3Role2 = it3.next();
Role minterm3Role3 = it3.next();
assertTrue(minterm3.contains(minterm3Role1));
assertTrue(minterm3.contains(minterm3Role2));
assertTrue(minterm3.contains(minterm3Role3));
break;
}
}
}
Aggregations