use of org.structr.core.graph.NodeInterface in project structr by structr.
the class ValidationTest method testEnumPropertyUniquenessValidation.
// ----- enum property validation tests -----
@Test
public void testEnumPropertyUniquenessValidation() {
final String keyName = "unique";
final Class<NodeInterface> testType = createTypeWithProperty("Test", keyName, "Enum(one, two, three)!");
final PropertyKey key = StructrApp.key(testType, keyName);
String uuid = null;
if (key != null) {
// test failure
try (final Tx tx = app.tx()) {
final Object value = ((EnumProperty) key).getEnumType().getEnumConstants()[0];
uuid = app.create(testType, new NodeAttribute<>(key, value)).getUuid();
app.create(testType, new NodeAttribute<>(key, value));
tx.success();
fail("Enum property uniqueness constraint violated!");
} catch (FrameworkException fex) {
final List<ErrorToken> tokens = fex.getErrorBuffer().getErrorTokens();
final ErrorToken token = tokens.get(0);
assertEquals("Invalid enum validation result", 1, tokens.size());
assertEquals("Invalid enum validation result", 422, fex.getStatus());
assertEquals("Invalid enum validation result", keyName, token.getProperty());
assertEquals("Invalid enum validation result", "Test", token.getType());
assertEquals("Invalid enum validation result", "already_taken", token.getToken());
assertEquals("Invalid enum validation result", uuid, token.getDetail());
}
}
}
use of org.structr.core.graph.NodeInterface in project structr by structr.
the class ValidationTest method testBooleanPropertyNotNullValidation.
// ----- boolean property validation tests -----
@Test
public void testBooleanPropertyNotNullValidation() {
final String keyName = "notNull";
final Class<NodeInterface> testType = createTypeWithProperty("Test", keyName, "+Boolean");
final PropertyKey key = StructrApp.key(testType, keyName);
if (key != null) {
// test failure
try (final Tx tx = app.tx()) {
/* Boolean properties are special. A boolean property will
* _always_ have a value, i.e. "null" equals "false" and
* will be returned as false.
*
* => a boolean property value can never be null!
*/
app.create(testType, new NodeAttribute<>(key, null));
app.create(testType, new NodeAttribute<>(key, true));
app.create(testType, new NodeAttribute<>(key, false));
tx.success();
} catch (FrameworkException fex) {
fail("Unexpected array property validation exception.");
}
}
}
use of org.structr.core.graph.NodeInterface in project structr by structr.
the class StructrGraphQLTest method cleanDatabase.
@Before
public void cleanDatabase() {
// configure RestAssured
RestAssured.basePath = restUrl;
RestAssured.baseURI = "http://" + host + ":" + httpPort;
RestAssured.port = httpPort;
try (final Tx tx = app.tx()) {
for (final NodeInterface node : app.nodeQuery().getAsList()) {
// System.out.println("Deleting node " + node.getType() + " with name " + node.getName() + " and ID " + node.getUuid());
app.delete(node);
}
// delete remaining nodes without UUIDs etc.
app.cypher("MATCH (n)-[r]-(m) DELETE n, r, m", Collections.emptyMap());
tx.success();
} catch (FrameworkException fex) {
logger.error("Exception while trying to clean database: {}", fex);
}
}
use of org.structr.core.graph.NodeInterface in project structr by structr.
the class TypeResource method identifyStartNode.
private NodeInterface identifyStartNode(final Relation template, final Map<String, Object> properties) throws FrameworkException {
final Property<String> sourceIdProperty = template.getSourceIdProperty();
final Class sourceType = template.getSourceType();
final Notion notion = template.getStartNodeNotion();
notion.setType(sourceType);
PropertyKey startNodeIdentifier = notion.getPrimaryPropertyKey();
if (startNodeIdentifier != null) {
Object identifierValue = properties.get(startNodeIdentifier.dbName());
properties.remove(sourceIdProperty.dbName());
return (NodeInterface) notion.getAdapterForSetter(securityContext).adapt(identifierValue);
}
return null;
}
use of org.structr.core.graph.NodeInterface in project structr by structr.
the class AbstractNode method grant.
@Override
public final void grant(Permission permission, Principal principal) throws FrameworkException {
if (!isGranted(Permission.accessControl, securityContext)) {
throw new FrameworkException(403, "Access control not permitted");
}
Security secRel = getSecurityRelationship(principal);
if (secRel == null) {
try {
// ensureCardinality is not neccessary here
final SecurityContext securityContext = SecurityContext.getSuperUserInstance();
securityContext.disableEnsureCardinality();
secRel = StructrApp.getInstance(securityContext).create(principal, (NodeInterface) this, Security.class);
} catch (FrameworkException ex) {
logger.error("Could not create security relationship!", ex);
}
}
// only access rel if it existss or was created successfully
if (secRel != null) {
secRel.addPermission(permission);
}
}
Aggregations