use of org.structr.core.entity.relationship.Ownership in project structr by structr.
the class AccessControlTest method test02SetDifferentPrincipalTypesAsOwner.
@Test
public void test02SetDifferentPrincipalTypesAsOwner() {
try (final Tx tx = app.tx()) {
final List<Principal> users = createTestNodes(Principal.class, 2);
final Principal user1 = (Principal) users.get(0);
final Group group1 = createTestNode(Group.class, "test group");
final TestOne t1 = createTestNode(TestOne.class);
t1.setProperty(AbstractNode.owner, user1);
t1.setProperty(AbstractNode.owner, group1);
assertEquals(group1, t1.getProperty(AbstractNode.owner));
Ownership ownerRel = t1.getIncomingRelationship(PrincipalOwnsNode.class);
assertNotNull(ownerRel);
// Do additional low-level check here to ensure cardinality!
List<Relationship> incomingRels = Iterables.toList(t1.getNode().getRelationships(Direction.INCOMING, new PrincipalOwnsNode()));
assertEquals(1, incomingRels.size());
tx.success();
} catch (FrameworkException ex) {
logger.error(ex.toString());
fail("Unexpected exception");
}
}
use of org.structr.core.entity.relationship.Ownership in project structr by structr.
the class AbstractNode method getOwnerNode.
/**
* Returns the owner node of this node, following an INCOMING OWNS
* relationship.
*
* @return the owner node of this node
*/
@Override
public final Principal getOwnerNode() {
if (cachedOwnerNode == null) {
final Ownership ownership = getIncomingRelationshipAsSuperUser(PrincipalOwnsNode.class);
if (ownership != null) {
Principal principal = ownership.getSourceNode();
cachedOwnerNode = (Principal) principal;
}
}
return cachedOwnerNode;
}
Aggregations