diff --git a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/OpenMRSBedAssignmentParser.java b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/OpenMRSBedAssignmentParser.java deleted file mode 100644 index 1fb5c8b3..00000000 --- a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/OpenMRSBedAssignmentParser.java +++ /dev/null @@ -1,46 +0,0 @@ -/* -* The contents of this file are subject to the Mozilla Public License -* Version 1.1 (the "License"); you may not use this file except in -* compliance with the License. You may obtain a copy of the License at -* http://www.mozilla.org/MPL/ -* -* Software distributed under the License is distributed on an "AS IS" -* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the -* License for the specific language governing rights and limitations under -* the License. -* -* The Original Code is OpenELIS code. -* -* Copyright (C) The Minnesota Department of Health. All Rights Reserved. -*/ - -package org.bahmni.feed.openerp; - -import com.fasterxml.jackson.databind.ObjectMapper; -import org.bahmni.feed.openerp.domain.encounter.bedassignment.OpenMRSBedAssignment; -import org.bahmni.openerp.web.request.OpenERPRequest; -import org.bahmni.openerp.web.request.builder.Parameter; -import org.bahmni.openerp.web.service.ProductService; - -import java.io.IOException; -import java.util.List; - -public class OpenMRSBedAssignmentParser implements WebClientResponseParser { - private ObjectMapper objectMapper; - - public OpenMRSBedAssignmentParser(ObjectMapper objectMapper) { - this.objectMapper = objectMapper; - } - - @Override - public OpenERPRequest parse(String responseContent, ProductService productService, String eventId, String feedURIForLastReadEntry, String feedURI) throws IOException { - OpenMRSBedAssignment openMRSBedAssignment = objectMapper.readValue(responseContent, OpenMRSBedAssignment.class); - if (!openMRSBedAssignment.shouldERPConsumeEvent()) { - return OpenERPRequest.DO_NOT_CONSUME; - } - - List parameters = openMRSBedAssignment.getParameters(eventId, productService, feedURIForLastReadEntry, feedURI); - return new OpenERPRequest("atom.event.worker", "process_event", parameters); - - } -} diff --git a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/TasksMonitoringResponse.java b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/TasksMonitoringResponse.java deleted file mode 100644 index fe435691..00000000 --- a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/TasksMonitoringResponse.java +++ /dev/null @@ -1,80 +0,0 @@ -package org.bahmni.feed.openerp; - -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Date; - -public class TasksMonitoringResponse { - private Boolean started; - private String taskClass; - private Date lastExecutionTime; - private Date nextExecutionTime; - private String lastExecutionTimeString; - private String nextExecutionTimeString; - - TasksMonitoringResponse() { - } - - public TasksMonitoringResponse(Boolean started, String taskClass, Date lastExecutionTime, Date nextExecutionTime) { - this.started = started; - this.taskClass = taskClass; - this.lastExecutionTime = lastExecutionTime; - this.nextExecutionTime = nextExecutionTime; - - DateFormat df = new SimpleDateFormat("dd/MM/yyyy 'T' HH:mm:ss"); - if (lastExecutionTime != null) { - this.lastExecutionTimeString = df.format(lastExecutionTime); - } - if (nextExecutionTime != null) { - this.nextExecutionTimeString = df.format(nextExecutionTime); - } - } - - public Boolean getStarted() { - return started; - } - - public String getTaskClass() { - return taskClass; - } - - public Date getLastExecutionTime() { - return lastExecutionTime; - } - - public Date getNextExecutionTime() { - return nextExecutionTime; - } - - public void setStarted(Boolean started) { - this.started = started; - } - - public void setTaskClass(String taskClass) { - this.taskClass = taskClass; - } - - public void setLastExecutionTime(Date lastExecutionTime) { - this.lastExecutionTime = lastExecutionTime; - } - - public void setNextExecutionTime(Date nextExecutionTime) { - this.nextExecutionTime = nextExecutionTime; - } - - public String getLastExecutionTimeString() { - return lastExecutionTimeString; - } - - public void setLastExecutionTimeString(String lastExecutionTimeString) { - this.lastExecutionTimeString = lastExecutionTimeString; - } - - public String getNextExecutionTimeString() { - return nextExecutionTimeString; - } - - public void setNextExecutionTimeString(String nextExecutionTimeString) { - this.nextExecutionTimeString = nextExecutionTimeString; - } -} diff --git a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/WebClientResponseParser.java b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/WebClientResponseParser.java deleted file mode 100644 index 04e12842..00000000 --- a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/WebClientResponseParser.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.bahmni.feed.openerp; - -import org.bahmni.openerp.web.request.OpenERPRequest; -import org.bahmni.openerp.web.service.ProductService; - -import java.io.IOException; - -public interface WebClientResponseParser { - OpenERPRequest parse(String responseContent, ProductService productService, String eventId, - String feedURIForLastReadEntry, String feedURI) throws IOException; - -} diff --git a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/controller/TaskMonitorController.java b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/controller/TaskMonitorController.java deleted file mode 100644 index bffa4a7f..00000000 --- a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/controller/TaskMonitorController.java +++ /dev/null @@ -1,62 +0,0 @@ -package org.bahmni.feed.openerp.controller; - -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.LogManager; -import org.bahmni.feed.openerp.TasksMonitoringResponse; -import org.bahmni.openerp.web.service.OpenERPService; -import org.quartz.JobKey; -import org.quartz.Scheduler; -import org.quartz.SchedulerException; -import org.quartz.Trigger; -import org.quartz.impl.matchers.GroupMatcher; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.scheduling.quartz.SchedulerFactoryBean; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.ResponseBody; - -import java.util.ArrayList; -import java.util.List; - -@Controller -// TODO : Mujir - this doesnt have any authentication right now. Change nagios when we add basic auth. -public class TaskMonitorController { - private OpenERPService openERPService; - private SchedulerFactoryBean schedulerFactoryBean; - - private static Logger logger = LogManager.getLogger(TaskMonitorController.class); - - @Autowired - public TaskMonitorController(SchedulerFactoryBean schedulerFactoryBean, OpenERPService openERPService) { - this.schedulerFactoryBean = schedulerFactoryBean; - this.openERPService = openERPService; - } - - @RequestMapping(value = "/tasks", method = RequestMethod.GET) - public - @ResponseBody - List taskStatus() { - List monitoringResponses = new ArrayList<>(); - try { - Scheduler scheduler = schedulerFactoryBean.getScheduler(); - for (String groupName : scheduler.getJobGroupNames()) { - for (JobKey jobKey : scheduler.getJobKeys(GroupMatcher.jobGroupEquals(groupName))) { - List triggers = (List) scheduler.getTriggersOfJob(jobKey); - Trigger trigger = triggers.get(0); - monitoringResponses.add(new TasksMonitoringResponse(scheduler.isStarted(), jobKey.getName(), trigger.getPreviousFireTime(), trigger.getNextFireTime())); - } - } - } catch (SchedulerException e) { - logger.error(e); - } - return monitoringResponses; - } - - @RequestMapping(value = "/customer", method = RequestMethod.GET, params = {"patientId"}) - @ResponseBody - public Object[] search(@RequestParam String patientId) { - return openERPService.findCustomers(patientId); - } -} diff --git a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/encounter/bedassignment/OpenMRSBed.java b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/encounter/bedassignment/OpenMRSBed.java deleted file mode 100644 index 77af8abf..00000000 --- a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/encounter/bedassignment/OpenMRSBed.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.bahmni.feed.openerp.domain.encounter.bedassignment; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; - -@JsonIgnoreProperties(ignoreUnknown = true) -public class OpenMRSBed { - private String id; - private String bedNumber; - private OpenMRSBedType bedType; - - private String status; - - public String getId() { - return id; - } - - public String getBedNumber() { - return bedNumber; - } - - public OpenMRSBedType getBedType() { - return bedType; - } - - public String getStatus() { - return status; - } -} diff --git a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/encounter/bedassignment/OpenMRSBedAssignment.java b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/encounter/bedassignment/OpenMRSBedAssignment.java deleted file mode 100644 index 597fc232..00000000 --- a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/encounter/bedassignment/OpenMRSBedAssignment.java +++ /dev/null @@ -1,74 +0,0 @@ -package org.bahmni.feed.openerp.domain.encounter.bedassignment; - -import org.bahmni.feed.openerp.ObjectMapperRepository; -import org.bahmni.feed.openerp.domain.OpenMRSPatient; -import org.bahmni.feed.openerp.domain.encounter.OpenERPOrder; -import org.bahmni.feed.openerp.domain.encounter.OpenERPOrders; -import org.bahmni.feed.openerp.domain.encounter.OpenMRSEncounter; -import org.bahmni.feed.openerp.domain.encounter.OpenMRSEncounterEvent; -import org.bahmni.openerp.web.OpenERPException; -import org.bahmni.openerp.web.request.builder.Parameter; -import org.bahmni.openerp.web.service.ProductService; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -@JsonIgnoreProperties(ignoreUnknown = true) -public class OpenMRSBedAssignment extends OpenMRSEncounterEvent { - private OpenMRSEncounter encounter; - private OpenMRSPatient patient; - private OpenMRSBed bed; - - public boolean shouldERPConsumeEvent() { - return bed != null && patient != null && encounter != null; - } - - public List getParameters(String eventId, ProductService productService, String feedURIForLastReadEntry, String feedURI) throws IOException { - validateUrls(feedURIForLastReadEntry, feedURI); - - List parameters = new ArrayList<>(); - - String patientId = patient.getDisplay().split(" ")[0]; - - parameters.add(createParameter("category", "create.sale.order", "string")); - parameters.add(createParameter("customer_id", patientId, "string")); - parameters.add(createParameter("feed_uri", feedURI, "string")); - parameters.add(createParameter("last_read_entry_id", eventId, "string")); - parameters.add(createParameter("feed_uri_for_last_read_entry", feedURIForLastReadEntry, "string")); - parameters.add(createParameter("orders", getOrderJson(productService, bed), "string")); - - return parameters; - } - - private String getOrderJson(ProductService productService, OpenMRSBed bed) throws IOException { - String productId = productService.findProductByName(bed.getBedType().getName()); - if (productId == null) - throw new OpenERPException("Product " + bed.getBedType().getName() + " not Found"); - - OpenERPOrder openERPOrder = new OpenERPOrder(); - openERPOrder.setVisitId(encounter.getVisitUuid()); -// openERPOrder.setVisitType(encounter.getVisit().getVisitType()); -// openERPOrder.setDescription(encounter.getVisit().getDescription()); - - openERPOrder.setProductId(productId); - - OpenERPOrders orders = new OpenERPOrders(bed.getId()); - orders.getOpenERPOrders().add(openERPOrder); - - return ObjectMapperRepository.objectMapper.writeValueAsString(orders); - } - - public OpenMRSEncounter getEncounter() { - return encounter; - } - - public OpenMRSPatient getPatient() { - return patient; - } - - public OpenMRSBed getBed() { - return bed; - } -} diff --git a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/encounter/bedassignment/OpenMRSBedType.java b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/encounter/bedassignment/OpenMRSBedType.java deleted file mode 100644 index e83aea9c..00000000 --- a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/encounter/bedassignment/OpenMRSBedType.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.bahmni.feed.openerp.domain.encounter.bedassignment; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; - -@JsonIgnoreProperties(ignoreUnknown = true) -public class OpenMRSBedType { - private String id; - private String name; - private String displayName; - - public String getId() { - return id; - } - - public String getName() { - return name; - } - - public String getDisplayName() { - return displayName; - } -} diff --git a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/openelis/OpenElisLabOrder.java b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/openelis/OpenElisLabOrder.java index 81902cb8..c48bacd4 100644 --- a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/openelis/OpenElisLabOrder.java +++ b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/openelis/OpenElisLabOrder.java @@ -5,7 +5,6 @@ import org.bahmni.feed.openerp.domain.encounter.OpenERPOrder; import org.bahmni.feed.openerp.domain.encounter.OpenERPOrders; import org.bahmni.openerp.web.request.builder.Parameter; -import org.bahmni.openerp.web.service.ProductService; import java.io.IOException; import java.util.ArrayList; @@ -23,7 +22,7 @@ public class OpenElisLabOrder { private String patientIdentifier; private Set testDetails = new HashSet<>(); - public List getParameters(String eventId, ProductService productService, String feedURIForLastReadEntry, String feedURI) throws IOException { + public List getParameters(String eventId, String feedURIForLastReadEntry, String feedURI) throws IOException { List parameters = new ArrayList<>(); String patientId = getPatientIdentifier(); @@ -34,11 +33,11 @@ public List getParameters(String eventId, ProductService productServi parameters.add(createParameter("feed_uri_for_last_read_entry", feedURIForLastReadEntry, "string")); OpenERPOrders orders = new OpenERPOrders(getAccessionUuid()); - mapOrders(parameters, orders, productService); + mapOrders(parameters, orders); return parameters; } - private void mapOrders(List parameters, OpenERPOrders orders, ProductService productService) throws IOException { + private void mapOrders(List parameters, OpenERPOrders orders) throws IOException { if (hasOrders()) { for (OpenElisTestDetail testDetail : testDetails) { if(testDetail.getPanelUuid() == null || !orderAlreadyPresent(orders, testDetail)) { diff --git a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/worker/OpenElisSaleOrderEventWorker.java b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/worker/OpenElisSaleOrderEventWorker.java index 0e51383a..c11e924e 100644 --- a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/worker/OpenElisSaleOrderEventWorker.java +++ b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/worker/OpenElisSaleOrderEventWorker.java @@ -8,7 +8,6 @@ import org.bahmni.openerp.web.client.strategy.OpenERPContext; import org.bahmni.openerp.web.request.OpenERPRequest; import org.bahmni.openerp.web.request.builder.Parameter; -import org.bahmni.openerp.web.service.ProductService; import org.ict4h.atomfeed.client.domain.Event; import org.ict4h.atomfeed.client.service.EventWorker; @@ -20,7 +19,6 @@ public class OpenElisSaleOrderEventWorker implements EventWorker { private final OpenERPContext openERPContext; private final OpenElisWebClient webClient; private final String urlPrefix; - private ProductService productService; private static final Logger logger = LogManager.getLogger(OpenElisSaleOrderEventWorker.class); @@ -53,7 +51,7 @@ private OpenERPRequest mapRequest(Event event) throws IOException { String labOrders = webClient.get(URI.create(urlPrefix + event.getContent())); OpenElisLabOrder openElisLabOrder = ObjectMapperRepository.objectMapper.readValue(labOrders, OpenElisLabOrder.class); - OpenERPRequest openERPRequest = new OpenERPRequest("atom.event.worker", "process_event", openElisLabOrder.getParameters(event.getId(),productService, event.getFeedUri(), feedUrl)); + OpenERPRequest openERPRequest = new OpenERPRequest("atom.event.worker", "process_event", openElisLabOrder.getParameters(event.getId(), event.getFeedUri(), feedUrl)); if (event.getFeedUri() == null) openERPRequest.addParameter(createParameter("is_failed_event", "1", "boolean")); diff --git a/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/worker/OpenERPSaleOrderEventWorkerIT.java b/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/worker/OpenERPSaleOrderEventWorkerIT.java index 41b6ab97..5f66cbcb 100644 --- a/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/worker/OpenERPSaleOrderEventWorkerIT.java +++ b/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/worker/OpenERPSaleOrderEventWorkerIT.java @@ -83,8 +83,8 @@ public void create_SaleOrder_In_ERP_For_Lab_Order(){ HashMap fieldMap = new HashMap(); fieldMap.put("uuid","12345"); - when(openERPContext.search(any(String.class), any(Vector.class))).thenReturn(new Object[]{12345}); - when(openERPContext.read(any(String.class),any(Vector.class), any(Vector.class))).thenReturn(new Object[]{fieldMap}); +// when(openERPContext.search(any(String.class), any(Vector.class))).thenReturn(new Object[]{12345}); +// when(openERPContext.read(any(String.class),any(Vector.class), any(Vector.class))).thenReturn(new Object[]{fieldMap}); String feedUrl = "http://xxxx/encounter/feed/2"; OpenERPSaleOrderEventWorker eventWorker = new OpenERPSaleOrderEventWorker(feedUrl,openERPContext,webClient,"http://mrs.auth.uri"); @@ -112,8 +112,8 @@ public void create_SaleOrder_For_Bed_In_ERP_When_Bed_Is_Assigned() { HashMap fieldMap = new HashMap(); fieldMap.put("uuid","12345"); - when(openERPContext.search(any(String.class), any(Vector.class))).thenReturn(new Object[]{12345}); - when(openERPContext.read(any(String.class),any(Vector.class), any(Vector.class))).thenReturn(new Object[]{fieldMap}); +// when(openERPContext.search(any(String.class), any(Vector.class))).thenReturn(new Object[]{12345}); +// when(openERPContext.read(any(String.class),any(Vector.class), any(Vector.class))).thenReturn(new Object[]{fieldMap}); String feedUrl = "http://xxxx/encounter/feed/2"; Event event = new Event("Test", feedUrl); diff --git a/openerp-client/src/main/java/org/bahmni/openerp/web/client/strategy/OpenERPClientStrategy.java b/openerp-client/src/main/java/org/bahmni/openerp/web/client/strategy/OpenERPClientStrategy.java index 29ea6eff..f0bd17d8 100644 --- a/openerp-client/src/main/java/org/bahmni/openerp/web/client/strategy/OpenERPClientStrategy.java +++ b/openerp-client/src/main/java/org/bahmni/openerp/web/client/strategy/OpenERPClientStrategy.java @@ -5,18 +5,6 @@ import java.util.Vector; public interface OpenERPClientStrategy { - - void delete(String resource, Vector params); - Object execute(OpenERPRequest openERPRequest); - Object execute(String resource, String operation, Vector params); - - Object executeRead(String resource, String operation, Vector ids, Vector params); - - Object read(String resource, Vector ids, Vector params); - - Object search(String resource, Vector params); - - Object updateCustomerReceivables(String resource, Vector params); } \ No newline at end of file diff --git a/openerp-client/src/main/java/org/bahmni/openerp/web/client/strategy/OpenERPContext.java b/openerp-client/src/main/java/org/bahmni/openerp/web/client/strategy/OpenERPContext.java index 027d314b..8eaedbc7 100644 --- a/openerp-client/src/main/java/org/bahmni/openerp/web/client/strategy/OpenERPContext.java +++ b/openerp-client/src/main/java/org/bahmni/openerp/web/client/strategy/OpenERPContext.java @@ -17,31 +17,8 @@ public OpenERPContext(OpenERPClientStrategy openERPClient) { this.openERPClient = openERPClient; } - public void delete(String resource, Vector params) { - openERPClient.delete(resource, params); - } - public Object execute(OpenERPRequest openERPRequest) { return openERPClient.execute(openERPRequest); } - public Object execute(String resource, String operation, Vector params) { - return openERPClient.execute(resource, operation, params); - } - - public Object executeRead(String resource, String operation, Vector ids, Vector params) { - return openERPClient.executeRead(resource, operation, ids, params); - } - - public Object read(String resource, Vector ids, Vector params) { - return openERPClient.read(resource, ids, params); - } - - public Object search(String resource, Vector params) { - return openERPClient.search(resource, params); - } - - public Object updateCustomerReceivables(String resource, Vector params) { - return openERPClient.updateCustomerReceivables(resource, params); - } } \ No newline at end of file diff --git a/openerp-client/src/main/java/org/bahmni/openerp/web/client/strategy/implementation/OpenERPXMLClient.java b/openerp-client/src/main/java/org/bahmni/openerp/web/client/strategy/implementation/OpenERPXMLClient.java index a43eb82f..ad959ff1 100644 --- a/openerp-client/src/main/java/org/bahmni/openerp/web/client/strategy/implementation/OpenERPXMLClient.java +++ b/openerp-client/src/main/java/org/bahmni/openerp/web/client/strategy/implementation/OpenERPXMLClient.java @@ -50,11 +50,6 @@ public OpenERPXMLClient(HttpClient httpClient, OpenERPProperties openERPProperti replyTimeoutInMilliseconds = openERPProperties.getReplyTimeoutInMilliseconds(); } - @Override - public void delete(String resource, Vector params) { - execute(resource, "unlink", params); - } - private void login() { if (id == null) { XmlRpcClient loginRpcClient = xmlRpcClient(XML_RPC_COMMON_ENDPOINT); @@ -80,44 +75,6 @@ public Object execute(OpenERPRequest openERPRequest){ return response; } - @Override - public Object execute(String resource, String operation, Vector params) { - login(); - Object[] args = {database, (Integer) id, password, resource, operation, params}; - - try { - return xmlRpcClient(XML_RPC_OBJECT_ENDPOINT).execute("execute", args); - } catch (XmlRpcException e) { - throw new OpenERPException(e); - } - } - - @Override - public Object executeRead(String resource, String operation,Vector ids, Vector params) { - login(); - Object[] args = {database, (Integer) id, password, resource, operation,ids, params}; - - try { - return xmlRpcClient(XML_RPC_OBJECT_ENDPOINT).execute("execute", args); - } catch (XmlRpcException e) { - throw new OpenERPException(e); - } - } - - @Override - public Object read(String resource,Vector ids, Vector params) { - return executeRead(resource, "read", ids, params); - } - - @Override - public Object search(String resource, Vector params) { - return execute(resource, "search", params); - } - - @Override - public Object updateCustomerReceivables(String resource, Vector params) { - return execute(resource, "update_customer_receivables", params); - } private Object executeRPC(XmlRpcClient loginRpcClient, Vector params, String methodName) { try { diff --git a/openerp-client/src/main/java/org/bahmni/openerp/web/service/CustomerAccountService.java b/openerp-client/src/main/java/org/bahmni/openerp/web/service/CustomerAccountService.java deleted file mode 100644 index 869d94cb..00000000 --- a/openerp-client/src/main/java/org/bahmni/openerp/web/service/CustomerAccountService.java +++ /dev/null @@ -1,50 +0,0 @@ -package org.bahmni.openerp.web.service; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.bahmni.openerp.web.OpenERPException; -import org.bahmni.openerp.web.client.strategy.OpenERPContext; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import java.util.Vector; - -@Service -public class CustomerAccountService { - OpenERPContext openERPContext; - private static Logger logger = LogManager.getLogger(CustomerAccountService.class); - - - @Autowired - public CustomerAccountService(OpenERPContext openERPContext) { - this.openERPContext = openERPContext; - } - - public void updateCustomerReceivables(String patientId, double amount) { - boolean success = tryUpdateReceivables(patientId, amount); - if (!success){ - logger.info("Retrying "); - success = tryUpdateReceivables(patientId, amount); - } - if(!success) - throw new OpenERPException(String.format("[%s] : Account Receivable update failed after 2 retries for amount of %s", patientId, amount)); - } - - public boolean tryUpdateReceivables(String patientId, double amount){ - Object args1[] = {"partner_id", patientId}; - Object args2[] = {"amount", amount}; - Vector params = new Vector(); - params.addElement(args1); - params.addElement(args2); - - try { - openERPContext.updateCustomerReceivables("account.receivables", params); - return true ; - } catch (Exception exception) { - logger.error(String.format("[%s] : Account Receivable update failed for amount of %s", patientId, amount), exception); - return false; - } - - - } -} diff --git a/openerp-client/src/main/java/org/bahmni/openerp/web/service/CustomerService.java b/openerp-client/src/main/java/org/bahmni/openerp/web/service/CustomerService.java deleted file mode 100644 index b772d143..00000000 --- a/openerp-client/src/main/java/org/bahmni/openerp/web/service/CustomerService.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.bahmni.openerp.web.service; - -import org.bahmni.openerp.web.OpenERPException; -import org.bahmni.openerp.web.client.strategy.OpenERPContext; -import org.bahmni.openerp.web.request.OpenERPRequest; -import org.bahmni.openerp.web.request.mapper.OpenERPCustomerParameterMapper; -import org.bahmni.openerp.web.service.domain.Customer; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import java.util.Vector; - -@Service -public class CustomerService { - private OpenERPContext openERPContext; - private OpenERPCustomerParameterMapper parameterMapper; - - @Autowired - public CustomerService(OpenERPContext openERPContext) { - this.openERPContext = openERPContext; - this.parameterMapper = new OpenERPCustomerParameterMapper(); - } - - CustomerService(OpenERPContext openERPContext,OpenERPCustomerParameterMapper parameterMapper) { - this.openERPContext = openERPContext; - this.parameterMapper = parameterMapper; - } - - public void create(Customer customer) { - if (noCustomersFound(findCustomersWithPatientReference(customer.getRef()))) { - OpenERPRequest request = parameterMapper.mapCustomerParams(customer, "create"); - openERPContext.execute(request); - } else - throw new OpenERPException(String.format("Customer with id, name already exists: %s, %s ", customer.getRef(), customer.getName())); - } - - public void deleteCustomerWithPatientReference(String patientId) { - Object[] customerIds = findCustomersWithPatientReference(patientId); - Vector params = new Vector(); - params.addElement(customerIds[0]); - openERPContext.delete("res.partner", params); - } - - public Object[] findCustomersWithPatientReference(String patientId) { - Object args[] = {"ref", "=", patientId}; - Vector params = new Vector(); - params.addElement(args); - return (Object[]) openERPContext.search("res.partner", params); - } - - private boolean noCustomersFound(Object[] customers) { - return customers.length == 0; - } -} diff --git a/openerp-client/src/main/java/org/bahmni/openerp/web/service/OpenERPService.java b/openerp-client/src/main/java/org/bahmni/openerp/web/service/OpenERPService.java deleted file mode 100644 index 3e70f7cd..00000000 --- a/openerp-client/src/main/java/org/bahmni/openerp/web/service/OpenERPService.java +++ /dev/null @@ -1,44 +0,0 @@ -package org.bahmni.openerp.web.service; - - -import org.bahmni.openerp.web.service.domain.Customer; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -@Service -public class OpenERPService { - private CustomerAccountService customerAccountService; - private CustomerService customerService; - private ProductService productService; - - @Autowired - public OpenERPService(CustomerService customerService, CustomerAccountService customerAccountService, ProductService productService){ - this.customerService = customerService; - this.customerAccountService = customerAccountService; - this.productService = productService; - } - - public void createCustomer(String name, String patientId, String village) { - customerService.create(new Customer(name,patientId,village)); - } - - public void updateCustomerBalance(String patientId, double balance) { - customerAccountService.updateCustomerReceivables(patientId, balance); - } - - public Object[] findCustomers(String patientId) { - Object[] customerIds = customerService.findCustomersWithPatientReference(patientId); - return customerIds; - } - - public void deleteCustomer(String patientId) throws Exception { - customerService.deleteCustomerWithPatientReference(patientId); - } - - public String findProduct(String name) { - return productService.findProductByName(name); - } - - -} - diff --git a/openerp-client/src/main/java/org/bahmni/openerp/web/service/ProductService.java b/openerp-client/src/main/java/org/bahmni/openerp/web/service/ProductService.java deleted file mode 100644 index 5a0eef58..00000000 --- a/openerp-client/src/main/java/org/bahmni/openerp/web/service/ProductService.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.bahmni.openerp.web.service; - -import org.bahmni.openerp.web.client.strategy.OpenERPContext; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import java.util.Map; -import java.util.Vector; - -@Service -public class ProductService { - private OpenERPContext openERPContext; - - @Autowired - public ProductService(OpenERPContext openERPContext) { - this.openERPContext = openERPContext; - } - - public String findProductByName(String name) { - Object args[] = {"name", "=", name}; - Vector params = new Vector(); - params.addElement(args); - Object[] productIds = (Object[])openERPContext.search("product.product", params); - Object[] productUUIDs = null; - if(productIds.length > 0) { - Integer prodId = (Integer) productIds[0]; - Vector ids = new Vector(); - ids.add(prodId); - Vector paramFields = new Vector(); - paramFields.add("uuid"); - productUUIDs = (Object[])openERPContext.read("product.product",ids, paramFields); - if(productUUIDs.length > 0){ - Map productUUID = (Map) productUUIDs[0]; - return (String) productUUID.get("uuid"); - } - } - - return null; - } -} diff --git a/openerp-client/src/test/java/org/bahmni/openerp/web/service/CustomerAccountServiceTest.java b/openerp-client/src/test/java/org/bahmni/openerp/web/service/CustomerAccountServiceTest.java deleted file mode 100644 index 8a3ca78a..00000000 --- a/openerp-client/src/test/java/org/bahmni/openerp/web/service/CustomerAccountServiceTest.java +++ /dev/null @@ -1,56 +0,0 @@ -package org.bahmni.openerp.web.service; - -import org.bahmni.openerp.web.OpenERPException; -import org.bahmni.openerp.web.client.strategy.OpenERPContext; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; - -import java.util.Vector; - -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.verify; -import static org.mockito.MockitoAnnotations.initMocks; - -public class CustomerAccountServiceTest { - @Mock - OpenERPContext openERPContext; - private CustomerAccountService customerAccountService; - - @Before - public void setUp() { - initMocks(this); - customerAccountService = new CustomerAccountService(openERPContext); - } - - @Test - public void shouldUpdateCustomerReceivables() { - String patientId = "12345"; - double amount = 27.0; - - Object args1[]={"patientId","12345"}; - Object args2[]={"amount",amount}; - Vector params = new Vector(); - params.addElement(args1); - params.addElement(args2); - - customerAccountService.updateCustomerReceivables(patientId,amount); - - verify(openERPContext).updateCustomerReceivables((String) any(),(Vector) any()); - } - - @Test - public void shouldThrowExceptionIfUpdationFails() { - String patientId = "12345"; - double amount = 27.0; - doThrow(new OpenERPException("message")).when(openERPContext).updateCustomerReceivables(anyString(), any(Vector.class)); - - try { - customerAccountService.updateCustomerReceivables(patientId, amount); - assert false; - } catch (Exception e) { - } - } -} diff --git a/openerp-client/src/test/java/org/bahmni/openerp/web/service/CustomerServiceTest.java b/openerp-client/src/test/java/org/bahmni/openerp/web/service/CustomerServiceTest.java deleted file mode 100644 index 66b2e961..00000000 --- a/openerp-client/src/test/java/org/bahmni/openerp/web/service/CustomerServiceTest.java +++ /dev/null @@ -1,77 +0,0 @@ -package org.bahmni.openerp.web.service; - -import org.bahmni.openerp.web.client.strategy.OpenERPContext; -import org.bahmni.openerp.web.request.OpenERPRequest; -import org.bahmni.openerp.web.request.builder.OpenERPRequestTestHelper; -import org.bahmni.openerp.web.request.builder.Parameter; -import org.bahmni.openerp.web.request.mapper.OpenERPCustomerParameterMapper; -import org.bahmni.openerp.web.service.domain.Customer; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; - -import java.util.List; -import java.util.Vector; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; - -public class CustomerServiceTest { - private CustomerService customerService; - - @Mock - private OpenERPContext openERPContext; - - @Mock - private OpenERPCustomerParameterMapper parameterMapper; - private OpenERPRequestTestHelper openERPRequestTestHelper; - - @Before - public void setup() { - initMocks(this); - customerService = new CustomerService(openERPContext, parameterMapper); - openERPRequestTestHelper = new OpenERPRequestTestHelper(); - } - - @Test - public void shouldCreateNewCustomerIfNotExisting() throws Exception { - String name = "Ram Singh"; - String patientId = "12345"; - String village = "Ganiyari"; - Customer customer = new Customer(name,patientId,village); - Vector searchparams = new Vector(); - searchparams.addElement(new Object[]{"ref", "=", "12345"}); - Object[] results = new Object[]{}; - when(openERPContext.search((String) any(), (Vector) any())).thenReturn(results); - - List parameters = openERPRequestTestHelper.createCustomerRequest(name,patientId,village); - OpenERPRequest request = new OpenERPRequest("res_partner", "execute", parameters); - - when(parameterMapper.mapCustomerParams(customer,"create")).thenReturn(request); - - customerService.create(customer); - - verify(openERPContext).execute(request); - } - - @Test - public void createCustomerShouldThrowExceptionIfCustomerAlreadyExisting() throws Exception { - String name = "Ram Singh"; - String patientId = "12345"; - Customer customer = new Customer(name,patientId,""); - Vector searchparams = new Vector(); - searchparams.addElement(new Object[]{"ref", "=", "12345"}); - Object[] results = new Object[]{new Object()}; - when(openERPContext.search((String) any(), (Vector) any())).thenReturn(results); - - try { - customerService.create(customer); - assert false; - } catch (Exception e) { - assertEquals(true, e.getMessage().contains("Customer with id, name already exists:")); - } - } -} diff --git a/openerp-client/src/test/java/org/bahmni/openerp/web/service/OpenERPServiceTest.java b/openerp-client/src/test/java/org/bahmni/openerp/web/service/OpenERPServiceTest.java deleted file mode 100644 index c42ee8f9..00000000 --- a/openerp-client/src/test/java/org/bahmni/openerp/web/service/OpenERPServiceTest.java +++ /dev/null @@ -1,78 +0,0 @@ -package org.bahmni.openerp.web.service; - -import org.bahmni.openerp.web.OpenERPException; -import org.bahmni.openerp.web.service.domain.Customer; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; - -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.fail; -import static org.mockito.Matchers.anyDouble; -import static org.mockito.Matchers.anyString; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.verify; -import static org.mockito.MockitoAnnotations.initMocks; - - -public class OpenERPServiceTest { - - private OpenERPService openERPService; - @Mock - CustomerAccountService customerAccountService; - @Mock - private CustomerService customerService; - @Mock - private ProductService productService; - - @Before - public void setUp() { - initMocks(this); - openERPService = new OpenERPService(customerService, customerAccountService, productService); - } - - @Test - public void shouldCreateCustomer() throws Exception { - String name = "name"; - String patientId = "12344"; - - openERPService.createCustomer(name, patientId, null); - - verify(customerService).create(new Customer(name,patientId,null)); - } - - @Test - public void shouldUpdatePatientBalanceForExistingPatients() throws Exception { - String patientId = "12345"; - float balance = 56; - - openERPService.updateCustomerBalance(patientId, balance); - - verify(customerAccountService).updateCustomerReceivables(patientId, balance); - } - - @Test - public void shouldThrowExceptionWhencreationOfCustomerFails() throws Exception { - String expectedMessage = "Failed to execute Exception"; - doThrow(new OpenERPException(expectedMessage)).when(customerService).create(new Customer("name", "12345", "Ganiyari")); - - try { - openERPService.createCustomer("name", "12345", "Ganiyari"); - fail("Should have thrown an exception"); - } catch (Exception ex) { - assertEquals(expectedMessage, ex.getMessage()); - } - } - - @Test - public void shouldThrowExceptionWhenUpdationOfCustomerWithBalanceFails() throws Exception { - String expectedMessage = "Failed to execute Exception"; - doThrow(new OpenERPException(expectedMessage)).when(customerAccountService).updateCustomerReceivables(anyString(),anyDouble()); - try { - openERPService.updateCustomerBalance("name", 12345); - fail("Should have thrown an exception"); - } catch (Exception ex) { - assertEquals(expectedMessage, ex.getMessage()); - } - } -}