Search in sources :

Example 46 with PropertyState

use of org.apache.jackrabbit.oak.api.PropertyState in project jackrabbit-oak by apache.

the class VersionGCQueryTest method noQueryForFirstLevelPrevDocs.

@Test
public void noQueryForFirstLevelPrevDocs() throws Exception {
    // create some garbage
    NodeBuilder builder = ns.getRoot().builder();
    for (int i = 0; i < 10; i++) {
        InputStream s = new RandomStream(10 * 1024, 42);
        PropertyState p = new BinaryPropertyState("p", ns.createBlob(s));
        builder.child("test").child("node-" + i).setProperty(p);
    }
    merge(builder);
    // overwrite with other binaries to force document splits
    builder = ns.getRoot().builder();
    for (int i = 0; i < 10; i++) {
        InputStream s = new RandomStream(10 * 1024, 17);
        PropertyState p = new BinaryPropertyState("p", ns.createBlob(s));
        builder.child("test").child("node-" + i).setProperty(p);
    }
    merge(builder);
    ns.runBackgroundOperations();
    builder = ns.getRoot().builder();
    builder.child("test").remove();
    merge(builder);
    ns.runBackgroundOperations();
    clock.waitUntil(clock.getTime() + TimeUnit.HOURS.toMillis(1));
    VersionGarbageCollector gc = new VersionGarbageCollector(ns, new VersionGCSupport(store));
    prevDocIds.clear();
    VersionGCStats stats = gc.gc(30, TimeUnit.MINUTES);
    assertEquals(11, stats.deletedDocGCCount);
    assertEquals(10, stats.splitDocGCCount);
    assertEquals(0, prevDocIds.size());
    assertEquals(1, Iterables.size(Utils.getAllDocuments(store)));
}
Also used : VersionGCStats(org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector.VersionGCStats) InputStream(java.io.InputStream) BinaryPropertyState(org.apache.jackrabbit.oak.plugins.memory.BinaryPropertyState) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) BinaryPropertyState(org.apache.jackrabbit.oak.plugins.memory.BinaryPropertyState) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) Test(org.junit.Test)

Example 47 with PropertyState

use of org.apache.jackrabbit.oak.api.PropertyState in project jackrabbit-oak by apache.

the class AbstractCompositeProviderTest method testIsGrantedNone.

@Test
public void testIsGrantedNone() throws Exception {
    PermissionProvider pp = createPermissionProvider();
    for (String p : NODE_PATHS) {
        Tree tree = readOnlyRoot.getTree(p);
        PropertyState ps = tree.getProperty(JcrConstants.JCR_PRIMARYTYPE);
        assertFalse(p, pp.isGranted(tree, null, Permissions.NO_PERMISSION));
        assertFalse(PathUtils.concat(p, JcrConstants.JCR_PRIMARYTYPE), pp.isGranted(tree, ps, Permissions.NO_PERMISSION));
    }
}
Also used : PermissionProvider(org.apache.jackrabbit.oak.spi.security.authorization.permission.PermissionProvider) AggregatedPermissionProvider(org.apache.jackrabbit.oak.spi.security.authorization.permission.AggregatedPermissionProvider) Tree(org.apache.jackrabbit.oak.api.Tree) ImmutableTree(org.apache.jackrabbit.oak.plugins.tree.impl.ImmutableTree) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 48 with PropertyState

use of org.apache.jackrabbit.oak.api.PropertyState in project jackrabbit-oak by apache.

the class RestrictionProviderImplTest method testGetPatternForAllSupported.

@Test
public void testGetPatternForAllSupported() throws Exception {
    Map<PropertyState, RestrictionPattern> map = newHashMap();
    map.put(PropertyStates.createProperty(REP_GLOB, "/*/jcr:content"), GlobPattern.create("/testPath", "/*/jcr:content"));
    List<String> ntNames = ImmutableList.of(JcrConstants.NT_FOLDER, JcrConstants.NT_LINKEDFILE);
    map.put(PropertyStates.createProperty(REP_NT_NAMES, ntNames, Type.NAMES), new NodeTypePattern(ntNames));
    List<String> prefixes = ImmutableList.of("rep", "jcr");
    map.put(PropertyStates.createProperty(REP_PREFIXES, prefixes, Type.STRINGS), new PrefixPattern(prefixes));
    List<String> itemNames = ImmutableList.of("abc", "jcr:primaryType");
    map.put(PropertyStates.createProperty(REP_ITEM_NAMES, prefixes, Type.NAMES), new ItemNamePattern(itemNames));
    NodeUtil tree = new NodeUtil(root.getTree("/")).getOrAddTree("testPath", JcrConstants.NT_UNSTRUCTURED);
    Tree restrictions = tree.addChild(REP_RESTRICTIONS, NT_REP_RESTRICTIONS).getTree();
    for (Map.Entry<PropertyState, RestrictionPattern> entry : map.entrySet()) {
        restrictions.setProperty(entry.getKey());
    }
    RestrictionPattern pattern = provider.getPattern("/testPath", restrictions);
    assertTrue(pattern instanceof CompositePattern);
}
Also used : RestrictionPattern(org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionPattern) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) CompositePattern(org.apache.jackrabbit.oak.spi.security.authorization.restriction.CompositePattern) Tree(org.apache.jackrabbit.oak.api.Tree) Map(java.util.Map) Maps.newHashMap(com.google.common.collect.Maps.newHashMap) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 49 with PropertyState

