diff --git a/pom.xml b/pom.xml
index 144cdbe30..daa053742 100755
--- a/pom.xml
+++ b/pom.xml
@@ -26,7 +26,7 @@
5.2.2.RELEASE
always
1.5.1
- 2.11.5-SNAPSHOT
+ 2.11.4-SNAPSHOT
2.3.0-SNAPSHOT
2.0.1-SNAPSHOT
2.0.3-SNAPSHOT
diff --git a/src/main/java/org/opensrp/web/rest/ProductCatalogueResource.java b/src/main/java/org/opensrp/web/rest/ProductCatalogueResource.java
index 3dfe09c58..e69fae4a7 100644
--- a/src/main/java/org/opensrp/web/rest/ProductCatalogueResource.java
+++ b/src/main/java/org/opensrp/web/rest/ProductCatalogueResource.java
@@ -1,5 +1,6 @@
package org.opensrp.web.rest;
+import org.apache.commons.lang.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.opensrp.domain.Multimedia;
@@ -44,6 +45,7 @@ public class ProductCatalogueResource {
private static final String DOWNLOAD_PHOTO_END_POINT = "/multimedia/media/";
+ @Deprecated
@GetMapping(produces = { MediaType.APPLICATION_JSON_VALUE })
public List getAll(
@RequestParam(value = "productName", defaultValue = "", required = false) String productName
@@ -63,6 +65,33 @@ public List getAll(
productCatalogueSearchBean.setServerVersion(lastSyncedServerVersion);
return productCatalogueService.getProductCatalogues(productCatalogueSearchBean, baseUrl);
+
+ }
+
+ @GetMapping(produces = { MediaType.APPLICATION_JSON_VALUE }, params = "limit")
+ public List getAll(
+ @RequestParam(value = "productName", defaultValue = "", required = false) String productName
+ , @RequestParam(value = "uniqueId", defaultValue = "0", required = false) Long uniqueId,
+ @RequestParam(value = "serverVersion", required = false) String serverVersion,
+ @RequestParam(value = "limit") String limit) {
+ final String baseUrl = ServletUriComponentsBuilder.fromCurrentContextPath().build().toUriString();
+
+ Long lastSyncedServerVersion = null;
+ if (serverVersion != null) {
+ lastSyncedServerVersion = Long.parseLong(serverVersion);
+ }
+
+ ProductCatalogueSearchBean productCatalogueSearchBean = new ProductCatalogueSearchBean();
+ productCatalogueSearchBean.setProductName(productName);
+ productCatalogueSearchBean.setUniqueId(uniqueId);
+ productCatalogueSearchBean.setServerVersion(lastSyncedServerVersion);
+
+ if (StringUtils.isBlank(limit)) {
+ return productCatalogueService.getProductCatalogues(productCatalogueSearchBean, Integer.MAX_VALUE, baseUrl);
+ } else {
+ return productCatalogueService
+ .getProductCatalogues(productCatalogueSearchBean, Integer.parseInt(limit), baseUrl);
+ }
}
@PostMapping(headers = { "Accept=multipart/form-data" })
@@ -71,7 +100,8 @@ public ResponseEntity create(@RequestPart(required = false) MultipartFil
try {
productCatalogueService.add(productCatalogue);
- ProductCatalogue createdProductCatalogue = productCatalogueService.getProductCatalogueByName(productCatalogue.getProductName());
+ ProductCatalogue createdProductCatalogue = productCatalogueService
+ .getProductCatalogueByName(productCatalogue.getProductName());
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
String userName = authentication.getName();
@@ -107,7 +137,7 @@ public ResponseEntity update(@PathVariable("id") Long uniqueId,
@RequestPart ProductCatalogue productCatalogue) {
try {
- if(file != null) {
+ if (file != null) {
productCatalogue.setPhotoURL(DOWNLOAD_PHOTO_END_POINT + productCatalogue.getUniqueId());
}
diff --git a/src/test/java/org/opensrp/web/rest/ProductCatalogueResourceTest.java b/src/test/java/org/opensrp/web/rest/ProductCatalogueResourceTest.java
index 51e382da0..4db8c0fef 100644
--- a/src/test/java/org/opensrp/web/rest/ProductCatalogueResourceTest.java
+++ b/src/test/java/org/opensrp/web/rest/ProductCatalogueResourceTest.java
@@ -35,6 +35,7 @@
import org.mockito.MockitoAnnotations;
import org.mockito.Mockito;
+
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.anyLong;
@@ -43,6 +44,7 @@
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.times;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
+
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@@ -103,7 +105,34 @@ public void testGetAll() throws Exception {
.andExpect(status().isOk())
.andReturn();
- List response = (List) result.getModelAndView().getModel().get("productCatalogueList");
+ List response = (List) result.getModelAndView().getModel()
+ .get("productCatalogueList");
+
+ if (response.size() == 0) {
+ fail("Test case failed");
+ }
+
+ assertEquals(response.size(), 1);
+ assertEquals(new Long(1), response.get(0).getUniqueId());
+ assertEquals("Scale", response.get(0).getProductName());
+ assertEquals("MT-123", response.get(0).getMaterialNumber());
+ }
+
+ @Test
+ public void testGetAllWithLimitParam() throws Exception {
+ ProductCatalogue productCatalogue = createProductCatalog();
+ productCatalogue.setUniqueId(1l);
+ List productCatalogues = new ArrayList<>();
+ productCatalogues.add(productCatalogue);
+ when(productCatalogueService
+ .getProductCatalogues(any(ProductCatalogueSearchBean.class), any(Integer.class), anyString()))
+ .thenReturn(productCatalogues);
+ MvcResult result = mockMvc.perform(get(BASE_URL + "?limit=10"))
+ .andExpect(status().isOk())
+ .andReturn();
+
+ List response = (List) result.getModelAndView().getModel()
+ .get("productCatalogueList");
if (response.size() == 0) {
fail("Test case failed");
@@ -135,9 +164,9 @@ public void testCreate() throws Exception {
when(multipartFile.getContentType()).thenReturn("");
when(multipartFile.getBytes()).thenReturn(bytes);
when(multipartFile.getOriginalFilename()).thenReturn("Midwifery kit image");
- when(multimediaService.saveFile(any(MultimediaDTO.class),any(byte[].class),anyString())).thenReturn("Success");
+ when(multimediaService.saveFile(any(MultimediaDTO.class), any(byte[].class), anyString())).thenReturn("Success");
- productCatalogueResource.create(multipartFile,productCatalogue);
+ productCatalogueResource.create(multipartFile, productCatalogue);
verify(productCatalogueService).add(argumentCaptor.capture());
@@ -175,9 +204,9 @@ public void testUpdate() throws Exception {
when(multipartFile.getContentType()).thenReturn("");
when(multipartFile.getBytes()).thenReturn(bytes);
when(multipartFile.getOriginalFilename()).thenReturn("Midwifery kit image");
- when(multimediaService.saveFile(any(MultimediaDTO.class),any(byte[].class),anyString())).thenReturn("Success");
+ when(multimediaService.saveFile(any(MultimediaDTO.class), any(byte[].class), anyString())).thenReturn("Success");
- productCatalogueResource.update(1l,multipartFile,productCatalogue);
+ productCatalogueResource.update(1l, multipartFile, productCatalogue);
verify(productCatalogueService).update(argumentCaptor.capture());
@@ -222,7 +251,6 @@ public void testDelete() throws Exception {
assertEquals(argumentCaptor.getValue().longValue(), 1);
}
-
private ProductCatalogue createProductCatalog() {
ProductCatalogue productCatalogue = new ProductCatalogue();
productCatalogue.setProductName("Scale");