From 222921215d96e155833861ff9f29c0d2927e4d60 Mon Sep 17 00:00:00 2001 From: Rahul Ramesh <121226043+rahu1ramesh@users.noreply.github.com> Date: Sat, 2 Dec 2023 10:46:03 +0530 Subject: [PATCH] Revert "BAH-3331 | Add. Rest Client Implementation for Create Drug" This reverts commit 1798255e8e14f89d0d6ab9b622f7e8064793b7ff. --- .../openerp/AtomfeedServiceConstants.java | 15 --- .../openerp/OpenERPAtomFeedProperties.java | 29 ++---- .../openerp/client/AtomFeedClientHelper.java | 22 ++--- .../openerp/client/FeedClientFactory.java | 17 ++-- .../openerp/client/WebClientProvider.java | 4 +- .../domain/openelis/OpenElisLabOrder.java | 2 +- .../openerp/job/{FeedURI.java => Jobs.java} | 4 +- .../openerp/job/OpenERPCustomerFeedJob.java | 4 +- .../feed/openerp/job/OpenERPDrugFeedJob.java | 4 +- .../feed/openerp/job/OpenERPLabFeedJob.java | 4 +- .../openerp/job/OpenERPSaleOrderFeedJob.java | 4 +- .../openerp/job/OpenERPSaleableFeedJob.java | 2 +- .../openerp/job/OpenElisSaleOrderFeedJob.java | 4 +- .../openerp/job/ReferenceDataFeedJob.java | 4 +- .../feed/openerp/job/SimpleFeedJob.java | 8 +- .../org/bahmni/feed/openerp/worker/Jobs.java | 15 --- .../OpenERPCustomerServiceEventWorker.java | 7 +- .../worker/OpenERPDrugServiceEventWorker.java | 55 +++++------ ...OpenERPLabOrderTypeServiceEventWorker.java | 7 +- .../worker/OpenERPSaleOrderEventWorker.java | 7 +- .../worker/OpenERPSaleableResourceWorker.java | 7 +- .../worker/OpenElisSaleOrderEventWorker.java | 7 +- .../feed/openerp/worker/WorkerFactory.java | 18 ++-- .../main/resources/erp-atomfeed.properties | 10 +- .../src/main/resources/jobs-context.xml | 2 - .../openerp/client/OpenERPCustomerFeedIT.java | 11 +-- ...OpenERPCustomerServiceEventWorkerTest.java | 6 +- .../openerp/job/OpenERPDrugFeedJobTest.java | 2 +- .../openerp/job/OpenERPLabFeedJobTest.java | 2 +- .../job/OpenERPSaleableFeedJobTest.java | 2 +- .../feed/openerp/server/AtomFeedServerIT.java | 1 + .../OpenERPDrugServiceEventWorkerTest.java | 8 +- ...ERPLabOrderTypeServiceEventWorkerTest.java | 15 ++- .../worker/OpenERPSaleOrderEventWorkerIT.java | 6 +- .../OpenERPSaleableResourceWorkerTest.java | 9 +- openerp-client/pom.xml | 31 ------ .../strategy/OpenERPClientStrategy.java | 2 +- .../web/client/strategy/OpenERPContext.java | 4 +- .../implementation/OdooRESTClient.java | 34 ------- .../implementation/OpenERPXMLClient.java | 17 ++-- .../{XMLClient.java => HttpClient.java} | 6 +- .../openerp/web/http/client/RestClient.java | 98 ------------------- .../web/request/builder/Parameter.java | 5 +- .../web/request/builder/RequestBuilder.java | 20 ---- .../request/template/rest_template.vm | 10 -- .../request/template/xml_template.vm | 62 ++++++------ .../request/builder/RequestBuilderTest.java | 13 +-- pom.xml | 9 +- 48 files changed, 171 insertions(+), 464 deletions(-) delete mode 100644 openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/AtomfeedServiceConstants.java rename openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/job/{FeedURI.java => Jobs.java} (91%) delete mode 100644 openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/worker/Jobs.java delete mode 100644 openerp-client/src/main/java/org/bahmni/openerp/web/client/strategy/implementation/OdooRESTClient.java rename openerp-client/src/main/java/org/bahmni/openerp/web/http/client/{XMLClient.java => HttpClient.java} (93%) delete mode 100644 openerp-client/src/main/java/org/bahmni/openerp/web/http/client/RestClient.java delete mode 100644 openerp-client/src/main/resources/request/template/rest_template.vm diff --git a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/AtomfeedServiceConstants.java b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/AtomfeedServiceConstants.java deleted file mode 100644 index 88fbf6d0..00000000 --- a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/AtomfeedServiceConstants.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.bahmni.feed.openerp; - -public enum AtomfeedServiceConstants { - IS_REST_ENABLED("IS_ODOO_16"); - - private final String atomfeedServiceConstants; - - AtomfeedServiceConstants(String atomfeedServiceConstants) { - this.atomfeedServiceConstants = atomfeedServiceConstants; - } - - public String getAtomfeedServiceConstants() { - return atomfeedServiceConstants; - } -} diff --git a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/OpenERPAtomFeedProperties.java b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/OpenERPAtomFeedProperties.java index 8f4400ea..3bfe5995 100644 --- a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/OpenERPAtomFeedProperties.java +++ b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/OpenERPAtomFeedProperties.java @@ -2,7 +2,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.bahmni.feed.openerp.job.FeedURI; +import org.bahmni.feed.openerp.job.Jobs; import org.bahmni.openerp.web.OpenERPProperties; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @@ -27,7 +27,7 @@ public String getSchedulerInitialDelay() { /** - * @deprecated replaced by {@link #getFeedUriForJob(FeedURI)} ()} + * @deprecated replaced by {@link #getFeedUriForJob(Jobs)} ()} */ @Deprecated public String getFeedUri(String feedname) { @@ -55,9 +55,8 @@ public String getFeedUri(String feedname) { @Value("${saleable.feed.generator.uri}") private String saleableFeedUri; - - public String getFeedUriForJob(FeedURI feedURIJob) { - switch (feedURIJob){ + public String getFeedUriForJob(Jobs feedJob) { + switch (feedJob){ case CUSTOMER_FEED: return customFeedUri; case SALEORDER_FEED: return saleOrderFeedUri; case OPENELIS_SALEORDER_FEED: return elisSaleOrderFeedUri; @@ -68,23 +67,6 @@ public String getFeedUriForJob(FeedURI feedURIJob) { throw new RuntimeException("Can not identify feed URI for requested Job."); } - public String getOdooURLForJob(FeedURI feedURIJob, boolean isRestEnabled) { - if (isRestEnabled) { - switch (feedURIJob) { - case CUSTOMER_FEED: - case SALEORDER_FEED: - case LAB_FEED: - case SALEABLE_FEED: return ""; - case DRUG_FEED: return "/api/bahmni-drug"; - default: - throw new RuntimeException("Can not identify Odoo URL for requested Job."); - } - } - else { - return "xmlrpc/object"; - } - } - @Value("${openerp.host}") private String openErpHost; @@ -209,6 +191,8 @@ private void debug() { logger.debug("**************** DEBUG OpenERPAtomFeedProperties ************************ "); } + + private HashMap getInfo() { HashMap values = new HashMap<>(); values.put("chunking.strategy",chunkingStrategy ); @@ -234,4 +218,5 @@ private HashMap getInfo() { return values; } + } diff --git a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/client/AtomFeedClientHelper.java b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/client/AtomFeedClientHelper.java index c887242f..4733f737 100644 --- a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/client/AtomFeedClientHelper.java +++ b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/client/AtomFeedClientHelper.java @@ -1,12 +1,10 @@ package org.bahmni.feed.openerp.client; -import org.bahmni.feed.openerp.AtomfeedServiceConstants; import org.bahmni.feed.openerp.FeedException; import org.bahmni.feed.openerp.OpenERPAtomFeedProperties; -import org.bahmni.feed.openerp.job.FeedURI; +import org.bahmni.feed.openerp.job.Jobs; import org.bahmni.feed.openerp.worker.WorkerFactory; import org.bahmni.openerp.web.client.strategy.OpenERPContext; -import org.bahmni.openerp.web.client.strategy.implementation.OdooRESTClient; import org.bahmni.openerp.web.client.strategy.implementation.OpenERPXMLClient; import org.bahmni.webclients.ClientCookies; import org.ict4h.atomfeed.client.AtomFeedProperties; @@ -17,27 +15,22 @@ import org.ict4h.atomfeed.client.repository.jdbc.AllMarkersJdbcImpl; import org.ict4h.atomfeed.client.service.FeedClient; import org.ict4h.atomfeed.server.transaction.AtomFeedSpringTransactionSupport; -import org.springframework.core.env.Environment; public class AtomFeedClientHelper { private final OpenERPAtomFeedProperties atomFeedProperties; private final AtomFeedSpringTransactionSupport transactionManager; private final OpenERPXMLClient openERPXMLClient; - private final OdooRESTClient odooRESTClient; private FeedClientFactory feedClientFactory; private final WebClientProvider webClientProvider; - private final Environment environment; - public AtomFeedClientHelper(OpenERPAtomFeedProperties atomFeedProperties, Environment environment, AtomFeedSpringTransactionSupport transactionManager, OpenERPXMLClient openERPXMLClient, OdooRESTClient odooRESTClient) { + public AtomFeedClientHelper(OpenERPAtomFeedProperties atomFeedProperties, AtomFeedSpringTransactionSupport transactionManager, OpenERPXMLClient openERPXMLClient) { this.atomFeedProperties = atomFeedProperties; this.transactionManager = transactionManager; this.openERPXMLClient = openERPXMLClient; this.webClientProvider = new WebClientProvider(atomFeedProperties); - this.odooRESTClient = odooRESTClient; - this.environment = environment; } - public FeedClient getAtomFeedClient(FeedURI jobName) throws FeedException { + public FeedClient getAtomFeedClient(Jobs jobName) throws FeedException { if(this.feedClientFactory == null){ WorkerFactory workerFactory = new WorkerFactory(webClientProvider); feedClientFactory = new FeedClientFactory(workerFactory); @@ -45,15 +38,14 @@ public FeedClient getAtomFeedClient(FeedURI jobName) throws FeedException { return getAtomFeedClient(jobName, feedClientFactory); } - FeedClient getAtomFeedClient(FeedURI jobName, FeedClientFactory feedClientFactory) throws FeedException { + FeedClient getAtomFeedClient(Jobs jobName, FeedClientFactory feedClientFactory) throws FeedException { ClientCookies cookies = webClientProvider.getWebClient(jobName).getCookies(); AllFeeds allFeeds = getAllFeeds(atomFeedProperties, cookies); AllMarkers allMarkers = new AllMarkersJdbcImpl(transactionManager); AllFailedEvents allFailedEvents = new AllFailedEventsJdbcImpl(transactionManager); - String isRestEnabled = environment.getProperty(AtomfeedServiceConstants.IS_REST_ENABLED.getAtomfeedServiceConstants()); - boolean isRestEnabledValue = Boolean.parseBoolean(isRestEnabled); - OpenERPContext openERPContext = isRestEnabledValue ? new OpenERPContext(odooRESTClient) : new OpenERPContext(openERPXMLClient); - return feedClientFactory.getFeedClient(atomFeedProperties, transactionManager, openERPContext, allFeeds, allMarkers, allFailedEvents, jobName, isRestEnabledValue); + //TODO: Create a toggle between rest and xml client + OpenERPContext openERPContext = new OpenERPContext(openERPXMLClient); + return feedClientFactory.getFeedClient(atomFeedProperties, transactionManager, openERPContext, allFeeds, allMarkers, allFailedEvents, jobName); } static AllFeeds getAllFeeds(OpenERPAtomFeedProperties atomFeedProperties, ClientCookies cookies) { diff --git a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/client/FeedClientFactory.java b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/client/FeedClientFactory.java index be76154b..f7fbcfaa 100644 --- a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/client/FeedClientFactory.java +++ b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/client/FeedClientFactory.java @@ -5,7 +5,7 @@ import org.apache.logging.log4j.Logger; import org.bahmni.feed.openerp.FeedException; import org.bahmni.feed.openerp.OpenERPAtomFeedProperties; -import org.bahmni.feed.openerp.job.FeedURI; +import org.bahmni.feed.openerp.job.Jobs; import org.bahmni.feed.openerp.worker.WorkerFactory; import org.bahmni.openerp.web.client.strategy.OpenERPContext; import org.ict4h.atomfeed.client.AtomFeedProperties; @@ -31,29 +31,24 @@ public FeedClientFactory(WorkerFactory workerFactory) { this.workerFactory = workerFactory; } - public AtomFeedClient getFeedClient(OpenERPAtomFeedProperties openERPAtomFeedProperties, AtomFeedSpringTransactionSupport transactionManager, OpenERPContext openERPContext, AllFeeds allFeeds, AllMarkers allMarkers, AllFailedEvents allFailedEvents, FeedURI jobName, boolean isRestEnabled) { + public AtomFeedClient getFeedClient(OpenERPAtomFeedProperties openERPAtomFeedProperties, AtomFeedSpringTransactionSupport transactionManager, OpenERPContext openERPContext, AllFeeds allFeeds, AllMarkers allMarkers, AllFailedEvents allFailedEvents, Jobs jobName) { String feedUri = openERPAtomFeedProperties.getFeedUriForJob(jobName); - String odooURL = openERPAtomFeedProperties.getOdooURLForJob(jobName,isRestEnabled); if (StringUtils.isBlank(feedUri)) { String message = String.format("No feed-uri defined for Job [%s][%s]", jobName, jobName.getFeedUriRef()); logger.warn(message); throw new FeedException(message); } - if (StringUtils.isBlank(odooURL)) { - String message = String.format("No Odoo URL defined for Job [%s][%s]", jobName, jobName.getFeedUriRef()); - logger.warn(message); - throw new FeedException(message); - } + try { String urlPrefix = getURLPrefix(jobName,openERPAtomFeedProperties); - EventWorker eventWorker = workerFactory.getWorker(jobName, feedUri, odooURL, openERPContext, urlPrefix); + EventWorker eventWorker = workerFactory.getWorker(jobName, feedUri, openERPContext, urlPrefix); return new AtomFeedClient(allFeeds, allMarkers, allFailedEvents, atomFeedProperties(openERPAtomFeedProperties), transactionManager, new URI(feedUri), eventWorker) ; } catch (URISyntaxException e) { throw new RuntimeException("error for uri:" + feedUri, e); } } - static String getURLPrefix(FeedURI jobName, OpenERPAtomFeedProperties atomFeedProperties) { + static String getURLPrefix(Jobs jobName, OpenERPAtomFeedProperties atomFeedProperties) { String endpointURI = getURIForJob(jobName,atomFeedProperties); try { if(endpointURI != null && !endpointURI.isEmpty()){ @@ -65,7 +60,7 @@ static String getURLPrefix(FeedURI jobName, OpenERPAtomFeedProperties atomFeedPr } } - private static String getURIForJob(FeedURI jobName, OpenERPAtomFeedProperties atomFeedProperties){ + private static String getURIForJob(Jobs jobName,OpenERPAtomFeedProperties atomFeedProperties){ switch (jobName){ case CUSTOMER_FEED: case SALEORDER_FEED: diff --git a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/client/WebClientProvider.java b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/client/WebClientProvider.java index ffb94763..273dfa61 100644 --- a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/client/WebClientProvider.java +++ b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/client/WebClientProvider.java @@ -1,7 +1,7 @@ package org.bahmni.feed.openerp.client; import org.bahmni.feed.openerp.OpenERPAtomFeedProperties; -import org.bahmni.feed.openerp.job.FeedURI; +import org.bahmni.feed.openerp.job.Jobs; import java.util.HashMap; import java.util.Map; @@ -38,7 +38,7 @@ public ReferenceDataWebClient referenceDataWebClient(){ return referenceDataWebClient; } - public AbstractWebClient getWebClient(FeedURI jobName){ + public AbstractWebClient getWebClient(Jobs jobName){ switch (jobName){ case CUSTOMER_FEED: return getOpenMRSWebClient() ; case DRUG_FEED: return getOpenMRSWebClient() ; 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 ae0382c9..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 @@ -60,7 +60,7 @@ private boolean orderAlreadyPresent(OpenERPOrders orders, OpenElisTestDetail tes } private boolean hasOrders() { - return !testDetails.isEmpty(); + return testDetails.size() > 0; } private void addNewOrder(OpenERPOrders orders, OpenElisTestDetail testDetail) { diff --git a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/job/FeedURI.java b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/job/Jobs.java similarity index 91% rename from openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/job/FeedURI.java rename to openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/job/Jobs.java index 5fbea626..a0497811 100644 --- a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/job/FeedURI.java +++ b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/job/Jobs.java @@ -1,7 +1,7 @@ package org.bahmni.feed.openerp.job; -public enum FeedURI { +public enum Jobs { CUSTOMER_FEED("customer.feed.generator.uri"), SALEORDER_FEED("saleorder.feed.generator.uri"), REFERENCE_DATA_FEED("referencedata.feed.generator.uri"), @@ -12,7 +12,7 @@ public enum FeedURI { private final String feedUriRef; - FeedURI(String feedUriRef) { + Jobs(String feedUriRef) { this.feedUriRef = feedUriRef; } diff --git a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/job/OpenERPCustomerFeedJob.java b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/job/OpenERPCustomerFeedJob.java index e2a18cf0..452a11ea 100644 --- a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/job/OpenERPCustomerFeedJob.java +++ b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/job/OpenERPCustomerFeedJob.java @@ -13,11 +13,11 @@ public OpenERPCustomerFeedJob(SimpleFeedJob openMRSFeedJob) throws FeedException } public void processFeed() { - openMRSFeedJob.processFeed(FeedURI.CUSTOMER_FEED); + openMRSFeedJob.processFeed(Jobs.CUSTOMER_FEED); } public void processFailedEvents() { - openMRSFeedJob.processFailedEvents(FeedURI.CUSTOMER_FEED); + openMRSFeedJob.processFailedEvents(Jobs.CUSTOMER_FEED); } } diff --git a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/job/OpenERPDrugFeedJob.java b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/job/OpenERPDrugFeedJob.java index 9a6a91bb..ebaeba29 100644 --- a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/job/OpenERPDrugFeedJob.java +++ b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/job/OpenERPDrugFeedJob.java @@ -14,11 +14,11 @@ public OpenERPDrugFeedJob(SimpleFeedJob openMRSFeedJob) throws FeedException { } public void processFeed() { - openMRSFeedJob.processFeed(FeedURI.DRUG_FEED); + openMRSFeedJob.processFeed(Jobs.DRUG_FEED); } public void processFailedEvents() { - openMRSFeedJob.processFailedEvents(FeedURI.DRUG_FEED); + openMRSFeedJob.processFailedEvents(Jobs.DRUG_FEED); } } diff --git a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/job/OpenERPLabFeedJob.java b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/job/OpenERPLabFeedJob.java index bbd4ef0a..f6658e58 100644 --- a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/job/OpenERPLabFeedJob.java +++ b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/job/OpenERPLabFeedJob.java @@ -14,11 +14,11 @@ public OpenERPLabFeedJob(SimpleFeedJob openMRSFeedJob) throws FeedException { } public void processFeed() { - openMRSFeedJob.processFeed(FeedURI.LAB_FEED); + openMRSFeedJob.processFeed(Jobs.LAB_FEED); } public void processFailedEvents() { - openMRSFeedJob.processFailedEvents(FeedURI.LAB_FEED); + openMRSFeedJob.processFailedEvents(Jobs.LAB_FEED); } } diff --git a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/job/OpenERPSaleOrderFeedJob.java b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/job/OpenERPSaleOrderFeedJob.java index eb0741d6..500361b5 100644 --- a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/job/OpenERPSaleOrderFeedJob.java +++ b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/job/OpenERPSaleOrderFeedJob.java @@ -13,10 +13,10 @@ public OpenERPSaleOrderFeedJob(SimpleFeedJob openMRSFeedJob) throws FeedExceptio } public void processFeed() { - openMRSFeedJob.processFeed(FeedURI.SALEORDER_FEED); + openMRSFeedJob.processFeed(Jobs.SALEORDER_FEED); } public void processFailedEvents() { - openMRSFeedJob.processFailedEvents(FeedURI.SALEORDER_FEED); + openMRSFeedJob.processFailedEvents(Jobs.SALEORDER_FEED); } } diff --git a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/job/OpenERPSaleableFeedJob.java b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/job/OpenERPSaleableFeedJob.java index 7863f584..322c9e9c 100644 --- a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/job/OpenERPSaleableFeedJob.java +++ b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/job/OpenERPSaleableFeedJob.java @@ -2,7 +2,7 @@ import com.sun.syndication.io.FeedException; -import static org.bahmni.feed.openerp.job.FeedURI.SALEABLE_FEED; +import static org.bahmni.feed.openerp.job.Jobs.SALEABLE_FEED; public class OpenERPSaleableFeedJob { private SimpleFeedJob feedJob; diff --git a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/job/OpenElisSaleOrderFeedJob.java b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/job/OpenElisSaleOrderFeedJob.java index 4e0ffa43..f1ae64a3 100644 --- a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/job/OpenElisSaleOrderFeedJob.java +++ b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/job/OpenElisSaleOrderFeedJob.java @@ -13,11 +13,11 @@ public OpenElisSaleOrderFeedJob(SimpleFeedJob openElisFeedJob) throws FeedExcept } public void processFeed() { - openElisFeedJob.processFeed(FeedURI.OPENELIS_SALEORDER_FEED); + openElisFeedJob.processFeed(Jobs.OPENELIS_SALEORDER_FEED); } public void processFailedEvents() { - openElisFeedJob.processFailedEvents(FeedURI.OPENELIS_SALEORDER_FEED); + openElisFeedJob.processFailedEvents(Jobs.OPENELIS_SALEORDER_FEED); } } diff --git a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/job/ReferenceDataFeedJob.java b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/job/ReferenceDataFeedJob.java index 2e0c6427..511bd695 100644 --- a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/job/ReferenceDataFeedJob.java +++ b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/job/ReferenceDataFeedJob.java @@ -13,11 +13,11 @@ public ReferenceDataFeedJob(SimpleFeedJob simpleFeedJob) throws FeedException { } public void processFeed() { - simpleFeedJob.processFeed(FeedURI.REFERENCE_DATA_FEED); + simpleFeedJob.processFeed(Jobs.REFERENCE_DATA_FEED); } public void processFailedEvents() { - simpleFeedJob.processFailedEvents(FeedURI.REFERENCE_DATA_FEED); + simpleFeedJob.processFailedEvents(Jobs.REFERENCE_DATA_FEED); } diff --git a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/job/SimpleFeedJob.java b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/job/SimpleFeedJob.java index 3984e689..63e98f1a 100644 --- a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/job/SimpleFeedJob.java +++ b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/job/SimpleFeedJob.java @@ -19,7 +19,7 @@ public SimpleFeedJob( this.atomFeedClientHelper = atomFeedClientHelper; } - public void processFeed(FeedURI jobName) { + public void processFeed(Jobs jobName) { try { logger.info(String.format("Processing Feed [%s] Job [%s]", jobName.getFeedUriRef(), jobName)); initAtomFeedClient(jobName); @@ -30,13 +30,13 @@ public void processFeed(FeedURI jobName) { } } - private void initAtomFeedClient(FeedURI jobName) { + private void initAtomFeedClient(Jobs jobName) { if(atomFeedClient == null){ atomFeedClient = (AtomFeedClient) atomFeedClientHelper.getAtomFeedClient(jobName); } } - public void processFailedEvents(FeedURI jobName) { + public void processFailedEvents(Jobs jobName) { try { logger.info(String.format("Processing failed events for Feed [%s]", jobName.getFeedUriRef())); initAtomFeedClient(jobName); @@ -49,7 +49,7 @@ public void processFailedEvents(FeedURI jobName) { } } - protected void handleAuthorizationException(Throwable e, FeedURI jobName) throws FeedException { + protected void handleAuthorizationException(Throwable e, Jobs jobName) throws FeedException { if (e != null && (ExceptionUtils.getStackTrace(e).contains("HTTP response code: 401") || ExceptionUtils.getStackTrace(e).contains("Bad response code of 403")) ) { diff --git a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/worker/Jobs.java b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/worker/Jobs.java deleted file mode 100644 index 1147183d..00000000 --- a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/worker/Jobs.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.bahmni.feed.openerp.worker; - -public enum Jobs { - DRUG_JOB("create.drug"); - - private final String jobRef; - - Jobs(String jobRef) { - this.jobRef = jobRef; - } - - public String getJobRef() { - return jobRef; - } -} diff --git a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/worker/OpenERPCustomerServiceEventWorker.java b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/worker/OpenERPCustomerServiceEventWorker.java index e33c67a4..e5c45f76 100644 --- a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/worker/OpenERPCustomerServiceEventWorker.java +++ b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/worker/OpenERPCustomerServiceEventWorker.java @@ -24,16 +24,13 @@ public class OpenERPCustomerServiceEventWorker implements EventWorker { OpenERPContext openERPContext; private String feedUrl; - - private String odooURL; private OpenMRSWebClient webClient; private String urlPrefix; private static Logger logger = LogManager.getLogger(OpenERPCustomerServiceEventWorker.class); - public OpenERPCustomerServiceEventWorker(String feedUrl, String odooURL, OpenERPContext openERPContext, OpenMRSWebClient webClient, String urlPrefix) { + public OpenERPCustomerServiceEventWorker(String feedUrl, OpenERPContext openERPContext, OpenMRSWebClient webClient, String urlPrefix) { this.feedUrl = feedUrl; - this.odooURL = odooURL; this.openERPContext = openERPContext; this.webClient = webClient; this.urlPrefix = urlPrefix; @@ -42,7 +39,7 @@ public OpenERPCustomerServiceEventWorker(String feedUrl, String odooURL, OpenERP @Override public void process(Event event) { try { - openERPContext.execute(mapRequest(event), odooURL); + openERPContext.execute(mapRequest(event)); } catch (Exception e) { throw new RuntimeException(e); } diff --git a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/worker/OpenERPDrugServiceEventWorker.java b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/worker/OpenERPDrugServiceEventWorker.java index 3e32d4b4..3ea2db41 100644 --- a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/worker/OpenERPDrugServiceEventWorker.java +++ b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/worker/OpenERPDrugServiceEventWorker.java @@ -18,21 +18,17 @@ public class OpenERPDrugServiceEventWorker implements EventWorker { - private static final Logger logger = LogManager.getLogger(OpenERPDrugServiceEventWorker.class); + private static Logger logger = LogManager.getLogger(OpenERPDrugServiceEventWorker.class); - private final OpenERPContext openERPContext; + private OpenERPContext openERPContext; private String feedUrl; + private OpenMRSWebClient webClient; + private String urlPrefix; - private final String odooURL; - private final OpenMRSWebClient webClient; - private final String urlPrefix; - - - public OpenERPDrugServiceEventWorker(String feedUrl, String odooURL, OpenERPContext openERPContext, OpenMRSWebClient openMRSWebClient, String urlPrefix) { + public OpenERPDrugServiceEventWorker(String feedUrl, OpenERPContext openERPContext, OpenMRSWebClient openMRSWebClient, String urlPrefix) { this.openERPContext = openERPContext; this.feedUrl = feedUrl; - this.odooURL = odooURL; this.webClient = openMRSWebClient; this.urlPrefix = urlPrefix; } @@ -41,7 +37,7 @@ public OpenERPDrugServiceEventWorker(String feedUrl, String odooURL, OpenERPCont public void process(Event event) { logger.debug("Processing the event [{}]", event.getContent()); try { - openERPContext.execute(mapRequest(event), odooURL); + openERPContext.execute(mapRequest(event)); } catch (Exception e) { throw new RuntimeException(e); } @@ -50,36 +46,35 @@ public void process(Event event) { private OpenERPRequest mapRequest(Event event) throws IOException { String drugJson = webClient.get(URI.create(urlPrefix + event.getContent())); OpenMRSDrug drug = ObjectMapperRepository.objectMapper.readValue(drugJson, OpenMRSDrug.class); + return new OpenERPRequest("atom.event.worker", "process_event", buildParameters(event,drug)); } - private List buildParameters(Event event, OpenMRSDrug drug) { + private List buildParameters(Event event,OpenMRSDrug drug) { List parameters = new ArrayList<>(); - addToParametersIfNotEmpty(parameters, "name", drug.getName()); - addToParametersIfNotEmpty(parameters, "shortName", drug.getShortName()); - addToParametersIfNotEmpty(parameters, "uuid", drug.getUuid()); - addToParametersIfNotEmpty(parameters, "combination", drug.getCombination()); - addToParametersIfNotEmpty(parameters, "strength", drug.getStrength()); - addToParametersIfNotEmpty(parameters, "dosageForm", drug.getDosageForm()); - addToParametersIfNotEmpty(parameters, "genericName", drug.getGenericName()); - addToParametersIfNotEmpty(parameters, "maximumDose", drug.getMaximumDose()); - addToParametersIfNotEmpty(parameters, "minimumDose", drug.getMinimumDose()); - addToParametersIfNotEmpty(parameters, "last_read_entry_id", event.getId()); - addToParametersIfNotEmpty(parameters, "category", Jobs.DRUG_JOB.getJobRef()); - addToParametersIfNotEmpty(parameters, "feed_uri_for_last_read_entry", event.getFeedUri()); + parameters.add(new Parameter("name",drug.getName())); + parameters.add(new Parameter("shortName",drug.getShortName())); + parameters.add(new Parameter("uuid",drug.getUuid())); + parameters.add(new Parameter("combination",drug.getCombination())); + parameters.add(new Parameter("strength",drug.getStrength())); + parameters.add(new Parameter("dosageForm",drug.getDosageForm())); + parameters.add(new Parameter("genericName",drug.getGenericName())); + parameters.add(new Parameter("maximumDose",drug.getMaximumDose())); + parameters.add(new Parameter("minimumDose",drug.getMinimumDose())); + + parameters.add(new Parameter("last_read_entry_id",event.getId())); + parameters.add(new Parameter("category", "create.drug")); + parameters.add(new Parameter("feed_uri_for_last_read_entry",event.getFeedUri())); + if (event.getFeedUri() == null) { - parameters.add(new Parameter("is_failed_event", "1", "boolean")); + parameters.add(new Parameter("is_failed_event","1","boolean")); } - return parameters; - } - private void addToParametersIfNotEmpty(List parameters, String name, String value) { - if (value != null && !value.isEmpty()) { - parameters.add(new Parameter(name, value)); - } + return parameters; } @Override public void cleanUp(Event event) { + } } diff --git a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/worker/OpenERPLabOrderTypeServiceEventWorker.java b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/worker/OpenERPLabOrderTypeServiceEventWorker.java index f2e5f2d0..a53efa60 100644 --- a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/worker/OpenERPLabOrderTypeServiceEventWorker.java +++ b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/worker/OpenERPLabOrderTypeServiceEventWorker.java @@ -23,17 +23,14 @@ public class OpenERPLabOrderTypeServiceEventWorker implements EventWorker { private OpenERPContext openERPContext; private String feedUrl; - - private String odooURL; private OpenMRSWebClient webClient; private String urlPrefix; private Map labOrderTypeEventMap = new HashMap<>(); - public OpenERPLabOrderTypeServiceEventWorker(String feedUrl, String odooURL, OpenERPContext openERPContext, OpenMRSWebClient openMRSWebClient, String urlPrefix) { + public OpenERPLabOrderTypeServiceEventWorker(String feedUrl, OpenERPContext openERPContext, OpenMRSWebClient openMRSWebClient, String urlPrefix) { this.openERPContext = openERPContext; this.feedUrl = feedUrl; - this.odooURL = odooURL; this.webClient = openMRSWebClient; this.urlPrefix = urlPrefix; labOrderTypeEventMap.put(OpenMRSRadiologyTestEvent.RADIOLOGY_TEST_EVENT_NAME, new OpenMRSRadiologyTestEvent()); @@ -47,7 +44,7 @@ public void process(Event event) { try { OpenMRSLabOrderTypeEvent openMRSLabOrderTypeEvent = labOrderTypeEventMap.get(event.getTitle()); if(openMRSLabOrderTypeEvent == null) return ; - openERPContext.execute(mapRequest(event, openMRSLabOrderTypeEvent), odooURL); + openERPContext.execute(mapRequest(event, openMRSLabOrderTypeEvent)); } catch (Exception e) { throw new RuntimeException(e); } diff --git a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/worker/OpenERPSaleOrderEventWorker.java b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/worker/OpenERPSaleOrderEventWorker.java index bdddc3b0..e00b5baa 100644 --- a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/worker/OpenERPSaleOrderEventWorker.java +++ b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/worker/OpenERPSaleOrderEventWorker.java @@ -19,17 +19,14 @@ public class OpenERPSaleOrderEventWorker implements EventWorker { OpenERPContext openERPContext; private String feedUrl; - - private String odooURL; private OpenMRSWebClient webClient; private String urlPrefix; private static Logger logger = LogManager.getLogger(OpenERPSaleOrderEventWorker.class); - public OpenERPSaleOrderEventWorker(String feedUrl, String odooURL, OpenERPContext openERPContext, OpenMRSWebClient webClient, String urlPrefix) { + public OpenERPSaleOrderEventWorker(String feedUrl, OpenERPContext openERPContext, OpenMRSWebClient webClient, String urlPrefix) { this.feedUrl = feedUrl; - this.odooURL = odooURL; this.openERPContext = openERPContext; this.webClient = webClient; this.urlPrefix = urlPrefix; @@ -41,7 +38,7 @@ public void process(Event event) { OpenERPRequest openERPRequest = mapRequest(event); if (!openERPRequest.shouldERPConsumeEvent()) return; - openERPContext.execute(openERPRequest, odooURL); + openERPContext.execute(openERPRequest); } catch (Exception e) { throw new RuntimeException(e); } diff --git a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/worker/OpenERPSaleableResourceWorker.java b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/worker/OpenERPSaleableResourceWorker.java index ef2ad7d3..2f4fae19 100644 --- a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/worker/OpenERPSaleableResourceWorker.java +++ b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/worker/OpenERPSaleableResourceWorker.java @@ -26,14 +26,11 @@ public class OpenERPSaleableResourceWorker implements EventWorker { private OpenMRSWebClient openMRSWebClient; private String urlPrefix; - private String odooURL; - private static Logger logger = LogManager.getLogger(OpenERPSaleableResourceWorker.class); - public OpenERPSaleableResourceWorker(String feedUrl, String odooURL, OpenERPContext openERPContext, OpenMRSWebClient openMRSWebClient, String urlPrefix) { + public OpenERPSaleableResourceWorker(String feedUrl, OpenERPContext openERPContext, OpenMRSWebClient openMRSWebClient, String urlPrefix) { this.openERPContext = openERPContext; this.feedUrl = feedUrl; - this.odooURL = odooURL; this.openMRSWebClient = openMRSWebClient; this.urlPrefix = urlPrefix; } @@ -47,7 +44,7 @@ public void process(Event event) { logger.info(String.format("Resource is not a saleable resource. Ignoring. Event [%s]", event.getId())); return; } - openERPContext.execute(mapToOpenERPRequest(event, resource), odooURL); + openERPContext.execute(mapToOpenERPRequest(event, resource)); } catch (Exception e) { logger.error(String.format("Error occurred while trying to process Saleable Event [%s]", event.getId()), e); throw new RuntimeException(String.format("Error occurred while trying to process Saleable Event [%s]", event.getId()), e); 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 a22dcd25..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 @@ -20,13 +20,10 @@ public class OpenElisSaleOrderEventWorker implements EventWorker { private final OpenElisWebClient webClient; private final String urlPrefix; - private String odooURL; - private static final Logger logger = LogManager.getLogger(OpenElisSaleOrderEventWorker.class); - public OpenElisSaleOrderEventWorker(String feedUrl, String odooURL, OpenERPContext openERPContext, OpenElisWebClient webClient, String urlPrefix) { + public OpenElisSaleOrderEventWorker(String feedUrl, OpenERPContext openERPContext, OpenElisWebClient webClient, String urlPrefix) { this.feedUrl = feedUrl; - this.odooURL = odooURL; this.openERPContext = openERPContext; this.webClient = webClient; this.urlPrefix = urlPrefix; @@ -39,7 +36,7 @@ public void process(Event event) { OpenERPRequest openERPRequest = mapRequest(event); if (!openERPRequest.shouldERPConsumeEvent()) return; - openERPContext.execute(openERPRequest, odooURL); + openERPContext.execute(openERPRequest); } catch (Exception e) { logger.error("Error processing openelis sale order event : {}", event.toString(), e); throw new RuntimeException(e); diff --git a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/worker/WorkerFactory.java b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/worker/WorkerFactory.java index 176e0992..b373bc45 100644 --- a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/worker/WorkerFactory.java +++ b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/worker/WorkerFactory.java @@ -1,6 +1,6 @@ package org.bahmni.feed.openerp.worker; -import org.bahmni.feed.openerp.job.FeedURI; +import org.bahmni.feed.openerp.job.Jobs; import org.bahmni.feed.openerp.client.WebClientProvider; import org.bahmni.openerp.web.client.strategy.OpenERPContext; import org.ict4h.atomfeed.client.service.EventWorker; @@ -14,14 +14,14 @@ public WorkerFactory(WebClientProvider webClientProvider) { } - public EventWorker getWorker(FeedURI jobName, String feedUrl, String odooURL, OpenERPContext openERPContext, String urlPrefix) { - switch (jobName) { - case CUSTOMER_FEED: return new OpenERPCustomerServiceEventWorker(feedUrl, odooURL, openERPContext, webClientProvider.getOpenMRSWebClient(), urlPrefix); - case SALEORDER_FEED: return new OpenERPSaleOrderEventWorker(feedUrl, odooURL, openERPContext, webClientProvider.getOpenMRSWebClient(), urlPrefix); - case OPENELIS_SALEORDER_FEED: return new OpenElisSaleOrderEventWorker(feedUrl, odooURL, openERPContext, webClientProvider.openElisWebClient(), urlPrefix); - case DRUG_FEED: return new OpenERPDrugServiceEventWorker(feedUrl, odooURL, openERPContext, webClientProvider.getOpenMRSWebClient(), urlPrefix); - case LAB_FEED: return new OpenERPLabOrderTypeServiceEventWorker(feedUrl, odooURL, openERPContext, webClientProvider.getOpenMRSWebClient(), urlPrefix); - case SALEABLE_FEED: return new OpenERPSaleableResourceWorker(feedUrl, odooURL, openERPContext, webClientProvider.getOpenMRSWebClient(), urlPrefix); + public EventWorker getWorker(Jobs jobName, String feedUrl, OpenERPContext openERPContext, String urlPrefix) { + switch (jobName){ + case CUSTOMER_FEED: return new OpenERPCustomerServiceEventWorker(feedUrl, openERPContext, webClientProvider.getOpenMRSWebClient(), urlPrefix); + case SALEORDER_FEED: return new OpenERPSaleOrderEventWorker(feedUrl, openERPContext, webClientProvider.getOpenMRSWebClient(), urlPrefix); + case OPENELIS_SALEORDER_FEED: return new OpenElisSaleOrderEventWorker(feedUrl, openERPContext, webClientProvider.openElisWebClient(), urlPrefix); + case DRUG_FEED: return new OpenERPDrugServiceEventWorker(feedUrl, openERPContext, webClientProvider.getOpenMRSWebClient(), urlPrefix); + case LAB_FEED: return new OpenERPLabOrderTypeServiceEventWorker(feedUrl, openERPContext, webClientProvider.getOpenMRSWebClient(), urlPrefix); + case SALEABLE_FEED: return new OpenERPSaleableResourceWorker(feedUrl, openERPContext, webClientProvider.getOpenMRSWebClient(), urlPrefix); } throw new RuntimeException(String.format("No worker for %s", jobName)); } diff --git a/openerp-atomfeed-service/src/main/resources/erp-atomfeed.properties b/openerp-atomfeed-service/src/main/resources/erp-atomfeed.properties index 9edcc32f..3e5969d5 100644 --- a/openerp-atomfeed-service/src/main/resources/erp-atomfeed.properties +++ b/openerp-atomfeed-service/src/main/resources/erp-atomfeed.properties @@ -50,12 +50,4 @@ openmrs.auth.uri=http://localhost:8050/openmrs/ws/rest/v1/session scheduler.initial.delay=60000 -referencedata.endpoint=http://localhost:8050/reference-data - -customer.endpoint=/api/bahmni-customer -drug.endpoint=/api/bahmni-drug -lab.endpoint=/api/bahmni-lab-test -radiology.endpoint=/api/bahmni-radiology-test -labpanel.endpoint=/api/bahmni-lab-panel -saleable.endpoint=/api/bahmni-service-sale -saleorder.endpoint=/api/bahmni-saleorder +referencedata.endpoint=http://localhost:8050/reference-data \ No newline at end of file diff --git a/openerp-atomfeed-service/src/main/resources/jobs-context.xml b/openerp-atomfeed-service/src/main/resources/jobs-context.xml index 696ff6ba..f079463f 100644 --- a/openerp-atomfeed-service/src/main/resources/jobs-context.xml +++ b/openerp-atomfeed-service/src/main/resources/jobs-context.xml @@ -250,8 +250,6 @@ - - diff --git a/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/client/OpenERPCustomerFeedIT.java b/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/client/OpenERPCustomerFeedIT.java index 4d2d0ab9..600f229b 100644 --- a/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/client/OpenERPCustomerFeedIT.java +++ b/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/client/OpenERPCustomerFeedIT.java @@ -2,12 +2,12 @@ import com.sun.syndication.feed.atom.Content; import com.sun.syndication.feed.atom.Entry; -import com.sun.syndication.feed.atom.Link; import com.sun.syndication.feed.atom.Feed; +import com.sun.syndication.feed.atom.Link; import com.sun.syndication.io.FeedException; import org.bahmni.feed.openerp.ObjectMapperRepository; import org.bahmni.feed.openerp.OpenERPAtomFeedProperties; -import org.bahmni.feed.openerp.job.FeedURI; +import org.bahmni.feed.openerp.job.Jobs; import org.bahmni.feed.openerp.job.OpenERPCustomerFeedJob; import org.bahmni.feed.openerp.job.SimpleFeedJob; import org.bahmni.feed.openerp.worker.OpenERPCustomerServiceEventWorker; @@ -164,7 +164,6 @@ private List getEntries(FeedEnumerator feedEnumerator) { @Test public void shouldCreateCustomerInOpenERP() throws URISyntaxException, FeedException { String feedUrl = "http://host/patients/notifications"; - String odooURL = "http://client/patients/notifications"; String feedname = "customer.feed.generator.uri"; when(atomFeedProperties.getFeedUri(feedname)).thenReturn(feedUrl); @@ -190,14 +189,14 @@ public void shouldCreateCustomerInOpenERP() throws URISyntaxException, FeedExcep authenticationResponse.setSessionId("sessionIdValue"); when(openMRSAuthenticator.authenticate("mrsuser", "mrspwd", ObjectMapperRepository.objectMapper)).thenReturn(authenticationResponse); - when(webClientProvider.getWebClient(any(FeedURI.class))).thenReturn(webClient); - when(workerFactory.getWorker(FeedURI.CUSTOMER_FEED, feedUrl,odooURL, openERPContext, "http://mrs.auth.uri")).thenReturn(openERPCustomerServiceEventWorker); + when(webClientProvider.getWebClient(any(Jobs.class))).thenReturn(webClient); + when(workerFactory.getWorker(Jobs.CUSTOMER_FEED, feedUrl, openERPContext, "http://mrs.auth.uri")).thenReturn(openERPCustomerServiceEventWorker); AtomFeedClientHelper clientHelper = mock(AtomFeedClientHelper.class); AtomFeedClient atomFeedClient = new AtomFeedClient(allFeedsMock, allMarkersJdbc, allFailedEvents, FeedClientFactory.atomFeedProperties(atomFeedProperties), transactionSupport, new URI(feedUrl), openERPCustomerServiceEventWorker); - when(clientHelper.getAtomFeedClient(FeedURI.CUSTOMER_FEED)). + when(clientHelper.getAtomFeedClient(Jobs.CUSTOMER_FEED)). thenReturn(atomFeedClient); SimpleFeedJob openMRSFeedJob = new SimpleFeedJob(clientHelper); diff --git a/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/event/OpenERPCustomerServiceEventWorkerTest.java b/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/event/OpenERPCustomerServiceEventWorkerTest.java index bafedc24..fa3fc111 100644 --- a/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/event/OpenERPCustomerServiceEventWorkerTest.java +++ b/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/event/OpenERPCustomerServiceEventWorkerTest.java @@ -28,8 +28,6 @@ public class OpenERPCustomerServiceEventWorkerTest { private OpenMRSWebClient mockWebClient; private String MRSURLPrefix; - private String odooURL = "https://client/openmrs/ws/atomfeed/customer/recent"; - @Before public void setUp() throws Exception { openERPContext = mock(OpenERPContext.class); @@ -40,7 +38,7 @@ public void setUp() throws Exception { public void shouldCallOpenERPClientWithRightParameters() throws FileNotFoundException { MRSURLPrefix = "urlPrefixTest"; OpenERPCustomerServiceEventWorker customerServiceEventWorker = - new OpenERPCustomerServiceEventWorker("www.openmrs.com", odooURL, openERPContext, mockWebClient, MRSURLPrefix); + new OpenERPCustomerServiceEventWorker("www.openmrs.com", openERPContext, mockWebClient, MRSURLPrefix); InputStream resourceAsStream = this.getClass().getClassLoader().getResourceAsStream("patientResource.xml"); String patientResource = new Scanner(resourceAsStream).useDelimiter("\\Z").next(); @@ -50,7 +48,7 @@ public void shouldCallOpenERPClientWithRightParameters() throws FileNotFoundExce customerServiceEventWorker.process(event); - verify(openERPContext).execute(createOpenERPRequest(event), odooURL); + verify(openERPContext).execute(createOpenERPRequest(event)); } diff --git a/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/job/OpenERPDrugFeedJobTest.java b/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/job/OpenERPDrugFeedJobTest.java index b737cf31..2cb080e1 100644 --- a/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/job/OpenERPDrugFeedJobTest.java +++ b/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/job/OpenERPDrugFeedJobTest.java @@ -6,7 +6,7 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import static org.bahmni.feed.openerp.job.FeedURI.DRUG_FEED; +import static org.bahmni.feed.openerp.job.Jobs.DRUG_FEED; import static org.mockito.Mockito.verify; public class OpenERPDrugFeedJobTest { diff --git a/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/job/OpenERPLabFeedJobTest.java b/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/job/OpenERPLabFeedJobTest.java index 2a6265ee..58edfe02 100644 --- a/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/job/OpenERPLabFeedJobTest.java +++ b/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/job/OpenERPLabFeedJobTest.java @@ -6,7 +6,7 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import static org.bahmni.feed.openerp.job.FeedURI.LAB_FEED; +import static org.bahmni.feed.openerp.job.Jobs.LAB_FEED; import static org.mockito.Mockito.verify; public class OpenERPLabFeedJobTest { diff --git a/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/job/OpenERPSaleableFeedJobTest.java b/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/job/OpenERPSaleableFeedJobTest.java index f45dcd21..453886a1 100644 --- a/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/job/OpenERPSaleableFeedJobTest.java +++ b/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/job/OpenERPSaleableFeedJobTest.java @@ -6,7 +6,7 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import static org.bahmni.feed.openerp.job.FeedURI.SALEABLE_FEED; +import static org.bahmni.feed.openerp.job.Jobs.SALEABLE_FEED; import static org.mockito.Mockito.verify; public class OpenERPSaleableFeedJobTest { diff --git a/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/server/AtomFeedServerIT.java b/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/server/AtomFeedServerIT.java index 6e6f5450..9acaf248 100644 --- a/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/server/AtomFeedServerIT.java +++ b/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/server/AtomFeedServerIT.java @@ -4,6 +4,7 @@ import org.bahmni.feed.openerp.utils.MVCTestUtils; import org.ict4h.atomfeed.Configuration; import org.ict4h.atomfeed.IntegrationTest; +import org.ict4h.atomfeed.client.service.AtomFeedClient; import org.ict4h.atomfeed.jdbc.JdbcConnectionProvider; import org.ict4h.atomfeed.jdbc.JdbcUtils; import org.ict4h.atomfeed.server.domain.EventRecord; diff --git a/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/worker/OpenERPDrugServiceEventWorkerTest.java b/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/worker/OpenERPDrugServiceEventWorkerTest.java index 0638330a..cd13c245 100644 --- a/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/worker/OpenERPDrugServiceEventWorkerTest.java +++ b/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/worker/OpenERPDrugServiceEventWorkerTest.java @@ -19,7 +19,6 @@ import java.util.List; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -33,7 +32,6 @@ public class OpenERPDrugServiceEventWorkerTest { private OpenMRSWebClient webClient; private String feedUri = "http://feeduri"; - private String odooURL = "http://client/prefix/"; private String drugOrderJson; private OpenERPDrugServiceEventWorker worker; @@ -51,7 +49,7 @@ public void setUp(){ " \"name\": \"Paracetamol 250mg\"\n" + "}"; MockitoAnnotations.initMocks(this); - worker = new OpenERPDrugServiceEventWorker(feedUri,odooURL,openERPContext,webClient,"http://prefix/"); + worker = new OpenERPDrugServiceEventWorker(feedUri,openERPContext,webClient,"http://prefix/"); } @@ -62,7 +60,7 @@ public void testProcess() throws IOException { worker.process(event); ArgumentCaptor erpRequestCatcher = ArgumentCaptor.forClass(OpenERPRequest.class); - verify(openERPContext).execute(erpRequestCatcher.capture(),eq(odooURL)); + verify(openERPContext).execute(erpRequestCatcher.capture()); OpenERPRequest openERPRequest = erpRequestCatcher.getValue(); List actualParameters = openERPRequest.getParameters(); @@ -89,7 +87,7 @@ public void testFailedEvent() throws IOException{ worker.process(event); ArgumentCaptor erpRequestCatcher = ArgumentCaptor.forClass(OpenERPRequest.class); - verify(openERPContext).execute(erpRequestCatcher.capture(),eq(odooURL)); + verify(openERPContext).execute(erpRequestCatcher.capture()); OpenERPRequest openERPRequest = erpRequestCatcher.getValue(); List actualParameters = openERPRequest.getParameters(); diff --git a/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/worker/OpenERPLabOrderTypeServiceEventWorkerTest.java b/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/worker/OpenERPLabOrderTypeServiceEventWorkerTest.java index 0c0c4c6f..de8bb7cd 100644 --- a/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/worker/OpenERPLabOrderTypeServiceEventWorkerTest.java +++ b/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/worker/OpenERPLabOrderTypeServiceEventWorkerTest.java @@ -21,7 +21,6 @@ import static org.bahmni.feed.openerp.domain.labOrderType.OpenMRSLabPanelEvent.LAB_PANEL_EVENT_NAME; import static org.bahmni.feed.openerp.domain.labOrderType.OpenMRSLabTestEvent.LAB_TEST_EVENT_NAME; import static org.bahmni.feed.openerp.domain.labOrderType.OpenMRSRadiologyTestEvent.RADIOLOGY_TEST_EVENT_NAME; -import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -35,8 +34,6 @@ public class OpenERPLabOrderTypeServiceEventWorkerTest { private OpenMRSWebClient webClient; private String feedUri = "http://feeduri"; - - private String odooURL = "http://client/prefix/"; private OpenERPLabOrderTypeServiceEventWorker worker; @Before @@ -87,7 +84,7 @@ public void setUp() { "}"; MockitoAnnotations.initMocks(this); - worker = new OpenERPLabOrderTypeServiceEventWorker(feedUri, odooURL, openERPContext, webClient, "http://prefix/"); + worker = new OpenERPLabOrderTypeServiceEventWorker(feedUri, openERPContext, webClient, "http://prefix/"); when(webClient.get(URI.create("http://prefix/radiology"))).thenReturn(radiologyTestJson); when(webClient.get(URI.create("http://prefix/test"))).thenReturn(labTestJson); when(webClient.get(URI.create("http://prefix/panel"))).thenReturn(labPanelJson); @@ -100,7 +97,7 @@ public void shouldProcessRadiologyTestEvent() throws IOException { worker.process(event); ArgumentCaptor erpRequestCatcher = ArgumentCaptor.forClass(OpenERPRequest.class); - verify(openERPContext).execute(erpRequestCatcher.capture(),eq(odooURL)); + verify(openERPContext).execute(erpRequestCatcher.capture()); OpenERPRequest openERPRequest = erpRequestCatcher.getValue(); List parameters = openERPRequest.getParameters(); @@ -120,7 +117,7 @@ public void shouldProcessLabTestEvent() throws IOException { worker.process(event); ArgumentCaptor erpRequestCatcher = ArgumentCaptor.forClass(OpenERPRequest.class); - verify(openERPContext).execute(erpRequestCatcher.capture(), eq(odooURL)); + verify(openERPContext).execute(erpRequestCatcher.capture()); OpenERPRequest openERPRequest = erpRequestCatcher.getValue(); List parameters = openERPRequest.getParameters(); @@ -139,7 +136,7 @@ public void shouldProcessLabPanelEvent() throws Exception { worker.process(event); ArgumentCaptor erpRequestCatcher = ArgumentCaptor.forClass(OpenERPRequest.class); - verify(openERPContext).execute(erpRequestCatcher.capture(), eq(odooURL)); + verify(openERPContext).execute(erpRequestCatcher.capture()); OpenERPRequest openERPRequest = erpRequestCatcher.getValue(); List parameters = openERPRequest.getParameters(); @@ -158,7 +155,7 @@ public void testRadiologyFailedEvent() throws IOException { worker.process(event); ArgumentCaptor erpRequestCatcher = ArgumentCaptor.forClass(OpenERPRequest.class); - verify(openERPContext).execute(erpRequestCatcher.capture(), eq(odooURL)); + verify(openERPContext).execute(erpRequestCatcher.capture()); OpenERPRequest openERPRequest = erpRequestCatcher.getValue(); List actualParameters = openERPRequest.getParameters(); @@ -172,7 +169,7 @@ public void testTestFailedEvent() throws IOException { worker.process(event); ArgumentCaptor erpRequestCatcher = ArgumentCaptor.forClass(OpenERPRequest.class); - verify(openERPContext).execute(erpRequestCatcher.capture(), eq(odooURL)); + verify(openERPContext).execute(erpRequestCatcher.capture()); OpenERPRequest openERPRequest = erpRequestCatcher.getValue(); List actualParameters = openERPRequest.getParameters(); 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 d4b1286c..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 @@ -87,8 +87,7 @@ public void create_SaleOrder_In_ERP_For_Lab_Order(){ // when(openERPContext.read(any(String.class),any(Vector.class), any(Vector.class))).thenReturn(new Object[]{fieldMap}); String feedUrl = "http://xxxx/encounter/feed/2"; - String odooURL = "http://xxxx/encounter/feed/2"; - OpenERPSaleOrderEventWorker eventWorker = new OpenERPSaleOrderEventWorker(feedUrl,odooURL,openERPContext, webClient,"http://mrs.auth.uri"); + OpenERPSaleOrderEventWorker eventWorker = new OpenERPSaleOrderEventWorker(feedUrl,openERPContext,webClient,"http://mrs.auth.uri"); Event event = new Event("Test",feedUrl); eventWorker.process(event); } @@ -119,8 +118,7 @@ public void create_SaleOrder_For_Bed_In_ERP_When_Bed_Is_Assigned() { String feedUrl = "http://xxxx/encounter/feed/2"; Event event = new Event("Test", feedUrl); - String odooURL = "http://xxxx/encounter/feed/2"; - OpenERPSaleOrderEventWorker eventWorker = new OpenERPSaleOrderEventWorker(feedUrl,odooURL,openERPContext, webClient,"http://mrs.auth.uri"); + OpenERPSaleOrderEventWorker eventWorker = new OpenERPSaleOrderEventWorker(feedUrl, openERPContext, webClient,"http://mrs.auth.uri"); eventWorker.process(event); } diff --git a/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/worker/OpenERPSaleableResourceWorkerTest.java b/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/worker/OpenERPSaleableResourceWorkerTest.java index 376b4357..2ffc7ebc 100644 --- a/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/worker/OpenERPSaleableResourceWorkerTest.java +++ b/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/worker/OpenERPSaleableResourceWorkerTest.java @@ -18,7 +18,6 @@ import java.util.List; import static org.bahmni.feed.openerp.worker.OpenERPSaleableResourceWorker.ERP_EVENT_CATEGORY; -import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -37,8 +36,6 @@ public class OpenERPSaleableResourceWorkerTest { private String eventUrl = "https://mybahmni/" + eventContent; private String feedUri = "https://mybahmni/openmrs/ws/atomfeed/saleable/recent"; - private String odooURL = "https://client/openmrs/ws/atomfeed/saleable/recent"; - String sampleProcedureJsonWithSaleableAsFalse = "{\n" + @@ -62,7 +59,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(feedUri, openERPContext, webClient, "https://mybahmni/"); when(webClient.get(URI.create(eventUrl))).thenReturn(sampleProcedureJson); } @@ -71,7 +68,7 @@ public void shouldProcessSaleableTypeEvent() throws Exception { Event event = new Event("1", eventContent, "Dressing", feedUri, new Date()); worker.process(event); ArgumentCaptor erpRequestCatcher = ArgumentCaptor.forClass(OpenERPRequest.class); - verify(openERPContext).execute(erpRequestCatcher.capture(), eq(odooURL)); + verify(openERPContext).execute(erpRequestCatcher.capture()); OpenERPRequest openERPRequest = erpRequestCatcher.getValue(); List parameters = openERPRequest.getParameters(); @@ -93,7 +90,7 @@ public void shouldUpdateAsInactiveWhenNotSaleableEvenWhenMRSResourceIsActive() t Event event = new Event("1", eventContent, "Dressing", feedUri, new Date()); worker.process(event); ArgumentCaptor erpRequestCatcher = ArgumentCaptor.forClass(OpenERPRequest.class); - verify(openERPContext).execute(erpRequestCatcher.capture(), eq(odooURL)); + verify(openERPContext).execute(erpRequestCatcher.capture()); List parameters = erpRequestCatcher.getValue().getParameters(); Assert.assertTrue(parameters.contains(new Parameter("name", "Dressing of Wound"))); diff --git a/openerp-client/pom.xml b/openerp-client/pom.xml index a516e2c6..5903255f 100644 --- a/openerp-client/pom.xml +++ b/openerp-client/pom.xml @@ -59,32 +59,6 @@ - - org.springframework - spring-webflux - ${spring.version} - - - commons-logging - commons-logging - - - - - io.projectreactor.netty - reactor-netty-http - 1.1.13 - - - org.springframework.boot - spring-boot-starter-webflux - 3.0.0 - - - com.fasterxml.jackson.dataformat - jackson-dataformat-xml - 2.15.2 - org.springframework spring-web @@ -99,11 +73,6 @@ org.apache.velocity velocity-engine-core - - org.apache.velocity.tools - velocity-tools-generic - 3.1 - org.apache.httpcomponents httpclient 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 ee690b92..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,6 +5,6 @@ import java.util.Vector; public interface OpenERPClientStrategy { - Object execute(OpenERPRequest openERPRequest, String URI); + Object execute(OpenERPRequest openERPRequest); } \ 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 aecc8ad4..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,8 +17,8 @@ public OpenERPContext(OpenERPClientStrategy openERPClient) { this.openERPClient = openERPClient; } - public Object execute(OpenERPRequest openERPRequest, String URI) { - return openERPClient.execute(openERPRequest, URI); + public Object execute(OpenERPRequest openERPRequest) { + return openERPClient.execute(openERPRequest); } } \ No newline at end of file diff --git a/openerp-client/src/main/java/org/bahmni/openerp/web/client/strategy/implementation/OdooRESTClient.java b/openerp-client/src/main/java/org/bahmni/openerp/web/client/strategy/implementation/OdooRESTClient.java deleted file mode 100644 index 07af23eb..00000000 --- a/openerp-client/src/main/java/org/bahmni/openerp/web/client/strategy/implementation/OdooRESTClient.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.bahmni.openerp.web.client.strategy.implementation; - -import org.bahmni.openerp.web.OpenERPProperties; -import org.bahmni.openerp.web.client.strategy.OpenERPClientStrategy; -import org.bahmni.openerp.web.http.client.RestClient; -import org.bahmni.openerp.web.request.OpenERPRequest; -import org.bahmni.openerp.web.request.builder.RequestBuilder; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Lazy; -import org.springframework.stereotype.Service; - -import java.util.UUID; - -@Service -@Lazy -public class OdooRESTClient implements OpenERPClientStrategy { - private final RestClient restClient; - - @Autowired - public OdooRESTClient(OpenERPProperties openERPProperties) { - String host = openERPProperties.getHost(); - int port = openERPProperties.getPort(); - String user = openERPProperties.getUser(); - String password = openERPProperties.getPassword(); - int connectionTimeoutInMilliseconds = openERPProperties.getConnectionTimeoutInMilliseconds(); - restClient = new RestClient("http://" + host + ":" + port, user, password, connectionTimeoutInMilliseconds); - } - - @Override - public Object execute(OpenERPRequest openERPRequest, String URI) { - String requestBody = RequestBuilder.buildNewRestRequest(openERPRequest, UUID.randomUUID().toString()); - return restClient.post(URI, requestBody); - } -} 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 81bf3659..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 @@ -5,7 +5,7 @@ import org.bahmni.openerp.web.client.OpenERPResponseErrorValidator; import org.bahmni.openerp.web.client.strategy.OpenERPClientStrategy; import org.bahmni.openerp.web.request.OpenERPRequest; -import org.bahmni.openerp.web.http.client.XMLClient; +import org.bahmni.openerp.web.http.client.HttpClient; import org.apache.xmlrpc.XmlRpcException; import org.apache.xmlrpc.client.XmlRpcClient; import org.apache.xmlrpc.client.XmlRpcClientConfigImpl; @@ -36,11 +36,11 @@ public class OpenERPXMLClient implements OpenERPClientStrategy { private Object id; private XmlRpcClient xmlRpcClient; - private final XMLClient xmlClient; + private final HttpClient httpClient; @Autowired - public OpenERPXMLClient(XMLClient xmlClient, OpenERPProperties openERPProperties) { - this.xmlClient = xmlClient; + public OpenERPXMLClient(HttpClient httpClient, OpenERPProperties openERPProperties) { + this.httpClient = httpClient; host = openERPProperties.getHost(); port = openERPProperties.getPort(); database = openERPProperties.getDatabase(); @@ -67,7 +67,7 @@ private void login() { } @Override - public Object execute(OpenERPRequest openERPRequest, String URI) { + public Object execute(OpenERPRequest openERPRequest){ login(); String request = RequestBuilder.buildNewXMLRequest(openERPRequest, id, database, password); String response = httpClient().post("http://" + host + ":" + port + XML_RPC_OBJECT_ENDPOINT, request); @@ -84,9 +84,9 @@ private Object executeRPC(XmlRpcClient loginRpcClient, Vector params, String met } } - private XMLClient httpClient() { - xmlClient.setTimeout(replyTimeoutInMilliseconds); - return xmlClient; + private HttpClient httpClient() { + httpClient.setTimeout(replyTimeoutInMilliseconds); + return httpClient; } private XmlRpcClient xmlRpcClient(String endpoint) { @@ -108,6 +108,7 @@ private XmlRpcClient createRPCClient() { clientConfiguration.setEnabledForExceptions(true); clientConfiguration.setConnectionTimeout(connectionTimeoutInMilliseconds); clientConfiguration.setReplyTimeout(replyTimeoutInMilliseconds); + XmlRpcClient rpcClient = new XmlRpcClient(); rpcClient.setTransportFactory(new XmlRpcSun15HttpTransportFactory(rpcClient)); rpcClient.setConfig(clientConfiguration); diff --git a/openerp-client/src/main/java/org/bahmni/openerp/web/http/client/XMLClient.java b/openerp-client/src/main/java/org/bahmni/openerp/web/http/client/HttpClient.java similarity index 93% rename from openerp-client/src/main/java/org/bahmni/openerp/web/http/client/XMLClient.java rename to openerp-client/src/main/java/org/bahmni/openerp/web/http/client/HttpClient.java index 090835b8..7165ba29 100644 --- a/openerp-client/src/main/java/org/bahmni/openerp/web/http/client/XMLClient.java +++ b/openerp-client/src/main/java/org/bahmni/openerp/web/http/client/HttpClient.java @@ -12,14 +12,14 @@ import org.springframework.web.client.RestTemplate; @Component -public class XMLClient { - private static final Logger logger = LogManager.getLogger(XMLClient.class); +public class HttpClient { + private static final Logger logger = LogManager.getLogger(HttpClient.class); private RestTemplate restTemplate; private boolean isTimeoutSet; @Autowired - public XMLClient(RestTemplate restTemplate) { + public HttpClient(RestTemplate restTemplate) { this.restTemplate = restTemplate; } diff --git a/openerp-client/src/main/java/org/bahmni/openerp/web/http/client/RestClient.java b/openerp-client/src/main/java/org/bahmni/openerp/web/http/client/RestClient.java deleted file mode 100644 index a4eafccf..00000000 --- a/openerp-client/src/main/java/org/bahmni/openerp/web/http/client/RestClient.java +++ /dev/null @@ -1,98 +0,0 @@ -package org.bahmni.openerp.web.http.client; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.bahmni.openerp.web.OpenERPException; -import org.bahmni.openerp.web.request.OpenERPRequest; -import org.bahmni.openerp.web.request.builder.Parameter; -import org.bahmni.openerp.web.request.builder.RequestBuilder; -import org.springframework.http.HttpHeaders; -import org.springframework.http.MediaType; -import org.springframework.web.reactive.function.client.WebClient; - -import java.time.Duration; -import java.util.Arrays; -import java.util.UUID; -import java.util.function.Consumer; - -public class RestClient { - private static final Logger logger = LogManager.getLogger(RestClient.class); - private WebClient webClient; - private final int connectionTimeout; - private String accessToken; - - private final String baseURL; - - private final String username; - - private final String password; - - public RestClient(String baseURL, String username, String password, int connectionTimeout) { - this.baseURL = baseURL; - this.username = username; - this.password = password; - this.connectionTimeout = connectionTimeout; - } - - private void login() { - if (accessToken == null) { - OpenERPRequest openERPRequest = new OpenERPRequest("res.users", "login", Arrays.asList(new Parameter("username", username), new Parameter("password", password))); - String requestBody = RequestBuilder.buildNewRestRequest(openERPRequest, UUID.randomUUID().toString()); - WebClient client = getWebClient(baseURL); - HttpHeaders headers = getHttpHeaders(); - Consumer consumer = httpHeaders -> httpHeaders.addAll(headers); - try{ - String response = client.post().uri("api/odoo-login").headers(consumer).bodyValue(requestBody).retrieve().bodyToMono(String.class).timeout(Duration.ofMillis(connectionTimeout)).block(); - if (response == null) { - throw new OpenERPException("Login failed"); - } - ObjectMapper objectMapper = new ObjectMapper(); - JsonNode responseNode = objectMapper.readTree(response); - accessToken = responseNode.get("result").get("data").get("access_token").asText(); - } - catch (Exception e){ - logger.debug("Failed to login for user {}", username); - throw new OpenERPException(String.format("Failed to login. The login user is : %s", username)); - } - } - } - - public String post(String URI, String requestBody) { - try { - login(); - logger.debug("Post Data: {}", requestBody); - WebClient client = getWebClient(baseURL); - HttpHeaders headers = getHttpHeaders(); - headers.set(HttpHeaders.AUTHORIZATION, accessToken); - Consumer consumer = httpHeaders -> httpHeaders.addAll(headers); - String response = client.post().uri(URI).headers(consumer).bodyValue(requestBody).retrieve().bodyToMono(String.class).timeout(Duration.ofMillis(connectionTimeout)).block(); - if (response == null) { - throw new OpenERPException(String.format("Could not post to %s", URI)); - } - return response; - } catch (Exception e) { - logger.error("Could not post to {}", URI, e); - logger.error("Post data: {}", requestBody); - throw new RuntimeException("Could not post message", e); - } - } - - private WebClient getWebClient(String baseURL) { - if(webClient == null){ - webClient = WebClient.builder() - .baseUrl(baseURL) - .build(); - } - return webClient; - } - - private HttpHeaders getHttpHeaders() { - HttpHeaders httpHeaders = new HttpHeaders(); - httpHeaders.setContentType(MediaType.APPLICATION_JSON); - httpHeaders.set(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE); - return httpHeaders; - } - -} diff --git a/openerp-client/src/main/java/org/bahmni/openerp/web/request/builder/Parameter.java b/openerp-client/src/main/java/org/bahmni/openerp/web/request/builder/Parameter.java index 42193685..f471ce5a 100644 --- a/openerp-client/src/main/java/org/bahmni/openerp/web/request/builder/Parameter.java +++ b/openerp-client/src/main/java/org/bahmni/openerp/web/request/builder/Parameter.java @@ -1,5 +1,8 @@ package org.bahmni.openerp.web.request.builder; + +import org.apache.commons.lang3.StringEscapeUtils; + public class Parameter { private String name; @@ -8,7 +11,7 @@ public class Parameter { public Parameter(String name, String value, String type) { this.name = name; - this.value = value; + this.value = StringEscapeUtils.escapeXml(value); this.type = type; } diff --git a/openerp-client/src/main/java/org/bahmni/openerp/web/request/builder/RequestBuilder.java b/openerp-client/src/main/java/org/bahmni/openerp/web/request/builder/RequestBuilder.java index e6004c44..01fab54f 100644 --- a/openerp-client/src/main/java/org/bahmni/openerp/web/request/builder/RequestBuilder.java +++ b/openerp-client/src/main/java/org/bahmni/openerp/web/request/builder/RequestBuilder.java @@ -5,7 +5,6 @@ import org.apache.velocity.app.VelocityEngine; import org.apache.velocity.runtime.RuntimeConstants; import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader; -import org.apache.velocity.tools.generic.EscapeTool; import org.bahmni.openerp.web.OpenERPException; import org.bahmni.openerp.web.request.OpenERPRequest; import org.springframework.stereotype.Service; @@ -23,7 +22,6 @@ public static String buildNewXMLRequest(OpenERPRequest openERPRequest, Object id velocityEngine.init(); Template template = velocityEngine.getTemplate("request/template/xml_template.vm"); VelocityContext context = new VelocityContext(); - context.put("esc", new EscapeTool()); //Refer : https://github.com/Bahmni/openerp-atomfeed-service/pull/80#discussion_r1410242808 context.put("parametersList", openERPRequest.getParameters()); context.put("id", id); context.put("database", database); @@ -38,22 +36,4 @@ public static String buildNewXMLRequest(OpenERPRequest openERPRequest, Object id throw new OpenERPException(e); } } - - public static String buildNewRestRequest(OpenERPRequest openERPRequest, String id) { - try { - VelocityEngine velocityEngine = new VelocityEngine(); - velocityEngine.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath"); - velocityEngine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName()); - velocityEngine.init(); - Template template = velocityEngine.getTemplate("request/template/rest_template.vm"); - VelocityContext context = new VelocityContext(); - context.put("parametersList", openERPRequest.getParameters()); - context.put("id", id); - StringWriter writer = new StringWriter(); - template.merge(context, writer); - return writer.toString(); - } catch (Exception e) { - throw new OpenERPException(e); - } - } } \ No newline at end of file diff --git a/openerp-client/src/main/resources/request/template/rest_template.vm b/openerp-client/src/main/resources/request/template/rest_template.vm deleted file mode 100644 index 34a8528c..00000000 --- a/openerp-client/src/main/resources/request/template/rest_template.vm +++ /dev/null @@ -1,10 +0,0 @@ -{ - "id": "$id", - "params": { - "data": { - #foreach( $param in $parametersList ) - "$param.name": "$param.value"#if($foreach.hasNext),#end - #end - } - } -} \ No newline at end of file diff --git a/openerp-client/src/main/resources/request/template/xml_template.vm b/openerp-client/src/main/resources/request/template/xml_template.vm index bc8353a6..755cce27 100644 --- a/openerp-client/src/main/resources/request/template/xml_template.vm +++ b/openerp-client/src/main/resources/request/template/xml_template.vm @@ -1,31 +1,31 @@ - - - execute - - - $database - - - $id - - - $password - - - $resource - - - $operation - - - - #foreach( $param in $parametersList ) - - $param.name - <$param.type>$esc.xml($!param.value) - - #end - - - - \ No newline at end of file + + + execute + + + $database + + + $id + + + $password + + + $resource + + + $operation + + + + #foreach( $param in $parametersList ) + + $param.name + <$param.type>$!param.value + + #end + + + + \ No newline at end of file diff --git a/openerp-client/src/test/java/org/bahmni/openerp/web/request/builder/RequestBuilderTest.java b/openerp-client/src/test/java/org/bahmni/openerp/web/request/builder/RequestBuilderTest.java index 92bf8914..2092b4d0 100644 --- a/openerp-client/src/test/java/org/bahmni/openerp/web/request/builder/RequestBuilderTest.java +++ b/openerp-client/src/test/java/org/bahmni/openerp/web/request/builder/RequestBuilderTest.java @@ -31,7 +31,7 @@ public void shouldCreateNewCustomerRequestWithPatientDataPopulated() throws Exce String requestXml = RequestBuilder.buildNewXMLRequest(request, id, database, password); String requestXmlForComparison = requestXml.replace("", " "); - String expected = "" + + String expected = "\n" + "" + " execute" + " " + @@ -66,7 +66,7 @@ public void shouldCreateNewCustomerRequestWithPatientDataPopulated() throws Exce " " + " " + " " + - " " + + " \n" + ""; comparingStringWithoutSpaces(requestXml, expected); @@ -88,7 +88,7 @@ public void shouldEscapeSpecialCharacters() throws Exception { String requestXml = RequestBuilder.buildNewXMLRequest(request, id, database, password); - String expected = "" + + String expected = "\n" + "" + " execute" + " " + @@ -115,7 +115,7 @@ public void shouldEscapeSpecialCharacters() throws Exception { " " + " " + " " + - " " + + " \n" + ""; comparingStringWithoutSpaces(requestXml, expected); @@ -137,7 +137,7 @@ public void shouldEscapeHindiCharacters() throws Exception { String requestXml = RequestBuilder.buildNewXMLRequest(request, id, database, password); - String expected = "" + + String expected = "\n" + "" + " execute" + " " + @@ -164,8 +164,9 @@ public void shouldEscapeHindiCharacters() throws Exception { " " + " " + " " + - " " + + " \n" + ""; + comparingStringWithoutSpaces(requestXml, expected); } diff --git a/pom.xml b/pom.xml index be20c856..7b8badc5 100644 --- a/pom.xml +++ b/pom.xml @@ -29,7 +29,7 @@ 4.9.0 2.13.5 4.4.5 - 4.5.13 + 4.5.13 3.0.1 2.17.1 0.94.3 @@ -37,11 +37,6 @@ - - org.springframework.boot - spring-boot-starter-webflux - 3.0.0 - commons-lang commons-lang @@ -227,7 +222,7 @@ org.apache.httpcomponents httpclient - ${XMLClient.version} + ${httpClient.version} commons-logging