@@ -58,7 +58,7 @@ Vagrant.configure("2") do |config| | |||
s.privileged = false | |||
s.inline = <<-SHELL | |||
# Copy shared bubble dir to ${HOME} | |||
rsync -a /vagrant ${HOME}/bubble | |||
cd ${HOME} && rsync -azc --exclude="**/target/**" /vagrant . && mv vagrant bubble | |||
# Initialize the system | |||
cd ${HOME}/bubble && ./bin/first_time_ubuntu.sh | |||
@@ -30,7 +30,7 @@ public class DelegatedPaymentDriver extends DelegatedCloudServiceDriverBase impl | |||
log.warn("getPaymentMethodType: delegated driver has non-delegated cloud: "+cloud.getUuid()); | |||
return cloud.getPaymentDriver(configuration).getPaymentMethodType(); | |||
} | |||
if (!configuration.getPaymentsEnabled()) { | |||
if (!configuration.paymentsEnabled()) { | |||
log.warn("getPaymentMethodType: payments not enabled, returning null"); | |||
return null; | |||
}; | |||
@@ -115,7 +115,7 @@ public class AccountPlanDAO extends AccountOwnedEntityDAO<AccountPlan> { | |||
if (errors.isInvalid()) throw invalidEx(errors); | |||
if (errors.hasSuggestedName()) accountPlan.setName(errors.getSuggestedName()); | |||
if (configuration.getPaymentsEnabled()) { | |||
if (configuration.paymentsEnabled()) { | |||
if (!accountPlan.hasPaymentMethodObject()) throw invalidEx("err.paymentMethod.required"); | |||
if (!accountPlan.getPaymentMethodObject().hasUuid()) throw invalidEx("err.paymentMethod.required"); | |||
@@ -149,7 +149,7 @@ public class AccountPlanDAO extends AccountOwnedEntityDAO<AccountPlan> { | |||
} | |||
@Override public AccountPlan postCreate(AccountPlan accountPlan, Object context) { | |||
if (configuration.getPaymentsEnabled()) { | |||
if (configuration.paymentsEnabled()) { | |||
final String accountPlanUuid = accountPlan.getUuid(); | |||
final String paymentMethodUuid = accountPlan.getPaymentMethodObject().getUuid(); | |||
final BubblePlan plan = planDAO.findByUuid(accountPlan.getPlan()); | |||
@@ -191,7 +191,7 @@ public class AccountPlanDAO extends AccountOwnedEntityDAO<AccountPlan> { | |||
networkDAO.delete(accountPlan.getDeletedNetwork()); | |||
} else { | |||
networkDAO.delete(accountPlan.getNetwork()); | |||
if (configuration.getPaymentsEnabled()) { | |||
if (configuration.paymentsEnabled()) { | |||
refundService.processRefunds(); | |||
} | |||
} | |||
@@ -95,6 +95,9 @@ public class CloudServiceDAO extends AccountOwnedTemplateDAO<CloudService> { | |||
} | |||
@Override public CloudService postCreate(CloudService cloud, Object context) { | |||
if (cloud.getType() == CloudServiceType.payment && !configuration.paymentsEnabled()) { | |||
configuration.resetPaymentsEnabled(); | |||
} | |||
if (!cloud.delegated() && !configuration.testMode()) { | |||
final ValidationResult errors = testDriver(cloud, configuration); | |||
if (errors.isInvalid()) throw invalidEx(errors); | |||
@@ -102,7 +105,7 @@ public class CloudServiceDAO extends AccountOwnedTemplateDAO<CloudService> { | |||
if (cloud.getType() == CloudServiceType.payment | |||
&& cloud.template() | |||
&& cloud.enabled() | |||
&& !configuration.getPaymentsEnabled()) { | |||
&& !configuration.paymentsEnabled()) { | |||
// a public template for a payment cloud has been added, and payments were not enabled -- now they are | |||
configuration.refreshPublicSystemConfigs(); | |||
} | |||
@@ -164,7 +167,9 @@ public class CloudServiceDAO extends AccountOwnedTemplateDAO<CloudService> { | |||
// TODO for these maybe an outside cron would be better solution. BulkDelete is used here to be fast. | |||
// For now this postServiceDelete is called within a single place where this method is used - Account Deletion. | |||
log.warn("Not calling postServiceDelete for services deleted in this way"); | |||
return super.bulkDeleteWhere(whereClause, parameters); | |||
int count = super.bulkDeleteWhere(whereClause, parameters); | |||
configuration.resetPaymentsEnabled(); | |||
return count; | |||
} | |||
@Transactional @Override public void delete(String uuid) { | |||
@@ -175,6 +180,7 @@ public class CloudServiceDAO extends AccountOwnedTemplateDAO<CloudService> { | |||
cs.getDriver().postServiceDelete(this, cs); | |||
super.delete(uuid); | |||
configuration.resetPaymentsEnabled(); | |||
} | |||
@Override public void delete(Collection<CloudService> entities) { | |||
@@ -185,5 +191,6 @@ public class CloudServiceDAO extends AccountOwnedTemplateDAO<CloudService> { | |||
} | |||
super.delete(entities); | |||
configuration.resetPaymentsEnabled(); | |||
} | |||
} |
@@ -367,7 +367,7 @@ public class AuthResource { | |||
} | |||
String currency = null; | |||
if (configuration.getPaymentsEnabled()) { | |||
if (configuration.paymentsEnabled()) { | |||
currency = currencyForLocale(request.getLocale(), getDEFAULT_LOCALE()); | |||
// do we have any plans with this currency? | |||
if (!planDAO.getSupportedCurrencies().contains(currency)) { | |||
@@ -393,7 +393,7 @@ public class AuthResource { | |||
final Account account = accountDAO.newAccount(req, null, request, parent); | |||
SimpleViolationException promoEx = null; | |||
if (configuration.getPaymentsEnabled()) { | |||
if (configuration.paymentsEnabled()) { | |||
if (request.hasPaymentMethod()) { | |||
final AccountPaymentMethod paymentMethodObject = request.getPaymentMethodObject(); | |||
log.info("register: found AccountPaymentMethod at registration-time: " + json(paymentMethodObject, COMPACT_MAPPER)); | |||
@@ -109,12 +109,12 @@ public class AccountPlansResource extends AccountOwnedResource<AccountPlan, Acco | |||
} | |||
@Override protected Object daoCreate(AccountPlan toCreate) { | |||
if (!configuration.getPaymentsEnabled()) toCreate.setEnabled(true); | |||
if (!configuration.paymentsEnabled()) toCreate.setEnabled(true); | |||
return super.daoCreate(toCreate); | |||
} | |||
@Override protected Object daoUpdate(AccountPlan toUpdate) { | |||
if (!configuration.getPaymentsEnabled()) toUpdate.setEnabled(true); | |||
if (!configuration.paymentsEnabled()) toUpdate.setEnabled(true); | |||
return super.daoUpdate(toUpdate); | |||
} | |||
@@ -258,7 +258,7 @@ public class AccountPlansResource extends AccountOwnedResource<AccountPlan, Acco | |||
} | |||
AccountPaymentMethod paymentMethod = null; | |||
if (configuration.getPaymentsEnabled()) { | |||
if (configuration.paymentsEnabled()) { | |||
if (!request.hasPaymentMethodObject()) { | |||
final List<AccountPaymentMethod> paymentMethods = paymentMethodDAO.findByAccountAndNotPromoAndNotDeleted(caller.getUuid()); | |||
if (empty(paymentMethods)) { | |||
@@ -296,7 +296,7 @@ public class AccountPlansResource extends AccountOwnedResource<AccountPlan, Acco | |||
request.setNetwork(newNetwork.getUuid()); | |||
} | |||
if (configuration.getPaymentsEnabled()) { | |||
if (configuration.paymentsEnabled()) { | |||
if (paymentMethod != null && !paymentMethod.hasUuid()) { | |||
final AccountPaymentMethod paymentMethodToCreate = new AccountPaymentMethod(request.getPaymentMethodObject()).setAccount(request.getAccount()); | |||
final AccountPaymentMethod paymentMethodCreated = paymentMethodDAO.create(paymentMethodToCreate); | |||
@@ -378,7 +378,7 @@ public class BubbleConfiguration extends PgRestServerConfiguration | |||
{TAG_NETWORK_UUID, thisNetwork == null ? null : thisNetwork.getUuid()}, | |||
{TAG_SAGE_LAUNCHER, thisNetwork == null || isSageLauncher()}, | |||
{TAG_BUBBLE_NODE, isSageLauncher() || thisNetwork == null ? null : thisNetwork.node()}, | |||
{TAG_PAYMENTS_ENABLED, getPaymentsEnabled()}, | |||
{TAG_PAYMENTS_ENABLED, paymentsEnabled()}, | |||
{TAG_LOCAL_NETWORK, thisNetwork == null || thisNetwork.local()}, | |||
{TAG_PROMO_CODE_POLICY, getPromoCodePolicy().name()}, | |||
{TAG_REQUIRE_SEND_METRICS, requireSendMetrics()}, | |||
@@ -416,11 +416,31 @@ public class BubbleConfiguration extends PgRestServerConfiguration | |||
background(this::getPublicSystemConfigs, "BubbleConfiguration.refreshPublicSystemConfigs"); | |||
} | |||
@Getter(lazy=true) private final Boolean paymentsEnabled = initPaymentsEnabled(); | |||
private boolean initPaymentsEnabled () { return getBean(CloudServiceDAO.class).paymentsEnabled(); } | |||
private final AtomicReference<Boolean> paymentsEnabled = new AtomicReference<>(null); | |||
public boolean paymentsEnabled() { | |||
Boolean enabled = paymentsEnabled.get(); | |||
if (enabled == null) { | |||
synchronized (paymentsEnabled) { | |||
enabled = paymentsEnabled.get(); | |||
if (enabled == null) { | |||
enabled = getBean(CloudServiceDAO.class).paymentsEnabled(); | |||
paymentsEnabled.set(enabled); | |||
} | |||
} | |||
} | |||
return enabled; | |||
} | |||
public boolean resetPaymentsEnabled () { | |||
synchronized (paymentsEnabled) { | |||
paymentsEnabled.set(null); | |||
} | |||
return paymentsEnabled(); | |||
} | |||
public void requiresPaymentsEnabled () { | |||
if (!getPaymentsEnabled()) throw invalidEx("err_noPaymentMethods"); | |||
if (!paymentsEnabled()) { | |||
throw invalidEx("err_noPaymentMethods"); | |||
} | |||
} | |||
@Getter @Setter private Boolean requireSendMetrics; | |||
@@ -181,7 +181,7 @@ public class StandardSelfNodeService implements SelfNodeService { | |||
} | |||
// start RefundService if payments are enabled and this is a SageLauncher | |||
if (c.getPaymentsEnabled() && c.isSageLauncher() && thisNode.sage()) { | |||
if (c.paymentsEnabled() && c.isSageLauncher() && thisNode.sage()) { | |||
log.info("onStart: starting BillingService and RefundService"); | |||
c.getBean(BillingService.class).start(); | |||
c.getBean(StandardRefundService.class).start(); | |||
@@ -454,7 +454,7 @@ public class StandardNetworkService implements NetworkService { | |||
} | |||
if (progressMeter != null) { | |||
if (!progressMeter.success() && configuration.getPaymentsEnabled()) { | |||
if (!progressMeter.success() && configuration.paymentsEnabled()) { | |||
final AccountPlan accountPlan = accountPlanDAO.findByNetwork(nn.getNetwork()); | |||
if (accountPlan != null) { | |||
final BubblePlan plan = planDAO.findByUuid(accountPlan.getPlan()); | |||
@@ -691,7 +691,7 @@ public class StandardNetworkService implements NetworkService { | |||
public NewNodeNotification startNetwork(BubbleNetwork network, NetLocation netLocation) { | |||
final String accountUuid = network.getAccount(); | |||
if (configuration.getPaymentsEnabled()) { | |||
if (configuration.paymentsEnabled()) { | |||
AccountPlan accountPlan = accountPlanDAO.findByAccountAndNetwork(accountUuid, network.getUuid()); | |||
if (accountPlan == null) throw invalidEx("err.accountPlan.notFound"); | |||
final long start = now(); | |||
@@ -62,7 +62,7 @@ public class FilteredEntityIterator extends EntityIterator { | |||
BubbleNode node, | |||
List<BubblePlanApp> planApps, | |||
AtomicReference<Exception> error) { | |||
super(error, configuration.getPaymentsEnabled()); | |||
super(error, configuration.paymentsEnabled()); | |||
this.configuration = configuration; | |||
this.account = account; | |||
this.network = network; | |||
@@ -31,7 +31,7 @@ public class FullEntityIterator extends EntityIterator { | |||
BubbleNetwork network, | |||
LaunchType launchType, | |||
AtomicReference<Exception> error) { | |||
super(error, configuration.getPaymentsEnabled()); | |||
super(error, configuration.paymentsEnabled()); | |||
this.configuration = configuration; | |||
this.network = network; | |||
this.account = account; | |||