use of com.haulmont.cuba.security.entity.Permission in project cuba by cuba-platform.
the class DefaultPermissionValuesConfig method parseConfigFile.
protected void parseConfigFile(String fileName) {
String fileContent = resources.getResourceAsString(fileName);
if (!Strings.isNullOrEmpty(fileContent)) {
Document document = Dom4j.readDocument(fileContent);
List<Element> permissionElements = Dom4j.elements(document.getRootElement(), "permission");
for (Element element : permissionElements) {
String target = element.attributeValue("target");
Integer value = Integer.valueOf(element.attributeValue("value"));
Integer type = Integer.valueOf(element.attributeValue("type"));
Permission permission = metadata.create(Permission.class);
permission.setTarget(target);
permission.setType(PermissionType.fromId(type));
permission.setValue(value);
permissionValues.put(target, permission);
}
} else {
log.error("File {} not found", fileName);
}
}
use of com.haulmont.cuba.security.entity.Permission in project cuba by cuba-platform.
the class UpdateDetachedTest method testRollback.
@Test
public void testRollback() {
Permission p = null;
Transaction tx = cont.persistence().createTransaction();
try {
EntityManager em = cont.persistence().getEntityManager();
View view = new View(Permission.class).addProperty("target").addProperty("role", new View(Role.class).addProperty("name"));
p = em.find(Permission.class, permissionId, view);
tx.commitRetaining();
p.setTarget("newTarget");
em = cont.persistence().getEntityManager();
p = em.merge(p);
throwException();
tx.commit();
} catch (RuntimeException e) {
// ok
} finally {
tx.end();
assertNotNull(p);
// assertNull(((PersistenceCapable) p).pcGetDetachedState());
}
}
use of com.haulmont.cuba.security.entity.Permission in project cuba by cuba-platform.
the class UpdateDetachedTest method testDataService.
@Test
public void testDataService() throws Exception {
Permission p;
DataService ds = AppBeans.get(DataService.NAME);
LoadContext<Permission> ctx = new LoadContext<>(Permission.class);
ctx.setId(permissionId);
ctx.setView(new View(Permission.class).addProperty("target").addProperty("role", new View(Role.class).addProperty("name")));
p = ds.load(ctx);
assertNotNull(p);
p.setTarget("newTarget");
CommitContext commitCtx = new CommitContext(Collections.singleton(p));
Set<Entity> entities = ds.commit(commitCtx);
Permission result = null;
for (Entity entity : entities) {
if (entity.equals(p))
result = (Permission) entity;
}
result = reserialize(result);
assertTrue(PersistenceHelper.isDetached(result));
assertNotNull(result.getRole());
assertTrue(PersistenceHelper.isDetached(result.getRole()));
assertTrue(PersistenceHelper.isLoaded(result, "role"));
}
use of com.haulmont.cuba.security.entity.Permission in project cuba by cuba-platform.
the class UpdateDetachedTest method test.
@Test
public void test() throws Exception {
Permission p;
Transaction tx = cont.persistence().createTransaction();
try {
EntityManager em = cont.persistence().getEntityManager();
View view = new View(Permission.class).addProperty("target").addProperty("role", new View(Role.class).addProperty("name"));
p = em.find(Permission.class, permissionId, view);
tx.commitRetaining();
assertNotNull(p);
p.setTarget("newTarget");
em = cont.persistence().getEntityManager();
p = em.merge(p);
tx.commit();
} finally {
tx.end();
}
p = reserialize(p);
assertTrue(PersistenceHelper.isDetached(p));
assertNotNull(p.getRole());
assertTrue(PersistenceHelper.isDetached(p.getRole()));
assertTrue(PersistenceHelper.isLoaded(p, "role"));
}
use of com.haulmont.cuba.security.entity.Permission in project cuba by cuba-platform.
the class SystemInfoWindow method generateInsert.
public void generateInsert() {
scriptArea.setEditable(true);
if (item instanceof Role) {
View localView = metadata.getViewRepository().getView(Role.class, View.LOCAL);
View roleView = new View(localView, Role.class, "role-export-view", true).addProperty("permissions", metadata.getViewRepository().getView(Permission.class, View.LOCAL));
item = getDsContext().getDataSupplier().reload(item, roleView);
StringBuilder result = new StringBuilder();
result.append(sqlGenerationService.generateInsertScript(item)).append("\n");
for (Permission permission : ((Role) item).getPermissions()) {
result.append(sqlGenerationService.generateInsertScript(permission)).append("\n");
}
scriptArea.setValue(result.toString());
} else {
scriptArea.setValue(sqlGenerationService.generateInsertScript(item));
}
showScriptArea();
}
Aggregations