Search in sources :

Example 6 with Composite

use of org.qi4j.api.composite.Composite in project qi4j-sdk by Qi4j.

the class RdfQueryParserImpl method processFilter.

private void processFilter(final Specification<Composite> expression, boolean allowInline, StringBuilder builder) {
    if (expression == null) {
        return;
    }
    if (expression instanceof AndSpecification) {
        final AndSpecification conjunction = (AndSpecification) expression;
        int start = builder.length();
        boolean first = true;
        for (Specification<Composite> operand : conjunction.operands()) {
            int size = builder.length();
            processFilter(operand, allowInline, builder);
            if (builder.length() > size) {
                if (first) {
                    first = false;
                } else {
                    builder.insert(size, " && ");
                }
            }
        }
        if (builder.length() > start) {
            builder.insert(start, '(');
            builder.append(')');
        }
    } else if (expression instanceof OrSpecification) {
        final OrSpecification disjunction = (OrSpecification) expression;
        int start = builder.length();
        boolean first = true;
        for (Specification<Composite> operand : disjunction.operands()) {
            int size = builder.length();
            processFilter(operand, false, builder);
            if (builder.length() > size) {
                if (first) {
                    first = false;
                } else {
                    builder.insert(size, "||");
                }
            }
        }
        if (builder.length() > start) {
            builder.insert(start, '(');
            builder.append(')');
        }
    } else if (expression instanceof NotSpecification) {
        builder.insert(0, "(!");
        processFilter(((NotSpecification) expression).operand(), false, builder);
        builder.append(")");
    } else if (expression instanceof ComparisonSpecification) {
        processComparisonPredicate(expression, allowInline, builder);
    } else if (expression instanceof ContainsAllSpecification) {
        processContainsAllPredicate((ContainsAllSpecification) expression, builder);
    } else if (expression instanceof ContainsSpecification<?>) {
        processContainsPredicate((ContainsSpecification<?>) expression, builder);
    } else if (expression instanceof MatchesSpecification) {
        processMatchesPredicate((MatchesSpecification) expression, builder);
    } else if (expression instanceof PropertyNotNullSpecification<?>) {
        processNotNullPredicate((PropertyNotNullSpecification) expression, builder);
    } else if (expression instanceof PropertyNullSpecification<?>) {
        processNullPredicate((PropertyNullSpecification) expression, builder);
    } else if (expression instanceof AssociationNotNullSpecification<?>) {
        processNotNullPredicate((AssociationNotNullSpecification) expression, builder);
    } else if (expression instanceof AssociationNullSpecification<?>) {
        processNullPredicate((AssociationNullSpecification) expression, builder);
    } else if (expression instanceof ManyAssociationContainsSpecification<?>) {
        processManyAssociationContainsPredicate((ManyAssociationContainsSpecification) expression, allowInline, builder);
    } else {
        throw new UnsupportedOperationException("Expression " + expression + " is not supported");
    }
}
Also used : OrSpecification(org.qi4j.api.query.grammar.OrSpecification) Composite(org.qi4j.api.composite.Composite) EntityComposite(org.qi4j.api.entity.EntityComposite) MatchesSpecification(org.qi4j.api.query.grammar.MatchesSpecification) ContainsSpecification(org.qi4j.api.query.grammar.ContainsSpecification) ContainsAllSpecification(org.qi4j.api.query.grammar.ContainsAllSpecification) ManyAssociationContainsSpecification(org.qi4j.api.query.grammar.ManyAssociationContainsSpecification) LeSpecification(org.qi4j.api.query.grammar.LeSpecification) PropertyNullSpecification(org.qi4j.api.query.grammar.PropertyNullSpecification) NotSpecification(org.qi4j.api.query.grammar.NotSpecification) PropertyNotNullSpecification(org.qi4j.api.query.grammar.PropertyNotNullSpecification) Specification(org.qi4j.functional.Specification) LtSpecification(org.qi4j.api.query.grammar.LtSpecification) GtSpecification(org.qi4j.api.query.grammar.GtSpecification) NeSpecification(org.qi4j.api.query.grammar.NeSpecification) EqSpecification(org.qi4j.api.query.grammar.EqSpecification) AssociationNotNullSpecification(org.qi4j.api.query.grammar.AssociationNotNullSpecification) ComparisonSpecification(org.qi4j.api.query.grammar.ComparisonSpecification) QuerySpecification(org.qi4j.api.query.grammar.QuerySpecification) OrSpecification(org.qi4j.api.query.grammar.OrSpecification) GeSpecification(org.qi4j.api.query.grammar.GeSpecification) AndSpecification(org.qi4j.api.query.grammar.AndSpecification) AssociationNullSpecification(org.qi4j.api.query.grammar.AssociationNullSpecification) ComparisonSpecification(org.qi4j.api.query.grammar.ComparisonSpecification) ContainsSpecification(org.qi4j.api.query.grammar.ContainsSpecification) ManyAssociationContainsSpecification(org.qi4j.api.query.grammar.ManyAssociationContainsSpecification) NotSpecification(org.qi4j.api.query.grammar.NotSpecification) AndSpecification(org.qi4j.api.query.grammar.AndSpecification) PropertyNullSpecification(org.qi4j.api.query.grammar.PropertyNullSpecification) MatchesSpecification(org.qi4j.api.query.grammar.MatchesSpecification) AssociationNotNullSpecification(org.qi4j.api.query.grammar.AssociationNotNullSpecification) ContainsAllSpecification(org.qi4j.api.query.grammar.ContainsAllSpecification) PropertyNotNullSpecification(org.qi4j.api.query.grammar.PropertyNotNullSpecification) ManyAssociationContainsSpecification(org.qi4j.api.query.grammar.ManyAssociationContainsSpecification) AssociationNullSpecification(org.qi4j.api.query.grammar.AssociationNullSpecification)

