Java Code Examples for org.springframework.data.jpa.domain.Specification#where()

The following examples show how to use org.springframework.data.jpa.domain.Specification#where() . 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: DimensionQueryService.java    From TeamDojo with Apache License 2.0 6 votes vote down vote up
/**
 * Function to convert DimensionCriteria to a {@link Specification}
 */
private Specification<Dimension> createSpecification(DimensionCriteria criteria) {
    Specification<Dimension> specification = Specification.where(null);
    if (criteria != null) {
        if (criteria.getId() != null) {
            specification = specification.and(buildSpecification(criteria.getId(), Dimension_.id));
        }
        if (criteria.getName() != null) {
            specification = specification.and(buildStringSpecification(criteria.getName(), Dimension_.name));
        }
        if (criteria.getDescription() != null) {
            specification = specification.and(buildStringSpecification(criteria.getDescription(), Dimension_.description));
        }
        if (criteria.getParticipantsId() != null) {
            specification = specification.and(buildReferringEntitySpecification(criteria.getParticipantsId(), Dimension_.participants, Team_.id));
        }
        if (criteria.getLevelsId() != null) {
            specification = specification.and(buildReferringEntitySpecification(criteria.getLevelsId(), Dimension_.levels, Level_.id));
        }
        if (criteria.getBadgesId() != null) {
            specification = specification.and(buildReferringEntitySpecification(criteria.getBadgesId(), Dimension_.badges, Badge_.id));
        }
    }
    return specification;
}
 
Example 2
Source File: CommentQueryService.java    From TeamDojo with Apache License 2.0 6 votes vote down vote up
/**
 * Function to convert CommentCriteria to a {@link Specification}
 */
private Specification<Comment> createSpecification(CommentCriteria criteria) {
    Specification<Comment> specification = Specification.where(null);
    if (criteria != null) {
        if (criteria.getId() != null) {
            specification = specification.and(buildSpecification(criteria.getId(), Comment_.id));
        }
        if (criteria.getText() != null) {
            specification = specification.and(buildStringSpecification(criteria.getText(), Comment_.text));
        }
        if (criteria.getCreationDate() != null) {
            specification = specification.and(buildRangeSpecification(criteria.getCreationDate(), Comment_.creationDate));
        }
        if (criteria.getTeamId() != null) {
            specification = specification.and(buildReferringEntitySpecification(criteria.getTeamId(), Comment_.team, Team_.id));
        }
        if (criteria.getSkillId() != null) {
            specification = specification.and(buildReferringEntitySpecification(criteria.getSkillId(), Comment_.skill, Skill_.id));
        }
    }
    return specification;
}
 
Example 3
Source File: ReportQueryService.java    From TeamDojo with Apache License 2.0 6 votes vote down vote up
/**
 * Function to convert ReportCriteria to a {@link Specification}
 */
private Specification<Report> createSpecification(ReportCriteria criteria) {
    Specification<Report> specification = Specification.where(null);
    if (criteria != null) {
        if (criteria.getId() != null) {
            specification = specification.and(buildSpecification(criteria.getId(), Report_.id));
        }
        if (criteria.getTitle() != null) {
            specification = specification.and(buildStringSpecification(criteria.getTitle(), Report_.title));
        }
        if (criteria.getDescription() != null) {
            specification = specification.and(buildStringSpecification(criteria.getDescription(), Report_.description));
        }
        if (criteria.getType() != null) {
            specification = specification.and(buildSpecification(criteria.getType(), Report_.type));
        }
        if (criteria.getCreationDate() != null) {
            specification = specification.and(buildRangeSpecification(criteria.getCreationDate(), Report_.creationDate));
        }
    }
    return specification;
}
 
Example 4
Source File: QuoteQueryService.java    From tutorials with MIT License 6 votes vote down vote up
/**
 * Function to convert QuoteCriteria to a {@link Specification}
 */
