Search in sources :

Example 1 with EntitlementPluginApiException

use of org.killbill.billing.entitlement.plugin.api.EntitlementPluginApiException in project killbill by killbill.

the class EntitlementPluginExecution method executeWithPlugin.

public <T> T executeWithPlugin(final WithEntitlementPlugin<T> callback, final EntitlementContext pluginContext) throws EntitlementApiException {
    try {
        final PriorEntitlementResult priorEntitlementResult = executePluginPriorCalls(pluginContext);
        if (priorEntitlementResult != null && priorEntitlementResult.isAborted()) {
            throw new EntitlementApiException(ErrorCode.ENT_PLUGIN_API_ABORTED);
        }
        final EntitlementContext updatedPluginContext = new DefaultEntitlementContext(pluginContext, priorEntitlementResult);
        try {
            final T result = callback.doCall(entitlementApi, updatedPluginContext);
            executePluginOnSuccessCalls(updatedPluginContext);
            return result;
        } catch (final EntitlementApiException e) {
            executePluginOnFailureCalls(updatedPluginContext);
            throw e;
        }
    } catch (final EntitlementPluginApiException e) {
        throw new EntitlementApiException(ErrorCode.ENT_PLUGIN_API_ABORTED, e.getMessage());
    }
}
Also used : PriorEntitlementResult(org.killbill.billing.entitlement.plugin.api.PriorEntitlementResult) EntitlementPluginApiException(org.killbill.billing.entitlement.plugin.api.EntitlementPluginApiException) EntitlementContext(org.killbill.billing.entitlement.plugin.api.EntitlementContext)

Example 2 with EntitlementPluginApiException

use of org.killbill.billing.entitlement.plugin.api.EntitlementPluginApiException in project killbill by killbill.

the class EntitlementPluginExecution method executeWithPlugin.

public void executeWithPlugin(final Callable<Void> preCallbacksCallback, final List<WithEntitlementPlugin> callbacks, final Iterable<EntitlementContext> pluginContexts) throws EntitlementApiException {
    final List<EntitlementContext> updatedPluginContexts = new LinkedList<EntitlementContext>();
    try {
        for (final EntitlementContext pluginContext : pluginContexts) {
            final PriorEntitlementResult priorEntitlementResult = executePluginPriorCalls(pluginContext);
            if (priorEntitlementResult != null && priorEntitlementResult.isAborted()) {
                throw new EntitlementApiException(ErrorCode.ENT_PLUGIN_API_ABORTED);
            }
            updatedPluginContexts.add(new DefaultEntitlementContext(pluginContext, priorEntitlementResult));
        }
        preCallbacksCallback.call();
        try {
            for (int i = 0; i < updatedPluginContexts.size(); i++) {
                final EntitlementContext updatedPluginContext = updatedPluginContexts.get(i);
                final WithEntitlementPlugin callback = callbacks.get(i);
                callback.doCall(entitlementApi, updatedPluginContext);
                executePluginOnSuccessCalls(updatedPluginContext);
            }
        } catch (final EntitlementApiException e) {
            for (final EntitlementContext updatedPluginContext : updatedPluginContexts) {
                executePluginOnFailureCalls(updatedPluginContext);
            }
            throw e;
        }
    } catch (final EntitlementPluginApiException e) {
        throw new EntitlementApiException(ErrorCode.ENT_PLUGIN_API_ABORTED, e.getMessage());
    } catch (final Exception e) {
        throw new EntitlementApiException(ErrorCode.ENT_PLUGIN_API_ABORTED, e.getMessage());
    }
}
Also used : PriorEntitlementResult(org.killbill.billing.entitlement.plugin.api.PriorEntitlementResult) EntitlementPluginApiException(org.killbill.billing.entitlement.plugin.api.EntitlementPluginApiException) LinkedList(java.util.LinkedList) EntitlementContext(org.killbill.billing.entitlement.plugin.api.EntitlementContext) EntitlementPluginApiException(org.killbill.billing.entitlement.plugin.api.EntitlementPluginApiException)

Aggregations

EntitlementContext (org.killbill.billing.entitlement.plugin.api.EntitlementContext)2 EntitlementPluginApiException (org.killbill.billing.entitlement.plugin.api.EntitlementPluginApiException)2 PriorEntitlementResult (org.killbill.billing.entitlement.plugin.api.PriorEntitlementResult)2 LinkedList (java.util.LinkedList)1