Skip to content

Commit

Permalink
Merge pull request #81 from Bahmni/revert-80-BAH-3331
Browse files Browse the repository at this point in the history
Revert "BAH-3331 | Add. Rest Client Implementation for Create Drug"
  • Loading branch information
rahu1ramesh authored Dec 2, 2023
2 parents 1798255 + 2229212 commit 5caa8d4
Show file tree
Hide file tree
Showing 48 changed files with 171 additions and 464 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -209,6 +191,8 @@ private void debug() {
logger.debug("**************** DEBUG OpenERPAtomFeedProperties ************************ ");
}



private HashMap<String, String> getInfo() {
HashMap<String, String> values = new HashMap<>();
values.put("chunking.strategy",chunkingStrategy );
Expand All @@ -234,4 +218,5 @@ private HashMap<String, String> getInfo() {
return values;
}


}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -17,43 +15,37 @@
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);
}
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()){
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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() ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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"),
Expand All @@ -12,7 +12,7 @@ public enum FeedURI {

private final String feedUriRef;

FeedURI(String feedUriRef) {
Jobs(String feedUriRef) {
this.feedUriRef = feedUriRef;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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"))
) {
Expand Down

This file was deleted.

Loading

0 comments on commit 5caa8d4

Please sign in to comment.