private Specification<Quote> createSpecification(QuoteCriteria criteria) {
    Specification<Quote> specification = Specification.where(null);
    if (criteria != null) {
        if (criteria.getId() != null) {
            specification = specification.and(buildSpecification(criteria.getId(), Quote_.id));
        }
        if (criteria.getSymbol() != null) {
            specification = specification.and(buildStringSpecification(criteria.getSymbol(), Quote_.symbol));
        }
        if (criteria.getPrice() != null) {
            specification = specification.and(buildRangeSpecification(criteria.getPrice(), Quote_.price));
        }
        if (criteria.getLastTrade() != null) {
            specification = specification.and(buildRangeSpecification(criteria.getLastTrade(), Quote_.lastTrade));
        }
    }
    return specification;
}
 
Example 5
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 {@link java.lang.Comparable}, where equality, less
 * than, greater than and less-than-or-equal-to and greater-than-or-equal-to and null/non-null conditions are
 * supported.
 *
 * @param <X>               The type of the attribute which is filtered.
 * @param filter            the individual attribute filter coming from the frontend.
 * @param metaclassFunction lambda, which based on a Root&lt;ENTITY&gt; returns Expression - basicaly picks a column
 * @return a Specification
 */
protected <X extends Comparable<? super X>> Specification<ENTITY> buildSpecification(RangeFilter<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());
    }

    Specification<ENTITY> result = Specification.where(null);
    if (filter.getSpecified() != null) {
        result = result.and(byFieldSpecified(metaclassFunction, filter.getSpecified()));
    }
    if (filter.getNotEquals() != null) {
        result = result.and(notEqualsSpecification(metaclassFunction, filter.getNotEquals()));
    }
    if (filter.getNotIn() != null) {
        result = result.and(valueNotIn(metaclassFunction, filter.getNotIn()));
    }
    if (filter.getGreaterThan() != null) {
        result = result.and(greaterThan(metaclassFunction, filter.getGreaterThan()));
    }
    if (filter.getGreaterThanOrEqual() != null) {
        result = result.and(greaterThanOrEqualTo(metaclassFunction, filter.getGreaterThanOrEqual()));
    }
    if (filter.getLessThan() != null) {
        result = result.and(lessThan(metaclassFunction, filter.getLessThan()));
    }
    if (filter.getLessThanOrEqual() != null) {
        result = result.and(lessThanOrEqualTo(metaclassFunction, filter.getLessThanOrEqual()));
    }
    return result;
}
 
Example 6
Source File: TeamSkillQueryService.java    From TeamDojo with Apache License 2.0 5 votes vote down vote up
/**
 * Function to convert TeamSkillCriteria to a {@link Specification}
 */
private Specification<TeamSkill> createSpecification(TeamSkillCriteria criteria) {
    Specification<TeamSkill> specification = Specification.where(null);
    if (criteria != null) {
        if (criteria.getId() != null) {
            specification = specification.and(buildSpecification(criteria.getId(), TeamSkill_.id));
        }
        if (criteria.getCompletedAt() != null) {
            specification = specification.and(buildRangeSpecification(criteria.getCompletedAt(), TeamSkill_.completedAt));
        }
        if (criteria.getVerifiedAt() != null) {
            specification = specification.and(buildRangeSpecification(criteria.getVerifiedAt(), TeamSkill_.verifiedAt));
        }
        if (criteria.getIrrelevant() != null) {
            specification = specification.and(buildSpecification(criteria.getIrrelevant(), TeamSkill_.irrelevant));
        }
        if (criteria.getNote() != null) {
            specification = specification.and(buildStringSpecification(criteria.getNote(), TeamSkill_.note));
        }
        if (criteria.getSkillId() != null) {
            specification = specification.and(buildReferringEntitySpecification(criteria.getSkillId(), TeamSkill_.skill, Skill_.id));
        }
        if (criteria.getTeamId() != null) {
            specification = specification.and(buildReferringEntitySpecification(criteria.getTeamId(), TeamSkill_.team, Team_.id));
        }
    }
    return specification;
}
 
Example 7
Source File: BadgeQueryService.java    From TeamDojo with Apache License 2.0 5 votes vote down vote up
/**
 * Function to convert BadgeCriteria to a {@link Specification}
 */
