@Override public int compareTo(final BlockingState arg0) { // effective_date column NOT NULL final int comparison = effectiveDate.compareTo(arg0.getEffectiveDate()); if (comparison == 0) { // Keep a stable ordering for ties final int comparison2 = createdDate.compareTo(arg0.getCreatedDate()); if (comparison2 == 0 && arg0 instanceof DefaultBlockingState) { final DefaultBlockingState other = (DefaultBlockingState) arg0; // New element is last if (totalOrdering == null) { return 1; } else if (other.getTotalOrdering() == null) { return -1; } else { return totalOrdering.compareTo(other.getTotalOrdering()); } } else { return comparison2; } } else { return comparison; } }
@Override public boolean apply(final BlockingState input) { return subscriptionEndDate == null || input.getEffectiveDate().compareTo(subscriptionEndDate) <= 0; } });
private void addDisabledDuration(final BlockingState firstBlockingState, @Nullable final DateTime disableDurationEndDate) { if (disableDurationEndDate == null || Days.daysBetween(firstBlockingState.getEffectiveDate(), disableDurationEndDate).getDays() >= 1) { // Don't disable for periods less than a day (see https://github.com/killbill/killbill/issues/267) result.add(new DisabledDuration(firstBlockingState.getEffectiveDate(), disableDurationEndDate)); } } }
public void addBlockingState(final BlockingState currentBlockingState) { final BlockingState firstBlockingState = perObjectTypeFirstBlockingState.get(currentBlockingState.getBlockedId()); if (currentBlockingState.isBlockBilling() && firstBlockingState == null) { perObjectTypeFirstBlockingState.put(currentBlockingState.getBlockedId(), currentBlockingState); } else if (!currentBlockingState.isBlockBilling() && firstBlockingState != null) { addDisabledDuration(firstBlockingState, currentBlockingState.getEffectiveDate()); perObjectTypeFirstBlockingState.put(currentBlockingState.getBlockedId(), null); } }
@Override public List<BlockingState> getBlockingState(final UUID blockableId, final BlockingStateType blockingStateType, final DateTime upToDate, final InternalTenantContext context) { final List<BlockingState> blockingStatesForId = blockingStates.get(blockableId); if (blockingStatesForId == null) { return new ArrayList<BlockingState>(); } final Map<String, BlockingState> tmp = new HashMap<String, BlockingState>(); for (BlockingState cur : blockingStatesForId) { final BlockingState curStateForService = tmp.get(cur.getService()); if (curStateForService == null || curStateForService.getEffectiveDate().compareTo(cur.getEffectiveDate()) < 0) { tmp.put(cur.getService(), cur); } } return new ArrayList<BlockingState>(tmp.values()); }
private void doCheckFutureBlockingStatesToCancel(final DefaultEntitlement addOnEntitlement, final DateTime effectiveCancellationDateTime, final Collection<BlockingState> blockingStatesForCancellation) { if (addOnEntitlement == null || effectiveCancellationDateTime == null) { Assert.assertEquals(blockingStatesForCancellation.size(), 0); } else { Assert.assertEquals(blockingStatesForCancellation.size(), 1); final BlockingState blockingState = blockingStatesForCancellation.iterator().next(); Assert.assertEquals(blockingState.getBlockedId(), addOnEntitlement.getId()); Assert.assertEquals(blockingState.getEffectiveDate(), effectiveCancellationDateTime); Assert.assertEquals(blockingState.getType(), BlockingStateType.SUBSCRIPTION); Assert.assertEquals(blockingState.getService(), KILLBILL_SERVICES.ENTITLEMENT_SERVICE.getServiceName()); Assert.assertEquals(blockingState.getStateName(), DefaultEntitlementApi.ENT_STATE_CANCELLED); } }
@Override public int compareTo(final BlockingState arg0) { // effective_date column NOT NULL final int comparison = effectiveDate.compareTo(arg0.getEffectiveDate()); if (comparison == 0) { // Keep a stable ordering for ties final int comparison2 = createdDate.compareTo(arg0.getCreatedDate()); if (comparison2 == 0 && arg0 instanceof DefaultBlockingState) { final DefaultBlockingState other = (DefaultBlockingState) arg0; // New element is last if (totalOrdering == null) { return 1; } else if (other.getTotalOrdering() == null) { return -1; } else { return totalOrdering.compareTo(other.getTotalOrdering()); } } else { return comparison2; } } else { return comparison; } }
private void doCheckActualBlockingStatesToCancel(final DefaultEntitlement addOnEntitlement, final DateTime effectiveCancellationDateTime, final boolean approximateDateCheck, final Collection<BlockingState> blockingStatesForCancellation) { if (effectiveCancellationDateTime == null) { Assert.assertEquals(blockingStatesForCancellation.size(), 0); } else { Assert.assertEquals(blockingStatesForCancellation.size(), 1); final BlockingState blockingState = blockingStatesForCancellation.iterator().next(); Assert.assertEquals(blockingState.getBlockedId(), addOnEntitlement.getId()); if (approximateDateCheck) { Assert.assertEquals(blockingState.getEffectiveDate().toLocalDate(), effectiveCancellationDateTime.toLocalDate()); Assert.assertEquals(blockingState.getEffectiveDate().getMinuteOfDay(), effectiveCancellationDateTime.getMinuteOfDay()); } else { Assert.assertEquals(blockingState.getEffectiveDate(), effectiveCancellationDateTime); } Assert.assertEquals(blockingState.getType(), BlockingStateType.SUBSCRIPTION); Assert.assertEquals(blockingState.getService(), KILLBILL_SERVICES.ENTITLEMENT_SERVICE.getServiceName()); Assert.assertEquals(blockingState.getStateName(), DefaultEntitlementApi.ENT_STATE_CANCELLED); } }
private void checkBlockingStatesDAO(final DefaultEntitlement baseEntitlement, final DefaultEntitlement addOnEntitlement, final LocalDate effectiveBaseCancellationDate, final LocalDate effectiveAddOnCancellationDate, final boolean isBaseCancelled) { final List<BlockingState> blockingStatesForBaseEntitlement = blockingStatesForBlockedId(baseEntitlement.getId()); Assert.assertEquals(blockingStatesForBaseEntitlement.size(), isBaseCancelled ? 2 : 1); if (isBaseCancelled) { Assert.assertEquals(blockingStatesForBaseEntitlement.get(1).getBlockedId(), baseEntitlement.getId()); Assert.assertEquals(blockingStatesForBaseEntitlement.get(1).getEffectiveDate().toLocalDate(), effectiveBaseCancellationDate); Assert.assertEquals(blockingStatesForBaseEntitlement.get(1).getType(), BlockingStateType.SUBSCRIPTION); Assert.assertEquals(blockingStatesForBaseEntitlement.get(1).getService(), KILLBILL_SERVICES.ENTITLEMENT_SERVICE.getServiceName()); Assert.assertEquals(blockingStatesForBaseEntitlement.get(1).getStateName(), DefaultEntitlementApi.ENT_STATE_CANCELLED); } final List<BlockingState> blockingStatesForAddOn = blockingStatesForBlockedId(addOnEntitlement.getId()); Assert.assertEquals(blockingStatesForAddOn.size(), 2); Assert.assertEquals(blockingStatesForAddOn.get(1).getBlockedId(), addOnEntitlement.getId()); Assert.assertEquals(blockingStatesForAddOn.get(1).getEffectiveDate().toLocalDate(), effectiveAddOnCancellationDate); Assert.assertEquals(blockingStatesForAddOn.get(1).getType(), BlockingStateType.SUBSCRIPTION); Assert.assertEquals(blockingStatesForAddOn.get(1).getService(), KILLBILL_SERVICES.ENTITLEMENT_SERVICE.getServiceName()); Assert.assertEquals(blockingStatesForAddOn.get(1).getStateName(), DefaultEntitlementApi.ENT_STATE_CANCELLED); }
private void verifyBlockingStates(final Iterable<BlockingState> result, final List<BlockingState> expected) { int i = 0; final Iterator<BlockingState> iterator = result.iterator(); while (iterator.hasNext()) { final BlockingState cur = iterator.next(); final BlockingState expectedItem = expected.get(i); assertEquals(cur.isBlockBilling(), expectedItem.isBlockBilling()); assertEquals(cur.isBlockEntitlement(), expectedItem.isBlockEntitlement()); assertEquals(cur.isBlockChange(), expectedItem.isBlockChange()); assertEquals(cur.getService(), expectedItem.getService()); assertEquals(cur.getStateName(), expectedItem.getStateName()); assertEquals(cur.getBlockedId(), expectedItem.getBlockedId()); assertEquals(internalCallContext.toLocalDate(cur.getEffectiveDate()).compareTo(internalCallContext.toLocalDate(expectedItem.getEffectiveDate())), 0); i++; } assertEquals(i, expected.size()); }
Assert.assertEquals(blockingStates1.get(0).getStateName(), state); Assert.assertEquals(blockingStates1.get(0).getService(), serviceA); Assert.assertEquals(blockingStates1.get(0).getEffectiveDate(), stateDateTime); Assert.assertEquals(blockingStates2.get(0).getStateName(), state); Assert.assertEquals(blockingStates2.get(0).getService(), serviceA); Assert.assertEquals(blockingStates2.get(0).getEffectiveDate(), stateDateTime); Assert.assertEquals(blockingStates3.get(0).getStateName(), state); Assert.assertEquals(blockingStates3.get(0).getService(), serviceA); Assert.assertEquals(blockingStates3.get(0).getEffectiveDate(), stateDateTime); Assert.assertEquals(blockingStates3.get(1).getBlockedId(), blockableId); Assert.assertEquals(blockingStates3.get(1).getStateName(), state); Assert.assertEquals(blockingStates3.get(1).getService(), serviceB); Assert.assertEquals(blockingStates3.get(1).getEffectiveDate(), stateDateTime); Assert.assertEquals(blockingStates4.get(0).getStateName(), state); Assert.assertEquals(blockingStates4.get(0).getService(), serviceA); Assert.assertEquals(blockingStates4.get(0).getEffectiveDate(), stateDateTime); Assert.assertEquals(blockingStates4.get(1).getBlockedId(), blockableId); Assert.assertEquals(blockingStates4.get(1).getStateName(), state); Assert.assertEquals(blockingStates4.get(1).getService(), serviceB); Assert.assertEquals(blockingStates4.get(1).getEffectiveDate(), stateDateTime); Assert.assertEquals(blockingStates5.get(0).getStateName(), state); Assert.assertEquals(blockingStates5.get(0).getService(), serviceA); Assert.assertEquals(blockingStates5.get(0).getEffectiveDate(), stateDateTime3); Assert.assertEquals(blockingStates5.get(1).getBlockedId(), blockableId); Assert.assertEquals(blockingStates5.get(1).getStateName(), state);
public BlockingStateJson(final BlockingState input, final AccountAuditLogs accountAuditLogs) { this(input.getBlockedId(), input.getStateName(), input.getService(), input.isBlockChange(), input.isBlockEntitlement(), input.isBlockBilling(), input.getEffectiveDate(), input.getType(), toAuditLogJson(accountAuditLogs == null ? null : accountAuditLogs.getAuditLogsForBlockingState(input.getId()))); }
assertEquals(events.get(2).getEffectiveDate().compareTo(new LocalDate(bs1.getEffectiveDate(), accountTimeZone)), 0); assertEquals(events.get(3).getEffectiveDate().compareTo(new LocalDate(tr2.getEffectiveTransitionTime(), accountTimeZone)), 0);
assertEquals(events.get(2).getEffectiveDate().compareTo(new LocalDate(bs1.getEffectiveDate(), accountTimeZone)), 0); assertEquals(events.get(3).getEffectiveDate().compareTo(new LocalDate(bs3.getEffectiveDate(), accountTimeZone)), 0);
assertEquals(events.get(5).getEffectiveDate().compareTo(new LocalDate(bs1.getEffectiveDate(), accountTimeZone)), 0); assertEquals(events.get(6).getEffectiveDate().compareTo(new LocalDate(bs1.getEffectiveDate(), accountTimeZone)), 0); assertEquals(events.get(8).getEffectiveDate().compareTo(new LocalDate(bs2.getEffectiveDate(), accountTimeZone)), 0);
assertEquals(events.get(1).getEffectiveDate().compareTo(new LocalDate(tr1.getEffectiveTransitionTime(), accountTimeZone)), 0); assertEquals(events.get(2).getEffectiveDate().compareTo(new LocalDate(tr2.getEffectiveTransitionTime(), accountTimeZone)), 0); assertEquals(events.get(3).getEffectiveDate().compareTo(new LocalDate(bs1.getEffectiveDate(), accountTimeZone)), 0); assertEquals(events.get(4).getEffectiveDate().compareTo(new LocalDate(tr3.getEffectiveTransitionTime(), accountTimeZone)), 0); assertEquals(events.get(5).getEffectiveDate().compareTo(new LocalDate(bs2.getEffectiveDate(), accountTimeZone)), 0);
assertEquals(events.get(1).getEffectiveDate().compareTo(new LocalDate(tr1.getEffectiveTransitionTime(), accountTimeZone)), 0); assertEquals(events.get(2).getEffectiveDate().compareTo(new LocalDate(tr2.getEffectiveTransitionTime(), accountTimeZone)), 0); assertEquals(events.get(3).getEffectiveDate().compareTo(new LocalDate(bs2.getEffectiveDate(), accountTimeZone)), 0); assertEquals(events.get(4).getEffectiveDate().compareTo(new LocalDate(tr3.getEffectiveTransitionTime(), accountTimeZone)), 0);
assertEquals(events.get(1).getEffectiveDate().compareTo(new LocalDate(tr1.getEffectiveTransitionTime(), accountTimeZone)), 0); assertEquals(events.get(2).getEffectiveDate().compareTo(new LocalDate(bs1.getEffectiveDate(), accountTimeZone)), 0); assertEquals(events.get(3).getEffectiveDate().compareTo(new LocalDate(bs1.getEffectiveDate(), accountTimeZone)), 0); assertEquals(events.get(4).getEffectiveDate().compareTo(new LocalDate(bs2.getEffectiveDate(), accountTimeZone)), 0); assertEquals(events.get(5).getEffectiveDate().compareTo(new LocalDate(bs2.getEffectiveDate(), accountTimeZone)), 0); assertEquals(events.get(6).getEffectiveDate().compareTo(new LocalDate(bs3.getEffectiveDate(), accountTimeZone)), 0); assertEquals(events.get(7).getEffectiveDate().compareTo(new LocalDate(bs3.getEffectiveDate(), accountTimeZone)), 0); assertEquals(events.get(8).getEffectiveDate().compareTo(new LocalDate(bs4.getEffectiveDate(), accountTimeZone)), 0); assertEquals(events.get(9).getEffectiveDate().compareTo(new LocalDate(bs4.getEffectiveDate(), accountTimeZone)), 0); assertEquals(events.get(10).getEffectiveDate().compareTo(new LocalDate(bs5.getEffectiveDate(), accountTimeZone)), 0);
assertEquals(events.get(1).getEffectiveDate().compareTo(new LocalDate(tr1.getEffectiveTransitionTime(), accountTimeZone)), 0); assertEquals(events.get(2).getEffectiveDate().compareTo(new LocalDate(tr2.getEffectiveTransitionTime(), accountTimeZone)), 0); assertEquals(events.get(3).getEffectiveDate().compareTo(new LocalDate(bs1.getEffectiveDate(), accountTimeZone)), 0); assertEquals(events.get(4).getEffectiveDate().compareTo(new LocalDate(bs1.getEffectiveDate(), accountTimeZone)), 0); assertEquals(events.get(5).getEffectiveDate().compareTo(new LocalDate(bs2.getEffectiveDate(), accountTimeZone)), 0); assertEquals(events.get(6).getEffectiveDate().compareTo(new LocalDate(bs2.getEffectiveDate(), accountTimeZone)), 0); assertEquals(events.get(7).getEffectiveDate().compareTo(new LocalDate(bs3.getEffectiveDate(), accountTimeZone)), 0); assertEquals(events.get(8).getEffectiveDate().compareTo(new LocalDate(bs4.getEffectiveDate(), accountTimeZone)), 0);
assertEquals(events.get(1).getEffectiveDate().compareTo(new LocalDate(tr1.getEffectiveTransitionTime(), accountTimeZone)), 0); assertEquals(events.get(2).getEffectiveDate().compareTo(new LocalDate(tr2.getEffectiveTransitionTime(), accountTimeZone)), 0); assertEquals(events.get(3).getEffectiveDate().compareTo(new LocalDate(bs1.getEffectiveDate(), accountTimeZone)), 0); assertEquals(events.get(4).getEffectiveDate().compareTo(new LocalDate(tr3.getEffectiveTransitionTime(), accountTimeZone)), 0); assertEquals(events.get(5).getEffectiveDate().compareTo(new LocalDate(tr3.getEffectiveTransitionTime(), accountTimeZone)), 0);