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