use of org.killbill.billing.invoice.generator.InvoiceWithMetadata.SubscriptionFutureNotificationDates.UsageDef in project killbill by killbill.
the class InvoiceDispatcher method createNextFutureNotificationDate.
private FutureAccountNotifications createNextFutureNotificationDate(final InvoiceWithMetadata invoiceWithMetadata, final InternalCallContext context) {
final Map<UUID, List<SubscriptionNotification>> result = new HashMap<UUID, List<SubscriptionNotification>>();
for (final UUID subscriptionId : invoiceWithMetadata.getPerSubscriptionFutureNotificationDates().keySet()) {
final List<SubscriptionNotification> perSubscriptionNotifications = new ArrayList<SubscriptionNotification>();
final SubscriptionFutureNotificationDates subscriptionFutureNotificationDates = invoiceWithMetadata.getPerSubscriptionFutureNotificationDates().get(subscriptionId);
// Add next recurring date if any
if (subscriptionFutureNotificationDates.getNextRecurringDate() != null) {
perSubscriptionNotifications.add(new SubscriptionNotification(context.toUTCDateTime(subscriptionFutureNotificationDates.getNextRecurringDate()), true));
}
// Add next usage dates if any
if (subscriptionFutureNotificationDates.getNextUsageDates() != null) {
for (final UsageDef usageDef : subscriptionFutureNotificationDates.getNextUsageDates().keySet()) {
final LocalDate nextNotificationDateForUsage = subscriptionFutureNotificationDates.getNextUsageDates().get(usageDef);
final DateTime subscriptionUsageCallbackDate = nextNotificationDateForUsage != null ? context.toUTCDateTime(nextNotificationDateForUsage) : null;
perSubscriptionNotifications.add(new SubscriptionNotification(subscriptionUsageCallbackDate, true));
}
}
if (!perSubscriptionNotifications.isEmpty()) {
result.put(subscriptionId, perSubscriptionNotifications);
}
}
// If dryRunNotification is enabled we also need to fetch the upcoming PHASE dates (we add SubscriptionNotification with isForInvoiceNotificationTrigger = false)
final boolean isInvoiceNotificationEnabled = invoiceConfig.getDryRunNotificationSchedule(context).getMillis() > 0;
if (isInvoiceNotificationEnabled) {
final Map<UUID, DateTime> upcomingPhasesForSubscriptions = subscriptionApi.getNextFutureEventForSubscriptions(SubscriptionBaseTransitionType.PHASE, context);
for (final UUID cur : upcomingPhasesForSubscriptions.keySet()) {
final DateTime curDate = upcomingPhasesForSubscriptions.get(cur);
List<SubscriptionNotification> resultValue = result.get(cur);
if (resultValue == null) {
resultValue = new ArrayList<SubscriptionNotification>();
}
resultValue.add(new SubscriptionNotification(curDate, false));
result.put(cur, resultValue);
}
}
return new FutureAccountNotifications(result);
}
Aggregations