Example 7 with Composite

use of org.qi4j.api.composite.Composite in project qi4j-sdk by Qi4j.

the class ConstraintViolationInterceptor method messageKey.

/**
     * <p>The message key is generated based on the type of the target, the name of the property and the type of the
     * constraint violation.  So, if the target has type ItemEntity with a name property that has a not empty constraint
     * and the user doesn't enter anything for the value, the corresponding message key would be
     * 'item.name.not.empty.constraint.violated'.</p>
     *
     * <p>Note that if the type name of the target ends with 'Composite' or 'Entity', those will be removed and the
     * rest of the name will be converted from camel-case to a dot notation.  This is true of the constraint types as
     * well.  So a constraint named NotEmpty will be converted to not.empty as in the example above.</p>
     * @param target JAVADOC
     * @param propertyName JAVADOC
     * @param violation JAVADOC
     * @return JAVADOC
     */
protected String messageKey(Object target, String propertyName, ConstraintViolation violation) {
    Iterable<Class<?>> types;
    if (target instanceof Composite) {
        Composite composite = (Composite) target;
        types = Qi4j.FUNCTION_DESCRIPTOR_FOR.map(composite).types();
    } else {
        ArrayList<Class<?>> list = new ArrayList<Class<?>>(1);
        list.add(target.getClass());
        types = list;
    }
    return classNameInDotNotation(types, withoutCompositeOrEntitySuffix) + "." + propertyName + "." + constraintKeyPart(violation) + ".constraint.violated";
}
Also used : Composite(org.qi4j.api.composite.Composite) ArrayList(java.util.ArrayList)

Aggregations

Composite (org.qi4j.api.composite.Composite)7 EntityComposite (org.qi4j.api.entity.EntityComposite)2 ValueComposite (org.qi4j.api.value.ValueComposite)2 ArrayList (java.util.ArrayList)1 BNode (org.openrdf.model.BNode)1 URI (org.openrdf.model.URI)1 ValueFactory (org.openrdf.model.ValueFactory)1 ConstructionException (org.qi4j.api.common.ConstructionException)1 InvalidCompositeException (org.qi4j.api.composite.InvalidCompositeException)1 PropertyDescriptor (org.qi4j.api.property.PropertyDescriptor)1 AndSpecification (org.qi4j.api.query.grammar.AndSpecification)1 AssociationNotNullSpecification (org.qi4j.api.query.grammar.AssociationNotNullSpecification)1 AssociationNullSpecification (org.qi4j.api.query.grammar.AssociationNullSpecification)1 ComparisonSpecification (org.qi4j.api.query.grammar.ComparisonSpecification)1 ContainsAllSpecification (org.qi4j.api.query.grammar.ContainsAllSpecification)1 ContainsSpecification (org.qi4j.api.query.grammar.ContainsSpecification)1 EqSpecification (org.qi4j.api.query.grammar.EqSpecification)1 GeSpecification (org.qi4j.api.query.grammar.GeSpecification)1 GtSpecification (org.qi4j.api.query.grammar.GtSpecification)1 LeSpecification (org.qi4j.api.query.grammar.LeSpecification)1