use of org.apache.jackrabbit.oak.spi.state.ChildNodeEntry in project jackrabbit-oak by apache.
the class BundledTypesRegistry method from.
public static BundledTypesRegistry from(NodeState configParentState) {
Map<String, DocumentBundlor> bundlors = Maps.newHashMap();
for (ChildNodeEntry e : configParentState.getChildNodeEntries()) {
NodeState config = e.getNodeState();
if (config.getBoolean(DocumentBundlor.PROP_DISABLED)) {
continue;
}
bundlors.put(e.getName(), DocumentBundlor.from(config));
}
return new BundledTypesRegistry(bundlors);
}
use of org.apache.jackrabbit.oak.spi.state.ChildNodeEntry in project jackrabbit-oak by apache.
the class EffectiveType method getDefinition.
/**
* Finds a matching definition for a property with the given name and type.
*
* @param property modified property
* @return matching property definition, or {@code null}
*/
@CheckForNull
NodeState getDefinition(@Nonnull PropertyState property) {
String propertyName = property.getName();
Type<?> propertyType = property.getType();
String escapedName;
if (JCR_PRIMARYTYPE.equals(propertyName)) {
escapedName = NodeTypeConstants.REP_PRIMARY_TYPE;
} else if (JCR_MIXINTYPES.equals(propertyName)) {
escapedName = NodeTypeConstants.REP_MIXIN_TYPES;
} else if (JCR_UUID.equals(propertyName)) {
escapedName = NodeTypeConstants.REP_UUID;
} else {
escapedName = propertyName;
}
String definedType = propertyType.toString();
String undefinedType;
if (propertyType.isArray()) {
undefinedType = UNDEFINEDS.toString();
} else {
undefinedType = UNDEFINED.toString();
}
// Find matching named property definition
for (NodeState type : types) {
NodeState definitions = type.getChildNode(REP_NAMED_PROPERTY_DEFINITIONS).getChildNode(escapedName);
NodeState definition = definitions.getChildNode(definedType);
if (definition.exists()) {
return definition;
}
definition = definitions.getChildNode(undefinedType);
if (definition.exists()) {
return definition;
}
// TODO: unnecessary if the OAK-713 fallback wasn't needed below
for (ChildNodeEntry entry : definitions.getChildNodeEntries()) {
definition = entry.getNodeState();
if (definition.getBoolean(JCR_MANDATORY)) {
return definition;
}
}
// TODO: Fall back to residual definitions until we have consensus on OAK-713
// throw new ConstraintViolationException(
// "No matching definition found for property " + propertyName);
}
// Find matching residual property definition
for (NodeState type : types) {
NodeState residual = type.getChildNode(REP_RESIDUAL_PROPERTY_DEFINITIONS);
NodeState definition = residual.getChildNode(definedType);
if (!definition.exists()) {
definition = residual.getChildNode(undefinedType);
}
if (definition.exists()) {
return definition;
}
}
return null;
}
use of org.apache.jackrabbit.oak.spi.state.ChildNodeEntry in project jackrabbit-oak by apache.
the class EffectiveType method isValidChildNode.
/**
* Finds a matching definition for a child node with the given name and
* types.
*
* @param nameWithIndex child node name, possibly with an SNS index
* @param effective effective types of the child node
* @return {@code true} if there's a matching child node definition,
* {@code false} otherwise
*/
boolean isValidChildNode(@Nonnull String nameWithIndex, @Nonnull EffectiveType effective) {
String name = dropIndexFromName(nameWithIndex);
boolean sns = !name.equals(nameWithIndex);
Set<String> typeNames = effective.getTypeNames();
// Find matching named child node definition
for (NodeState type : types) {
NodeState definitions = type.getChildNode(REP_NAMED_CHILD_NODE_DEFINITIONS).getChildNode(name);
for (String typeName : typeNames) {
NodeState definition = definitions.getChildNode(typeName);
if (definition.exists() && snsMatch(sns, definition)) {
return true;
}
}
// TODO: unnecessary if the OAK-713 fallback wasn't needed below
for (ChildNodeEntry entry : definitions.getChildNodeEntries()) {
NodeState definition = entry.getNodeState();
if (definition.getBoolean(JCR_MANDATORY)) {
return false;
}
}
// TODO: Fall back to residual definitions until we have consensus on OAK-713
// throw new ConstraintViolationException(
// "Incorrect node type of child node " + nodeName);
}
// Find matching residual child node definition
for (NodeState type : types) {
NodeState residual = type.getChildNode(REP_RESIDUAL_CHILD_NODE_DEFINITIONS);
for (String typeName : typeNames) {
NodeState definition = residual.getChildNode(typeName);
if (definition.exists() && snsMatch(sns, definition)) {
return true;
}
}
}
return false;
}
use of org.apache.jackrabbit.oak.spi.state.ChildNodeEntry in project jackrabbit-oak by apache.
the class BlobMigrator method migrateNode.
private void migrateNode(NodeBuilder rootBuilder, DepthFirstNodeIterator iterator) throws IOException {
ChildNodeEntry node = iterator.next();
NodeState state = node.getNodeState();
for (PropertyState property : state.getProperties()) {
PropertyState newProperty;
if (property.getType() == Type.BINARY) {
newProperty = migrateProperty(property);
} else if (property.getType() == Type.BINARIES) {
newProperty = migrateMultiProperty(property);
} else {
newProperty = null;
}
if (newProperty != null) {
NodeBuilder builder = iterator.getBuilder(rootBuilder);
if (builder.exists()) {
builder.setProperty(newProperty);
migratedNodes++;
log.debug("Migrated property {}/{}", lastPath, property.getName());
} else {
log.warn("Can't migrate blobs for a non-existing node: {}", lastPath);
}
}
}
}
use of org.apache.jackrabbit.oak.spi.state.ChildNodeEntry in project jackrabbit-oak by apache.
the class DepthFirstNodeIterator method computeNext.
@Override
protected ChildNodeEntry computeNext() {
if (itQueue.isEmpty()) {
return endOfData();
}
if (itQueue.peekLast().hasNext()) {
ChildNodeEntry next = itQueue.peekLast().next();
itQueue.add(next.getNodeState().getChildNodeEntries().iterator());
nameQueue.add(next.getName());
return next;
} else {
itQueue.pollLast();
if (!nameQueue.isEmpty()) {
nameQueue.pollLast();
}
return computeNext();
}
}
Aggregations