Search in sources :

Example 41 with PropertyValue

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

the class ContentRemoteResultTest method testBooleanColumn.

@Test
public void testBooleanColumn() {
    PropertyValue value = mock(PropertyValue.class);
    doReturn(Type.BOOLEAN).when(value).getType();
    doReturn(true).when(value).getValue(Type.BOOLEAN);
    ResultRow row = mock(ResultRow.class);
    doReturn(value).when(row).getValue("column");
    ContentRemoteResult result = createResult(row);
    RemoteValue remoteValue = result.getColumnValue("column");
    assertEquals(true, remoteValue.asBoolean());
}
Also used : ResultRow(org.apache.jackrabbit.oak.api.ResultRow) PropertyValue(org.apache.jackrabbit.oak.api.PropertyValue) RemoteValue(org.apache.jackrabbit.oak.remote.RemoteValue) Test(org.junit.Test)

Example 42 with PropertyValue

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

the class NativeFunctionImpl method restrict.

@Override
public void restrict(FilterImpl f) {
    if (f.getSelector().equals(selector)) {
        PropertyValue v = nativeSearchExpression.currentValue();
        f.restrictProperty(NATIVE_PREFIX + language, Operator.EQUAL, v);
    }
}
Also used : PropertyValue(org.apache.jackrabbit.oak.api.PropertyValue)

Example 43 with PropertyValue

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

the class SelectorImpl method currentOakProperty.

private PropertyValue currentOakProperty(String oakPropertyName, Integer propertyType) {
    boolean asterisk = oakPropertyName.indexOf('*') >= 0;
    if (asterisk) {
        Tree t = currentTree();
        if (t != null) {
            LOG.trace("currentOakProperty() - '*' case. looking for '{}' in '{}'", oakPropertyName, t.getPath());
        }
        ArrayList<PropertyValue> list = new ArrayList<PropertyValue>();
        readOakProperties(list, t, oakPropertyName, propertyType);
        if (list.size() == 0) {
            return null;
        } else if (list.size() == 1) {
            return list.get(0);
        }
        Type<?> type = list.get(0).getType();
        for (int i = 1; i < list.size(); i++) {
            Type<?> t2 = list.get(i).getType();
            if (t2 != type) {
                // types don't match
                type = Type.STRING;
                break;
            }
        }
        if (type == Type.STRING) {
            ArrayList<String> strings = new ArrayList<String>();
            for (PropertyValue p : list) {
                Iterables.addAll(strings, p.getValue(Type.STRINGS));
            }
            return PropertyValues.newString(strings);
        }
        Type<?> baseType = type.isArray() ? type.getBaseType() : type;
        @SuppressWarnings("unchecked") PropertyBuilder<Object> builder = (PropertyBuilder<Object>) PropertyBuilder.array(baseType);
        builder.setName("");
        for (PropertyValue v : list) {
            if (type.isArray()) {
                for (Object value : (Iterable<?>) v.getValue(type)) {
                    builder.addValue(value);
                }
            } else {
                builder.addValue(v.getValue(type));
            }
        }
        PropertyState s = builder.getPropertyState();
        return PropertyValues.create(s);
    }
    boolean relative = oakPropertyName.indexOf('/') >= 0;
    Tree t = currentTree();
    if (relative) {
        for (String p : PathUtils.elements(PathUtils.getParentPath(oakPropertyName))) {
            if (t == null) {
                return null;
            }
            if (p.equals("..")) {
                t = t.isRoot() ? null : t.getParent();
            } else if (p.equals(".")) {
            // same node
            } else {
                t = t.getChild(p);
            }
        }
        oakPropertyName = PathUtils.getName(oakPropertyName);
    }
    return currentOakProperty(t, oakPropertyName, propertyType);
}
Also used : ArrayList(java.util.ArrayList) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) PropertyValue(org.apache.jackrabbit.oak.api.PropertyValue) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) Tree(org.apache.jackrabbit.oak.api.Tree) PropertyBuilder(org.apache.jackrabbit.oak.plugins.memory.PropertyBuilder)

Example 44 with PropertyValue

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

the class SelectorImpl method readOakProperties.

