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);
}
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);
}
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);
}
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;
}
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));
}
Aggregations