private Specification<Badge> createSpecification(BadgeCriteria criteria) {
    Specification<Badge> specification = Specification.where(null);
    if (criteria != null) {
        if (criteria.getId() != null) {
            specification = specification.and(buildSpecification(criteria.getId(), Badge_.id));
        }
        if (criteria.getName() != null) {
            specification = specification.and(buildStringSpecification(criteria.getName(), Badge_.name));
        }
        if (criteria.getDescription() != null) {
            specification = specification.and(buildStringSpecification(criteria.getDescription(), Badge_.description));
        }
        if (criteria.getAvailableUntil() != null) {
            specification = specification.and(buildRangeSpecification(criteria.getAvailableUntil(), Badge_.availableUntil));
        }
        if (criteria.getAvailableAmount() != null) {
            specification = specification.and(buildRangeSpecification(criteria.getAvailableAmount(), Badge_.availableAmount));
        }
        if (criteria.getRequiredScore() != null) {
            specification = specification.and(buildRangeSpecification(criteria.getRequiredScore(), Badge_.requiredScore));
        }
        if (criteria.getInstantMultiplier() != null) {
            specification = specification.and(buildRangeSpecification(criteria.getInstantMultiplier(), Badge_.instantMultiplier));
        }
        if (criteria.getCompletionBonus() != null) {
            specification = specification.and(buildRangeSpecification(criteria.getCompletionBonus(), Badge_.completionBonus));
        }
        if (criteria.getSkillsId() != null) {
            specification = specification.and(buildReferringEntitySpecification(criteria.getSkillsId(), Badge_.skills, BadgeSkill_.id));
        }
        if (criteria.getDimensionsId() != null) {
            specification = specification.and(buildReferringEntitySpecification(criteria.getDimensionsId(), Badge_.dimensions, Dimension_.id));
        }
        if (criteria.getImageId() != null) {
            specification = specification.and(buildReferringEntitySpecification(criteria.getImageId(), Badge_.image, Image_.id));
        }
    }
    return specification;
}
 
Example 8
Source File: SpecificationExecutorProjectionTest.java    From specification-with-projection with MIT License 5 votes vote down vote up
@Test
public void find_single_page() {
    Specification<Document> where = Specification.where(DocumentSpecs.idEq(24L));
    Page<DocumentRepository.OnlyParent> all = documentRepository.findAll(where, DocumentRepository.OnlyParent.class, PageRequest.of(0,10));
    Assertions.assertThat(all).isNotEmpty();
    Assertions.assertThat(all.getTotalElements()).isEqualTo(1);
    Assertions.assertThat(all.getTotalPages()).isEqualTo(1);
}
 
Example 9
Source File: SpecificationExecutorProjectionTest.java    From specification-with-projection with MIT License 5 votes vote down vote up
@Test
public void findAll4() {
    Specification<Document> where = Specification.where(DocumentSpecs.idEq(24L));
    Page<DocumentRepository.DocumentWithoutParent> all = documentRepository.findAll(where, DocumentRepository.DocumentWithoutParent.class, PageRequest.of(0,10));
    Assertions.assertThat(all).isNotEmpty();
    Assertions.assertThat(all.getContent().get(0).getChild()).isNull();
}
 
Example 10
Source File: ImageQueryService.java    From TeamDojo with Apache License 2.0 5 votes vote down vote up
/**
 * Function to convert ImageCriteria to a {@link Specification}
 */
private Specification<Image> createSpecification(ImageCriteria criteria) {
    Specification<Image> specification = Specification.where(null);
    if (criteria != null) {
        if (criteria.getId() != null) {
            specification = specification.and(buildSpecification(criteria.getId(), Image_.id));
        }
        if (criteria.getName() != null) {
            specification = specification.and(buildStringSpecification(criteria.getName(), Image_.name));
        }
    }
    return specification;
}
 
Example 11
Source File: FieldQueryService.java    From alchemy with Apache License 2.0 5 votes vote down vote up
/**
 * Function to convert FieldCriteria to a {@link Specification}.
 */
