io.github.jhipster.service.filter.Filter Java Examples

The following examples show how to use io.github.jhipster.service.filter.Filter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: QueryService.java    From jhipster with Apache License 2.0 5 votes vote down vote up
/**
 * Helper function to return a specification for filtering on a single field, where equality, and null/non-null
 * conditions are supported.
 *
 * @param filter            the individual attribute filter coming from the frontend.
 * @param metaclassFunction the function, which navigates from the current entity to a column, for which the filter applies.
 * @param <X>               The type of the attribute which is filtered.
 * @return a Specification
 */
protected <X> Specification<ENTITY> buildSpecification(Filter<X> filter, Function<Root<ENTITY>, Expression<X>> metaclassFunction) {
    if (filter.getEquals() != null) {
        return equalsSpecification(metaclassFunction, filter.getEquals());
    } else if (filter.getIn() != null) {
        return valueIn(metaclassFunction, filter.getIn());
    } else if (filter.getNotIn() != null) {
        return valueNotIn(metaclassFunction, filter.getNotIn());
    } else if (filter.getNotEquals() != null) {
        return notEqualsSpecification(metaclassFunction, filter.getNotEquals());
    } else if (filter.getSpecified() != null) {
        return byFieldSpecified(metaclassFunction, filter.getSpecified());
    }
    return null;
}
 
Example #2
Source File: QueryService.java    From jhipster with Apache License 2.0 3 votes vote down vote up
/**
 * Helper function to return a specification for filtering on a single field, where equality, and null/non-null
 * conditions are supported.
 *
 * @param filter the individual attribute filter coming from the frontend.
 * @param field  the JPA static metamodel representing the field.
 * @param <X>    The type of the attribute which is filtered.
 * @return a Specification
 */
protected <X> Specification<ENTITY> buildSpecification(Filter<X> filter, SingularAttribute<? super ENTITY, X>
    field) {
    return buildSpecification(filter, root -> root.get(field));
}
 
Example #3
Source File: QueryService.java    From jhipster with Apache License 2.0 2 votes vote down vote up
/**
 * Helper function to return a specification for filtering on one-to-one or many-to-one reference. Usage:
 * <pre>
 *   Specification&lt;Employee&gt; specByProjectId = buildReferringEntitySpecification(criteria.getProjectId(),
 * Employee_.project, Project_.id);
 *   Specification&lt;Employee&gt; specByProjectName = buildReferringEntitySpecification(criteria.getProjectName(),
 * Employee_.project, Project_.name);
 * </pre>
 *
 * @param filter     the filter object which contains a value, which needs to match or a flag if nullness is
 *                   checked.
 * @param reference  the attribute of the static metamodel for the referring entity.
 * @param valueField the attribute of the static metamodel of the referred entity, where the equality should be
 *                   checked.
 * @param <OTHER>    The type of the referenced entity.
 * @param <X>        The type of the attribute which is filtered.
 * @return a Specification
 */
protected <OTHER, X> Specification<ENTITY> buildReferringEntitySpecification(Filter<X> filter,
                                                                             SingularAttribute<? super ENTITY, OTHER> reference,
                                                                             SingularAttribute<? super OTHER, X> valueField) {
    return buildSpecification(filter, root -> root.get(reference).get(valueField));
}
 
Example #4
Source File: QueryService.java    From jhipster with Apache License 2.0 2 votes vote down vote up
/**
 * Helper function to return a specification for filtering on one-to-many or many-to-many reference. Usage:
 * <pre>
 *   Specification&lt;Employee&gt; specByEmployeeId = buildReferringEntitySpecification(criteria.getEmployeId(),
 * Project_.employees, Employee_.id);
 *   Specification&lt;Employee&gt; specByEmployeeName = buildReferringEntitySpecification(criteria.getEmployeName(),
 * Project_.project, Project_.name);
 * </pre>
 *
 * @param filter     the filter object which contains a value, which needs to match or a flag if emptiness is
 *                   checked.
 * @param reference  the attribute of the static metamodel for the referring entity.
 * @param valueField the attribute of the static metamodel of the referred entity, where the equality should be
 *                   checked.
 * @param <OTHER>    The type of the referenced entity.
 * @param <X>        The type of the attribute which is filtered.
 * @return a Specification
 */
protected <OTHER, X> Specification<ENTITY> buildReferringEntitySpecification(Filter<X> filter,
                                                                             SetAttribute<ENTITY, OTHER> reference,
                                                                             SingularAttribute<OTHER, X> valueField) {
    return buildReferringEntitySpecification(filter, root -> root.join(reference), entity -> entity.get(valueField));
}
 
Example #5
Source File: QueryService.java    From jhipster with Apache License 2.0 2 votes vote down vote up
/**
 * Helper function to return a specification for filtering on one-to-many or many-to-many reference.Usage:<pre>
 *   Specification&lt;Employee&gt; specByEmployeeId = buildReferringEntitySpecification(
 *          criteria.getEmployeId(),
 *          root -&gt; root.get(Project_.company).join(Company_.employees),
 *          entity -&gt; entity.get(Employee_.id));
 *   Specification&lt;Employee&gt; specByProjectName = buildReferringEntitySpecification(
 *          criteria.getProjectName(),
 *          root -&gt; root.get(Project_.project)
 *          entity -&gt; entity.get(Project_.name));
 * </pre>
 *
 * @param filter           the filter object which contains a value, which needs to match or a flag if emptiness is
 *                         checked.
 * @param functionToEntity the function, which joins he current entity to the entity set, on which the filtering is applied.
 * @param entityToColumn   the function, which of the static metamodel of the referred entity, where the equality should be
 *                         checked.
 * @param <OTHER>          The type of the referenced entity.
 * @param <MISC>           The type of the entity which is the last before the OTHER in the chain.
 * @param <X>              The type of the attribute which is filtered.
 * @return a Specification
 */
protected <OTHER, MISC, X> Specification<ENTITY> buildReferringEntitySpecification(Filter<X> filter,
                                                                                   Function<Root<ENTITY>, SetJoin<MISC, OTHER>> functionToEntity,
                                                                                   Function<SetJoin<MISC, OTHER>, Expression<X>> entityToColumn) {
    if (filter.getEquals() != null) {
        return equalsSpecification(functionToEntity.andThen(entityToColumn), filter.getEquals());
    } else if (filter.getSpecified() != null) {
        // Interestingly, 'functionToEntity' doesn't work, we need the longer lambda formula
        return byFieldSpecified(root -> functionToEntity.apply(root), filter.getSpecified());
    }
    return null;
}