use of org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate in project jackrabbit-oak by apache.
the class NodeImpl method addNode.
@Override
@Nonnull
public Node addNode(final String relPath, String primaryNodeTypeName) throws RepositoryException {
final String oakPath = getOakPathOrThrowNotFound(relPath);
final String oakTypeName;
if (primaryNodeTypeName != null) {
oakTypeName = getOakName(primaryNodeTypeName);
} else {
oakTypeName = null;
}
checkIndexOnName(relPath);
return perform(new ItemWriteOperation<Node>("addNode") {
@Nonnull
@Override
public Node perform() throws RepositoryException {
String oakName = PathUtils.getName(oakPath);
String parentPath = PathUtils.getParentPath(oakPath);
NodeDelegate parent = dlg.getChild(parentPath);
if (parent == null) {
// is it a property?
String grandParentPath = PathUtils.getParentPath(parentPath);
NodeDelegate grandParent = dlg.getChild(grandParentPath);
if (grandParent != null) {
String propName = PathUtils.getName(parentPath);
if (grandParent.getPropertyOrNull(propName) != null) {
throw new ConstraintViolationException("Can't add new node to property.");
}
}
throw new PathNotFoundException(relPath);
}
if (parent.getChild(oakName) != null) {
throw new ItemExistsException(relPath);
}
// modification of that property in the PermissionValidator
if (oakTypeName != null) {
PropertyState prop = PropertyStates.createProperty(JCR_PRIMARYTYPE, oakTypeName, NAME);
sessionContext.getAccessManager().checkPermissions(parent.getTree(), prop, Permissions.NODE_TYPE_MANAGEMENT);
}
NodeDelegate added = parent.addChild(oakName, oakTypeName);
if (added == null) {
throw new ItemExistsException(format("Node [%s/%s] exists", getNodePath(), oakName));
}
return createNode(added, sessionContext);
}
@Override
public String toString() {
return format("Adding node [%s/%s]", dlg.getPath(), relPath);
}
});
}
use of org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate in project jackrabbit-oak by apache.
the class NodeImpl method createNode.
@Nonnull
public static NodeImpl<? extends NodeDelegate> createNode(@Nonnull NodeDelegate delegate, @Nonnull SessionContext context) throws RepositoryException {
PropertyDelegate pd = delegate.getPropertyOrNull(JCR_PRIMARYTYPE);
String type = pd != null ? pd.getString() : null;
if (JcrConstants.NT_VERSION.equals(type)) {
VersionManagerDelegate vmd = VersionManagerDelegate.create(context.getSessionDelegate());
return new VersionImpl(vmd.createVersion(delegate), context);
} else if (JcrConstants.NT_VERSIONHISTORY.equals(type)) {
VersionManagerDelegate vmd = VersionManagerDelegate.create(context.getSessionDelegate());
return new VersionHistoryImpl(vmd.createVersionHistory(delegate), context);
} else {
return new NodeImpl<NodeDelegate>(delegate, context);
}
}
use of org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate in project jackrabbit-oak by apache.
the class VersionManagerImpl method getExisting.
/**
* Returns referenceable nodes outside of the versionable sub-graphs
* identified by <code>versionablePaths</code>, which are also present
* in the versionable state captured by <code>version</code>.
*
* @param version the version.
* @param versionablePaths identifies the starting points of the versionable
* sub-graphs.
* @return existing nodes in this workspace.
*/
private List<NodeDelegate> getExisting(@Nonnull Version version, @Nonnull Set<String> versionablePaths) throws RepositoryException {
// collect uuids
final List<String> uuids = new ArrayList<String>();
version.getFrozenNode().accept(new TraversingItemVisitor.Default() {
@Override
protected void entering(Node node, int level) throws RepositoryException {
if (node.isNodeType(NodeType.NT_FROZEN_NODE)) {
String id = node.getProperty(Property.JCR_FROZEN_UUID).getString();
if (id.length() > 0) {
uuids.add(id);
}
} else if (node.isNodeType(NodeType.NT_VERSIONED_CHILD)) {
Node history = node.getProperty(Property.JCR_CHILD_VERSION_HISTORY).getNode();
uuids.add(history.getProperty(Property.JCR_VERSIONABLE_UUID).getString());
// TODO: further traverse versioned children with some selector (date?)
}
}
});
SessionDelegate delegate = sessionContext.getSessionDelegate();
if (uuids.isEmpty()) {
return Collections.emptyList();
}
List<NodeDelegate> existing = new ArrayList<NodeDelegate>();
for (String uuid : uuids) {
NodeDelegate node = delegate.getNodeByIdentifier(uuid);
if (node != null) {
boolean inSubGraph = false;
for (String versionablePath : versionablePaths) {
if (node.getPath().startsWith(versionablePath)) {
inSubGraph = true;
break;
}
}
if (!inSubGraph) {
existing.add(node);
}
}
}
return existing;
}
use of org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate in project jackrabbit-oak by apache.
the class VersionManagerImpl method ensureParentExists.
/**
* Returns the parent for the given <code>absPath</code> or throws a
* {@link PathNotFoundException} if it doesn't exist.
*
* @param sessionDelegate session delegate.
* @param absPath an absolute path
* @return the parent for the given <code>absPath</code>.
* @throws PathNotFoundException if the node does not exist.
*/
@Nonnull
private NodeDelegate ensureParentExists(@Nonnull SessionDelegate sessionDelegate, @Nonnull String absPath) throws PathNotFoundException {
String oakParentPath = getOakPathOrThrowNotFound(PathUtils.getParentPath(checkNotNull(absPath)));
NodeDelegate parent = checkNotNull(sessionDelegate).getNode(oakParentPath);
if (parent == null) {
throw new PathNotFoundException(PathUtils.getParentPath(absPath));
}
return parent;
}
Aggregations