generated from hmcts/spring-boot-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement more search critera for search endpoint
- Loading branch information
1 parent
166666b
commit caae708
Showing
4 changed files
with
116 additions
and
4 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
src/main/java/uk/gov/hmcts/opal/repository/jpa/AddressSpecs.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package uk.gov.hmcts.opal.repository.jpa; | ||
|
||
import org.springframework.data.jpa.domain.Specification; | ||
import uk.gov.hmcts.opal.dto.search.AddressSearch; | ||
import uk.gov.hmcts.opal.entity.AddressEntity; | ||
import uk.gov.hmcts.opal.entity.AddressEntity_; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public abstract class AddressSpecs<E extends AddressEntity> extends EntitySpecs<E> { | ||
|
||
@SuppressWarnings("unchecked") | ||
public List<Optional<Specification<E>>> findByAddressCriteria(AddressSearch criteria) { | ||
return new ArrayList(Arrays.asList( | ||
notBlank(criteria.getName()).map(this::equalsName), | ||
notBlank(criteria.getAddressLine()).map(this::equalsAddressLine), | ||
notBlank(criteria.getPostcode()).map(this::equalsPostcode) | ||
)); | ||
} | ||
|
||
public Specification<E> equalsName(String name) { | ||
return (root, query, builder) -> builder.equal(root.get(AddressEntity_.name), name); | ||
} | ||
|
||
public Specification<E> equalsAddressLine(String addressLine) { | ||
return (root, query, builder) -> builder.equal(root.get(AddressEntity_.addressLine1), addressLine); | ||
} | ||
|
||
public Specification<E> equalsPostcode(String postcode) { | ||
return (root, query, builder) -> builder.equal(root.get(AddressEntity_.postcode), postcode); | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/uk/gov/hmcts/opal/repository/jpa/BaseCourtSpecs.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package uk.gov.hmcts.opal.repository.jpa; | ||
|
||
import org.springframework.data.jpa.domain.Specification; | ||
import uk.gov.hmcts.opal.dto.search.BaseCourtSearch; | ||
import uk.gov.hmcts.opal.entity.EnforcerCourtBaseEntity; | ||
import uk.gov.hmcts.opal.entity.EnforcerCourtBaseEntity_; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public abstract class BaseCourtSpecs<E extends EnforcerCourtBaseEntity> extends AddressSpecs<E> { | ||
|
||
@SuppressWarnings("unchecked") | ||
public List<Optional<Specification<E>>> findByBaseCourtCriteria(BaseCourtSearch criteria) { | ||
return combine(findByAddressCriteria(criteria), | ||
notBlank(criteria.getBusinessUnitId()).map(this::equalsBusinessUnitId), | ||
notBlank(criteria.getNameCy()).map(this::equalsNameCy), | ||
notBlank(criteria.getAddressLineCy()).map(this::equalsAddressLineCy)); | ||
} | ||
|
||
|
||
public Specification<E> equalsBusinessUnitId(String businessUnitId) { | ||
return (root, query, builder) -> builder.equal(root.get(EnforcerCourtBaseEntity_.businessUnitId), | ||
businessUnitId); | ||
} | ||
|
||
public Specification<E> equalsNameCy(String nameCy) { | ||
return (root, query, builder) -> builder.equal(root.get(EnforcerCourtBaseEntity_.nameCy), nameCy); | ||
} | ||
|
||
public Specification<E> equalsAddressLineCy(String addressLineCy) { | ||
return (root, query, builder) -> builder.equal(root.get(EnforcerCourtBaseEntity_.addressLine1Cy), | ||
addressLineCy); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters