killbill-memoizeit

analytics: integrate with origin/analytics-as-osgi-plugin-support Signed-off-by:

4/5/2013 4:26:49 PM

Details

diff --git a/osgi-bundles/bundles/analytics/src/main/java/com/ning/billing/osgi/bundles/analytics/api/user/AnalyticsUserApi.java b/osgi-bundles/bundles/analytics/src/main/java/com/ning/billing/osgi/bundles/analytics/api/user/AnalyticsUserApi.java
index 197c8bd..84e928f 100644
--- a/osgi-bundles/bundles/analytics/src/main/java/com/ning/billing/osgi/bundles/analytics/api/user/AnalyticsUserApi.java
+++ b/osgi-bundles/bundles/analytics/src/main/java/com/ning/billing/osgi/bundles/analytics/api/user/AnalyticsUserApi.java
@@ -112,13 +112,11 @@ public class AnalyticsUserApi extends BusinessAnalyticsBase {
         // Refresh tags
         bTagDao.update(accountId, context);
 
-        for (final ObjectType objectType : ObjectType.values()) {
-            // Refresh BOS
-            bosDao.update(accountId, objectType, context);
+        // Refresh fields
+        bFieldDao.update(accountId, context);
 
-            // Refresh fields
-            bFieldDao.update(accountId, objectType, context);
-        }
+        // Refresh BOS (bundles only for now)
+        bosDao.update(accountId, ObjectType.BUNDLE, context);
 
         logService.log(LogService.LOG_INFO, "Finished rebuild of Analytics for account " + accountId);
     }
