Skip to content

Commit

Permalink
HCMPRE-348: integrated product mdms changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kanishq-egov committed Sep 17, 2024
1 parent 1e1755e commit 9dc61d0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.egov.product.config.ProductConfiguration;
import org.egov.tracer.model.CustomException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.springframework.web.client.RestTemplate;
Expand All @@ -41,12 +42,14 @@ public class MdmsV2Service {
private final ProductConfiguration configs;

@Autowired
public MdmsV2Service(RestTemplate restTemplate, ObjectMapper mapper, ProductConfiguration configs) {
public MdmsV2Service(RestTemplate restTemplate, @Qualifier("objectMapper") ObjectMapper mapper, ProductConfiguration configs) {
this.restTemplate = restTemplate;
this.mapper = mapper;
this.configs = configs;
}

// public List<Product> fetchProduct

public Object fetchMdmsData(RequestInfo requestInfo, String tenantId, Boolean isProduct) {
StringBuilder uri = new StringBuilder();
uri.append(configs.getMdmsHost()).append(configs.getMdmsEndPoint());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.jayway.jsonpath.JsonPath;
import lombok.extern.slf4j.Slf4j;
import org.egov.common.models.product.Product;
import org.egov.common.models.product.ProductRequest;
Expand Down Expand Up @@ -109,8 +110,9 @@ public List<Product> search(ProductSearchRequest productSearchRequest,
Object jsonNode = mdmsV2Service.fetchMdmsData(productSearchRequest.getRequestInfo(), tenantId, Boolean.TRUE);
List<Product> products = Collections.emptyList();
try {
Object jsonArray = JsonPath.read(jsonNode, "$.HCM-Product.Products");
// Convert JSON string to List<Product>
products = objectMapper.readValue(jsonNode, new TypeReference<List<Product>>() {});
products = objectMapper.convertValue(jsonArray, new TypeReference<List<Product>>() {});
} catch (Exception e) {
e.printStackTrace();
}
Expand Down

0 comments on commit 9dc61d0

Please sign in to comment.