Search in sources :

Example 1 with ObjectType

use of org.killbill.billing.ObjectType in project killbill by killbill.

the class EhCacheOverriddenPlanCache method getOverriddenPlan.

@Override
public DefaultPlan getOverriddenPlan(final String planName, final StaticCatalog catalog, final InternalTenantContext context) {
    final ObjectType irrelevant = null;
    final Object[] args = new Object[2];
    args[0] = loaderCallback;
    args[1] = catalog;
    final CacheLoaderArgument argument = new CacheLoaderArgument(irrelevant, args, context);
    return (DefaultPlan) cacheController.get(planName, argument);
}
Also used : ObjectType(org.killbill.billing.ObjectType) DefaultPlan(org.killbill.billing.catalog.DefaultPlan) CacheLoaderArgument(org.killbill.billing.util.cache.CacheLoaderArgument) PlanPhasePriceOverride(org.killbill.billing.catalog.api.PlanPhasePriceOverride) DefaultPriceOverride(org.killbill.billing.catalog.override.DefaultPriceOverride) DefaultPlanPhasePriceOverride(org.killbill.billing.catalog.DefaultPlanPhasePriceOverride)

Example 2 with ObjectType

use of org.killbill.billing.ObjectType in project killbill by killbill.

the class EhCacheStateMachineConfigCache method createCacheLoaderArgument.

private CacheLoaderArgument createCacheLoaderArgument(final String pluginName) {
    final Object[] args = new Object[2];
    args[0] = loaderCallback;
    args[1] = pluginName;
    final ObjectType irrelevant = null;
    final InternalTenantContext notUsed = null;
    return new CacheLoaderArgument(irrelevant, args, notUsed);
}
Also used : ObjectType(org.killbill.billing.ObjectType) InternalTenantContext(org.killbill.billing.callcontext.InternalTenantContext) CacheLoaderArgument(org.killbill.billing.util.cache.CacheLoaderArgument)

Example 3 with ObjectType

use of org.killbill.billing.ObjectType in project killbill by killbill.

the class EhCacheOverdueConfigCache method initializeCacheLoaderArgument.

private CacheLoaderArgument initializeCacheLoaderArgument() {
    final LoaderCallback loaderCallback = new LoaderCallback() {

        @Override
        public Object loadOverdueConfig(final String overdueConfigXML) throws OverdueApiException {
            final InputStream overdueConfigStream = new ByteArrayInputStream(overdueConfigXML.getBytes());
            final URI uri;
            try {
                uri = new URI("/overdueConfig");
                final DefaultOverdueConfig overdueConfig = XMLLoader.getObjectFromStream(uri, overdueConfigStream, DefaultOverdueConfig.class);
                return overdueConfig;
            } catch (final Exception e) {
                throw new OverdueApiException(ErrorCode.OVERDUE_INVALID_FOR_TENANT, "Problem encountered loading overdue config ", e);
            }
        }
    };
    final Object[] args = new Object[1];
    args[0] = loaderCallback;
    final ObjectType irrelevant = null;
    final InternalTenantContext notUsed = null;
    return new CacheLoaderArgument(irrelevant, args, notUsed);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) URI(java.net.URI) DefaultOverdueConfig(org.killbill.billing.overdue.config.DefaultOverdueConfig) LoaderCallback(org.killbill.billing.util.cache.TenantOverdueConfigCacheLoader.LoaderCallback) OverdueApiException(org.killbill.billing.overdue.api.OverdueApiException) CacheLoaderArgument(org.killbill.billing.util.cache.CacheLoaderArgument) OverdueApiException(org.killbill.billing.overdue.api.OverdueApiException) ObjectType(org.killbill.billing.ObjectType) ByteArrayInputStream(java.io.ByteArrayInputStream) InternalTenantContext(org.killbill.billing.callcontext.InternalTenantContext)

Example 4 with ObjectType

use of org.killbill.billing.ObjectType in project killbill by killbill.

the class EntitySqlDaoWrapperInvocationHandler method invokeWithCaching.

private Object invokeWithCaching(final Cachable cachableAnnotation, final Method method, final Object[] args) throws Throwable {
    final ObjectType objectType = getObjectType();
    final CacheType cacheType = cachableAnnotation.value();
    final CacheController<Object, Object> cache = cacheControllerDispatcher.getCacheController(cacheType);
    Object result = null;
    if (cache != null) {
        // Find all arguments marked with @CachableKey
        final Map<Integer, Object> keyPieces = new LinkedHashMap<Integer, Object>();
        final Annotation[][] annotations = method.getParameterAnnotations();
        for (int i = 0; i < annotations.length; i++) {
            for (int j = 0; j < annotations[i].length; j++) {
                final Annotation annotation = annotations[i][j];
                if (CachableKey.class.equals(annotation.annotationType())) {
                    // CachableKey position starts at 1
                    keyPieces.put(((CachableKey) annotation).value() - 1, args[i]);
                    break;
                }
            }
        }
        // Build the Cache key
        final String cacheKey = buildCacheKey(keyPieces);
        final InternalTenantContext internalTenantContext = (InternalTenantContext) Iterables.find(ImmutableList.copyOf(args), new Predicate<Object>() {

            @Override
            public boolean apply(final Object input) {
                return input instanceof InternalTenantContext;
            }
        }, null);
        final CacheLoaderArgument cacheLoaderArgument = new CacheLoaderArgument(objectType, args, internalTenantContext, handle);
        return cache.get(cacheKey, cacheLoaderArgument);
    }
    if (result == null) {
        result = prof.executeWithProfiling(ProfilingFeatureType.DAO_DETAILS, sqlDaoClass.getSimpleName() + "(raw) :" + method.getName(), new WithProfilingCallback() {

            @Override
            public Object execute() throws Throwable {
                return method.invoke(sqlDao, args);
            }
        });
    }
    return result;
}
Also used : Annotation(java.lang.annotation.Annotation) CacheLoaderArgument(org.killbill.billing.util.cache.CacheLoaderArgument) CacheType(org.killbill.billing.util.cache.Cachable.CacheType) LinkedHashMap(java.util.LinkedHashMap) Predicate(com.google.common.base.Predicate) WithProfilingCallback(org.killbill.commons.profiling.Profiling.WithProfilingCallback) ObjectType(org.killbill.billing.ObjectType) InternalTenantContext(org.killbill.billing.callcontext.InternalTenantContext) CachableKey(org.killbill.billing.util.cache.CachableKey)

