public void process( CreateNodeRequest request ) {
logger.trace(request.toString());
Location actualLocation = null;
try {
// Find the workspace ...
WorkspaceEntity workspace = getExistingWorkspace(request.inWorkspace(), request);
if (workspace == null) return;
Long workspaceId = workspace.getId();
assert workspaceId != null;
// Create nodes have to be defined via a path ...
Location parentLocation = request.under();
ActualLocation actual = getActualLocation(workspace.getId(), parentLocation);
String parentUuidString = actual.uuid;
assert parentUuidString != null;
// We need to look for an existing UUID property in the request,
// so since we have to iterate through the properties, go ahead an serialize them right away ...
String uuidString = null;
for (Property property : request.properties()) {
if (property.getName().equals(DnaLexicon.UUID)) {
uuidString = stringFactory.create(property.getFirstValue());
break;
}
}
if (uuidString == null) uuidString = UUID.randomUUID().toString();
assert uuidString != null;
createProperties(workspaceId, uuidString, request.properties());
// Find or create the namespace for the child ...
Name childName = request.named();
String childNsUri = childName.getNamespaceUri();
NamespaceEntity ns = namespaces.get(childNsUri, true);
assert ns != null;
final Path parentPath = actual.location.getPath();
assert parentPath != null;
// Figure out the next SNS index and index-in-parent for this new child ...
actualLocation = addNewChild(workspaceId, actual, uuidString, childName, true);
// Since we've just created this node, we know about all the children (actually, there are none).
cache.setAllChildren(workspace.getId(), actualLocation.getPath(), new LinkedList<Location>());
// Flush the entities ...
// entities.flush();
} catch (Throwable e) { // Includes PathNotFoundException