diff --git a/osgi-bundles/bundles/analytics/src/main/java/com/ning/billing/osgi/bundles/analytics/BusinessAnalyticsBase.java b/osgi-bundles/bundles/analytics/src/main/java/com/ning/billing/osgi/bundles/analytics/BusinessAnalyticsBase.java
index f40fcd4..f2db9b6 100644
--- a/osgi-bundles/bundles/analytics/src/main/java/com/ning/billing/osgi/bundles/analytics/BusinessAnalyticsBase.java
+++ b/osgi-bundles/bundles/analytics/src/main/java/com/ning/billing/osgi/bundles/analytics/BusinessAnalyticsBase.java
@@ -83,7 +83,7 @@ public abstract class BusinessAnalyticsBase {
 
     protected Long getTenantRecordId(final TenantContext context) throws AnalyticsRefreshException {
         final RecordIdApi recordIdUserApi = getRecordIdUserApi();
-        return recordIdUserApi.getRecordId(context.getTenantId(), ObjectType.TENANT);
+        return recordIdUserApi.getRecordId(context.getTenantId(), ObjectType.TENANT, context);
     }
 
     //
@@ -114,7 +114,7 @@ public abstract class BusinessAnalyticsBase {
 
     protected Long getAccountRecordId(final UUID accountId, final TenantContext context) throws AnalyticsRefreshException {
         final RecordIdApi recordIdUserApi = getRecordIdUserApi();
-        return recordIdUserApi.getRecordId(accountId, ObjectType.ACCOUNT);
+        return recordIdUserApi.getRecordId(accountId, ObjectType.ACCOUNT, context);
     }
 
     //
@@ -166,7 +166,7 @@ public abstract class BusinessAnalyticsBase {
 
     protected Long getSubscriptionEventRecordId(final UUID subscriptionEventId, final TenantContext context) throws AnalyticsRefreshException {
         final RecordIdApi recordIdUserApi = getRecordIdUserApi();
-        return recordIdUserApi.getRecordId(subscriptionEventId, ObjectType.SUBSCRIPTION_EVENT);
+        return recordIdUserApi.getRecordId(subscriptionEventId, ObjectType.SUBSCRIPTION_EVENT, context);
     }
 
     //
@@ -196,7 +196,7 @@ public abstract class BusinessAnalyticsBase {
 
     protected Long getBlockingStateRecordId(final UUID blockingStateId, final TenantContext context) throws AnalyticsRefreshException {
         final RecordIdApi recordIdUserApi = getRecordIdUserApi();
-        return recordIdUserApi.getRecordId(blockingStateId, ObjectType.BLOCKING_STATES);
+        return recordIdUserApi.getRecordId(blockingStateId, ObjectType.BLOCKING_STATES, context);
     }
 
     //
@@ -226,7 +226,7 @@ public abstract class BusinessAnalyticsBase {
 
     protected Long getInvoiceRecordId(final UUID invoiceId, final TenantContext context) throws AnalyticsRefreshException {
         final RecordIdApi recordIdUserApi = getRecordIdUserApi();
-        return recordIdUserApi.getRecordId(invoiceId, ObjectType.INVOICE);
+        return recordIdUserApi.getRecordId(invoiceId, ObjectType.INVOICE, context);
     }
 
     protected AuditLog getInvoiceItemCreationAuditLog(final UUID invoiceItemId, final TenantContext context) throws AnalyticsRefreshException {
@@ -242,7 +242,7 @@ public abstract class BusinessAnalyticsBase {
 
     protected Long getInvoiceItemRecordId(final UUID invoiceItemId, final TenantContext context) throws AnalyticsRefreshException {
         final RecordIdApi recordIdUserApi = getRecordIdUserApi();
-        return recordIdUserApi.getRecordId(invoiceItemId, ObjectType.INVOICE_ITEM);
+        return recordIdUserApi.getRecordId(invoiceItemId, ObjectType.INVOICE_ITEM, context);
     }
 
     protected Collection<Invoice> getInvoicesByAccountId(final UUID accountId, final CallContext context) throws AnalyticsRefreshException {
@@ -317,7 +317,7 @@ public abstract class BusinessAnalyticsBase {
 
     protected Long getInvoicePaymentRecordId(final UUID invoicePaymentId, final TenantContext context) throws AnalyticsRefreshException {
         final RecordIdApi recordIdUserApi = getRecordIdUserApi();
-        return recordIdUserApi.getRecordId(invoicePaymentId, ObjectType.INVOICE_PAYMENT);
+        return recordIdUserApi.getRecordId(invoicePaymentId, ObjectType.INVOICE_PAYMENT, context);
     }
 
     //
@@ -372,11 +372,9 @@ public abstract class BusinessAnalyticsBase {
     // FIELD
     //
 
-    protected Collection<CustomField> getFieldsForAccountAndObjectType(final UUID accountId, final ObjectType objectType, final TenantContext context) throws AnalyticsRefreshException {
+    protected Collection<CustomField> getFieldsForAccount(final UUID accountId, final TenantContext context) throws AnalyticsRefreshException {
         final CustomFieldUserApi tagUserApi = getCustomFieldUserApi();
-        // TODO
-        //return tagUserApi.getCustomFieldsForAccount(accountId, objectType, context);
-        return null;
+        return tagUserApi.getCustomFieldsForAccount(accountId, context);
     }
 
     protected AuditLog getFieldCreationAuditLog(final UUID fieldId, final TenantContext context) throws AnalyticsRefreshException {
@@ -392,7 +390,7 @@ public abstract class BusinessAnalyticsBase {
 
     protected Long getFieldRecordId(final UUID fieldId, final TenantContext context) throws AnalyticsRefreshException {
         final RecordIdApi recordIdUserApi = getRecordIdUserApi();
-        return recordIdUserApi.getRecordId(fieldId, ObjectType.CUSTOM_FIELD);
+        return recordIdUserApi.getRecordId(fieldId, ObjectType.CUSTOM_FIELD, context);
     }
 
     //
@@ -428,7 +426,7 @@ public abstract class BusinessAnalyticsBase {
 
     protected Long getTagRecordId(final UUID tagId, final TenantContext context) throws AnalyticsRefreshException {
         final RecordIdApi recordIdUserApi = getRecordIdUserApi();
-        return recordIdUserApi.getRecordId(tagId, ObjectType.TAG);
+        return recordIdUserApi.getRecordId(tagId, ObjectType.TAG, context);
     }
 
     //
diff --git a/osgi-bundles/bundles/analytics/src/main/java/com/ning/billing/osgi/bundles/analytics/dao/BusinessFieldDao.java b/osgi-bundles/bundles/analytics/src/main/java/com/ning/billing/osgi/bundles/analytics/dao/BusinessFieldDao.java
index 2a8287f..5f27d3e 100644
--- a/osgi-bundles/bundles/analytics/src/main/java/com/ning/billing/osgi/bundles/analytics/dao/BusinessFieldDao.java
+++ b/osgi-bundles/bundles/analytics/src/main/java/com/ning/billing/osgi/bundles/analytics/dao/BusinessFieldDao.java
@@ -23,7 +23,6 @@ import java.util.UUID;
 import org.skife.jdbi.v2.Transaction;
 import org.skife.jdbi.v2.TransactionStatus;
 
-import com.ning.billing.ObjectType;
 import com.ning.billing.account.api.Account;
 import com.ning.billing.osgi.bundles.analytics.AnalyticsRefreshException;
 import com.ning.billing.osgi.bundles.analytics.dao.model.BusinessFieldModelDao;
@@ -42,10 +41,10 @@ public class BusinessFieldDao extends BusinessAnalyticsDaoBase {
         super(logService, osgiKillbillAPI, osgiKillbillDataSource);
     }
 
-    public void update(final UUID accountId, final ObjectType objectType, final CallContext context) throws AnalyticsRefreshException {
+    public void update(final UUID accountId, final CallContext context) throws AnalyticsRefreshException {
         final Account account = getAccount(accountId, context);
 
-        final Collection<BusinessFieldModelDao> fieldModelDaos = createBusinessFields(account, objectType, context);
+        final Collection<BusinessFieldModelDao> fieldModelDaos = createBusinessFields(account, context);
 
         sqlDao.inTransaction(new Transaction<Void, BusinessAnalyticsSqlDao>() {
             @Override
@@ -70,11 +69,11 @@ public class BusinessFieldDao extends BusinessAnalyticsDaoBase {
         }
     }
 
-    private Collection<BusinessFieldModelDao> createBusinessFields(final Account account, final ObjectType objectType, final CallContext context) throws AnalyticsRefreshException {
+    private Collection<BusinessFieldModelDao> createBusinessFields(final Account account, final CallContext context) throws AnalyticsRefreshException {
         final Long accountRecordId = getAccountRecordId(account.getId(), context);
         final Long tenantRecordId = getTenantRecordId(context);
 
-        final Collection<CustomField> fields = getFieldsForAccountAndObjectType(account.getId(), objectType, context);
+        final Collection<CustomField> fields = getFieldsForAccount(account.getId(), context);
 
         final Collection<BusinessFieldModelDao> fieldModelDaos = new LinkedList<BusinessFieldModelDao>();
         for (final CustomField field : fields) {