use of org.structr.core.graph.Tx in project structr by structr.
the class StructrLDAPClientModuleTest method createTestNode.
protected <T extends AbstractNode> T createTestNode(final Class<T> type, final NodeAttribute... attributes) throws FrameworkException {
try (final Tx tx = app.tx()) {
final T newNode = app.create(type, attributes);
tx.success();
return newNode;
}
}
use of org.structr.core.graph.Tx in project structr by structr.
the class StructrLDAPClientModuleTest method createTestNode.
protected <T extends AbstractNode> T createTestNode(final Class<T> type, final PropertyMap props) throws FrameworkException {
props.put(AbstractNode.type, type.getSimpleName());
try (final Tx tx = app.tx()) {
final T newNode = app.create(type, props);
tx.success();
return newNode;
}
}
use of org.structr.core.graph.Tx in project structr by structr.
the class StructrLDAPClientModuleTest method createTestRelationships.
protected <T extends Relation> List<T> createTestRelationships(final Class<T> relType, final int number) throws FrameworkException {
List<GenericNode> nodes = createTestNodes(GenericNode.class, 2);
final NodeInterface startNode = nodes.get(0);
final NodeInterface endNode = nodes.get(1);
try (final Tx tx = app.tx()) {
List<T> rels = new LinkedList<>();
for (int i = 0; i < number; i++) {
rels.add((T) app.create(startNode, endNode, relType));
}
tx.success();
return rels;
}
}
use of org.structr.core.graph.Tx in project structr by structr.
the class TestLDAPClient method testLDAPClient.
@Test
public void testLDAPClient() {
final Class type = StructrApp.getConfiguration().getNodeEntityClass("LDAPUser");
Assert.assertNotNull("Type LDAPUser should exist", type);
try (final Tx tx = app.tx()) {
app.create(User.class, new NodeAttribute<>(StructrApp.key(User.class, "name"), "admin"), new NodeAttribute<>(StructrApp.key(User.class, "password"), "admin"), new NodeAttribute<>(StructrApp.key(User.class, "isAdmin"), true));
tx.success();
} catch (Throwable t) {
fail("Unexpected exception");
}
try (final Tx tx = app.tx()) {
app.create(type, new NodeAttribute<>(StructrApp.key(LDAPUser.class, "name"), "test"), new NodeAttribute<>(StructrApp.key(LDAPUser.class, "distinguishedName"), "distinguishedName"), new NodeAttribute<>(StructrApp.key(LDAPUser.class, "description"), "description"), new NodeAttribute<>(StructrApp.key(LDAPUser.class, "commonName"), "commonName"), new NodeAttribute<>(StructrApp.key(LDAPUser.class, "entryUuid"), "entryUuid"));
tx.success();
} catch (Throwable t) {
fail("Unexpected exception");
}
RestAssured.given().filter(ResponseLoggingFilter.logResponseTo(System.out)).contentType("application/json; charset=UTF-8").headers("X-User", "admin", "X-Password", "admin").expect().statusCode(200).when().get("/LDAPUser");
}
use of org.structr.core.graph.Tx in project structr by structr.
the class StructrLDAPWrapper method add.
public void add(final Entry entry) throws LdapException {
try (final Tx tx = app().tx()) {
// create while descending
final Dn dn = entry.getDn();
final LDAPNode parent = find(dn.getParent());
if (parent != null) {
final Attribute objectClasses = entry.get(schemaManager.getAttributeType(SchemaConstants.OBJECT_CLASS_AT_OID));
final ObjectClassRegistry reg = schemaManager.getObjectClassRegistry();
final Set<String> classes = new LinkedHashSet<>();
final Rdn rdn = dn.getRdn();
String mainClass = null;
// make rdn schema aware
if (!rdn.isSchemaAware()) {
rdn.apply(schemaManager);
}
if (objectClasses != null) {
for (final Value<?> value : objectClasses) {
final String cls = value.getString();
final String objectClassOid = reg.getOidByName(cls);
if (reg.get(objectClassOid).isStructural()) {
mainClass = cls;
} else {
classes.add(cls);
}
}
final LDAPNode newChild = parent.createChild(rdn.getNormName(), rdn.getName(), mainClass, classes);
if (newChild != null) {
for (final Attribute attr : entry) {
AttributeType type = attr.getAttributeType();
String oid = null;
if (type != null) {
oid = type.getOid();
} else {
type = schemaManager.getAttributeType(attr.getUpId());
oid = type.getOid();
}
newChild.createAttribute(oid, attr.getUpId(), attr);
}
} else {
logger.warn("Unable to add entry {}, could not create new instance", entry);
}
} else {
logger.warn("Unable to add entry {}, could not determine object class(es)", entry);
}
} else {
logger.warn("Unable to add entry {}, parent not found", entry);
}
tx.success();
} catch (FrameworkException fex) {
handleException(fex);
}
}
Aggregations