Skip to content

Commit

Permalink
[Parvathy, Rahul] | Add. Replace OpenERPClient With XML Strategy Impl…
Browse files Browse the repository at this point in the history
…ementation

Co-authored-by: Parvathy Babu <[email protected]>
  • Loading branch information
rahu1ramesh and parvathy00 committed Nov 22, 2023
1 parent 00f6757 commit b6bb47d
Show file tree
Hide file tree
Showing 22 changed files with 141 additions and 305 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import org.bahmni.feed.openerp.OpenERPAtomFeedProperties;
import org.bahmni.feed.openerp.job.Jobs;
import org.bahmni.feed.openerp.worker.WorkerFactory;
import org.bahmni.openerp.web.client.OpenERPClient;
import org.bahmni.openerp.web.client.strategy.OpenERPContext;
import org.bahmni.openerp.web.client.strategy.implementation.OpenERPXMLClient;
import org.bahmni.webclients.ClientCookies;
import org.ict4h.atomfeed.client.AtomFeedProperties;
import org.ict4h.atomfeed.client.repository.AllFailedEvents;
Expand All @@ -16,16 +17,16 @@
import org.ict4h.atomfeed.server.transaction.AtomFeedSpringTransactionSupport;

public class AtomFeedClientHelper {
private OpenERPAtomFeedProperties atomFeedProperties;
private AtomFeedSpringTransactionSupport transactionManager;
private OpenERPClient openERPClient;
private final OpenERPAtomFeedProperties atomFeedProperties;
private final AtomFeedSpringTransactionSupport transactionManager;
private final OpenERPXMLClient openERPXMLClient;
private FeedClientFactory feedClientFactory;
private WebClientProvider webClientProvider;
private final WebClientProvider webClientProvider;

public AtomFeedClientHelper(OpenERPAtomFeedProperties atomFeedProperties, AtomFeedSpringTransactionSupport transactionManager, OpenERPClient openERPClient) {
public AtomFeedClientHelper(OpenERPAtomFeedProperties atomFeedProperties, AtomFeedSpringTransactionSupport transactionManager, OpenERPXMLClient openERPXMLClient) {
this.atomFeedProperties = atomFeedProperties;
this.transactionManager = transactionManager;
this.openERPClient = openERPClient;
this.openERPXMLClient = openERPXMLClient;
this.webClientProvider = new WebClientProvider(atomFeedProperties);
}

Expand All @@ -42,7 +43,9 @@ FeedClient getAtomFeedClient(Jobs jobName, FeedClientFactory feedClientFactory)
AllFeeds allFeeds = getAllFeeds(atomFeedProperties, cookies);
AllMarkers allMarkers = new AllMarkersJdbcImpl(transactionManager);
AllFailedEvents allFailedEvents = new AllFailedEventsJdbcImpl(transactionManager);
return feedClientFactory.getFeedClient(atomFeedProperties, transactionManager, openERPClient, allFeeds, allMarkers, allFailedEvents, jobName);
//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 @@ -7,7 +7,7 @@
import org.bahmni.feed.openerp.OpenERPAtomFeedProperties;
import org.bahmni.feed.openerp.job.Jobs;
import org.bahmni.feed.openerp.worker.WorkerFactory;
import org.bahmni.openerp.web.client.OpenERPClient;
import org.bahmni.openerp.web.client.strategy.OpenERPContext;
import org.ict4h.atomfeed.client.AtomFeedProperties;
import org.ict4h.atomfeed.client.repository.AllFailedEvents;
import org.ict4h.atomfeed.client.repository.AllFeeds;
Expand All @@ -24,15 +24,14 @@
public class FeedClientFactory {


private WorkerFactory workerFactory;
private static Logger logger = LogManager.getLogger(FeedClientFactory.class);
private final WorkerFactory workerFactory;
private static final Logger logger = LogManager.getLogger(FeedClientFactory.class);

public FeedClientFactory(WorkerFactory workerFactory) {
this.workerFactory = workerFactory;
}

public AtomFeedClient getFeedClient(OpenERPAtomFeedProperties openERPAtomFeedProperties, AtomFeedSpringTransactionSupport transactionManager,
OpenERPClient openERPClient, AllFeeds allFeeds, AllMarkers allMarkers, AllFailedEvents allFailedEvents, Jobs jobName) {
public AtomFeedClient getFeedClient(OpenERPAtomFeedProperties openERPAtomFeedProperties, AtomFeedSpringTransactionSupport transactionManager, OpenERPContext openERPContext, AllFeeds allFeeds, AllMarkers allMarkers, AllFailedEvents allFailedEvents, Jobs jobName) {
String feedUri = openERPAtomFeedProperties.getFeedUriForJob(jobName);
if (StringUtils.isBlank(feedUri)) {
String message = String.format("No feed-uri defined for Job [%s][%s]", jobName, jobName.getFeedUriRef());
Expand All @@ -42,31 +41,33 @@ public AtomFeedClient getFeedClient(OpenERPAtomFeedProperties openERPAtomFeedPro

try {
String urlPrefix = getURLPrefix(jobName,openERPAtomFeedProperties);
EventWorker eventWorker = workerFactory.getWorker(jobName, feedUri, openERPClient,
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(Jobs jobName,OpenERPAtomFeedProperties atomFeedProperties) {
static String getURLPrefix(Jobs jobName, OpenERPAtomFeedProperties atomFeedProperties) {
String endpointURI = getURIForJob(jobName,atomFeedProperties);
try {
URL endpointUrl = new URL(endpointURI);
return String.format("%s://%s", endpointUrl.getProtocol(), endpointUrl.getAuthority());
if(endpointURI != null && !endpointURI.isEmpty()){
URL endpointUrl = new URL(endpointURI);
return String.format("%s://%s", endpointUrl.getProtocol(), endpointUrl.getAuthority());
} else throw new RuntimeException("Endpoint URI is null or empty");
} catch (MalformedURLException e) {
throw new RuntimeException("Is not a valid URI - " + endpointURI, e);
}
}

private static String getURIForJob(Jobs jobName,OpenERPAtomFeedProperties atomFeedProperties){
switch (jobName){
case CUSTOMER_FEED: return atomFeedProperties.getAuthenticationURI();
case SALEORDER_FEED: return atomFeedProperties.getAuthenticationURI();
case DRUG_FEED: return atomFeedProperties.getAuthenticationURI();
case LAB_FEED: return atomFeedProperties.getAuthenticationURI();
case SALEABLE_FEED: return atomFeedProperties.getAuthenticationURI();
case CUSTOMER_FEED:
case SALEORDER_FEED:
case SALEABLE_FEED:
case DRUG_FEED:
case LAB_FEED:
return atomFeedProperties.getAuthenticationURI();
case REFERENCE_DATA_FEED: return atomFeedProperties.getReferenceDataEndpointURI();
case OPENELIS_SALEORDER_FEED: return atomFeedProperties.getOpenElisURI();
default: return null;
Expand All @@ -79,8 +80,6 @@ static AtomFeedProperties atomFeedProperties(OpenERPAtomFeedProperties openERPAt
atomFeedProperties.setConnectTimeout(openERPAtomFeedProperties.getConnectionTimeoutInMilliseconds());
atomFeedProperties.setReadTimeout(openERPAtomFeedProperties.getReplyTimeoutInMilliseconds());
atomFeedProperties.setMaxFailedEvents(openERPAtomFeedProperties.getMaxFailedEvents());

return atomFeedProperties;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.bahmni.feed.openerp.domain.OpenMRSPatientIdentifier;
import org.bahmni.feed.openerp.domain.OpenMRSPerson;
import org.bahmni.feed.openerp.domain.OpenMRSPersonAddress;
import org.bahmni.openerp.web.client.OpenERPClient;
import org.bahmni.openerp.web.client.strategy.OpenERPContext;
import org.bahmni.openerp.web.request.OpenERPRequest;
import org.bahmni.openerp.web.request.builder.Parameter;
import org.ict4h.atomfeed.client.domain.Event;
Expand All @@ -22,24 +22,24 @@
import java.util.List;

public class OpenERPCustomerServiceEventWorker implements EventWorker {
OpenERPClient openERPClient;
OpenERPContext openERPContext;
private String feedUrl;
private OpenMRSWebClient webClient;
private String urlPrefix;

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

public OpenERPCustomerServiceEventWorker(String feedUrl, OpenERPClient openERPClient, OpenMRSWebClient webClient, String urlPrefix) {
public OpenERPCustomerServiceEventWorker(String feedUrl, OpenERPContext openERPContext, OpenMRSWebClient webClient, String urlPrefix) {
this.feedUrl = feedUrl;
this.openERPClient = openERPClient;
this.openERPContext = openERPContext;
this.webClient = webClient;
this.urlPrefix = urlPrefix;
}

@Override
public void process(Event event) {
try {
openERPClient.execute(mapRequest(event));
openERPContext.execute(mapRequest(event));
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.bahmni.feed.openerp.ObjectMapperRepository;
import org.bahmni.feed.openerp.domain.OpenMRSDrug;
import org.bahmni.feed.openerp.client.OpenMRSWebClient;
import org.bahmni.openerp.web.client.OpenERPClient;
import org.bahmni.openerp.web.client.strategy.OpenERPContext;
import org.bahmni.openerp.web.request.OpenERPRequest;
import org.bahmni.openerp.web.request.builder.Parameter;
import org.ict4h.atomfeed.client.domain.Event;
Expand All @@ -20,14 +20,14 @@ public class OpenERPDrugServiceEventWorker implements EventWorker {

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

private OpenERPClient openERPClient;
private OpenERPContext openERPContext;
private String feedUrl;
private OpenMRSWebClient webClient;
private String urlPrefix;


public OpenERPDrugServiceEventWorker(String feedUrl, OpenERPClient openERPClient, OpenMRSWebClient openMRSWebClient, String urlPrefix) {
this.openERPClient = openERPClient;
public OpenERPDrugServiceEventWorker(String feedUrl, OpenERPContext openERPContext, OpenMRSWebClient openMRSWebClient, String urlPrefix) {
this.openERPContext = openERPContext;
this.feedUrl = feedUrl;
this.webClient = openMRSWebClient;
this.urlPrefix = urlPrefix;
Expand All @@ -37,7 +37,7 @@ public OpenERPDrugServiceEventWorker(String feedUrl, OpenERPClient openERPClient
public void process(Event event) {
logger.debug("Processing the event [{}]", event.getContent());
try {
openERPClient.execute(mapRequest(event));
openERPContext.execute(mapRequest(event));
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.bahmni.feed.openerp.domain.labOrderType.OpenMRSLabPanelEvent;
import org.bahmni.feed.openerp.domain.labOrderType.OpenMRSLabTestEvent;
import org.bahmni.feed.openerp.domain.labOrderType.OpenMRSRadiologyTestEvent;
import org.bahmni.openerp.web.client.OpenERPClient;
import org.bahmni.openerp.web.client.strategy.OpenERPContext;
import org.bahmni.openerp.web.request.OpenERPRequest;
import org.ict4h.atomfeed.client.domain.Event;
import org.ict4h.atomfeed.client.service.EventWorker;
Expand All @@ -21,19 +21,18 @@ public class OpenERPLabOrderTypeServiceEventWorker implements EventWorker {

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

private OpenERPClient openERPClient;
private OpenERPContext openERPContext;
private String feedUrl;
private OpenMRSWebClient webClient;
private String urlPrefix;
private Map<String, OpenMRSLabOrderTypeEvent> labOrderTypeEventMap = new HashMap<>();


public OpenERPLabOrderTypeServiceEventWorker(String feedUrl, OpenERPClient openERPClient, OpenMRSWebClient openMRSWebClient, String urlPrefix) {
this.openERPClient = openERPClient;
public OpenERPLabOrderTypeServiceEventWorker(String feedUrl, OpenERPContext openERPContext, OpenMRSWebClient openMRSWebClient, String urlPrefix) {
this.openERPContext = openERPContext;
this.feedUrl = feedUrl;
this.webClient = openMRSWebClient;
this.urlPrefix = urlPrefix;

labOrderTypeEventMap.put(OpenMRSRadiologyTestEvent.RADIOLOGY_TEST_EVENT_NAME, new OpenMRSRadiologyTestEvent());
labOrderTypeEventMap.put(OpenMRSLabTestEvent.LAB_TEST_EVENT_NAME, new OpenMRSLabTestEvent());
labOrderTypeEventMap.put(OpenMRSLabPanelEvent.LAB_PANEL_EVENT_NAME, new OpenMRSLabPanelEvent());
Expand All @@ -45,7 +44,7 @@ public void process(Event event) {
try {
OpenMRSLabOrderTypeEvent openMRSLabOrderTypeEvent = labOrderTypeEventMap.get(event.getTitle());
if(openMRSLabOrderTypeEvent == null) return ;
openERPClient.execute(mapRequest(event, openMRSLabOrderTypeEvent));
openERPContext.execute(mapRequest(event, openMRSLabOrderTypeEvent));
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.bahmni.feed.openerp.domain.encounter.MapERPOrders;
import org.bahmni.feed.openerp.domain.encounter.OpenMRSEncounter;
import org.bahmni.feed.openerp.domain.visit.OpenMRSVisit;
import org.bahmni.openerp.web.client.OpenERPClient;
import org.bahmni.openerp.web.client.strategy.OpenERPContext;
import org.bahmni.openerp.web.request.OpenERPRequest;
import org.bahmni.openerp.web.request.builder.Parameter;
import org.ict4h.atomfeed.client.domain.Event;
Expand All @@ -17,17 +17,17 @@
import java.net.URI;

public class OpenERPSaleOrderEventWorker implements EventWorker {
OpenERPClient openERPClient;
OpenERPContext openERPContext;
private String feedUrl;
private OpenMRSWebClient webClient;
private String urlPrefix;


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

public OpenERPSaleOrderEventWorker(String feedUrl, OpenERPClient openERPClient, OpenMRSWebClient webClient, String urlPrefix) {
public OpenERPSaleOrderEventWorker(String feedUrl, OpenERPContext openERPContext, OpenMRSWebClient webClient, String urlPrefix) {
this.feedUrl = feedUrl;
this.openERPClient = openERPClient;
this.openERPContext = openERPContext;
this.webClient = webClient;
this.urlPrefix = urlPrefix;
}
Expand All @@ -38,8 +38,7 @@ public void process(Event event) {
OpenERPRequest openERPRequest = mapRequest(event);
if (!openERPRequest.shouldERPConsumeEvent())
return;

openERPClient.execute(openERPRequest);
openERPContext.execute(openERPRequest);
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.bahmni.feed.openerp.ObjectMapperRepository;
import org.bahmni.feed.openerp.client.OpenMRSWebClient;
import org.bahmni.feed.openerp.domain.OpenMRSResource;
import org.bahmni.openerp.web.client.OpenERPClient;
import org.bahmni.openerp.web.client.strategy.OpenERPContext;
import org.bahmni.openerp.web.request.OpenERPRequest;
import org.bahmni.openerp.web.request.builder.Parameter;
import org.ict4h.atomfeed.client.domain.Event;
Expand All @@ -21,15 +21,15 @@ public class OpenERPSaleableResourceWorker implements EventWorker {
public static final String ERP_EVENT_CATEGORY = "create.service.saleable";
public static final String SALEABLE_PROPERTY_NAME = "saleable";
public static final String PRODUCT_CATEGORY = "product_category";
private OpenERPClient openERPClient;
private OpenERPContext openERPContext;
private String feedUrl;
private OpenMRSWebClient openMRSWebClient;
private String urlPrefix;

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

public OpenERPSaleableResourceWorker(String feedUrl, OpenERPClient openERPClient, OpenMRSWebClient openMRSWebClient, String urlPrefix) {
this.openERPClient = openERPClient;
public OpenERPSaleableResourceWorker(String feedUrl, OpenERPContext openERPContext, OpenMRSWebClient openMRSWebClient, String urlPrefix) {
this.openERPContext = openERPContext;
this.feedUrl = feedUrl;
this.openMRSWebClient = openMRSWebClient;
this.urlPrefix = urlPrefix;
Expand All @@ -44,7 +44,7 @@ public void process(Event event) {
logger.info(String.format("Resource is not a saleable resource. Ignoring. Event [%s]", event.getId()));
return;
}
openERPClient.execute(mapToOpenERPRequest(event, resource));
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.bahmni.feed.openerp.ObjectMapperRepository;
import org.bahmni.feed.openerp.client.OpenElisWebClient;
import org.bahmni.feed.openerp.domain.openelis.OpenElisLabOrder;
import org.bahmni.openerp.web.client.OpenERPClient;
import org.bahmni.openerp.web.client.strategy.OpenERPContext;
import org.bahmni.openerp.web.request.OpenERPRequest;
import org.bahmni.openerp.web.request.builder.Parameter;
import org.bahmni.openerp.web.service.ProductService;
Expand All @@ -16,18 +16,17 @@
import java.net.URI;

public class OpenElisSaleOrderEventWorker implements EventWorker {
private String feedUrl;
private OpenERPClient openERPClient;
private OpenElisWebClient webClient;
private String urlPrefix;
private final String feedUrl;
private final OpenERPContext openERPContext;
private final OpenElisWebClient webClient;
private final String urlPrefix;
private ProductService productService;

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

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

public OpenElisSaleOrderEventWorker(String feedUrl, OpenERPClient openERPClient, OpenElisWebClient webClient, String urlPrefix) {
public OpenElisSaleOrderEventWorker(String feedUrl, OpenERPContext openERPContext, OpenElisWebClient webClient, String urlPrefix) {
this.feedUrl = feedUrl;
this.openERPClient = openERPClient;
this.openERPContext = openERPContext;
this.webClient = webClient;
this.urlPrefix = urlPrefix;
}
Expand All @@ -39,8 +38,7 @@ public void process(Event event) {
OpenERPRequest openERPRequest = mapRequest(event);
if (!openERPRequest.shouldERPConsumeEvent())
return;

openERPClient.execute(openERPRequest);
openERPContext.execute(openERPRequest);
} catch (Exception e) {
logger.error("Error processing openelis sale order event : {}", event.toString(), e);
throw new RuntimeException(e);
Expand Down
Loading

0 comments on commit b6bb47d

Please sign in to comment.