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);
}
use of org.apache.jackrabbit.spi.NodeId in project jackrabbit by apache.
the class VersionManagerImpl method resolveMergeConflict.
public void resolveMergeConflict(NodeState nodeState, NodeState versionState, boolean done) throws RepositoryException {
NodeId vId = versionState.getNodeId();
PropertyState mergeFailedState = nodeState.getPropertyState(NameConstants.JCR_MERGEFAILED);
QValue[] vs = mergeFailedState.getValues();
NodeId[] mergeFailedIds = new NodeId[vs.length - 1];
for (int i = 0, j = 0; i < vs.length; i++) {
NodeId id = workspaceManager.getIdFactory().createNodeId(vs[i].getString());
if (!id.equals(vId)) {
mergeFailedIds[j] = id;
j++;
}
// else: the version id is being solved by this call and not
// part of 'jcr:mergefailed' any more
}
PropertyState predecessorState = nodeState.getPropertyState(NameConstants.JCR_PREDECESSORS);
vs = predecessorState.getValues();
int noOfPredecessors = (done) ? vs.length + 1 : vs.length;
NodeId[] predecessorIds = new NodeId[noOfPredecessors];
int i = 0;
while (i < vs.length) {
predecessorIds[i] = workspaceManager.getIdFactory().createNodeId(vs[i].getString());
i++;
}
if (done) {
predecessorIds[i] = vId;
}
Operation op = ResolveMergeConflict.create(nodeState, mergeFailedIds, predecessorIds, done);
workspaceManager.execute(op);
}
use of org.apache.jackrabbit.spi.NodeId in project jackrabbit by apache.
the class EventFilterImpl method accept.
/**
* {@inheritDoc}
*/
public boolean accept(Event event, boolean isLocal) {
int type = event.getType();
// check type
if ((type & eventTypes) == 0) {
return false;
}
// check local flag
if (isLocal && noLocal) {
return false;
}
// UUIDs, types, and paths do not need to match for persist
if (event.getType() == Event.PERSIST) {
return true;
}
// check UUIDs
NodeId parentId = event.getParentId();
if (uuids != null) {
if (parentId.getPath() == null) {
if (!uuids.contains(parentId.getUniqueID())) {
return false;
}
} else {
return false;
}
}
// check node types
if (nodeTypeNames != null) {
Set<Name> eventTypes = new HashSet<Name>();
eventTypes.addAll(Arrays.asList(event.getMixinTypeNames()));
eventTypes.add(event.getPrimaryNodeTypeName());
// create intersection
eventTypes.retainAll(nodeTypeNames);
if (eventTypes.isEmpty()) {
return false;
}
}
// finally check path
try {
Path eventPath = event.getPath().getAncestor(1);
boolean match = eventPath.equals(absPath);
if (!match && isDeep) {
match = eventPath.isDescendantOf(absPath);
}
return match;
} catch (RepositoryException e) {
// should never get here
}
// if we get here an exception occurred while checking for the path
return false;
}
use of org.apache.jackrabbit.spi.NodeId in project jackrabbit by apache.
the class PropertyInfoImpl method createSerializablePropertyInfo.
/**
* Creates a new serializable property info for the given
* <code>PropertyInfo</code>.
*
* @param propertyInfo
*/
public static PropertyInfo createSerializablePropertyInfo(PropertyInfo propertyInfo, IdFactory idFactory) {
if (propertyInfo instanceof Serializable) {
return propertyInfo;
} else {
NodeId parentId = propertyInfo.getId().getParentId();
parentId = idFactory.createNodeId(parentId.getUniqueID(), parentId.getPath());
PropertyId propId = idFactory.createPropertyId(parentId, propertyInfo.getId().getName());
return new PropertyInfoImpl(propertyInfo.getPath(), propId, propertyInfo.getType(), propertyInfo.isMultiValued(), propertyInfo.getValues());
}
}
Aggregations