Skip to content

Commit

Permalink
Merge pull request #125 from bcgov/develop/sree
Browse files Browse the repository at this point in the history
Develop/sree
  • Loading branch information
infstar authored Jun 29, 2022
2 parents fd6b4de + cf11390 commit fd9ea35
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ public ResponseEntity<List<Psi>> getPSIByParams(
@RequestParam(value = "psiName", required = false) String psiName,
@RequestParam(value = "psiCode", required = false) String psiCode,
@RequestParam(value = "cslCode", required = false) String cslCode,
@RequestParam(value = "transmissionMode", required = false) String transmissionMode) {
return response.GET(psiService.getPSIByParams(psiName,psiCode,cslCode,transmissionMode));
@RequestParam(value = "transmissionMode", required = false) String transmissionMode,
@RequestParam(value = "openFlag", required = false) String openFlag,
@RequestParam(value = "psiGrouping", required = false) String psiGrouping) {
return response.GET(psiService.getPSIByParams(psiName,psiCode,cslCode,transmissionMode,openFlag,psiGrouping));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public class PsiService {
@SuppressWarnings("unused")
private static Logger logger = LoggerFactory.getLogger(PsiService.class);


private static final String PSI_NAME = "psiName";
/**
* Get all Schools in PSI DTO
*/
Expand All @@ -62,17 +64,19 @@ public Psi getPSIDetails(String psiCode) {
return psi;
}

public List<Psi> getPSIByParams(String psiName, String psiCode, String cslCode, String transmissionMode) {
public List<Psi> getPSIByParams(String psiName, String psiCode, String cslCode, String transmissionMode,String openFlag,String psiGrouping) {
CriteriaHelper criteria = new CriteriaHelper();
getSearchCriteria("psiCode", psiCode,"psiCode", criteria);
getSearchCriteria("psiName", psiName,"psiName", criteria);
getSearchCriteria(PSI_NAME, psiName,PSI_NAME, criteria);
getSearchCriteria("cslCode", cslCode,"cslCode", criteria);
getSearchCriteria("transmissionMode",transmissionMode,"transmissionMode", criteria);
return psiTransformer.transformToDTO(psiCriteriaQueryRepository.findByCriteria(criteria, PsiEntity.class));
getSearchCriteria("transmissionMode",transmissionMode,"transmissionMode", criteria);
getSearchCriteria("openFlag",openFlag,"openFlag", criteria);
getSearchCriteria("psiGrouping",psiGrouping,"psiGrouping", criteria);
return psiTransformer.transformToDTO(psiCriteriaQueryRepository.findByCriteria(criteria, PsiEntity.class));
}

public CriteriaHelper getSearchCriteria(String roolElement, String value, String parameterType, CriteriaHelper criteria) {
if(parameterType.equalsIgnoreCase("psiName")) {
if(parameterType.equalsIgnoreCase(PSI_NAME)) {
if (StringUtils.isNotBlank(value)) {
if (StringUtils.contains(value, "*")) {
criteria.add(roolElement, OperationEnum.LIKE, StringUtils.strip(value.toUpperCase(), "*"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ public void testGetPsisByParams() {
school.setPsiCode("1234567");
school.setPsiName("Test Psi");

Mockito.when(psiService.getPSIByParams("Test Psi", "1234567", null,null)).thenReturn(Arrays.asList(school));
psiController.getPSIByParams("Test Psi","1234567", null, null);
Mockito.verify(psiService).getPSIByParams("Test Psi", "1234567", null,null);
Mockito.when(psiService.getPSIByParams("Test Psi", "1234567", null,null,null,null)).thenReturn(List.of(school));
psiController.getPSIByParams("Test Psi","1234567", null, null,null,null);
Mockito.verify(psiService).getPSIByParams("Test Psi", "1234567", null,null,null,null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public void testGetPSIsByParams() {
obj.setOpenFlag("Y");
obj.setPhone1("123213 ");
obj.setPostal("V3T1C4 ");
List<PsiEntity> list = new ArrayList<PsiEntity>();
List<PsiEntity> list = new ArrayList<>();
list.add(obj);
// Country
GradCountry country = new GradCountry();
Expand All @@ -188,7 +188,7 @@ public void testGetPSIsByParams() {
when(codeService.getSpecificCountryCode(obj.getCountryCode())).thenReturn(country);
when(codeService.getSpecificProvinceCode(obj.getProvinceCode())).thenReturn(province);

var result = psiService.getPSIByParams("Autobody", "AB", null,null);
var result = psiService.getPSIByParams("Autobody", "AB", null,null,null,null);
assertThat(result).isNotNull();
assertThat(result.size()).isEqualTo(1);
assertThat(result.get(0).getPsiCode()).isEqualTo("AB");
Expand All @@ -213,7 +213,7 @@ public void testGetPSIsByParamsStar() {
obj.setOpenFlag("Y");
obj.setPhone1("123213 ");
obj.setPostal("V3T1C4 ");
List<PsiEntity> list = new ArrayList<PsiEntity>();
List<PsiEntity> list = new ArrayList<>();
list.add(obj);
// Country
GradCountry country = new GradCountry();
Expand All @@ -231,7 +231,7 @@ public void testGetPSIsByParamsStar() {
when(codeService.getSpecificCountryCode(obj.getCountryCode())).thenReturn(country);
when(codeService.getSpecificProvinceCode(obj.getProvinceCode())).thenReturn(province);

var result = psiService.getPSIByParams("Autobody", "AB*", null,null);
var result = psiService.getPSIByParams("Autobody", "AB*", null,null,null,null);
assertThat(result).isNotNull();
assertThat(result.size()).isEqualTo(1);
assertThat(result.get(0).getPsiCode()).isEqualTo("AB");
Expand Down

0 comments on commit fd9ea35

Please sign in to comment.