1375 - addBlockingState - Fix as per review comments
@@ -334,7 +334,7 @@ public class DefaultSubscriptionApi implements SubscriptionApi {
logAddBlockingState(log, inputBlockingState, inputEffectiveDate);
- final InternalCallContext internalCallContextWithValidAccountId = internalCallContextFactory.createInternalCallContext(inputBlockingState.getBlockedId(), callContext); //TODO_1375 - Will this work or do we need to use internalCallContextFactory.createInternalCallContext(inputBlockingState.getBlockedId(), ObjectType.ACCOUNT, callContext) within a switch statement?
+ final InternalCallContext internalCallContextWithValidAccountId = getInternalCallContextUsingBlockingState(inputBlockingState, callContext);
final DateTime effectiveDate = inputEffectiveDate == null ? callContext.getCreatedDate() : internalCallContextWithValidAccountId.toUTCDateTime(inputEffectiveDate);
addBlockingState(inputBlockingState, effectiveDate, properties, callContext);
@@ -356,7 +356,7 @@ public class DefaultSubscriptionApi implements SubscriptionApi {
throw new EntitlementApiException(ErrorCode.SUB_BLOCKING_STATE_INVALID_ARG, "Need to specify a valid stateName");
}
- final InternalCallContext internalCallContextWithValidAccountId;
+ final InternalCallContext internalCallContextWithValidAccountId = getInternalCallContextUsingBlockingState(inputBlockingState, callContext);
final ImmutableAccountData account;
final UUID accountId;
final UUID bundleId;
@@ -364,7 +364,6 @@ public class DefaultSubscriptionApi implements SubscriptionApi {
try {
switch (inputBlockingState.getType()) {
case ACCOUNT:
- internalCallContextWithValidAccountId = internalCallContextFactory.createInternalCallContext(inputBlockingState.getBlockedId(), ObjectType.ACCOUNT, callContext);
account = accountApi.getImmutableAccountDataById(inputBlockingState.getBlockedId(), internalCallContextWithValidAccountId);
externalKey = account.getExternalKey();
accountId = account.getId();
@@ -372,7 +371,6 @@ public class DefaultSubscriptionApi implements SubscriptionApi {
break;
case SUBSCRIPTION_BUNDLE:
- internalCallContextWithValidAccountId = internalCallContextFactory.createInternalCallContext(inputBlockingState.getBlockedId(), ObjectType.BUNDLE, callContext);
final SubscriptionBaseBundle bundle = subscriptionBaseInternalApi.getBundleFromId(inputBlockingState.getBlockedId(), internalCallContextWithValidAccountId);
externalKey = bundle.getExternalKey();
bundleId = bundle.getId();
@@ -380,7 +378,6 @@ public class DefaultSubscriptionApi implements SubscriptionApi {
break;
case SUBSCRIPTION:
- internalCallContextWithValidAccountId = internalCallContextFactory.createInternalCallContext(inputBlockingState.getBlockedId(), ObjectType.SUBSCRIPTION, callContext);
final Entitlement entitlement = entitlementInternalApi.getEntitlementForId(inputBlockingState.getBlockedId(), internalCallContextWithValidAccountId);
bundleId = entitlement.getBundleId();
accountId = entitlement.getAccountId();
@@ -557,4 +554,26 @@ public class DefaultSubscriptionApi implements SubscriptionApi {
return subscriptionsPerBundle;
}
+ private InternalCallContext getInternalCallContextUsingBlockingState(final BlockingState inputBlockingState, final CallContext callContext) {
+ final InternalCallContext internalCallContext;
+ switch (inputBlockingState.getType()) {
+ case ACCOUNT:
+ internalCallContext = internalCallContextFactory.createInternalCallContext(inputBlockingState.getBlockedId(), ObjectType.ACCOUNT, callContext);
+ break;
+
+ case SUBSCRIPTION_BUNDLE:
+ internalCallContext = internalCallContextFactory.createInternalCallContext(inputBlockingState.getBlockedId(), ObjectType.BUNDLE, callContext);
+ break;
+
+ case SUBSCRIPTION:
+ internalCallContext = internalCallContextFactory.createInternalCallContext(inputBlockingState.getBlockedId(), ObjectType.SUBSCRIPTION, callContext);
+ break;
+
+ default:
+ throw new IllegalStateException("Invalid blockingStateType " + inputBlockingState.getType());
+
+ }
+ return internalCallContext;
+ }
+
}