private Specification<Field> createSpecification(FieldCriteria criteria) {
    Specification<Field> specification = Specification.where(null);
    if (criteria != null) {
        if (criteria.getId() != null) {
            specification = specification.and(buildSpecification(criteria.getId(), Field_.id));
        }
        if (criteria.getColumnName() != null) {
            specification = specification.and(buildStringSpecification(criteria.getColumnName(), Field_.columnName));
        }
        if (criteria.getColumnType() != null) {
            specification = specification.and(buildStringSpecification(criteria.getColumnType(), Field_.columnType));
        }
        if (criteria.getConfig() != null) {
            specification = specification.and(buildStringSpecification(criteria.getConfig(), Field_.config));
        }
        if (criteria.getCreatedBy() != null) {
            specification = specification.and(buildStringSpecification(criteria.getCreatedBy(), Field_.createdBy));
        }
        if (criteria.getCreatedDate() != null) {
            specification = specification.and(buildRangeSpecification(criteria.getCreatedDate(), Field_.createdDate));
        }
        if (criteria.getLastModifiedBy() != null) {
            specification = specification.and(buildStringSpecification(criteria.getLastModifiedBy(), Field_.lastModifiedBy));
        }
        if (criteria.getLastModifiedDate() != null) {
            specification = specification.and(buildRangeSpecification(criteria.getLastModifiedDate(), Field_.lastModifiedDate));
        }
        if (criteria.getSourceId() != null) {
            specification = specification.and(buildSpecification(criteria.getSourceId(),
                root -> root.join(Field_.source, JoinType.LEFT).get(Source_.id)));
        }
    }
    return specification;
}
 
Example 12
Source File: ChildEntityQueryService.java    From jhipster with Apache License 2.0 5 votes vote down vote up
public Specification<ChildEntity> createSpecification(ChildEntityCriteria criteria) {
    Specification<ChildEntity> specification = Specification.where(null);
    if (criteria.getParentId() != null) {
        specification = specification.and(buildReferringEntitySpecification(criteria.getParentId(), ChildEntity_.parent, ParentEntity_.id));
    }
    return specification;
}
 
Example 13
Source File: ClusterQueryService.java    From alchemy with Apache License 2.0 5 votes vote down vote up
/**
 * Function to convert ClusterCriteria to a {@link Specification}.
 */
private Specification<Cluster> createSpecification(ClusterCriteria criteria) {
    Specification<Cluster> specification = Specification.where(null);
    if (criteria != null) {
        if (criteria.getId() != null) {
            specification = specification.and(buildSpecification(criteria.getId(), Cluster_.id));
        }
        if (criteria.getName() != null) {
            specification = specification.and(buildStringSpecification(criteria.getName(), Cluster_.name));
        }
        if (criteria.getType() != null) {
            specification = specification.and(buildSpecification(criteria.getType(), Cluster_.type));
        }
        if (criteria.getRemark() != null) {
            specification = specification.and(buildStringSpecification(criteria.getRemark(), Cluster_.remark));
        }
        if (criteria.getCreatedBy() != null) {
            specification = specification.and(buildStringSpecification(criteria.getCreatedBy(), Cluster_.createdBy));
        }
        if (criteria.getCreatedDate() != null) {
            specification = specification.and(buildRangeSpecification(criteria.getCreatedDate(), Cluster_.createdDate));
        }
        if (criteria.getLastModifiedBy() != null) {
            specification = specification.and(buildStringSpecification(criteria.getLastModifiedBy(), Cluster_.lastModifiedBy));
        }
        if (criteria.getLastModifiedDate() != null) {
            specification = specification.and(buildRangeSpecification(criteria.getLastModifiedDate(), Cluster_.lastModifiedDate));
        }
        if (criteria.getBusinessId() != null) {
            specification = specification.and(buildSpecification(criteria.getBusinessId(),
                root -> root.join(Cluster_.business, JoinType.LEFT).get(Business_.id)));
        }
        if (criteria.getJobId() != null) {
            specification = specification.and(buildSpecification(criteria.getJobId(),
                root -> root.join(Cluster_.jobs, JoinType.LEFT).get(Job_.id)));
        }
    }
    return specification;
}
 
