Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
163 commits
Select commit Hold shift + click to select a range
511e8ba
jaxrs: add support for HPP combo call
pierre Aug 11, 2015
a06e75d
payment: add missing pending states in PaymentStateMachineHelper#getP…
pierre Aug 11, 2015
ee7a00f
jaxrs: add API to authorize/purchase/credit by account external key
pierre Aug 11, 2015
ac72e58
payment: don't require amount/currency for completion operations
pierre Aug 11, 2015
e11aa6e
jaxrs: add missing payment complete API by payment id / external key
pierre Aug 11, 2015
7efb9b7
Merge remote-tracking branch 'origin/master' into hpp-combo
pierre Aug 11, 2015
9f60de4
payment: reduce logging in IncompletePaymentTransactionTask
pierre Aug 11, 2015
f6e13d4
payment: protect PaymentTransactionInfoPluginConverter against NPE
pierre Aug 11, 2015
6f35287
payment: add tests for completion operations
pierre Aug 11, 2015
c6d52ad
payment: enhance complete operations tests
pierre Aug 11, 2015
408db8c
server: trivial refactoring of TestPayment
pierre Aug 12, 2015
4140dd9
jaxrs: relax constraints for complete operations
pierre Aug 12, 2015
e6f7f13
server: fix typos in TestPayment
pierre Aug 12, 2015
fa71706
jaxrs: allow complete operations by specifying the transaction id
pierre Aug 12, 2015
69aee77
Implementation for buildFormDescriptorWithPaymentControl and processN…
sbrossie Aug 13, 2015
9d24b52
Add payment tests for new api buildFormDescriptorWithPaymentControl. …
sbrossie Aug 13, 2015
4d45fce
Merge branch 'master' of github.com:killbill/killbill
sbrossie Aug 13, 2015
7c6bf27
Fixes #350
sbrossie Aug 13, 2015
c077096
Fix regression introduced by 69aee775b22fcc9b61c7f472a4d8f6394e23f7bc
sbrossie Aug 13, 2015
601bf53
Update server properties to match new queue configuration change
sbrossie Aug 18, 2015
3a8e3f9
Remove unused configuration file
sbrossie Aug 18, 2015
d84d3bd
Add missing queue properties in default killbill-server.properties
sbrossie Aug 18, 2015
98c09ec
Update to released OSS version
sbrossie Aug 18, 2015
17581ae
util: don't trust user-specified UUID in CustomFieldModelDao
pierre Aug 18, 2015
8205c8b
Merge branch 'master' of github.com:killbill/killbill
pierre Aug 18, 2015
6de3d1d
Fixes #375
sbrossie Aug 19, 2015
7a0a5c9
Add new filter to attach a ThreadLocal RequestId (and provide support…
sbrossie Aug 19, 2015
1df0daf
jaxrs: add support for control plugins in PaymentGatewayResource
pierre Aug 20, 2015
2998b9d
Add ThreadGroup for payment plugin thread
sbrossie Aug 20, 2015
d0d6390
Merge branch 'master' of github.com:killbill/killbill
sbrossie Aug 20, 2015
12ac001
payment: fix NPE if control plugin is not registered
pierre Aug 20, 2015
a24ed2b
jaxrs: fix warning on startup
pierre Aug 20, 2015
39a8d61
payment: look-up payment by external key if no payment id is passed
pierre Aug 20, 2015
f20b73b
Fixes #355
sbrossie Aug 21, 2015
08211b5
Rename RequestIdFilter -> RequestDataFilter
sbrossie Aug 21, 2015
c974e19
Remove unwanted test check file
sbrossie Aug 21, 2015
ca2e264
See #355
sbrossie Aug 21, 2015
9bf8ab9
payment: Fix broken payment tests after introducing the PaymentExecutors
sbrossie Aug 21, 2015
681cea4
Update oss version with released versions
killbillio Aug 21, 2015
6be7d1e
pom.xml: updates for release 0.15.3
killbillio Aug 21, 2015
2467f53
[maven-release-plugin] prepare release killbill-0.15.3
killbillio Aug 21, 2015
2aa4e71
[maven-release-plugin] prepare for next development iteration
killbillio Aug 21, 2015
e9655b2
Add -H support for db-helper
darth30joker Aug 24, 2015
ed348a6
Merge pull request #384 from david-xie/db-helper
sbrossie Aug 24, 2015
3de4599
Remove subscription base deactivate/reactivate API which is not used …
sbrossie Aug 26, 2015
c972061
Remove unused processedDate for subscription events (similar to creat…
sbrossie Aug 26, 2015
5aca0cd
subscription: Fixes #377
sbrossie Aug 27, 2015
441ed79
Merge branch 'master' of github.com:killbill/killbill
sbrossie Aug 27, 2015
f3aad9a
util: Fixes #386
sbrossie Aug 27, 2015
65d54b9
junction: Fix major typo where recurringBillingMode ends up being null!
sbrossie Aug 28, 2015
94f91b4
invoice: See #321 Initial implementation for billingMode IN_ARREAR
sbrossie Aug 28, 2015
25e55cc
invoice: See #321 Add unit test for IN_ARREAR recurring BillingMode
sbrossie Aug 29, 2015
68e8376
invoice: Refactor the computation of next invoice future notitications
sbrossie Aug 31, 2015
5af598e
invoice: Refactor the computation of next invoice future notitication…
sbrossie Sep 2, 2015
a75db15
payment: Increment # tries for global lock to match the new the defau…
sbrossie Sep 2, 2015
e9c1323
junction: Modify BillingEvent api
sbrossie Sep 2, 2015
41bfa0a
invoice: Rework next notification date for in arrear usage billing.
sbrossie Sep 3, 2015
7d8f44c
invoice: Fix issue for in arrear usage billing where subscription can…
sbrossie Sep 3, 2015
f1b2815
invoice: Fix issue with recurring billing in arrear
sbrossie Sep 3, 2015
58d8015
Merge remote-tracking branch 'origin/master' into invoice_and_usage
sbrossie Sep 3, 2015
01a165d
invoice: Fix test failure due to commit f1b2815d8afe32656fc857f22ea5c…
sbrossie Sep 3, 2015
88f19a5
catalog: Fix missing currency entry in SpyCarAdvanced.xml
sbrossie Sep 3, 2015
9cb89f0
Merge remote-tracking branch 'origin/master' into invoice_and_usage
sbrossie Sep 3, 2015
9178b21
payment: Fix infinite retry loop in janitor when a PENDING/UNKNWON tr…
sbrossie Sep 4, 2015
f72e1db
invoice, payment: Export a new system property org.killbill.(payment|…
sbrossie Sep 4, 2015
30826e6
Merge remote-tracking branch 'origin/master' into invoice_and_usage
sbrossie Sep 4, 2015
4168e48
Update pom with latest oss released version
sbrossie Sep 4, 2015
80d6e88
Merge remote-tracking branch 'origin/master' into invoice_and_usage
sbrossie Sep 4, 2015
5aaf406
invoice: Refactor DefaultInvoiceGenerator and remove BillingModeGener…
sbrossie Sep 4, 2015
3802ad2
Add PostgreSQL support to db-helper
darth30joker Sep 1, 2015
b617a5c
Fixes #362
sbrossie Aug 5, 2015
b1790a8
Fixes #361
sbrossie Aug 5, 2015
255f4c4
Merge pull request #389 from david-xie/add_pg_support
sbrossie Sep 8, 2015
c17c438
Merge branch 'master' of github.com:killbill/killbill
sbrossie Sep 9, 2015
3098120
jaxrs: Remove unsued extra parameter to buildComboFormDescriptor
sbrossie Sep 9, 2015
45aebae
payment: Fixes #374
sbrossie Sep 9, 2015
96f1342
jaxrs: Add ability to retrieve all tags for an account (and option to…
sbrossie Sep 9, 2015
4f8a23f
payment: Fixes #378
sbrossie Sep 9, 2015
159ea86
jaxrs: Fixes #289
sbrossie Sep 9, 2015
a64e8de
beatrix: Minor tweak in existing test (no change of behavior)
sbrossie Sep 9, 2015
557b8b5
Add postgresql in the allow_failures block from travis config (see #382)
sbrossie Sep 9, 2015
33acb88
subscription: Fixes #387
sbrossie Sep 9, 2015
aeaf855
Error code cleanup
sbrossie Sep 10, 2015
9522fc2
Update killbill-api (with ErrorCode cleanup)
sbrossie Sep 10, 2015
e41be34
Remove postgresql build until known issue has been fixed (previous co…
sbrossie Sep 10, 2015
f0e5088
jaxrs: Remove constraint to pass currency when creating external char…
sbrossie Sep 10, 2015
f9d03a7
invoice, payment: See #393
sbrossie Sep 11, 2015
fc2c3c7
invoice: Fix usage issue (missing usage items or incomplete).
sbrossie Sep 13, 2015
2e8126e
invoice: cleanup unsued file
sbrossie Sep 13, 2015
862d141
invoice: @See #361. Previous fix b1790a85d8f3e64677f309ca03758a43eb59…
sbrossie Sep 13, 2015
7d43124
catalog: Add ANNUAL plan for product Sport (catalog SpyCarAdvanced)
sbrossie Sep 13, 2015
86ae0d2
invoice: @See #361. Previous fix 862d141e0524ff32c0666de0d36437e87053…
sbrossie Sep 13, 2015
c8462b0
jaxrs: Code review integration for 159ea86613628789452ce4c703b2f4bc07…
sbrossie Sep 13, 2015
955bc6f
pom.xml: updates for release 0.15.4
killbillio Sep 14, 2015
edb6f34
[maven-release-plugin] prepare release killbill-0.15.4
killbillio Sep 14, 2015
67ba21d
[maven-release-plugin] prepare for next development iteration
killbillio Sep 14, 2015
998000d
account: Make sure account non null fields have a default value even …
sbrossie Sep 16, 2015
ce2ed36
jaxrs: Fix broken test because of commit 8b8c444296bfa2d65ec1bec3e5d5…
sbrossie Sep 16, 2015
d33e6ef
pom.xml: updates for release 0.15.5
killbillio Sep 16, 2015
445aaab
[maven-release-plugin] prepare release killbill-0.15.5
killbillio Sep 16, 2015
c23960f
[maven-release-plugin] prepare for next development iteration
killbillio Sep 16, 2015
1c1fdf6
payment: Make payment control api consistent with row payment api (by…
sbrossie Sep 17, 2015
afe8738
jaxrs: revert change for 998000d8266f1abee83611e5e653fbef2af63b0a sin…
sbrossie Sep 17, 2015
364ce2b
jaxrs: fix payment test after semantics change from 1c1fdf63b08ce2df4…
sbrossie Sep 18, 2015
ab2ba00
jaxrs: filter out plugin properties for which the value is null
sbrossie Sep 18, 2015
6f898ff
Combo auth returns 404 if can't find payment method.
andrenpaes Sep 19, 2015
d978ab1
jaxrs: enhance Tag model to also return the objectId (matching the ob…
sbrossie Sep 19, 2015
fc33c28
Merge pull request #398 from andrenpaes/comboauth-fix-pm-lookup
sbrossie Sep 21, 2015
95a4ed0
Add getopt check for db-helper
darth30joker Sep 21, 2015
3019abd
Merge pull request #399 from david-xie/getopt_upgrade
sbrossie Sep 22, 2015
b18a12c
server: Introduce a new system property to allow returning gzip http …
sbrossie Sep 23, 2015
85704ca
start script: Configure by default the http gzip filter
sbrossie Sep 23, 2015
925d7ce
Merge branch 'master' of github.com:killbill/killbill
sbrossie Sep 23, 2015
20291ec
payment: allow plugin to set the payment method external key
pierre Sep 23, 2015
75e1d01
jaxrs: Add new threadpool to allow some apis to run independant tasks…
sbrossie Sep 24, 2015
ce36048
Increment oss pom version to use latest commons (and switch the payme…
sbrossie Sep 29, 2015
3b6b157
Merge branch 'payment-method-external-key-set-by-plugin'
pierre Sep 30, 2015
5bec17d
Introduce new internal account api to optimize code path and avoid fe…
sbrossie Oct 1, 2015
8637993
Introduce 2 new ehcaches to take care of immutable account data and B…
sbrossie Oct 2, 2015
ad41bf1
Code review integration for 86379933aa486c9e81cef2ab3113a68d2dced360
sbrossie Oct 2, 2015
01dbd19
account: Fix regression introduced in 86379933aa486c9e81cef2ab3113a68…
sbrossie Oct 4, 2015
879d013
invoice: Modify dryRun api to allow queriying for upcoming invoices t…
sbrossie Oct 5, 2015
15d0e36
issues:396 - UTC was set as default account timezone.
Oct 5, 2015
c0bcd7b
Merge pull request #402 from vp-maguero/master
pierre Oct 5, 2015
4110ad6
Adding Unit Test to verify the behavior when trying to Cancel a Subsc…
Oct 5, 2015
7759b81
Fixing Unit Test for TestUserApiCancel
Oct 5, 2015
1489880
Merge pull request #403 from vp-maguero/master
sbrossie Oct 5, 2015
25ab392
invoice: Implement filtering to opnly return items matching specific …
sbrossie Oct 5, 2015
520bb25
Update pom with released oss version
sbrossie Oct 5, 2015
9013abf
Merge branch 'caching'
sbrossie Oct 5, 2015
2eda0f0
api: fix compilation on 1.6
pierre Oct 6, 2015
ebeac2a
Adding fix for Issue #162. Added Unit Tests and test custom XML catalog
Oct 6, 2015
e36f28a
Fix Unit Test to match path folders
Oct 6, 2015
b764b9c
issue 118: Invoice formatter displays now correct currency symbol
Oct 6, 2015
b0425e6
Changing library to Google Guava Files
Oct 6, 2015
4a92a94
Fix Unit Tests based on comments during Pull Request
Oct 6, 2015
27dad56
Merge branch 'master' of https://github.com/vp-maguero/killbill into …
pierre Oct 6, 2015
ea7d605
Update oss version to include latest correction on BillingPeriod changes
sbrossie Oct 6, 2015
8bb9fe8
Merge branch 'master' of github.com:killbill/killbill
sbrossie Oct 6, 2015
3d2dfb5
catalog: trivial fixes in TestVersionedCatalogLoader
pierre Oct 6, 2015
56abfee
Merge branch 'vp-maguero-master'
pierre Oct 6, 2015
3a0902b
util: make KillbillCredentialsMatcher respect KillbillConfigSource
pierre Oct 7, 2015
d0ad5c2
server: update killbill.properties with new property name
pierre Oct 7, 2015
43afb07
Changes made according pull reques discussion. https://github.com/kil…
Oct 7, 2015
02f751b
Merge branch 'issue-118-maguero' of https://github.com/vp-maguero/kil…
pierre Oct 7, 2015
896ec16
invoice: trivial cleanups in formatters
pierre Oct 7, 2015
8ea9e88
invoice: share the currency -> locale map in tests
pierre Oct 7, 2015
abe94d6
invoice: catch only IllegalArgumentException if the currency isn't known
pierre Oct 7, 2015
fbf57b8
invoice: remove third digit in euro test
pierre Oct 7, 2015
5927458
invoice: add test with OMR currency
pierre Oct 7, 2015
3165f48
Merge branch 'vp-maguero-issue-118-maguero'
pierre Oct 7, 2015
9db9a0d
Update oss pom version to 0.52
killbillio Oct 7, 2015
157c328
Merge branch 'master' of github.com:killbill/killbill
sbrossie Oct 7, 2015
75b1e02
Update NEWS file for 0.15.6
killbillio Oct 7, 2015
e5420a8
[maven-release-plugin] prepare release killbill-0.15.6
killbillio Oct 7, 2015
35d8028
[maven-release-plugin] prepare for next development iteration
killbillio Oct 7, 2015
1f88176
payment: remove legacy NoOpPaymentPluginApi
pierre Oct 8, 2015
93abd23
profiles: Rely on the config isConfiguredToReturnGZIPResponses method…
sbrossie Oct 12, 2015
e96b39a
util: Fixes #408
sbrossie Oct 12, 2015
2470160
util: Code review integratiuon for e96b39ae50b5b12ab64f3aaaebe915ff7d…
sbrossie Oct 12, 2015
c58de48
jaxrs: Fixes #407
sbrossie Oct 12, 2015
3f89f3e
payment: Modify MockPaymentProviderPluginProvider to set gatewayError…
sbrossie Oct 14, 2015
956ad98
Merge branch 'master' of https://github.com/killbill/killbill
Oct 14, 2015
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
10 changes: 0 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,6 @@ matrix:
jdk: oraclejdk7
- env: PHASE="-Pmysql,jdk18"
jdk: oraclejdk8
- env: PHASE="-Ppostgresql"
jdk: openjdk7
- env: PHASE="-Ppostgresql"
jdk: oraclejdk7
- env: PHASE="-Ppostgresql,jdk17"
jdk: openjdk7
- env: PHASE="-Ppostgresql,jdk17"
jdk: oraclejdk7
- env: PHASE="-Ppostgresql,jdk18"
jdk: oraclejdk8
- env: PHASE="-Ptravis"
jdk: openjdk7
- env: PHASE="-Ptravis"
Expand Down
12 changes: 12 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
0.15.6
See https://github.com/killbill/killbill/releases/tag/killbill-0.15.6

0.15.5
Fix with issue with payment combo call where default account fields are not part of the request

0.15.4
See https://github.com/killbill/killbill/issues?q=milestone%3ARelease-0.15.4+is%3Aclosed

0.15.3
Release for milestone 0.15.3: https://github.com/killbill/killbill/issues?q=is%3Aissue+milestone%3ARelease-0.15.3+is%3Aclosed

0.15.2
See https://github.com/killbill/killbill/issues?q=milestone%3ARelease-0.15.2+is%3Aclosed

Expand Down
2 changes: 1 addition & 1 deletion account/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<parent>
<artifactId>killbill</artifactId>
<groupId>org.kill-bill.billing</groupId>
<version>0.15.3-SNAPSHOT</version>
<version>0.15.7-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>killbill-account</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,15 +295,18 @@ public Account mergeWithDelegate(final Account currentAccount) {
accountData.setCurrency(currentAccount.getCurrency());
}

if (billCycleDayLocal != null && billCycleDayLocal != DEFAULT_BILLING_CYCLE_DAY_LOCAL && currentAccount.getBillCycleDayLocal() != null && currentAccount.getBillCycleDayLocal() != DEFAULT_BILLING_CYCLE_DAY_LOCAL && !billCycleDayLocal.equals(currentAccount.getBillCycleDayLocal())) {
throw new IllegalArgumentException(String.format("Killbill doesn't support updating the account BCD yet: new=%s, current=%s",
billCycleDayLocal, currentAccount.getBillCycleDayLocal()));
} else if (billCycleDayLocal != null && billCycleDayLocal != DEFAULT_BILLING_CYCLE_DAY_LOCAL) {
// Junction sets it

if (currentAccount.getBillCycleDayLocal() != DEFAULT_BILLING_CYCLE_DAY_LOCAL && // There is already a BCD set
billCycleDayLocal != null && // and the proposed date is not null
billCycleDayLocal != DEFAULT_BILLING_CYCLE_DAY_LOCAL && // and the proposed date is not 0
!currentAccount.getBillCycleDayLocal().equals(billCycleDayLocal)) { // and it does not match we we have
throw new IllegalArgumentException(String.format("Killbill doesn't support updating the account BCD yet: new=%s, current=%s", billCycleDayLocal, currentAccount.getBillCycleDayLocal()));
} else if (currentAccount.getBillCycleDayLocal() == DEFAULT_BILLING_CYCLE_DAY_LOCAL && // There is *not* already a BCD set
billCycleDayLocal != null && // and the value proposed is not null
billCycleDayLocal != DEFAULT_BILLING_CYCLE_DAY_LOCAL) { // and the proposed date is not 0
accountData.setBillCycleDayLocal(billCycleDayLocal);
} else {
// Default to current value
accountData.setBillCycleDayLocal(currentAccount.getBillCycleDayLocal() == null ? DEFAULT_BILLING_CYCLE_DAY_LOCAL : currentAccount.getBillCycleDayLocal());
accountData.setBillCycleDayLocal(currentAccount.getBillCycleDayLocal());
}

// Set all updatable fields with the new values if non null, otherwise defaults to the current values
Expand Down Expand Up @@ -336,6 +339,10 @@ public Account mergeWithDelegate(final Account currentAccount) {
return new DefaultAccount(currentAccount.getId(), accountData);
}

public ImmutableAccountData toImmutableAccountData() {
return new DefaultImmutableAccountData(this);
}

@Override
public String toString() {
return "DefaultAccount [externalKey=" + externalKey +
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright 2014-2015 Groupon, Inc
* Copyright 2014-2015 The Billing Project, LLC
*
* The Billing Project licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

package org.killbill.billing.account.api;

import java.util.UUID;

import org.joda.time.DateTimeZone;
import org.killbill.billing.catalog.api.Currency;

public class DefaultImmutableAccountData implements ImmutableAccountData {

private final UUID id;
private final String externalKey;
private final Currency currency;
private final DateTimeZone dateTimeZone;

public DefaultImmutableAccountData(final UUID id, final String externalKey, final Currency currency, final DateTimeZone dateTimeZone) {
this.id = id;
this.externalKey = externalKey;
this.currency = currency;
this.dateTimeZone = dateTimeZone;
}

public DefaultImmutableAccountData(final Account account) {
this(account.getId(), account.getExternalKey(), account.getCurrency(), account.getTimeZone());
}

@Override
public UUID getId() {
return id;
}

@Override
public String getExternalKey() {
return externalKey;
}

@Override
public Currency getCurrency() {
return currency;
}

@Override
public DateTimeZone getTimeZone() {
return dateTimeZone;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,65 +22,95 @@
import javax.inject.Inject;

import org.killbill.billing.ErrorCode;
import org.killbill.billing.ObjectType;
import org.killbill.billing.account.api.Account;
import org.killbill.billing.account.api.AccountApiException;
import org.killbill.billing.account.api.AccountData;
import org.killbill.billing.account.api.AccountEmail;
import org.killbill.billing.account.api.AccountInternalApi;
import org.killbill.billing.account.api.DefaultAccount;
import org.killbill.billing.account.api.DefaultAccountEmail;
import org.killbill.billing.account.api.DefaultImmutableAccountData;
import org.killbill.billing.account.api.DefaultMutableAccountData;
import org.killbill.billing.account.api.ImmutableAccountData;
import org.killbill.billing.account.api.MutableAccountData;
import org.killbill.billing.account.api.user.DefaultAccountApiBase;
import org.killbill.billing.account.dao.AccountDao;
import org.killbill.billing.account.dao.AccountEmailModelDao;
import org.killbill.billing.account.dao.AccountModelDao;
import org.killbill.billing.callcontext.InternalCallContext;
import org.killbill.billing.callcontext.InternalTenantContext;
import org.killbill.billing.util.entity.DefaultPagination;
import org.killbill.billing.util.entity.Pagination;
import org.killbill.billing.util.cache.AccountBCDCacheLoader;
import org.killbill.billing.util.cache.Cachable.CacheType;
import org.killbill.billing.util.cache.CacheController;
import org.killbill.billing.util.cache.CacheControllerDispatcher;
import org.killbill.billing.util.cache.CacheLoaderArgument;
import org.killbill.billing.util.cache.ImmutableAccountCacheLoader.LoaderCallback;
import org.killbill.billing.util.dao.NonEntityDao;

import com.google.common.base.Function;
import com.google.common.collect.Collections2;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterators;

public class DefaultAccountInternalApi implements AccountInternalApi {
public class DefaultAccountInternalApi extends DefaultAccountApiBase implements AccountInternalApi {

private final AccountDao accountDao;
private final CacheControllerDispatcher cacheControllerDispatcher;
private final CacheController accountCacheController;
private final CacheController bcdCacheController;
private final NonEntityDao nonEntityDao;

@Inject
public DefaultAccountInternalApi(final AccountDao accountDao) {
public DefaultAccountInternalApi(final AccountDao accountDao,
final NonEntityDao nonEntityDao,
final CacheControllerDispatcher cacheControllerDispatcher) {
super(accountDao, nonEntityDao, cacheControllerDispatcher);
this.accountDao = accountDao;
this.nonEntityDao = nonEntityDao;
this.cacheControllerDispatcher = cacheControllerDispatcher;
this.accountCacheController = cacheControllerDispatcher.getCacheController(CacheType.ACCOUNT_IMMUTABLE);
this.bcdCacheController = cacheControllerDispatcher.getCacheController(CacheType.ACCOUNT_BCD);
}

@Override
public Account getAccountById(final UUID accountId, final InternalTenantContext context) throws AccountApiException {
final AccountModelDao account = accountDao.getById(accountId, context);
if (account == null) {
throw new AccountApiException(ErrorCode.ACCOUNT_DOES_NOT_EXIST_FOR_ID, accountId);
}
return new DefaultAccount(account);
return super.getAccountById(accountId, context);
}

@Override
public Account getAccountByKey(final String key, final InternalTenantContext context) throws AccountApiException {
return super.getAccountByKey(key, context);
}

@Override
public Account getAccountByRecordId(final Long recordId, final InternalTenantContext context) throws AccountApiException {
final AccountModelDao accountModelDao = getAccountModelDaoByRecordId(recordId, context);
return new DefaultAccount(accountModelDao);
return super.getAccountByRecordId(recordId, context);
}

@Override
public void updateAccount(final String externalKey, final AccountData accountData,
final InternalCallContext context) throws AccountApiException {
public void updateBCD(final String externalKey, final int bcd,
final InternalCallContext context) throws AccountApiException {
final Account currentAccount = getAccountByKey(externalKey, context);
if (currentAccount == null) {
throw new AccountApiException(ErrorCode.ACCOUNT_DOES_NOT_EXIST_FOR_KEY, externalKey);
}
if (currentAccount.getBillCycleDayLocal() != DefaultMutableAccountData.DEFAULT_BILLING_CYCLE_DAY_LOCAL) {
throw new AccountApiException(ErrorCode.ACCOUNT_UPDATE_FAILED);
}

// Set unspecified (null) fields to their current values
final Account updatedAccount = new DefaultAccount(currentAccount.getId(), accountData);
final AccountModelDao accountToUpdate = new AccountModelDao(currentAccount.getId(), updatedAccount.mergeWithDelegate(currentAccount));

final MutableAccountData mutableAccountData = currentAccount.toMutableAccountData();
mutableAccountData.setBillCycleDayLocal(bcd);
final AccountModelDao accountToUpdate = new AccountModelDao(currentAccount.getId(), mutableAccountData);
bcdCacheController.remove(currentAccount.getId());
bcdCacheController.putIfAbsent(currentAccount.getId(), new Integer(bcd));
accountDao.update(accountToUpdate, context);
}

@Override
public int getBCD(final UUID accountId, final InternalTenantContext context) throws AccountApiException {
final CacheLoaderArgument arg = createBCDCacheLoaderArgument(context);
final Integer result = (Integer) bcdCacheController.get(accountId, arg);
return result != null ? result : DefaultMutableAccountData.DEFAULT_BILLING_CYCLE_DAY_LOCAL;
}

@Override
public List<AccountEmail> getEmails(final UUID accountId,
final InternalTenantContext context) {
Expand All @@ -93,15 +123,6 @@ public AccountEmail apply(final AccountEmailModelDao input) {
}));
}

@Override
public Account getAccountByKey(final String key, final InternalTenantContext context) throws AccountApiException {
final AccountModelDao accountModelDao = accountDao.getAccountByKey(key, context);
if (accountModelDao == null) {
throw new AccountApiException(ErrorCode.ACCOUNT_DOES_NOT_EXIST_FOR_KEY, key);
}
return new DefaultAccount(accountModelDao);
}

@Override
public void removePaymentMethod(final UUID accountId, final InternalCallContext context) throws AccountApiException {
updatePaymentMethod(accountId, null, context);
Expand All @@ -119,11 +140,56 @@ public UUID getByRecordId(final Long recordId, final InternalTenantContext conte
return accountModelDao.getId();
}

@Override
public ImmutableAccountData getImmutableAccountDataById(final UUID accountId, final InternalTenantContext context) throws AccountApiException {
final Long recordId = nonEntityDao.retrieveRecordIdFromObject(accountId, ObjectType.ACCOUNT, cacheControllerDispatcher.getCacheController(CacheType.RECORD_ID));
return getImmutableAccountDataByRecordId(recordId, context);
}

@Override
public ImmutableAccountData getImmutableAccountDataByRecordId(final Long recordId, final InternalTenantContext context) throws AccountApiException {
final CacheLoaderArgument arg = createImmutableAccountCacheLoaderArgument(context);
return (ImmutableAccountData) accountCacheController.get(recordId, arg);
}

private AccountModelDao getAccountModelDaoByRecordId(final Long recordId, final InternalTenantContext context) throws AccountApiException {
final AccountModelDao accountModelDao = accountDao.getByRecordId(recordId, context);
if (accountModelDao == null) {
throw new AccountApiException(ErrorCode.ACCOUNT_DOES_NOT_EXIST_FOR_RECORD_ID, recordId);
}
return accountModelDao;
}

private int getBCDInternal(final UUID accountId, final InternalTenantContext context) {
final Integer bcd = accountDao.getAccountBCD(accountId, context);
return bcd != null ? bcd : DefaultMutableAccountData.DEFAULT_BILLING_CYCLE_DAY_LOCAL;
}

private CacheLoaderArgument createImmutableAccountCacheLoaderArgument(final InternalTenantContext context) {
final LoaderCallback loaderCallback = new LoaderCallback() {
@Override
public Object loadAccount(final Long recordId, final InternalTenantContext context) {
final Account account = getAccountByRecordIdInternal(recordId, context);
return account != null ? new DefaultImmutableAccountData(account) : null;
}
};
final Object[] args = new Object[1];
args[0] = loaderCallback;
final ObjectType irrelevant = null;
return new CacheLoaderArgument(irrelevant, args, context);
}

private CacheLoaderArgument createBCDCacheLoaderArgument(final InternalTenantContext context) {
final AccountBCDCacheLoader.LoaderCallback loaderCallback = new AccountBCDCacheLoader.LoaderCallback() {
@Override
public Object loadAccountBCD(final UUID accountId, final InternalTenantContext context) {
int bcd = getBCDInternal(accountId, context);
return new Integer(bcd);
}
};
final Object[] args = new Object[1];
args[0] = loaderCallback;
final ObjectType irrelevant = null;
return new CacheLoaderArgument(irrelevant, args, context);
}
}
Loading