use of org.apache.jackrabbit.oak.api.PropertyState in project jackrabbit-oak by apache.

the class Namespaces method addCustomMapping.

public static String addCustomMapping(NodeBuilder namespaces, String uri, String prefixHint) {
    // first look for an existing mapping for the given URI
    for (PropertyState property : namespaces.getProperties()) {
        if (property.getType() == STRING) {
            String prefix = property.getName();
            if (isValidPrefix(prefix) && uri.equals(property.getValue(STRING))) {
                return prefix;
            }
        }
    }
    // no existing mapping found for the URI, make sure prefix is unique
    String prefix = prefixHint;
    int iteration = 1;
    while (namespaces.hasProperty(prefix)) {
        prefix = prefixHint + ++iteration;
    }
    // add the new mapping with its unique prefix
    namespaces.setProperty(prefix, uri);
    return prefix;
}
Also used : PropertyState(org.apache.jackrabbit.oak.api.PropertyState)

Example 50 with PropertyState

use of org.apache.jackrabbit.oak.api.PropertyState in project jackrabbit-oak by apache.

the class PropertyIndexLookup method getIndexNode.

/**
     * Get the node with the index definition for the given property, if there
     * is an applicable index with data.
     * 
     * @param propertyName the property name
     * @param filter the filter (which contains information of all supertypes,
     *            unless the filter matches all types)
     * @return the node where the index definition (metadata) is stored (the
     *         parent of ":index"), or null if no index definition or index data
     *         node was found
     */
@Nullable
NodeState getIndexNode(NodeState node, String propertyName, Filter filter) {
    // keep a fallback to a matching index def that has *no* node type constraints
    // (initially, there is no fallback)
    NodeState fallback = null;
    NodeState state = node.getChildNode(INDEX_DEFINITIONS_NAME);
    for (ChildNodeEntry entry : state.getChildNodeEntries()) {
        NodeState index = entry.getNodeState();
        PropertyState type = index.getProperty(TYPE_PROPERTY_NAME);
        if (type == null || type.isArray() || !getType().equals(type.getValue(Type.STRING))) {
            continue;
        }
        if (contains(getNames(index, PROPERTY_NAMES), propertyName)) {
            NodeState indexContent = index.getChildNode(INDEX_CONTENT_NODE_NAME);
            if (!indexContent.exists()) {
                continue;
            }
            Set<String> supertypes = getSuperTypes(filter);
            if (index.hasProperty(DECLARING_NODE_TYPES)) {
                if (supertypes != null) {
                    for (String typeName : getNames(index, DECLARING_NODE_TYPES)) {
                        if (supertypes.contains(typeName)) {
                            // TODO: prefer the most specific type restriction
                            return index;
                        }
                    }
                }
            } else if (supertypes == null) {
                return index;
            } else if (fallback == null) {
                // update the fallback
                fallback = index;
            }
        }
    }
    return fallback;
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) ChildNodeEntry(org.apache.jackrabbit.oak.spi.state.ChildNodeEntry) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) Nullable(javax.annotation.Nullable)

Aggregations

PropertyState (org.apache.jackrabbit.oak.api.PropertyState)404 Test (org.junit.Test)189 Tree (org.apache.jackrabbit.oak.api.Tree)138 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)49 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)45 Nonnull (javax.annotation.Nonnull)31 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)29 RemoteTree (org.apache.jackrabbit.oak.remote.RemoteTree)28 RemoteValue (org.apache.jackrabbit.oak.remote.RemoteValue)28 Blob (org.apache.jackrabbit.oak.api.Blob)21 ArrayList (java.util.ArrayList)20 LongPropertyState (org.apache.jackrabbit.oak.plugins.memory.LongPropertyState)17 ChildNodeEntry (org.apache.jackrabbit.oak.spi.state.ChildNodeEntry)16 EmptyNodeState (org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState)14 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)13 CheckForNull (javax.annotation.CheckForNull)12 RepositoryException (javax.jcr.RepositoryException)10 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)10 Map (java.util.Map)9 Value (javax.jcr.Value)9