Example 14
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 one-to-many or many-to-many reference.Where equality, less
than, greater than and less-than-or-equal-to and greater-than-or-equal-to and null/non-null conditions are
supported. Usage:
<pre><code>
    *   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));
    * </code>
    * </pre>
    *
    * @param <X>              The type of the attribute which is filtered.
    * @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.
    * @return a Specification
    */
   protected <OTHER, MISC, X extends Comparable<? super X>> Specification<ENTITY> buildReferringEntitySpecification(final RangeFilter<X> filter,
                                                                                                                    Function<Root<ENTITY>, SetJoin<MISC, OTHER>> functionToEntity,
                                                                                                                    Function<SetJoin<MISC, OTHER>, Expression<X>> entityToColumn) {

       Function<Root<ENTITY>, Expression<X>> fused = functionToEntity.andThen(entityToColumn);
       if (filter.getEquals() != null) {
           return equalsSpecification(fused, filter.getEquals());
       } else if (filter.getIn() != null) {
           return valueIn(fused, filter.getIn());
       }
       Specification<ENTITY> result = Specification.where(null);
       if (filter.getSpecified() != null) {
           // Interestingly, 'functionToEntity' doesn't work, we need the longer lambda formula
           result = result.and(byFieldSpecified(root -> functionToEntity.apply(root), filter.getSpecified()));
       }
       if (filter.getNotEquals() != null) {
           result = result.and(notEqualsSpecification(fused, filter.getNotEquals()));
       }
       if (filter.getNotIn() != null) {
           result = result.and(valueNotIn(fused, filter.getNotIn()));
       }
       if (filter.getGreaterThan() != null) {
           result = result.and(greaterThan(fused, filter.getGreaterThan()));
       }
       if (filter.getGreaterThanOrEqual() != null) {
           result = result.and(greaterThanOrEqualTo(fused, filter.getGreaterThanOrEqual()));
       }
       if (filter.getLessThan() != null) {
           result = result.and(lessThan(fused, filter.getLessThan()));
       }
       if (filter.getLessThanOrEqual() != null) {
           result = result.and(lessThanOrEqualTo(fused, filter.getLessThanOrEqual()));
       }
       return result;
   }
 
Example 15
Source File: Datatable.java    From kafka-webview with MIT License 4 votes vote down vote up
private Page<T> getPage() {
    // Return calculated value if already set.
    if (this.page != null) {
        return this.page;
    }

    // Add search criteria
    String searchValue = null;
    if (hasSearch()) {
        searchValue = getSearch().getCurrentSearchTerm();
        if (searchValue != null && searchValue.isEmpty()) {
            searchValue = null;
        }
    }
    Specification<T> specification;
    if (searchValue == null) {
        specification = Specification.where(null);
    } else {
        specification = Specification.where((root, query, builder) ->
            builder.like(
                builder.lower(root.get(getSearch().getField())), "%" + getSearch().getCurrentSearchTerm().toLowerCase() + "%"
            )
        );
    }

    // Add filter criterias
    for (final DatatableFilter filter : getFilters()) {
        // Skip non-provided filters.
        if (getCurrentFilterValueFor(filter).isEmpty()) {
            continue;
        }

        specification = specification.and(
            (root, query, builder) -> {
                final String[] fieldBits = filter.getField().split("\\.");
                Path<Object> queryPath = root.get(fieldBits[0]);
                for (int index = 1; index < fieldBits.length; index++) {
                    queryPath = queryPath.get(fieldBits[index]);
                }
                return builder.equal(queryPath, getCurrentFilterValueFor(filter));
            }
        );
    }

    // Execute
    page = repository.findAll(specification, pageable);
    return page;
}
 
