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);
}
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
}
}
}
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());
}
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;
}
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();
}
Aggregations