Example 5 with ObjectType

use of org.killbill.billing.ObjectType in project killbill by killbill.

the class TestCondition method testHasControlTag.

@Test(groups = "fast")
public void testHasControlTag() throws Exception {
    final String xml = "<condition>" + "	<controlTagInclusion>OVERDUE_ENFORCEMENT_OFF</controlTagInclusion>" + "</condition>";
    final InputStream is = new ByteArrayInputStream(xml.getBytes());
    final MockCondition c = XMLLoader.getObjectFromStreamNoValidation(is, MockCondition.class);
    final UUID unpaidInvoiceId = UUID.randomUUID();
    final LocalDate now = new LocalDate();
    final ObjectType objectType = ObjectType.BUNDLE;
    final UUID objectId = new UUID(0L, 1L);
    final BillingState state0 = new BillingState(objectId, 0, BigDecimal.ZERO, null, unpaidInvoiceId, PaymentResponse.LOST_OR_STOLEN_CARD, new Tag[] { new DefaultControlTag(ControlTagType.AUTO_INVOICING_OFF, objectType, objectId, clock.getUTCNow()), new DescriptiveTag(UUID.randomUUID(), objectType, objectId, clock.getUTCNow()) });
    final BillingState state1 = new BillingState(objectId, 1, new BigDecimal("100.00"), now.minusDays(10), unpaidInvoiceId, PaymentResponse.INSUFFICIENT_FUNDS, new Tag[] { new DefaultControlTag(ControlTagType.OVERDUE_ENFORCEMENT_OFF, objectType, objectId, clock.getUTCNow()) });
    final BillingState state2 = new BillingState(objectId, 1, new BigDecimal("200.00"), now.minusDays(20), unpaidInvoiceId, PaymentResponse.DO_NOT_HONOR, new Tag[] { new DefaultControlTag(ControlTagType.OVERDUE_ENFORCEMENT_OFF, objectType, objectId, clock.getUTCNow()), new DefaultControlTag(ControlTagType.AUTO_INVOICING_OFF, objectType, objectId, clock.getUTCNow()), new DescriptiveTag(UUID.randomUUID(), objectType, objectId, clock.getUTCNow()) });
    Assert.assertTrue(!c.evaluate(state0, now));
    Assert.assertTrue(c.evaluate(state1, now));
    Assert.assertTrue(c.evaluate(state2, now));
}
Also used : ObjectType(org.killbill.billing.ObjectType) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DefaultControlTag(org.killbill.billing.util.tag.DefaultControlTag) UUID(java.util.UUID) LocalDate(org.joda.time.LocalDate) BillingState(org.killbill.billing.overdue.config.api.BillingState) DescriptiveTag(org.killbill.billing.util.tag.DescriptiveTag) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Aggregations

ObjectType (org.killbill.billing.ObjectType)41 UUID (java.util.UUID)27 Test (org.testng.annotations.Test)25 DefaultTagDefinition (org.killbill.billing.util.tag.DefaultTagDefinition)12 TagDefinition (org.killbill.billing.util.tag.TagDefinition)12 CacheLoaderArgument (org.killbill.billing.util.cache.CacheLoaderArgument)11 InternalTenantContext (org.killbill.billing.callcontext.InternalTenantContext)9 ObjectMapper (org.killbill.billing.util.jackson.ObjectMapper)6 ByteArrayInputStream (java.io.ByteArrayInputStream)3 InputStream (java.io.InputStream)3 TagInternalEvent (org.killbill.billing.events.TagInternalEvent)3 DescriptiveTag (org.killbill.billing.util.tag.DescriptiveTag)3 TagDefinitionModelDao (org.killbill.billing.util.tag.dao.TagDefinitionModelDao)3 ImmutableList (com.google.common.collect.ImmutableList)2 List (java.util.List)2 DefaultPlan (org.killbill.billing.catalog.DefaultPlan)2 DefaultPlanPhasePriceOverride (org.killbill.billing.catalog.DefaultPlanPhasePriceOverride)2 PlanPhasePriceOverride (org.killbill.billing.catalog.api.PlanPhasePriceOverride)2 ControlTagCreationInternalEvent (org.killbill.billing.events.ControlTagCreationInternalEvent)2 ControlTagDeletionInternalEvent (org.killbill.billing.events.ControlTagDeletionInternalEvent)2