Example 16
Source File: SpecificationExecutorProjectionTest.java    From specification-with-projection with MIT License 4 votes vote down vote up
@Test
public void findOne() {
    Specification<Document> where = Specification.where(DocumentSpecs.idEq(1L));
    Optional<DocumentRepository.DocumentWithoutParent> one = documentRepository.findOne(where, DocumentRepository.DocumentWithoutParent.class);
    Assertions.assertThat(one.get().getDocumentType()).isEqualTo("ต้นฉบับ");
}
 
Example 17
Source File: JobQueryService.java    From alchemy with Apache License 2.0 4 votes vote down vote up
/**
 * Function to convert JobCriteria to a {@link Specification}.
 */
private Specification<Job> createSpecification(JobCriteria criteria) {
    Specification<Job> specification = Specification.where(null);
    if (criteria != null) {
        if (criteria.getId() != null) {
            specification = specification.and(buildSpecification(criteria.getId(), Job_.id));
        }
        if (criteria.getName() != null) {
            specification = specification.and(buildStringSpecification(criteria.getName(), Job_.name));
        }
        if (criteria.getType() != null) {
            specification = specification.and(buildSpecification(criteria.getType(), Job_.type));
        }
        if (criteria.getRemark() != null) {
            specification = specification.and(buildStringSpecification(criteria.getRemark(), Job_.remark));
        }
        if (criteria.getClusterJobId() != null) {
            specification = specification.and(buildStringSpecification(criteria.getClusterJobId(), Job_.clusterJobId));
        }
        if (criteria.getStatus() != null) {
            specification = specification.and(buildSpecification(criteria.getStatus(), Job_.status));
        }
        if (criteria.getCreatedBy() != null) {
            specification = specification.and(buildStringSpecification(criteria.getCreatedBy(), Job_.createdBy));
        }
        if (criteria.getCreatedDate() != null) {
            specification = specification.and(buildRangeSpecification(criteria.getCreatedDate(), Job_.createdDate));
        }
        if (criteria.getLastModifiedBy() != null) {
            specification = specification.and(buildStringSpecification(criteria.getLastModifiedBy(), Job_.lastModifiedBy));
        }
        if (criteria.getLastModifiedDate() != null) {
            specification = specification.and(buildRangeSpecification(criteria.getLastModifiedDate(), Job_.lastModifiedDate));
        }
        if (criteria.getBusinessId() != null) {
            specification = specification.and(buildSpecification(criteria.getBusinessId(),
                root -> root.join(Job_.business, JoinType.LEFT).get(Business_.id)));
        }
        if (criteria.getClusterId() != null) {
            specification = specification.and(buildSpecification(criteria.getClusterId(),
                root -> root.join(Job_.cluster, JoinType.LEFT).get(Cluster_.id)));
        }
        if (criteria.getSqlId() != null) {
            specification = specification.and(buildSpecification(criteria.getSqlId(),
                root -> root.join(Job_.sqls, JoinType.LEFT).get(JobSql_.id)));
        }
    }
    return specification;
}
 
Example 18
Source File: GenericRsqlSpecBuilder.java    From tutorials with MIT License 4 votes vote down vote up
public Specification<T> createSpecification(final ComparisonNode comparisonNode) {
    return Specification.where(new GenericRsqlSpecification<T>(comparisonNode.getSelector(), comparisonNode.getOperator(), comparisonNode.getArguments()));
}
 
Example 19
Source File: SkillQueryService.java    From TeamDojo with Apache License 2.0 4 votes vote down vote up
/**
 * Function to convert SkillCriteria to a {@link Specification}
 */
