Skip to content

Commit

Permalink
update getProductCatalogues to allow limit and order by serverVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
LZRS committed Jun 2, 2021
1 parent 3536936 commit 9654d64
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<artifactId>opensrp-server-core</artifactId>
<packaging>jar</packaging>
<version>2.11.3-SNAPSHOT</version>
<version>2.11.4-SNAPSHOT</version>
<name>opensrp-server-core</name>
<description>OpenSRP Server Core module</description>
<url>https://github.com/OpenSRP/opensrp-server-core</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ public interface ProductCatalogueRepository extends BaseRepository<ProductCatalo

ProductCatalogue getById(Long uniqueId, String baseUrl);

@Deprecated(since = "2.11.4-SNAPSHOT", forRemoval = true)
List<ProductCatalogue> getProductCataloguesBySearchBean(ProductCatalogueSearchBean productCatalogueSearchBean, String baseUrl);

List<ProductCatalogue> getProductCataloguesBySearchBean(ProductCatalogueSearchBean productCatalogueSearchBean, int limit, String baseUrl);

void safeRemove(Long id);

ProductCatalogue getProductCatalogueByName(String productName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,17 @@ public ProductCatalogue getById(Long uniqueId, String baseUrl) {
}

@Override
public List<ProductCatalogue> getProductCataloguesBySearchBean(ProductCatalogueSearchBean productCatalogueSearchBean, String baseUrl) {
public List<ProductCatalogue> getProductCataloguesBySearchBean(ProductCatalogueSearchBean productCatalogueSearchBean, int limit, String baseUrl) {
ProductCatalogueExample productCatalogueExample = new ProductCatalogueExample();
populateProductCatalogueSearchCriteria(productCatalogueSearchBean,
productCatalogueExample);
return convert(customProductCatalogueMapper.selectMany(productCatalogueExample, 0, DEFAULT_FETCH_SIZE), baseUrl);
productCatalogueExample.setOrderByClause(this.getOrderByClause(SERVER_VERSION, ASCENDING));
return convert(customProductCatalogueMapper.selectMany(productCatalogueExample, 0, limit), baseUrl);
}

@Override
public List<ProductCatalogue> getProductCataloguesBySearchBean(ProductCatalogueSearchBean productCatalogueSearchBean, String baseUrl){
return getProductCataloguesBySearchBean(productCatalogueSearchBean, DEFAULT_FETCH_SIZE, baseUrl);
}

@Override
Expand Down Expand Up @@ -231,8 +237,9 @@ private ProductCatalogueExample.Criteria populateProductCatalogueSearchCriteria(

ProductCatalogueExample.Criteria criteria = productCatalogueExample.createCriteria();

if (productCatalogueSearchBean.getServerVersion() != null && productCatalogueSearchBean.getServerVersion() != 0)
if (productCatalogueSearchBean.getServerVersion() != null && productCatalogueSearchBean.getServerVersion() >= 0) {
criteria.andServerVersionGreaterThanOrEqualTo(productCatalogueSearchBean.getServerVersion());
}

if (StringUtils.isNotEmpty(productCatalogueSearchBean.getProductName()))
criteria.andProductNameEqualTo(productCatalogueSearchBean.getProductName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,21 @@ public void deleteProductCatalogueById(Long uniqueId) {

}

public List<ProductCatalogue> getProductCatalogues(ProductCatalogueSearchBean productCatalogueSearchBean, String baseUrl) {
public List<ProductCatalogue> getProductCatalogues(ProductCatalogueSearchBean productCatalogueSearchBean, int limit, String baseUrl) {
if (StringUtils.isBlank(productCatalogueSearchBean.getProductName()) &&
productCatalogueSearchBean.getUniqueId() == 0
&& productCatalogueSearchBean.getServerVersion() == null) {
return findAllProductCatalogues(baseUrl);
} else {
return productCatalogueRepository.getProductCataloguesBySearchBean(productCatalogueSearchBean, baseUrl);
return productCatalogueRepository.getProductCataloguesBySearchBean(productCatalogueSearchBean, limit, baseUrl);
}
}

@Deprecated(since = "2.11.4-SNAPSHOT")
public List<ProductCatalogue> getProductCatalogues(ProductCatalogueSearchBean productCatalogueSearchBean, String baseUrl) {
return getProductCatalogues(productCatalogueSearchBean, Integer.MAX_VALUE, baseUrl);
}

public ProductCatalogue getProductCatalogueByName(String productName) {
return productCatalogueRepository.getProductCatalogueByName(productName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,18 @@ public void testGetById() {
}

@Test
public void testGetProductCataloguesBySearchBean(){
public void testGetProductCataloguesBySearchBeanWithLimit(){
ProductCatalogueSearchBean productCatalogueSearchBean = new ProductCatalogueSearchBean();
productCatalogueSearchBean.setUniqueId(1l);
int limit = Integer.MAX_VALUE;
List<ProductCatalogue> productCatalogues = productCatalogueRepository.getProductCataloguesBySearchBean(productCatalogueSearchBean, limit, "http://localhost:8080/opensrp");
assertEquals(1,productCatalogues.size());
assertEquals("Midwifery Kit", productCatalogues.get(0).getProductName());

}

@Test
public void testGetProductCataloguesBySearchBeanWithNoLimitSet(){
ProductCatalogueSearchBean productCatalogueSearchBean = new ProductCatalogueSearchBean();
productCatalogueSearchBean.setUniqueId(1l);
List<ProductCatalogue> productCatalogues = productCatalogueRepository.getProductCataloguesBySearchBean(productCatalogueSearchBean, "http://localhost:8080/opensrp");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,18 @@ protected Set<String> getDatabaseScripts() {
}

@Test
public void testFindAllProductCatalogs() {
public void testFindAllProductCatalogsWithLimitSet() {
ProductCatalogueSearchBean productCatalogueSearchBean = new ProductCatalogueSearchBean();
productCatalogueSearchBean.setProductName("");
productCatalogueSearchBean.setUniqueId(0l);
int limit = Integer.MAX_VALUE;
List<ProductCatalogue> productCatalogueList = productCatalogueService
.getProductCatalogues(productCatalogueSearchBean, limit, "http://localhost:8080/opensrp");
assertEquals(1, productCatalogueList.size());
}

@Test
public void testFindAllProductCatalogsWithNoLimitSet() {
ProductCatalogueSearchBean productCatalogueSearchBean = new ProductCatalogueSearchBean();
productCatalogueSearchBean.setProductName("");
productCatalogueSearchBean.setUniqueId(0l);
Expand Down

0 comments on commit 9654d64

Please sign in to comment.