if (graphDb != null) {
Date now = new Date();
// Determine node type
PropertyMap properties = new PropertyMap(attributes);
Object typeObject = properties.get(AbstractNode.type);
Class nodeType = typeObject != null ? SchemaHelper.getEntityClassForRawType(typeObject.toString()) : StructrApp.getConfiguration().getFactoryDefinition().getGenericNodeType();
NodeFactory<T> nodeFactory = new NodeFactory<>(securityContext);
boolean isCreation = true;
// Create node with type
node = (T) nodeFactory.instantiateWithType(graphDb.createNode(), nodeType, isCreation);
if(node != null) {
TransactionCommand.nodeCreated(node);
// set type
if (nodeType != null) {
node.unlockReadOnlyPropertiesOnce();
node.setProperty(GraphObject.type, nodeType.getSimpleName());
}
// set UUID
node.unlockReadOnlyPropertiesOnce();
node.setProperty(GraphObject.id, getNextUuid());
// set created date
node.unlockReadOnlyPropertiesOnce();
node.setProperty(AbstractNode.createdDate, now);
// set last modified date
node.unlockReadOnlyPropertiesOnce();
node.setProperty(AbstractNode.lastModifiedDate, now);
// properties.remove(AbstractNode.type);
if ((user != null) && user instanceof AbstractNode) {
// Create new relationship to user and grant permissions to user or group
Principal owner = (Principal)user;
App app = StructrApp.getInstance(securityContext);
app.create(owner, (NodeInterface)node, PrincipalOwnsNode.class);
Security securityRel = app.create(owner, (NodeInterface)node, Security.class);
securityRel.setAllowed(Permission.values());
node.unlockReadOnlyPropertiesOnce();
node.setProperty(AbstractNode.createdBy, user.getProperty(GraphObject.id));
}
for (Entry<PropertyKey, Object> attr : properties.entrySet()) {
Object value = attr.getValue();
PropertyKey key = attr.getKey();
if (key.isReadOnly()) {
node.unlockReadOnlyPropertiesOnce();
}
node.setProperty(key, value);
}
properties.clear();
}
}
if (node != null) {