use of org.apache.jackrabbit.spi.NodeId in project jackrabbit by apache.
the class RepositoryServiceImpl method restore.
/**
* {@inheritDoc}
*/
public void restore(final SessionInfo sessionInfo, final NodeId nodeId, final NodeId versionId, final boolean removeExisting) throws VersionException, PathNotFoundException, ItemExistsException, UnsupportedRepositoryOperationException, LockException, InvalidItemStateException, RepositoryException {
final SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
executeWithLocalEvents(new Callable() {
public Object run() throws RepositoryException {
Version v = (Version) getNode(versionId, sInfo);
if (hasNode(sessionInfo, nodeId)) {
Node n = getNode(nodeId, sInfo);
n.restore(v, removeExisting);
} else {
// restore with rel-Path part
Node n = null;
Path relPath = null;
Path path = nodeId.getPath();
if (nodeId.getUniqueID() != null) {
n = getNode(idFactory.createNodeId(nodeId.getUniqueID()), sInfo);
relPath = (path.isAbsolute()) ? getPathFactory().getRootPath().computeRelativePath(nodeId.getPath()) : path;
} else {
int degree = 0;
while (degree < path.getLength()) {
Path ancestorPath = path.getAncestor(degree);
NodeId parentId = idFactory.createNodeId(nodeId.getUniqueID(), ancestorPath);
if (hasNode(sessionInfo, parentId)) {
n = getNode(parentId, sInfo);
relPath = ancestorPath.computeRelativePath(path);
}
degree++;
}
}
if (n == null) {
throw new PathNotFoundException("Path not found " + nodeId);
} else {
n.restore(v, sInfo.getNamePathResolver().getJCRPath(relPath), removeExisting);
}
}
return null;
}
}, sInfo);
}
use of org.apache.jackrabbit.spi.NodeId in project jackrabbit by apache.
the class NodeEntryImpl method getDeepNodeEntry.
/**
* @see NodeEntry#getDeepNodeEntry(Path)
*/
public NodeEntry getDeepNodeEntry(Path path) throws PathNotFoundException, RepositoryException {
NodeEntryImpl entry = this;
Path.Element[] elems = path.getElements();
for (int i = 0; i < elems.length; i++) {
Path.Element elem = elems[i];
// check for root element
if (elem.denotesRoot()) {
if (entry.getParent() != null) {
throw new RepositoryException("NodeEntry out of 'hierarchy' " + path.toString());
}
continue;
}
int index = elem.getNormalizedIndex();
Name name = elem.getName();
// first try to resolve to known node or property entry
NodeEntry cne = entry.getNodeEntry(name, index, false);
if (cne != null) {
entry = (NodeEntryImpl) cne;
} else {
// on the persistent layer.
if (entry.childNodeEntries.isComplete()) {
throw new PathNotFoundException(factory.saveGetJCRPath(path));
}
// -> check for moved child entry in node-attic
// -> check if child points to a removed/moved sns
List<NodeEntry> siblings = entry.childNodeEntries.get(name);
if (entry.containsAtticChild(siblings, name, index)) {
throw new PathNotFoundException(factory.saveGetJCRPath(path));
}
// elements -> hierarchy doesn't exist anyway.
if (entry.getStatus() == Status.NEW) {
throw new PathNotFoundException(factory.saveGetJCRPath(path));
}
/*
* Unknown entry (not-existing or not yet loaded):
* Skip all intermediate entries and directly try to load the ItemState
* (including building the intermediate entries. If that fails
* ItemNotFoundException is thrown.
*
* Since 'path' might be ambiguous (Node or Property):
* 1) first try Node
* 2) if the NameElement does not have SNS-index => try Property
* 3) else throw
*/
PathBuilder pb = new PathBuilder(getPathFactory());
for (int j = i; j < elems.length; j++) {
pb.addLast(elems[j]);
}
Path remainingPath = pb.getPath();
NodeId parentId = entry.getWorkspaceId();
IdFactory idFactory = factory.getIdFactory();
NodeId nodeId = idFactory.createNodeId(parentId, remainingPath);
NodeEntry ne = entry.loadNodeEntry(nodeId);
if (ne != null) {
return ne;
} else {
throw new PathNotFoundException(factory.saveGetJCRPath(path));
}
}
}
return entry;
}
use of org.apache.jackrabbit.spi.NodeId in project jackrabbit by apache.
the class NodeEntryImpl method getNodeEntry.
/**
* @see NodeEntry#getNodeEntry(Name, int, boolean)
*/
public NodeEntry getNodeEntry(Name nodeName, int index, boolean loadIfNotFound) throws RepositoryException {
List<NodeEntry> entries = childNodeEntries.get(nodeName);
NodeEntry cne = null;
if (entries.size() >= index) {
// position of entry might differ from index-1 if a SNS with lower
// index has been transiently removed.
int eIndex = 1;
for (int i = 0; i < entries.size() && cne == null; i++) {
NodeEntry ne = entries.get(i);
if (EntryValidation.isValidNodeEntry(ne)) {
if (eIndex == index) {
cne = ne;
}
eIndex++;
}
}
}
if (cne == null && loadIfNotFound && !containsAtticChild(entries, nodeName, index) && !childNodeEntries.isComplete()) {
NodeId cId = getIdFactory().createNodeId(getWorkspaceId(), getPathFactory().create(nodeName, index));
cne = loadNodeEntry(cId);
}
return cne;
}
use of org.apache.jackrabbit.spi.NodeId in project jackrabbit by apache.
the class SessionImporter method startNode.
/**
* {@inheritDoc}
*/
public void startNode(NodeInfo nodeInfo, List<PropInfo> propInfos, NamePathResolver resolver) throws RepositoryException {
if (isClosed()) {
// workspace-importer only: ignore if import has been aborted before.
return;
}
checkSession();
NodeState parent = parents.peek();
if (parent == null) {
// parent node was skipped, skip this child node also
// push null onto stack for skipped node
parents.push(null);
log.debug("Skipping node '" + nodeInfo.getName() + "'.");
return;
}
NodeEntry parentEntry = (NodeEntry) parent.getHierarchyEntry();
NodeState nodeState = null;
if (parentEntry.hasNodeEntry(nodeInfo.getName())) {
try {
// a valid child node with that name already exists
NodeEntry entry = parentEntry.getNodeEntry(nodeInfo.getName(), Path.INDEX_DEFAULT);
NodeState existing = entry.getNodeState();
QNodeDefinition def = existing.getDefinition();
if (!def.allowsSameNameSiblings()) {
// existing doesn't allow same-name siblings, check for conflicts
EffectiveNodeTypeProvider provider = session.getEffectiveNodeTypeProvider();
Name[] ntNames = existing.getAllNodeTypeNames();
EffectiveNodeType entExisting = provider.getEffectiveNodeType(ntNames);
if (def.isProtected() && entExisting.includesNodeType(nodeInfo.getNodeTypeName())) {
// skip protected node
// push null onto stack for skipped node
parents.push(null);
log.debug("skipping protected node " + LogUtil.safeGetJCRPath(existing, session.getPathResolver()));
return;
}
if (def.isAutoCreated() && entExisting.includesNodeType(nodeInfo.getNodeTypeName())) {
// this node has already been auto-created, no need to create it
nodeState = existing;
} else {
throw new ItemExistsException(LogUtil.safeGetJCRPath(existing, session.getPathResolver()));
}
}
} catch (ItemNotFoundException e) {
// 'existing' doesn't exist any more -> ignore
}
}
if (nodeState == null) {
// node does not exist -> create new one
if (nodeInfo.getUUID() == null) {
// no potential uuid conflict, add new node from given info
nodeState = importNode(nodeInfo, parent);
} else {
// make sure the import does not define a uuid without having
// a primaryType or mixin that makes the new node referenceable
checkIncludesMixReferenceable(nodeInfo);
// potential uuid conflict
try {
NodeId conflictingId = session.getIdFactory().createNodeId(nodeInfo.getUUID());
NodeEntry conflicting = session.getHierarchyManager().getNodeEntry(conflictingId);
// assert that the entry is available
conflicting.getItemState();
nodeState = resolveUUIDConflict(parent, conflicting, nodeInfo);
} catch (ItemNotFoundException e) {
// no conflict: create new with given uuid
nodeState = importNode(nodeInfo, parent);
}
}
}
// node state may be 'null' if applicable def is protected
if (nodeState != null) {
// process properties
for (PropInfo pi : propInfos) {
importProperty(pi, nodeState, resolver);
}
}
// push current nodeState onto stack of parents
parents.push(nodeState);
}
use of org.apache.jackrabbit.spi.NodeId in project jackrabbit by apache.
the class VersionManagerImpl method getVersionableNodeEntry.
public NodeEntry getVersionableNodeEntry(NodeState versionState) throws RepositoryException {
NodeState ns = versionState.getChildNodeState(NameConstants.JCR_FROZENNODE, Path.INDEX_DEFAULT);
PropertyState ps = ns.getPropertyState(NameConstants.JCR_FROZENUUID);
String uniqueID = ps.getValue().getString();
NodeId versionableId = workspaceManager.getIdFactory().createNodeId(uniqueID);
return workspaceManager.getHierarchyManager().getNodeEntry(versionableId);
}
Aggregations