private Specification<Skill> createSpecification(SkillCriteria criteria) {
    Specification<Skill> specification = Specification.where(null);
    if (criteria != null) {
        if (criteria.getId() != null) {
            specification = specification.and(buildSpecification(criteria.getId(), Skill_.id));
        }
        if (criteria.getTitle() != null) {
            specification = specification.and(buildStringSpecification(criteria.getTitle(), Skill_.title));
        }
        if (criteria.getDescription() != null) {
            specification = specification.and(buildStringSpecification(criteria.getDescription(), Skill_.description));
        }
        if (criteria.getImplementation() != null) {
            specification = specification.and(buildStringSpecification(criteria.getImplementation(), Skill_.implementation));
        }
        if (criteria.getValidation() != null) {
            specification = specification.and(buildStringSpecification(criteria.getValidation(), Skill_.validation));
        }
        if (criteria.getExpiryPeriod() != null) {
            specification = specification.and(buildRangeSpecification(criteria.getExpiryPeriod(), Skill_.expiryPeriod));
        }
        if (criteria.getScore() != null) {
            specification = specification.and(buildRangeSpecification(criteria.getScore(), Skill_.score));
        }
        if (criteria.getContact() != null) {
            specification = specification.and(buildStringSpecification(criteria.getContact(), Skill_.contact));
        }
        if (criteria.getScore() != null) {
            specification = specification.and(buildRangeSpecification(criteria.getScore(), Skill_.score));
        }
        if (criteria.getRateScore() != null) {
            specification = specification.and(buildRangeSpecification(criteria.getRateScore(), Skill_.rateScore));
        }
        if (criteria.getRateCount() != null) {
            specification = specification.and(buildRangeSpecification(criteria.getRateCount(), Skill_.rateCount));
        }
        if (criteria.getTeamsId() != null) {
            specification = specification.and(buildReferringEntitySpecification(criteria.getTeamsId(), Skill_.teams, TeamSkill_.id));
        }
        if (criteria.getBadgesId() != null) {
            specification = specification.and(buildReferringEntitySpecification(criteria.getBadgesId(), Skill_.badges, BadgeSkill_.id));
        }
        if (criteria.getLevelsId() != null) {
            specification = specification.and(buildReferringEntitySpecification(criteria.getLevelsId(), Skill_.levels, LevelSkill_.id));
        }
    }
    return specification;
}
 
Example 20
Source File: CountryQueryService.java    From Spring-5.0-Projects with MIT License 4 votes vote down vote up
/**
 * Function to convert CountryCriteria to a {@link Specification}
 */
private Specification<Country> createSpecification(CountryCriteria criteria) {
    Specification<Country> specification = Specification.where(null);
    if (criteria != null) {
        if (criteria.getId() != null) {
            specification = specification.and(buildSpecification(criteria.getId(), Country_.id));
        }
        if (criteria.getCode() != null) {
            specification = specification.and(buildStringSpecification(criteria.getCode(), Country_.code));
        }
        if (criteria.getName() != null) {
            specification = specification.and(buildStringSpecification(criteria.getName(), Country_.name));
        }
        if (criteria.getContinent() != null) {
            specification = specification.and(buildSpecification(criteria.getContinent(), Country_.continent));
        }
        if (criteria.getRegion() != null) {
            specification = specification.and(buildStringSpecification(criteria.getRegion(), Country_.region));
        }
        if (criteria.getSurfaceArea() != null) {
            specification = specification.and(buildRangeSpecification(criteria.getSurfaceArea(), Country_.surfaceArea));
        }
        if (criteria.getPopulation() != null) {
            specification = specification.and(buildRangeSpecification(criteria.getPopulation(), Country_.population));
        }
        if (criteria.getLifeExpectancy() != null) {
            specification = specification.and(buildRangeSpecification(criteria.getLifeExpectancy(), Country_.lifeExpectancy));
        }
        if (criteria.getLocalName() != null) {
            specification = specification.and(buildStringSpecification(criteria.getLocalName(), Country_.localName));
        }
        if (criteria.getGovernmentForm() != null) {
            specification = specification.and(buildStringSpecification(criteria.getGovernmentForm(), Country_.governmentForm));
        }
        if (criteria.getCityId() != null) {
            specification = specification.and(buildSpecification(criteria.getCityId(),
                root -> root.join(Country_.cities, JoinType.LEFT).get(City_.id)));
        }
        if (criteria.getCountryLanguageId() != null) {
            specification = specification.and(buildSpecification(criteria.getCountryLanguageId(),
                root -> root.join(Country_.countryLanguages, JoinType.LEFT).get(CountryLanguage_.id)));
        }
    }
    return specification;
}