private void readOakProperties(ArrayList<PropertyValue> target, Tree t, String oakPropertyName, Integer propertyType) {
    boolean skipCurrentNode = false;
    while (!skipCurrentNode) {
        if (t == null || !t.exists()) {
            return;
        }
        LOG.trace("readOakProperties() - reading '{}' for '{}'", t.getPath(), oakPropertyName);
        int slash = oakPropertyName.indexOf('/');
        if (slash < 0) {
            break;
        }
        String parent = oakPropertyName.substring(0, slash);
        oakPropertyName = oakPropertyName.substring(slash + 1);
        if (parent.equals("..")) {
            t = t.isRoot() ? null : t.getParent();
        } else if (parent.equals(".")) {
        // same node
        } else if (parent.equals("*")) {
            for (Tree child : t.getChildren()) {
                readOakProperties(target, child, oakPropertyName, propertyType);
            }
            skipCurrentNode = true;
        } else {
            t = t.getChild(parent);
        }
    }
    if (skipCurrentNode) {
        return;
    }
    if (!"*".equals(oakPropertyName)) {
        PropertyValue value = currentOakProperty(t, oakPropertyName, propertyType);
        if (value != null) {
            LOG.trace("readOakProperties() - adding: '{}' from '{}'", value, t.getPath());
            target.add(value);
        }
        return;
    }
    for (PropertyState p : t.getProperties()) {
        if (propertyType == null || p.getType().tag() == propertyType) {
            PropertyValue v = PropertyValues.create(p);
            target.add(v);
        }
    }
}
Also used : Tree(org.apache.jackrabbit.oak.api.Tree) PropertyValue(org.apache.jackrabbit.oak.api.PropertyValue) PropertyState(org.apache.jackrabbit.oak.api.PropertyState)

Example 45 with PropertyValue

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

the class SelectorImpl method currentOakProperty.

private PropertyValue currentOakProperty(Tree t, String oakPropertyName, Integer propertyType) {
    PropertyValue result;
    if ((t == null || !t.exists()) && (currentRow == null || !currentRow.isVirtualRow())) {
        return null;
    }
    if (oakPropertyName.equals(QueryImpl.JCR_PATH)) {
        String path = currentPath();
        String local = getLocalPath(path);
        if (local == null) {
            // not a local path
            return null;
        }
        result = PropertyValues.newString(local);
    } else if (oakPropertyName.equals(QueryImpl.JCR_SCORE)) {
        result = currentRow.getValue(QueryImpl.JCR_SCORE);
    } else if (oakPropertyName.equals(QueryImpl.REP_EXCERPT)) {
        result = currentRow.getValue(QueryImpl.REP_EXCERPT);
    } else if (oakPropertyName.equals(QueryImpl.OAK_SCORE_EXPLANATION)) {
        result = currentRow.getValue(QueryImpl.OAK_SCORE_EXPLANATION);
    } else if (oakPropertyName.equals(QueryImpl.REP_SPELLCHECK)) {
        result = currentRow.getValue(QueryImpl.REP_SPELLCHECK);
    } else if (oakPropertyName.equals(QueryImpl.REP_SUGGEST)) {
        result = currentRow.getValue(QueryImpl.REP_SUGGEST);
    } else if (oakPropertyName.startsWith(QueryImpl.REP_FACET)) {
        result = currentRow.getValue(oakPropertyName);
    } else {
        result = PropertyValues.create(t.getProperty(oakPropertyName));
    }
    if (result == null) {
        return null;
    }
    if (propertyType != null && result.getType().tag() != propertyType) {
        return null;
    }
    return result;
}
Also used : PropertyValue(org.apache.jackrabbit.oak.api.PropertyValue)

Aggregations

PropertyValue (org.apache.jackrabbit.oak.api.PropertyValue)57 Test (org.junit.Test)28 ResultRow (org.apache.jackrabbit.oak.api.ResultRow)26 RemoteValue (org.apache.jackrabbit.oak.remote.RemoteValue)24 Tree (org.apache.jackrabbit.oak.api.Tree)5 ParseException (java.text.ParseException)4 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)4 ArrayList (java.util.ArrayList)3 Result (org.apache.jackrabbit.oak.api.Result)3 Date (java.util.Date)2 Blob (org.apache.jackrabbit.oak.api.Blob)2 LiteralImpl (org.apache.jackrabbit.oak.query.ast.LiteralImpl)2 StaticOperandImpl (org.apache.jackrabbit.oak.query.ast.StaticOperandImpl)2 FulltextQueryIndex (org.apache.jackrabbit.oak.spi.query.QueryIndex.FulltextQueryIndex)2 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 BigDecimal (java.math.BigDecimal)1 Calendar (java.util.Calendar)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 InvalidQueryException (javax.jcr.query.InvalidQueryException)1