use of org.apache.jackrabbit.core.state.NodeState in project jackrabbit by apache.
the class ProtectedItemModifier method addNode.
protected NodeImpl addNode(NodeImpl parentImpl, Name name, Name ntName, NodeId nodeId) throws RepositoryException {
checkPermission(parentImpl, name, getPermission(true, false));
// validation: make sure Node is not locked or checked-in.
parentImpl.checkSetProperty();
NodeTypeImpl nodeType = parentImpl.sessionContext.getNodeTypeManager().getNodeType(ntName);
org.apache.jackrabbit.spi.commons.nodetype.NodeDefinitionImpl def = parentImpl.getApplicableChildNodeDefinition(name, ntName);
// check for name collisions
// TODO: improve. copied from NodeImpl
NodeState thisState = parentImpl.getNodeState();
ChildNodeEntry cne = thisState.getChildNodeEntry(name, 1);
if (cne != null) {
// check same-name sibling setting of new node
if (!def.allowsSameNameSiblings()) {
throw new ItemExistsException();
}
// check same-name sibling setting of existing node
NodeId newId = cne.getId();
NodeImpl n = (NodeImpl) parentImpl.sessionContext.getItemManager().getItem(newId);
if (!n.getDefinition().allowsSameNameSiblings()) {
throw new ItemExistsException();
}
}
return parentImpl.createChildNode(name, nodeType, nodeId);
}
use of org.apache.jackrabbit.core.state.NodeState in project jackrabbit by apache.
the class NodeImpl method getSharedSet.
//-------------------------------------------------------< shareable nodes >
/**
* Returns an iterator over all nodes that are in the shared set of this
* node. If this node is not shared then the returned iterator contains
* only this node.
*
* @return a <code>NodeIterator</code>
* @throws RepositoryException if an error occurs.
* @since JCR 2.0
*/
public NodeIterator getSharedSet() throws RepositoryException {
// check state of this instance
sanityCheck();
ArrayList<NodeImpl> list = new ArrayList<NodeImpl>();
if (!isShareable()) {
list.add(this);
} else {
NodeState state = data.getNodeState();
for (NodeId parentId : state.getSharedSet()) {
list.add(itemMgr.getNode(getNodeId(), parentId));
}
}
return new NodeIteratorAdapter(list);
}
use of org.apache.jackrabbit.core.state.NodeState in project jackrabbit by apache.
the class PersistenceCopier method copy.
/**
* Recursively copies the identified node and all its descendants.
* Explicitly excluded nodes and nodes that have already been copied
* are automatically skipped.
*
* @param id identifier of the node to be copied
* @throws RepositoryException if the copy operation fails
*/
public void copy(NodeId id) throws RepositoryException {
if (!exclude.contains(id)) {
try {
NodeState node = source.load(id);
for (ChildNodeEntry entry : node.getChildNodeEntries()) {
copy(entry.getId());
}
copy(node);
exclude.add(id);
} catch (ItemStateException e) {
throw new RepositoryException("Unable to copy " + id, e);
}
}
}
use of org.apache.jackrabbit.core.state.NodeState in project jackrabbit by apache.
the class EventStateCollection method createShareableNodeEvents.
//----------------------------< internal >----------------------------------
private void createShareableNodeEvents(NodeState n, ChangeLog changes, ChangeLogBasedHierarchyMgr hmgr, ItemStateManager stateMgr) throws ItemStateException {
if (n.isShareable()) {
// check if a share was added or removed
for (NodeId parentId : n.getAddedShares()) {
// ignore primary parent id
if (n.getParentId().equals(parentId)) {
continue;
}
NodeState parent = (NodeState) changes.get(parentId);
if (parent == null) {
// happens when mix:shareable is added to an existing node
// usually the parent node state is in the change log
// when a node is added to a shared set -> new child node
// entry on parent node state.
parent = (NodeState) stateMgr.getItemState(parentId);
}
Name ntName = getNodeType(parent, session).getQName();
EventState es = EventState.childNodeAdded(parentId, getPath(parentId, hmgr), n.getNodeId(), getNameElement(n.getNodeId(), parentId, hmgr), ntName, parent.getMixinTypeNames(), session);
es.setShareableNode(true);
events.add(es);
}
for (NodeId parentId : n.getRemovedShares()) {
// parent ids that are not primary
if (n.getParentId().equals(parentId)) {
continue;
}
NodeState parent = null;
try {
parent = (NodeState) changes.get(parentId);
} catch (NoSuchItemStateException e) {
// parent has been removed as well
// ignore and retrieve from stateMgr
}
if (parent == null) {
// happens when mix:shareable is removed from an existing
// node. Usually the parent node state is in the change log
// when a node is removed to a shared set -> removed child
// node entry on parent node state.
parent = (NodeState) stateMgr.getItemState(parentId);
}
Name ntName = getNodeType(parent, session).getQName();
EventState es = EventState.childNodeRemoved(parentId, getZombiePath(parentId, hmgr), n.getNodeId(), getZombieNameElement(n.getNodeId(), parentId, hmgr), ntName, parent.getMixinTypeNames(), session);
es.setShareableNode(true);
events.add(es);
}
}
}
use of org.apache.jackrabbit.core.state.NodeState in project jackrabbit by apache.
the class SearchIndexConsistencyCheckTest method testIndexContainsUnknownNode.
public void testIndexContainsUnknownNode() throws Exception {
Session s = getHelper().getSuperuserSession();
SearchManager searchManager = TestHelper.getSearchManager(s);
SearchIndex searchIndex = (SearchIndex) searchManager.getQueryHandler();
NodeId nodeId = new NodeId(0, 0);
NodeState nodeState = new NodeState(nodeId, null, null, 1, false);
Iterator<NodeId> remove = Collections.<NodeId>emptyList().iterator();
Iterator<NodeState> add = Collections.singletonList(nodeState).iterator();
searchIndex.updateNodes(remove, add);
ConsistencyCheck consistencyCheck = searchIndex.runConsistencyCheck();
List<ConsistencyCheckError> errors = consistencyCheck.getErrors();
assertEquals("Expected 1 index consistency error", 1, errors.size());
ConsistencyCheckError error = errors.iterator().next();
assertEquals("Different node was reported to be unknown", error.id, nodeId);
consistencyCheck.repair(false);
assertFalse("Index was not repaired properly", searchIndexContainsNode(searchIndex, nodeId));
assertTrue("Consistency check still reports errors", searchIndex.runConsistencyCheck().getErrors().isEmpty());
}
Aggregations