Search in sources :

Example 21 with ValueFormatException

use of javax.jcr.ValueFormatException in project jackrabbit by apache.

the class PathPropertyTest method testGetDate.

/**
 * Tests failure of conversion from Path type to Date type.
 */
public void testGetDate() throws RepositoryException {
    try {
        Value val = PropertyUtil.getValue(prop);
        val.getDate();
        fail("Conversion from a Path value to a Date value " + "should throw a ValueFormatException.");
    } catch (ValueFormatException vfe) {
    // ok
    }
}
Also used : Value(javax.jcr.Value) ValueFormatException(javax.jcr.ValueFormatException)

Example 22 with ValueFormatException

use of javax.jcr.ValueFormatException in project jackrabbit by apache.

the class PathPropertyTest method testGetLong.

/**
 * Tests failure of conversion from Path type to Long type.
 */
public void testGetLong() throws RepositoryException {
    try {
        Value val = PropertyUtil.getValue(prop);
        val.getLong();
        fail("Conversion from a Path value to a Long value " + "should throw a ValueFormatException.");
    } catch (ValueFormatException vfe) {
    // ok
    }
}
Also used : Value(javax.jcr.Value) ValueFormatException(javax.jcr.ValueFormatException)

Example 23 with ValueFormatException

use of javax.jcr.ValueFormatException in project jackrabbit by apache.

the class PropertyReadMethodsTest method testGetValues.

/**
 * Tests failure of Property.getValues() method for a single value
 * property.
 */
public void testGetValues() throws RepositoryException, NotExecutableException {
    Property singleProp = PropertyUtil.searchSingleValuedProperty(testRootNode);
    if (singleProp == null) {
        throw new NotExecutableException("No single valued property found.");
    }
    try {
        singleProp.getValues();
        fail("Property.getValues() called on a single property " + "should throw a ValueFormatException.");
    } catch (ValueFormatException vfe) {
    // ok
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) ValueFormatException(javax.jcr.ValueFormatException) Property(javax.jcr.Property)

Example 24 with ValueFormatException

use of javax.jcr.ValueFormatException in project jackrabbit by apache.

the class ReferencePropertyTest method testGetDate.

/**
 * Tests failure of conversion from Reference type to Date type.
 */
public void testGetDate() throws RepositoryException {
    try {
        Value val = PropertyUtil.getValue(prop);
        val.getDate();
        fail("Conversion from a Reference value to a Date value " + "should throw a ValueFormatException.");
    } catch (ValueFormatException vfe) {
    // ok
    }
}
Also used : Value(javax.jcr.Value) ValueFormatException(javax.jcr.ValueFormatException)

Example 25 with ValueFormatException

use of javax.jcr.ValueFormatException in project jackrabbit by apache.

the class LuceneQueryFactory method mapConstraintToQueryAndFilter.

protected Predicate mapConstraintToQueryAndFilter(QueryPair query, Constraint constraint, Map<String, NodeType> selectorMap, JackrabbitIndexSearcher searcher, IndexReader reader) throws RepositoryException, IOException {
    Predicate filter = Predicate.TRUE;
    if (constraint instanceof And) {
        And and = (And) constraint;
        filter = mapConstraintToQueryAndFilter(query, and.getConstraint1(), selectorMap, searcher, reader);
        Predicate other = mapConstraintToQueryAndFilter(query, and.getConstraint2(), selectorMap, searcher, reader);
        if (filter == Predicate.TRUE) {
            filter = other;
        } else if (other != Predicate.TRUE) {
            filter = Predicates.and(filter, other);
        }
    } else if (constraint instanceof Comparison) {
        Comparison c = (Comparison) constraint;
        Transform transform = new Transform(c.getOperand1());
        DynamicOperand left = transform.operand;
        final String operator = c.getOperator();
        StaticOperand right = c.getOperand2();
        if (left instanceof Length || left instanceof FullTextSearchScore || (((!JCR_OPERATOR_EQUAL_TO.equals(operator) && !JCR_OPERATOR_LIKE.equals(operator)) || transform.transform != TRANSFORM_NONE) && (left instanceof NodeName || left instanceof NodeLocalName))) {
            try {
                int type = PropertyType.UNDEFINED;
                if (left instanceof Length) {
                    type = PropertyType.LONG;
                } else if (left instanceof FullTextSearchScore) {
                    type = PropertyType.DOUBLE;
                }
                final DynamicOperand operand = c.getOperand1();
                final Value value = evaluator.getValue(right, type);
                filter = new RowPredicate() {

                    @Override
                    protected boolean evaluate(Row row) throws RepositoryException {
                        return new ValueComparator().evaluate(operator, evaluator.getValue(operand, row), value);
                    }
                };
            } catch (ValueFormatException e) {
                throw new InvalidQueryException(e);
            }
        } else {
            Query cq = getComparisonQuery(left, transform.transform, operator, right, selectorMap);
            query.subQuery.add(cq, MUST);
        }
    } else if (constraint instanceof DescendantNode) {
        final DescendantNode descendantNode = (DescendantNode) constraint;
        Query context = getNodeIdQuery(UUID, descendantNode.getAncestorPath());
        query.mainQuery = new DescendantSelfAxisQuery(context, query.subQuery, false);
    } else {
        query.subQuery.add(create(constraint, selectorMap, searcher), MUST);
    }
    return filter;
}
Also used : Query(org.apache.lucene.search.Query) BooleanQuery(org.apache.lucene.search.BooleanQuery) DynamicOperand(javax.jcr.query.qom.DynamicOperand) StaticOperand(javax.jcr.query.qom.StaticOperand) NodeName(javax.jcr.query.qom.NodeName) ValueComparator(org.apache.jackrabbit.core.query.lucene.join.ValueComparator) Predicate(org.apache.jackrabbit.commons.predicate.Predicate) RowPredicate(org.apache.jackrabbit.commons.predicate.RowPredicate) NodeLocalName(javax.jcr.query.qom.NodeLocalName) RowPredicate(org.apache.jackrabbit.commons.predicate.RowPredicate) Comparison(javax.jcr.query.qom.Comparison) Length(javax.jcr.query.qom.Length) And(javax.jcr.query.qom.And) DescendantNode(javax.jcr.query.qom.DescendantNode) Value(javax.jcr.Value) PropertyValue(javax.jcr.query.qom.PropertyValue) ValueFormatException(javax.jcr.ValueFormatException) FullTextSearchScore(javax.jcr.query.qom.FullTextSearchScore) SelectorRow(org.apache.jackrabbit.core.query.lucene.join.SelectorRow) Row(javax.jcr.query.Row) InvalidQueryException(javax.jcr.query.InvalidQueryException)

Aggregations

ValueFormatException (javax.jcr.ValueFormatException)106 Value (javax.jcr.Value)53 Property (javax.jcr.Property)34 RepositoryException (javax.jcr.RepositoryException)16 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)12 Calendar (java.util.Calendar)10 ItemNotFoundException (javax.jcr.ItemNotFoundException)10 Node (javax.jcr.Node)10 QValue (org.apache.jackrabbit.spi.QValue)10 PathNotFoundException (javax.jcr.PathNotFoundException)6 Name (org.apache.jackrabbit.spi.Name)6 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)5 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)5 InternalValue (org.apache.jackrabbit.core.value.InternalValue)5 InputStream (java.io.InputStream)4 BigDecimal (java.math.BigDecimal)4 Date (java.util.Date)4 Path (org.apache.jackrabbit.spi.Path)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3