Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@
<artifactId>stockmanagement-api</artifactId>
</dependency>

<dependency>
<groupId>org.openmrs</groupId>
<artifactId>event-api</artifactId>
</dependency>

<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>uiframework-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,32 @@
*/
package org.openmrs.module.billing;

import java.util.ArrayList;
import java.util.List;

import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.openmrs.api.context.Context;
import org.openmrs.event.Event;
import org.openmrs.module.BaseModuleActivator;
import org.openmrs.module.DaemonToken;
import org.openmrs.module.DaemonTokenAware;
import org.openmrs.module.Module;
import org.openmrs.module.ModuleFactory;
import org.openmrs.module.billing.api.billing.BillingEventListener;
import org.openmrs.module.billing.web.CashierWebConstants;
import org.openmrs.module.web.WebModuleUtil;

/**
* This class contains the logic that is run every time this module is either started or stopped.
*/
@Slf4j
public class BillingModuleActivator extends BaseModuleActivator {
@Setter
public class BillingModuleActivator extends BaseModuleActivator implements DaemonTokenAware {

private DaemonToken daemonToken;

private final List<BillingEventListener> subscribedListeners = new ArrayList<>();

/**
* @see BaseModuleActivator#contextRefreshed()
Expand All @@ -40,16 +54,50 @@ public void contextRefreshed() {
@Override
public void started() {
log.info("OpenMRS Billing Module started");

subscribeBillingEventListeners();
}

/**
* @see BaseModuleActivator#stopped()
*/
@Override
public void stopped() {
unsubscribeBillingEventListeners();

Module module = ModuleFactory.getModuleById(CashierWebConstants.OPENHMIS_CASHIER_MODULE_ID);
WebModuleUtil.unloadFilters(module);

log.info("OpenMRS Billing Module stopped");
}

private void subscribeBillingEventListeners() {
List<BillingEventListener> listeners = Context.getRegisteredComponents(BillingEventListener.class);
for (BillingEventListener listener : listeners) {
try {
listener.setDaemonToken(daemonToken);
Event.subscribe(listener.getSubscribedClass(), listener.getSubscribedAction().name(), listener);
subscribedListeners.add(listener);
log.info("Subscribed {} to {} {} events", listener.getClass().getSimpleName(),
listener.getSubscribedClass().getSimpleName(), listener.getSubscribedAction());
}
catch (Exception e) {
log.error("Failed to subscribe {}", listener.getClass().getSimpleName(), e);
}
}
}

private void unsubscribeBillingEventListeners() {
for (BillingEventListener listener : subscribedListeners) {
try {
Event.unsubscribe(listener.getSubscribedClass(), listener.getSubscribedAction(), listener);
log.info("Unsubscribed {} from {} {} events", listener.getClass().getSimpleName(),
listener.getSubscribedClass().getSimpleName(), listener.getSubscribedAction());
}
catch (Exception e) {
log.error("Failed to unsubscribe {}", listener.getClass().getSimpleName(), e);
}
}
subscribedListeners.clear();
}
}

This file was deleted.

Loading
Loading