entitlement: code review integration in DefaultEntitlementApi
@@ -412,14 +412,19 @@ public class DefaultEntitlementApi extends DefaultEntitlementApiBase implements
contextWithValidAccountRecordId);
upTo = upTo == null || upTo.compareTo(entitlementRequestedDate) < 0 ? entitlementRequestedDate : upTo;
- // Verify if the operation is valid for that bundle
- preCheckAddEntitlement(baseEntitlementWithAddOnsSpecifier,
- entitlementRequestedDate,
+ final UUID bundleId = populateCaches(baseEntitlementWithAddOnsSpecifier,
eventsStreamForBaseSubscriptionPerBundle,
bundleKeyToIdMapping,
catalog,
callContext,
contextWithValidAccountRecordId);
+ if (bundleId != null) {
+ final Optional<EventsStream> eventsStreamForBaseSubscription = eventsStreamForBaseSubscriptionPerBundle.get(bundleId);
+ if (eventsStreamForBaseSubscription.isPresent()) {
+ // Verify if the operation is valid for that bundle
+ preCheckAddEntitlement(bundleId, entitlementRequestedDate, baseEntitlementWithAddOnsSpecifier, eventsStreamForBaseSubscription.get());
+ }
+ }
final SubscriptionBaseWithAddOnsSpecifier subscriptionBaseWithAddOnsSpecifier = new SubscriptionBaseWithAddOnsSpecifier(baseEntitlementWithAddOnsSpecifier.getBundleId(),
baseEntitlementWithAddOnsSpecifier.getExternalKey(),
@@ -461,8 +466,7 @@ public class DefaultEntitlementApi extends DefaultEntitlementApiBase implements
return iterator.next();
}
- private void preCheckAddEntitlement(final BaseEntitlementWithAddOnsSpecifier baseEntitlementWithAddOnsSpecifier,
- final DateTime entitlementRequestedDate,
+ private UUID populateCaches(final BaseEntitlementWithAddOnsSpecifier baseEntitlementWithAddOnsSpecifier,
final Map<UUID, Optional<EventsStream>> eventsStreamForBaseSubscriptionPerBundle,
final Map<String, Optional<UUID>> bundleKeyToIdMapping,
final Catalog catalog,
@@ -481,15 +485,12 @@ public class DefaultEntitlementApi extends DefaultEntitlementApiBase implements
}
if (bundleId == null) {
- return;
+ return null;
}
populateEventsStreamForBaseSubscriptionPerBundleCache(bundleId, eventsStreamForBaseSubscriptionPerBundle, callContext, contextWithValidAccountRecordId);
- final Optional<EventsStream> eventsStreamForBaseSubscription = eventsStreamForBaseSubscriptionPerBundle.get(bundleId);
- if (eventsStreamForBaseSubscription.isPresent()) {
- preCheckAddEntitlement(bundleId, entitlementRequestedDate, baseEntitlementWithAddOnsSpecifier, eventsStreamForBaseSubscription.get());
- }
+ return bundleId;
}
private void populateBundleKeyToIdMappingCache(final BaseEntitlementWithAddOnsSpecifier baseEntitlementWithAddOnsSpecifier, final Map<String, Optional<UUID>> bundleKeyToIdMapping, final Catalog catalog, final InternalCallContext contextWithValidAccountRecordId) throws EntitlementApiException {
