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