Search in sources :

Example 86 with PropertyState

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

the class PrivilegeBitsProviderTest method testGetPrivilegeNamesWithAggregation.

@Test
public void testGetPrivilegeNamesWithAggregation() {
    when(privTree.exists()).thenReturn(true);
    when(privTree.getChildren()).thenReturn(ImmutableSet.of(pTree));
    Tree anotherPriv = Mockito.mock(Tree.class);
    when(anotherPriv.exists()).thenReturn(true);
    when(anotherPriv.getName()).thenReturn("name2");
    when(anotherPriv.hasProperty(REP_AGGREGATES)).thenReturn(true);
    when(anotherPriv.getProperty(REP_AGGREGATES)).thenReturn(PropertyStates.createProperty(REP_AGGREGATES, ImmutableList.of(KNOWN_PRIV_NAME), Type.NAMES));
    PropertyState bits2 = PropertyStates.createProperty(REP_BITS, Long.valueOf(7500));
    when(anotherPriv.getProperty(REP_BITS)).thenReturn(bits2);
    when(privTree.getChildren()).thenReturn(ImmutableSet.of(pTree, anotherPriv));
    // aggregation must be removed from the result set
    Set<String> expected = ImmutableSet.of("name2");
    Set<String> result = bitsProvider.getPrivilegeNames(PrivilegeBits.getInstance(PrivilegeBits.getInstance(bits), PrivilegeBits.getInstance(bits2)));
    assertEquals(expected, result);
}
Also used : Tree(org.apache.jackrabbit.oak.api.Tree) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) Test(org.junit.Test)

Example 87 with PropertyState

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

the class PrivilegeBitsTest method testGetInstanceFromPropertyState.

@Test
public void testGetInstanceFromPropertyState() {
    for (long l : LONGS) {
        PropertyState property = createPropertyState(l);
        PrivilegeBits pb = PrivilegeBits.getInstance(property);
        assertEquivalent(pb, PrivilegeBits.getInstance(property));
        assertSame(pb, pb.unmodifiable());
        assertEquivalent(pb, PrivilegeBits.getInstance(pb));
        assertEquivalent(PrivilegeBits.getInstance(pb), pb);
        assertNotSame(pb, PrivilegeBits.getInstance(pb));
        try {
            pb.add(READ_NODES_PRIVILEGE_BITS);
            fail("UnsupportedOperation expected");
        } catch (UnsupportedOperationException e) {
        // success
        }
        try {
            pb.addDifference(READ_NODES_PRIVILEGE_BITS, READ_NODES_PRIVILEGE_BITS);
            fail("UnsupportedOperation expected");
        } catch (UnsupportedOperationException e) {
        // success
        }
        try {
            pb.diff(READ_NODES_PRIVILEGE_BITS);
            fail("UnsupportedOperation expected");
        } catch (UnsupportedOperationException e) {
        // success
        }
    }
}
Also used : PropertyState(org.apache.jackrabbit.oak.api.PropertyState) Test(org.junit.Test)

Example 88 with PropertyState

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

the class MutableTreeTest method getProperties.

@Test
public void getProperties() {
    Tree tree = root.getTree("/");
    Set<PropertyState> expectedProperties = Sets.newHashSet(LongPropertyState.createLongProperty("a", 1L), LongPropertyState.createLongProperty("b", 2L), LongPropertyState.createLongProperty("c", 3L));
    Iterable<? extends PropertyState> properties = tree.getProperties();
    for (PropertyState property : properties) {
        assertTrue(expectedProperties.remove(property));
    }
    assertTrue(expectedProperties.isEmpty());
    assertEquals(3, tree.getPropertyCount());
}
Also used : Tree(org.apache.jackrabbit.oak.api.Tree) LongPropertyState(org.apache.jackrabbit.oak.plugins.memory.LongPropertyState) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) Test(org.junit.Test) OakBaseTest(org.apache.jackrabbit.oak.OakBaseTest)

Example 89 with PropertyState

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

the class FunctionIndexProcessor method calculateFunction.

private static PropertyState calculateFunction(String functionName, Deque<PropertyState> stack) {
    PropertyState ps = stack.pop();
    Type<?> type = null;
    ArrayList<Object> values = new ArrayList<Object>(ps.count());
    for (int i = 0; i < ps.count(); i++) {
        String s = ps.getValue(Type.STRING, i);
        Object x;
        if ("lower".equals(functionName)) {
            x = s.toLowerCase();
            type = Type.STRING;
        } else if ("upper".equals(functionName)) {
            x = s.toUpperCase();
            type = Type.STRING;
        } else if ("length".equals(functionName)) {
            x = (long) s.length();
            type = Type.LONG;
        } else {
            LOG.debug("Unknown function {}", functionName);
            return null;
        }
        values.add(x);
    }
    PropertyState result;
    if (values.size() == 1) {
        result = PropertyStates.createProperty("value", values.get(0), type);
    } else {
        type = type.getArrayType();
        result = PropertyStates.createProperty("value", values, type);
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) PropertyState(org.apache.jackrabbit.oak.api.PropertyState)

Example 90 with PropertyState

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

the class FunctionIndexProcessor method tryCalculateValue.

/**
     * Try to calculate the value for the given function code.
     * 
     * @param path the path of the node
     * @param state the node state
     * @param functionCode the tokens, for example ["function", "lower", "@name"]
     * @return null, or the calculated value
     */
public static PropertyState tryCalculateValue(String path, NodeState state, String[] functionCode) {
    Deque<PropertyState> stack = new ArrayDeque<PropertyState>();
    for (int i = functionCode.length - 1; i > 0; i--) {
        String token = functionCode[i];
        PropertyState ps;
        if (token.startsWith("@")) {
            String propertyName = token.substring(1);
            ps = getProperty(path, state, propertyName);
        } else {
            ps = calculateFunction(token, stack);
        }
        if (ps == null) {
            // currently, all operations involving null return null
            return null;
        }
        stack.push(ps);
    }
    return stack.pop();
}
Also used : ArrayDeque(java.util.ArrayDeque) PropertyState(org.apache.jackrabbit.oak.api.PropertyState)

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