Skip to content

Commit

Permalink
[Rahul] | BAH-3303 | Add. Rest Client Implementation for Saleables
Browse files Browse the repository at this point in the history
Rest Client Implementation for Saleable Drug and Lab Test
  • Loading branch information
rahu1ramesh committed Dec 13, 2023
1 parent 6bb11a7 commit e77294c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public String getOdooXMLUrlEndpoint() {
public String getOdooRESTUrlEndPoint(Jobs feedJob) {
switch (feedJob) {
case SALEORDER_FEED:
case SALEABLE_FEED: return "";
case SALEABLE_FEED: return "/api/bahmni-service-sale";
case CUSTOMER_FEED: return "/api/bahmni-customer";
case LAB_TEST_FEED: return "/api/bahmni-lab-test";
case LAB_PANEL_FEED: return "/api/bahmni-lab-panel";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,22 @@
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class OpenERPSaleableResourceWorker implements EventWorker {

public static final String ERP_EVENT_CATEGORY = "create.service.saleable";
public static final String SALEABLE_PROPERTY_NAME = "saleable";
public static final String PRODUCT_CATEGORY = "product_category";
private final OpenERPContext openERPContext;
private final String feedUrl;
private final String odooURL;
private final OpenMRSWebClient openMRSWebClient;
private final String urlPrefix;

private static final Logger logger = LogManager.getLogger(OpenERPSaleableResourceWorker.class);

public OpenERPSaleableResourceWorker(String feedUrl, String odooURL, OpenERPContext openERPContext, OpenMRSWebClient openMRSWebClient, String urlPrefix) {
public OpenERPSaleableResourceWorker(String odooURL, OpenERPContext openERPContext, OpenMRSWebClient openMRSWebClient, String urlPrefix) {
this.openERPContext = openERPContext;
this.feedUrl = feedUrl;
this.odooURL = odooURL;
this.openMRSWebClient = openMRSWebClient;
this.urlPrefix = urlPrefix;
Expand Down Expand Up @@ -77,35 +76,37 @@ private OpenMRSResource getOpenMRSResource(Event event) throws IOException {

private List<Parameter> buildParameters(Event event, OpenMRSResource resource) {
List<Parameter> parameters = new ArrayList<>();
parameters.add(new Parameter("name", resource.getName()));
parameters.add(new Parameter("uuid", resource.getUuid()));
addToParametersIfNotEmpty(parameters, "name", resource.getName());
addToParametersIfNotEmpty(parameters, "uuid", resource.getUuid());
Boolean saleActiveStatus = isSaleableActive(resource);
parameters.add(new Parameter("is_active", (saleActiveStatus ? "1" : "0"), "boolean"));

parameters.add(new Parameter("category", ERP_EVENT_CATEGORY));

parameters.add(new Parameter("feed_uri", event.getFeedUri()));
parameters.add(new Parameter("last_read_entry_id",event.getId()));
parameters.add(new Parameter("feed_uri_for_last_read_entry",event.getFeedUri()));

addToParametersIfNotEmpty(parameters, "category", ERP_EVENT_CATEGORY);
addToParametersIfNotEmpty(parameters, "feed_uri", event.getFeedUri());
addToParametersIfNotEmpty(parameters, "last_read_entry_id",event.getId());
addToParametersIfNotEmpty(parameters, "feed_uri_for_last_read_entry",event.getFeedUri());
if (event.getFeedUri() == null) {
parameters.add(new Parameter("is_failed_event","1","boolean"));
}

Parameter categoryParam = getProductCategoryParameter(resource);
if (categoryParam != null) {
parameters.add(categoryParam);
}
return parameters;
}

private void addToParametersIfNotEmpty(List<Parameter> parameters, String name, String value) {
if (value != null && !value.isEmpty()) {
parameters.add(new Parameter(name, value));
}
}

private Boolean isSaleableActive(OpenMRSResource resource) {
if (!resource.isActive()) {
return false;
}
if (resource.getProperties() != null) {
String saleable = resource.getProperties().get(SALEABLE_PROPERTY_NAME);
if ((saleable != null) && !"".equals(saleable)) {
if ((saleable != null) && !saleable.isEmpty() && !Objects.equals(saleable, "")) {
return Boolean.valueOf(saleable);
}
}
Expand All @@ -115,7 +116,7 @@ private Boolean isSaleableActive(OpenMRSResource resource) {
private Parameter getProductCategoryParameter(OpenMRSResource resource) {
if (resource.getProperties() != null) {
String product_category = resource.getProperties().get(PRODUCT_CATEGORY);
if ((product_category != null) && !"".equals(product_category)) {
if ((product_category != null) && !product_category.isEmpty() && !Objects.equals(product_category, "")) {
return new Parameter(PRODUCT_CATEGORY, product_category);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public EventWorker getWorker(Jobs jobName, String feedUrl, String odooURL, OpenE
case LAB_TEST_FEED: return new OpenERPLabTestServiceEventWorker(feedUrl, odooURL, openERPContext, webClientProvider.getOpenMRSWebClient(), urlPrefix);
case LAB_PANEL_FEED: return new OpenERPLabPanelServiceEventWorker(feedUrl, odooURL, openERPContext, webClientProvider.getOpenMRSWebClient(), urlPrefix);
case RADIOLOGY_TEST_FEED: return new OpenERPRadiologyTestServiceEventWorker(feedUrl, odooURL, openERPContext, webClientProvider.getOpenMRSWebClient(), urlPrefix);
case SALEABLE_FEED: return new OpenERPSaleableResourceWorker(feedUrl, odooURL, openERPContext, webClientProvider.getOpenMRSWebClient(), urlPrefix);
case SALEABLE_FEED: return new OpenERPSaleableResourceWorker(odooURL, openERPContext, webClientProvider.getOpenMRSWebClient(), urlPrefix);
}
throw new RuntimeException(String.format("No worker for %s", jobName));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class OpenERPSaleableResourceWorkerTest {
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
worker = new OpenERPSaleableResourceWorker(feedUri, odooURL, openERPContext, webClient, "https://mybahmni/");
worker = new OpenERPSaleableResourceWorker(odooURL, openERPContext, webClient, "https://mybahmni/");
when(webClient.get(URI.create(eventUrl))).thenReturn(sampleProcedureJson);
}

Expand Down

0 comments on commit e77294c

Please sign in to comment.