Skip to content

Commit

Permalink
overdue: Add handling of WRITTEN_OFF tags to correctly recompute the …
Browse files Browse the repository at this point in the history
…state. See #476.
  • Loading branch information
sbrossie committed Jan 28, 2016
1 parent f84fc5d commit 59bb052
Showing 1 changed file with 24 additions and 2 deletions.
Expand Up @@ -27,10 +27,15 @@
import org.killbill.billing.events.InvoiceAdjustmentInternalEvent;
import org.killbill.billing.events.PaymentErrorInternalEvent;
import org.killbill.billing.events.PaymentInfoInternalEvent;
import org.killbill.billing.invoice.api.InvoiceApiException;
import org.killbill.billing.invoice.api.InvoiceInternalApi;
import org.killbill.billing.overdue.OverdueInternalApi;
import org.killbill.billing.util.cache.Cachable.CacheType;
import org.killbill.billing.util.cache.CacheControllerDispatcher;
import org.killbill.billing.util.callcontext.CallOrigin;
import org.killbill.billing.util.callcontext.InternalCallContextFactory;
import org.killbill.billing.util.callcontext.UserType;
import org.killbill.billing.util.dao.NonEntityDao;
import org.killbill.billing.util.tag.ControlTagType;
import org.killbill.bus.api.BusEvent;
import org.slf4j.Logger;
Expand All @@ -46,28 +51,45 @@ public class OverdueListener {

private final OverdueInternalApi overdueInternalApi;
private final InternalCallContextFactory internalCallContextFactory;
private final CacheControllerDispatcher cacheControllerDispatcher;

private final NonEntityDao nonEntityDao;

@Inject
public OverdueListener(final OverdueInternalApi overdueInternalApi,
final NonEntityDao nonEntityDao,
final CacheControllerDispatcher cacheControllerDispatcher,
final InternalCallContextFactory internalCallContextFactory) {
this.overdueInternalApi = overdueInternalApi;
this.nonEntityDao = nonEntityDao;
this.cacheControllerDispatcher = cacheControllerDispatcher;
this.internalCallContextFactory = internalCallContextFactory;
}




@AllowConcurrentEvents
@Subscribe
public void handle_OVERDUE_ENFORCEMENT_OFF_Insert(final ControlTagCreationInternalEvent event) {
public void handleTagInsert(final ControlTagCreationInternalEvent event) {
if (event.getTagDefinition().getName().equals(ControlTagType.OVERDUE_ENFORCEMENT_OFF.toString()) && event.getObjectType() == ObjectType.ACCOUNT) {
final InternalCallContext callContext = createCallContext(event.getUserToken(), event.getSearchKey1(), event.getSearchKey2());
overdueInternalApi.scheduleOverdueClear(event.getObjectId(), callContext);
} else if (event.getTagDefinition().getName().equals(ControlTagType.WRITTEN_OFF.toString()) && event.getObjectType() == ObjectType.INVOICE) {
final UUID accountId = nonEntityDao.retrieveIdFromObject(event.getSearchKey1(), ObjectType.ACCOUNT, cacheControllerDispatcher.getCacheController(CacheType.OBJECT_ID));
insertBusEventIntoNotificationQueue(accountId, event);
}
}


@AllowConcurrentEvents
@Subscribe
public void handle_OVERDUE_ENFORCEMENT_OFF_Removal(final ControlTagDeletionInternalEvent event) {
public void handleTagRemoval(final ControlTagDeletionInternalEvent event) {
if (event.getTagDefinition().getName().equals(ControlTagType.OVERDUE_ENFORCEMENT_OFF.toString()) && event.getObjectType() == ObjectType.ACCOUNT) {
insertBusEventIntoNotificationQueue(event.getObjectId(), event);
} else if (event.getTagDefinition().getName().equals(ControlTagType.WRITTEN_OFF.toString()) && event.getObjectType() == ObjectType.INVOICE) {
final UUID accountId = nonEntityDao.retrieveIdFromObject(event.getSearchKey1(), ObjectType.ACCOUNT, cacheControllerDispatcher.getCacheController(CacheType.OBJECT_ID));
insertBusEventIntoNotificationQueue(accountId, event);
}
}

Expand Down

1 comment on commit 59bb052

@pierre
Copy link
Member

@pierre pierre commented on 59bb052 Jan 28, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Please sign in to comment.