У меня проблема с получением результатов с использованием полного значения строк, передаваемых в конечную точку REST.
Если я передаю полную 6-символьную строку для значения "communityNo", я получаю пустой Jsonмассив обратно.Если я передам 1-3 из первых 6 символов для communityNo, то получу тонны записей.
REST endpt url: http://localhost:8080/web-portal/api/aw501?stateId=2&communityNo=200
Критерии API спецификации
public static Specification<Aw501> findAllByStateId(String stateId){
return new Specification <Aw501>(){
public Predicate toPredicate(Root<Aw501> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
return cb.like(root.get(Aw501_.stateId), stateId + "%"); //MDB
}
} ;
}
public static Specification<Aw501> findAllByCommunityNo(String communityNo){
return new Specification <Aw501>(){
public Predicate toPredicate(Root<Aw501> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
return cb.like(root.get(Aw501_.communityNo), communityNo + "%"); //MDB
}
} ;
}
}
интерфейс репозитория
package pivot.fema.dhs.gov.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import pivot.fema.dhs.gov.domain.report.Aw501;
import java.util.List;
/**
* Spring Data JPA repository for the Claims entity.
*/
@Repository
public interface Aw501Repository
extends JpaRepository<Aw501, Long>, JpaSpecificationExecutor<Aw501> {
}
класс обслуживания
@Service
@Transactional
public class Aw501Service {
private final Logger log = LoggerFactory.getLogger(Aw501Service.class);
private final Aw501Repository aw501Repository;
private final CacheManager cacheManager;
private ReportSessionParameters reportSessionParameters;
@Inject
private ApplicationProperties applicationProperties;
private ApplicationProperties.Performance performance;
public Aw501Service(Aw501Repository aw501Repository,
CacheManager cacheManager){
this.aw501Repository = aw501Repository;
this.cacheManager = cacheManager;
}
@Transactional(readOnly = true)
public Page<Aw501DTO> getAw501Reports(Integer pageNumber,
Integer pageSize,
String sortBy,
String sortOrder,
String stateId,
String communityNo){
boolean flagStateId = StringUtils.isNotBlank(stateId) ;
boolean flagCommunityNo = StringUtils.isNotBlank(communityNo) ;
if(flagStateId){
log.info("****Aw501Service.java flag input for flagStateId :" + true + "****");
}else{
}
if(flagCommunityNo){
log.info("****Aw501Service.java flag input for flagCommunityNo :" + true + "****");
}else{
}
Specifications<Aw501> predicates = null ;
if(flagStateId && flagCommunityNo){
predicates = Specifications.where(Aw501Spec.findAllByStateId(stateId)) ;
predicates = predicates.and(Specifications.where(Aw501Spec.findAllByCommunityNo(communityNo)));
}
if( flagStateId && flagCommunityNo){
if(flagStateId){
log.info("****Aw501Service.java (flagStateId && flagCommunityNo):" + true + "**** predicates = " + predicates.toString());
}else{
}
}
if(flagStateId && !flagCommunityNo){
predicates = Specifications.where(Aw501Spec.findAllByStateId(stateId)) ;
}
if(flagStateId && !flagCommunityNo){
log.info("****Aw501Service.java (flagStateId && !flagCommunityNo):" + true + "**** predicates = " + predicates.toString());
}else{
}
if( !flagStateId && flagCommunityNo){
predicates = Specifications.where(Aw501Spec.findAllByCommunityNo(communityNo)) ;
}
if(!flagStateId && flagCommunityNo ){
log.info("****Aw501Service.java (!flagStateId && flagCommunityNo):" + true + "**** predicates = " + predicates.toString());
}else{
}
PageRequest pageRequest = new PageRequest(1,25);
if(pageRequest != null ){
log.info("****Aw501Service.java (pageRequest): pageRequest is not null" + "**** pageNumber = " + pageRequest.toString() + " pageOffset : " + "" );
}else{
log.info("****Aw501Service.java (pageRequest): pageRequest is null" + "**** " );
}
Page<Aw501DTO> foobar = aw501Repository
.findAll(predicates,pageRequest)
.map(Aw501DTO::new);
if(foobar != null ){
log.info("****Aw501Service.java (foobar): foobaris not null" + "**** foobar = " + foobar.hasContent() + " pageOffset : " + "" );
}else{
log.info("****Aw501Service.java (foobar): pageRequest is null" + "**** " );
}
return foobar ;
}//end getAw501Reports
}
Класс RestController:
@RestController
@RequestMapping("/api")
public class Aw501Resource{
Page<Aw501DTO> page = new PageImpl<Aw501DTO>(Collections.<Aw501DTO>emptyList());
private final Logger log = LoggerFactory.getLogger(Aw501Resource.class);
private final Aw501Repository aw501Repository;
private final Aw501Service aw501Service;
private final ReportSessionParameters reportSessionParameters;
public Aw501Resource(Aw501Repository aw501Repository,
Aw501Service aw501Service,
ReportSessionParameters reportSessionParameters) {
this.aw501Repository = aw501Repository;
this.aw501Service = aw501Service;
this.reportSessionParameters = reportSessionParameters;
}
/*
A page is a sublist of a list of objects. It allows gain
information about the about the posistion of it in
th e containing entire list.
*/
@GetMapping("/aw501")
public Page<Aw501DTO> getAw501(@RequestParam(name = "stateId", required = false) String stateId,
@RequestParam(name = "communityNo", required = false) String communityNo,
@RequestParam(name = "sortBy", required = false) String sortBy,
@RequestParam(name = "sortOrder", required = false) String sortOrder,
@RequestParam(name = "pageSize", required = false) Integer pageSize,
@RequestParam(name = "pageNumber", required = false) Integer pageNumber){
if (StringUtils.isNotBlank(stateId)){
log.info("****Aw501Resource.java input for stateId :" + stateId + "****");
stateId = stateId.trim() ;
}
if (StringUtils.isNotBlank(communityNo)){
log.info("****Aw501Resource.java input for communityNo :" + communityNo + "****");
communityNo = communityNo.trim() ;
}
if (StringUtils.isNotBlank(sortBy)){
log.info("****Aw501Resource.java input for sortBy :" + sortBy + "****");
sortBy = sortBy.trim() ;
}
if (StringUtils.isNotBlank(sortOrder)){
log.info("****Aw501Resource.java input for sortOrder :" + sortOrder + "****");
sortOrder = sortOrder.trim() ;
}
if (pageNumber != null && pageNumber.compareTo(0) > 0){
log.info("****Aw501Resource.java input for pageNumber :" + pageNumber.toString() + "****");
pageNumber-- ;
log.info("****Aw501Resource.java input for pageNumber-- :" + pageNumber.toString() + "****");
}
return aw501Service.getAw501Reports(pageNumber, pageSize, sortBy, sortOrder, stateId,communityNo);
}
@GetMapping("/foobar")
public Map<String,String> foobar(@RequestParam(name = "stateId", required = false) String stateId,
@RequestParam(name = "communityNo", required = false) String communityNo,
@RequestParam(name = "sortBy", required = false) String sortBy,
@RequestParam(name = "sortOrder", required = false) String sortOrder,
@RequestParam(name = "pageSize", required = false) Integer pageSize,
@RequestParam(name = "pageNumber", required = false) Integer pageNumber){
Map<String , String> map = new HashMap<String,String>() ;
map.put("stateId","51") ;
map.put("sortBy","DESC");
map.put("pageSize","25");
map.put("pageNumber","100");
return map ;
}
}
Любая помощь, которую вы, ребята, могли бы оказать, была бы очень признательна !!!!Спасибо !!!