Skip to content

Commit

Permalink
HSC-319: Able to run without EMR API module and add a erp.properties …
Browse files Browse the repository at this point in the history
…file location (#12)
  • Loading branch information
Ruhanga authored Oct 14, 2024
1 parent 95a79af commit c42ebcd
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 88 deletions.
11 changes: 6 additions & 5 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@
<artifactId>openmrs-api</artifactId>
<version>${openmrsPlatformVersion}</version>
</dependency>
<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>emrapi-api</artifactId>
<version>${emrapiVersion}</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
Expand Down Expand Up @@ -73,6 +68,12 @@
<version>${providermanagementVersion}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>emrapi-api</artifactId>
<version>${emrapiVersion}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>emrapi-api-1.12</artifactId>
Expand Down
37 changes: 0 additions & 37 deletions api/src/main/java/org/openmrs/module/erp/ErpContext.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ private ErpPropertiesFile() {

public static File getFile() {
String fileName = ErpConstants.ERP_PROPERTY_FILE_NAME;
return new File(OpenmrsUtil.getApplicationDataDirectory(), fileName);
File file = new File(OpenmrsUtil.getApplicationDataDirectory(), fileName);
if (file.exists()) {
return file;
}
LogFactory.getLog(ErpPropertiesFile.class).warn("Could not find erp.properties file in directory: " + file.getParent() + ". Failing over to location /etc/properties/.");
return new File("/etc/properties/", fileName);
}

public static InputStream getInputStream() throws FileNotFoundException {
Expand Down
16 changes: 13 additions & 3 deletions api/src/test/java/org/openmrs/module/erp/api/utils/TestHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
//import com.odoojava.api.*;
import org.openmrs.module.erp.ErpActivator;
import org.openmrs.module.erp.ErpConstants;
import org.openmrs.module.erp.ErpContext;
import org.openmrs.module.erp.api.ErpInvoiceService;
import org.openmrs.module.erp.api.ErpOrderService;
import org.openmrs.module.erp.api.ErpPartnerService;
import org.openmrs.util.OpenmrsUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
Expand All @@ -29,8 +31,16 @@ public class TestHelper {
private ErpActivator erpActivator;

@Autowired
@Qualifier(ErpConstants.COMPONENT_ERP_CONTEXT)
protected ErpContext context;
@Qualifier(ErpConstants.COMPONENT_ODOO_ORDER_SERVICE)
protected ErpOrderService erpOrderService;

@Autowired
@Qualifier(ErpConstants.COMPONENT_ODOO_INVOICE_SERVICE)
protected ErpInvoiceService erpInvoiceService;

@Autowired
@Qualifier(ErpConstants.COMPONENT_ODOO_PARTNER_SERVICE)
protected ErpPartnerService erpPartnerService;

public static void createErpPropertiesFile() {
File erpPropsFile = new File(OpenmrsUtil.getApplicationDataDirectory(), fileName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import org.json.JSONArray;
import org.json.JSONObject;
import org.openmrs.module.erp.ErpConstants;
import org.openmrs.module.erp.ErpContext;
import org.openmrs.module.erp.Filter;
import org.openmrs.module.erp.api.ErpInvoiceService;
import org.openmrs.module.erp.web.RecordRepresentation;
import org.openmrs.module.webservices.rest.web.RestConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

Expand All @@ -21,16 +21,13 @@
public class ErpInvoiceController {

@Autowired
protected ErpContext erpContext;

@Autowired
private ErpInvoiceService erpInvoiceService;

@Qualifier(ErpConstants.COMPONENT_ODOO_INVOICE_SERVICE)
protected ErpInvoiceService erpInvoiceService;

@RequestMapping(method = RequestMethod.POST)
@ResponseBody
public Object getInvoicesByFilters(@RequestBody String jsonString,
@RequestParam(value = "rep", defaultValue = "default") String rep) {
erpInvoiceService = erpContext.getErpInvoiceService();

RecordRepresentation recordRepresentation = new RecordRepresentation(erpInvoiceService.defaultModelAttributes());

Expand Down Expand Up @@ -65,8 +62,6 @@ public Object getInvoicesByFilters(@RequestBody String jsonString,
public Object getInvoiceById(@PathVariable("id") String invoiceId,
@RequestParam(value = "rep", defaultValue = "default") String rep) {

erpInvoiceService = erpContext.getErpInvoiceService();

return new RecordRepresentation(erpInvoiceService.defaultModelAttributes())
.getRepresentedRecord(erpInvoiceService.getInvoiceById(invoiceId), rep);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
import org.json.JSONArray;
import org.json.JSONObject;
import org.openmrs.module.erp.ErpConstants;
import org.openmrs.module.erp.ErpContext;
import org.openmrs.module.erp.Filter;
import org.openmrs.module.erp.api.ErpOrderService;
import org.openmrs.module.erp.web.RecordRepresentation;
import org.openmrs.module.webservices.rest.web.RestConstants;
import org.openmrs.module.webservices.rest.web.v1_0.controller.BaseRestController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

Expand All @@ -22,16 +22,14 @@
public class ErpOrderController extends BaseRestController {

@Autowired
protected ErpContext erpContext;

@Autowired
private ErpOrderService erpOrderService;
@Qualifier(ErpConstants.COMPONENT_ODOO_ORDER_SERVICE)
protected ErpOrderService erpOrderService;

@RequestMapping(method = RequestMethod.POST)
@ResponseBody
public Object getErpOrdersByFilters(@RequestBody String jsonString,
@RequestParam(value = "rep", defaultValue = "default") String rep) {
erpOrderService = erpContext.getErpOrderService();

RecordRepresentation recordRepresentation = new RecordRepresentation(erpOrderService.defaultModelAttributes());

ArrayList<Filter> filtersArray = new ArrayList<>();
Expand Down Expand Up @@ -64,7 +62,7 @@ public Object getErpOrdersByFilters(@RequestBody String jsonString,
@ResponseBody
public Object getErpOrderById(@PathVariable("id") String id,
@RequestParam(value = "rep", defaultValue = "default") String rep) {
erpOrderService = erpContext.getErpOrderService();

return new RecordRepresentation(erpOrderService.defaultModelAttributes())
.getRepresentedRecord(erpOrderService.getErpOrderById(id), rep);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
import org.json.JSONArray;
import org.json.JSONObject;
import org.openmrs.module.erp.ErpConstants;
import org.openmrs.module.erp.ErpContext;
import org.openmrs.module.erp.Filter;
import org.openmrs.module.erp.api.ErpPartnerService;
import org.openmrs.module.erp.web.RecordRepresentation;
import org.openmrs.module.webservices.rest.web.RestConstants;
import org.openmrs.module.webservices.rest.web.v1_0.controller.BaseRestController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

Expand All @@ -22,16 +22,14 @@
public class ErpPartnerController extends BaseRestController {

@Autowired
protected ErpContext erpContext;

@Autowired
private ErpPartnerService erpPartnerService;
@Qualifier(ErpConstants.COMPONENT_ODOO_PARTNER_SERVICE)
protected ErpPartnerService erpPartnerService;

@RequestMapping(method = RequestMethod.POST)
@ResponseBody
public Object getErpPartnersByFilters(@RequestBody String jsonString,
@RequestParam(value = "rep", defaultValue = "default") String rep) {
erpPartnerService = erpContext.getErpPartnerService();

RecordRepresentation recordRepresentation = new RecordRepresentation(erpPartnerService.defaultModelAttributes());

ArrayList<Filter> filtersArray = new ArrayList<>();
Expand Down Expand Up @@ -64,7 +62,7 @@ public Object getErpPartnersByFilters(@RequestBody String jsonString,
@ResponseBody
public Object getErpPartnerById(@PathVariable("id") String id,
@RequestParam(value = "rep", defaultValue = "default") String rep) {
erpPartnerService = erpContext.getErpPartnerService();

return new RecordRepresentation(erpPartnerService.defaultModelAttributes())
.getRepresentedRecord(erpPartnerService.getErpPartnerById(id), rep);
}
Expand Down
3 changes: 0 additions & 3 deletions omod/src/main/resources/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
<require_module version="${webservices.restVersion}">
org.openmrs.module.webservices.rest
</require_module>
<require_module version="${emrapiVersion}">
org.openmrs.module.emrapi
</require_module>
</require_modules>

<!-- Privileges -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,22 @@
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.openmrs.module.erp.ErpContext;
import org.openmrs.module.erp.api.ErpInvoiceService;
import org.openmrs.module.erp.api.utils.TestHelper;
import org.openmrs.web.test.BaseModuleWebContextSensitiveTest;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.mock;

public class ErpInvoiceControllerTest extends BaseModuleWebContextSensitiveTest {

@Mock
protected ErpContext erpContext;
protected ErpInvoiceService erpInvoiceService;

@InjectMocks
@Autowired
Expand All @@ -40,9 +37,7 @@ public ErpInvoiceControllerTest() {
public void setup() {

MockitoAnnotations.initMocks(this);
ErpInvoiceService erpInvoiceService = mock(ErpInvoiceService.class);

Mockito.doReturn(erpInvoiceService).when(erpContext).getErpInvoiceService();
Mockito.doReturn(getInvoice()).when(erpInvoiceService).getInvoiceById(anyString());
Mockito.doReturn(Collections.singletonList(getInvoice())).when(erpInvoiceService).getInvoicesByFilters(any());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.openmrs.module.erp.ErpContext;
import org.openmrs.module.erp.api.ErpOrderService;
import org.openmrs.module.erp.api.utils.TestHelper;
import org.openmrs.web.test.BaseModuleWebContextSensitiveTest;
Expand All @@ -17,12 +16,11 @@
import java.util.*;

import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;

public class ErpOrderControllerTest extends BaseModuleWebContextSensitiveTest {

@Mock
protected ErpContext erpContext;
protected ErpOrderService erpOrderService;

@InjectMocks
@Autowired
Expand All @@ -37,9 +35,7 @@ public ErpOrderControllerTest() {
public void setup() {

MockitoAnnotations.initMocks(this);
ErpOrderService erpOrderService = mock(ErpOrderService.class);

Mockito.doReturn(erpOrderService).when(erpContext).getErpOrderService();
Mockito.doReturn(Collections.singletonList(getOrder())).when(erpOrderService).getErpOrdersByFilters(any());

Mockito.doReturn(getOrder()).when(erpOrderService).getErpOrderById(any());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.openmrs.module.erp.ErpContext;
import org.openmrs.module.erp.api.ErpPartnerService;
import org.openmrs.module.erp.api.utils.TestHelper;
import org.openmrs.web.test.BaseModuleWebContextSensitiveTest;
Expand All @@ -20,12 +19,11 @@
import java.util.Map;

import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;

public class ErpPartnerControllerTest extends BaseModuleWebContextSensitiveTest {

@Mock
protected ErpContext erpContext;
protected ErpPartnerService erpPartnerService;

@InjectMocks
@Autowired
Expand All @@ -40,9 +38,7 @@ public ErpPartnerControllerTest() {
public void setup() {

MockitoAnnotations.initMocks(this);
ErpPartnerService erpPartnerService = mock(ErpPartnerService.class);

Mockito.doReturn(erpPartnerService).when(erpContext).getErpPartnerService();
Mockito.doReturn(Collections.singletonList(getPartner())).when(erpPartnerService).getErpPartnersByFilters(any());

Mockito.doReturn(getPartner()).when(erpPartnerService).getErpPartnerById(any());
Expand Down

0 comments on commit c42ebcd

Please sign in to comment.