diff --git a/bubble-server/src/main/java/bubble/cloud/payment/promo/accountCredit/AccountCreditPaymentDriver.java b/bubble-server/src/main/java/bubble/cloud/payment/promo/accountCredit/AccountCreditPaymentDriver.java index 78c0a2c6..f411d669 100644 --- a/bubble-server/src/main/java/bubble/cloud/payment/promo/accountCredit/AccountCreditPaymentDriver.java +++ b/bubble-server/src/main/java/bubble/cloud/payment/promo/accountCredit/AccountCreditPaymentDriver.java @@ -9,10 +9,14 @@ import bubble.cloud.payment.promo.PromotionalPaymentDriverBase; import bubble.cloud.payment.promo.PromotionalPaymentServiceDriver; import bubble.model.account.Account; import bubble.model.bill.*; +import lombok.extern.slf4j.Slf4j; import java.util.List; import java.util.Set; +import static org.cobbzilla.util.daemon.ZillaRuntime.now; + +@Slf4j public class AccountCreditPaymentDriver extends PromotionalPaymentDriverBase { @Override public boolean adminAddPromoToAccount(Promotion promo, Account account) { @@ -20,7 +24,7 @@ public class AccountCreditPaymentDriver extends PromotionalPaymentDriverBase { return findByUniqueFields("account", accountUuid, "network", networkUuid); } + public AccountPlan findByAccountAndNetworkAndNotDeleted(String accountUuid, String networkUuid) { + return findByUniqueFields("account", accountUuid, "network", networkUuid, "deleted", null); + } + public AccountPlan findByNetwork(String networkUuid) { return findByUniqueField("network", networkUuid); } public List findByAccountAndNotDeleted(String account) { return findByFields("account", account, "deleted", null); } + public AccountPlan findByAccountAndIdAndNotDeleted(String account, String id) { + final AccountPlan accountPlan = findByUniqueFields("account", account, "uuid", id, "deleted", null); + return accountPlan != null ? accountPlan : findByUniqueFields("account", account, "name", id, "deleted", null); + } + public List findByAccountAndPaymentMethodAndNotDeleted(String account, String paymentMethod) { return findByFields("account", account, "paymentMethod", paymentMethod, "deleted", null); } diff --git a/bubble-server/src/main/java/bubble/dao/bill/PromotionDAO.java b/bubble-server/src/main/java/bubble/dao/bill/PromotionDAO.java index a44201b8..86bcc713 100644 --- a/bubble-server/src/main/java/bubble/dao/bill/PromotionDAO.java +++ b/bubble-server/src/main/java/bubble/dao/bill/PromotionDAO.java @@ -47,6 +47,16 @@ public class PromotionDAO extends AbstractCRUDDAO { "adminAssignOnly", false)); } + public List findEnabledAndActiveAndLaunchFailureWithNoCode(String currency) { + return filterActive(findByFields( + "enabled", true, + "code", null, + "referral", false, + "launchFailureCredit", true, + "currency", currency, + "adminAssignOnly", false)); + } + public List findVisibleAndEnabledAndActiveWithNoCodeOrWithCode(String code, String currency) { if (empty(code)) { return filterActive(findByFields( diff --git a/bubble-server/src/main/java/bubble/model/bill/AccountPaymentMethod.java b/bubble-server/src/main/java/bubble/model/bill/AccountPaymentMethod.java index 3ccc58e4..5b2e704d 100644 --- a/bubble-server/src/main/java/bubble/model/bill/AccountPaymentMethod.java +++ b/bubble-server/src/main/java/bubble/model/bill/AccountPaymentMethod.java @@ -37,7 +37,7 @@ import static org.cobbzilla.wizard.model.crypto.EncryptedTypes.ENC_PAD; @Entity @ECType(root=true) @ECTypeCreate(method="DISABLED") @NoArgsConstructor @Accessors(chain=true) -@ECIndexes({ @ECIndex(unique=true, of={"paymentMethodType", "paymentInfo"}) }) +@ECIndexes({ @ECIndex(unique=true, of={"paymentMethodType", "paymentInfo"}, where="deleted IS NULL") }) @Slf4j public class AccountPaymentMethod extends IdentifiableBase implements HasAccountNoName, Scrubbable { diff --git a/bubble-server/src/main/java/bubble/model/bill/AccountPlan.java b/bubble-server/src/main/java/bubble/model/bill/AccountPlan.java index d0a6e273..174eadf8 100644 --- a/bubble-server/src/main/java/bubble/model/bill/AccountPlan.java +++ b/bubble-server/src/main/java/bubble/model/bill/AccountPlan.java @@ -15,6 +15,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.experimental.Accessors; +import lombok.extern.slf4j.Slf4j; import org.cobbzilla.util.collection.ArrayUtil; import org.cobbzilla.wizard.model.Identifiable; import org.cobbzilla.wizard.model.IdentifiableBase; @@ -34,9 +35,9 @@ import static org.cobbzilla.util.reflect.ReflectionUtil.copy; @ECType(root=true) @ECTypeCreate(method="DISABLED") @ECTypeURIs(listFields={"account", "plan", "network", "name"}) -@Entity @NoArgsConstructor @Accessors(chain=true) +@Entity @NoArgsConstructor @Accessors(chain=true) @Slf4j @ECIndexes({ - @ECIndex(unique=true, of={"account", "name"}), + @ECIndex(unique=true, of={"account", "name"}, where="deleted IS NULL"), @ECIndex(unique=true, of={"account", "network"}), @ECIndex(unique=true, of={"plan", "network"}) }) diff --git a/bubble-server/src/main/java/bubble/model/bill/Promotion.java b/bubble-server/src/main/java/bubble/model/bill/Promotion.java index 64486ee8..8581b293 100644 --- a/bubble-server/src/main/java/bubble/model/bill/Promotion.java +++ b/bubble-server/src/main/java/bubble/model/bill/Promotion.java @@ -99,22 +99,27 @@ public class Promotion extends IdentifiableBase public boolean notAdminAssignOnly() { return !adminAssignOnly(); } @ECSearchable @ECField(index=80) + @ECIndex @Column(nullable=false) + @Getter @Setter private Boolean launchFailureCredit = false; + public boolean launchFailureCredit() { return launchFailureCredit != null && launchFailureCredit; } + + @ECSearchable @ECField(index=90) @ECIndex @Getter @Setter private Long validFrom; public boolean hasStarted () { return validFrom == null || validFrom > now(); } - @ECSearchable @ECField(index=90) + @ECSearchable @ECField(index=100) @ECIndex @Getter @Setter private Long validTo; public boolean hasEnded () { return validTo != null && validTo > now(); } public boolean active () { return enabled() && hasStarted() && !hasEnded(); } public boolean inactive () { return !active(); } - @ECSearchable @ECField(index=100) + @ECSearchable @ECField(index=110) @ECIndex @Column(nullable=false) @Getter @Setter private Boolean referral = false; public boolean referral () { return referral != null && referral; } - @ECSearchable @ECField(index=110) + @ECSearchable @ECField(index=120) @ECIndex @Column(nullable=false, updatable=false, length=10) @Getter @Setter private String currency; @@ -122,11 +127,11 @@ public class Promotion extends IdentifiableBase return currency != null && currency.equalsIgnoreCase(this.currency); } - @ECSearchable @ECField(index=120) + @ECSearchable @ECField(index=130) @ECIndex @Column(nullable=false, updatable=false) @Getter @Setter private Integer minValue = 100; - @ECSearchable @ECField(index=130) + @ECSearchable @ECField(index=140) @ECIndex @Column(nullable=false, updatable=false) @Getter @Setter private Integer maxValue; diff --git a/bubble-server/src/main/java/bubble/model/cloud/BubbleNetwork.java b/bubble-server/src/main/java/bubble/model/cloud/BubbleNetwork.java index 8280196b..9f43bfdd 100644 --- a/bubble-server/src/main/java/bubble/model/cloud/BubbleNetwork.java +++ b/bubble-server/src/main/java/bubble/model/cloud/BubbleNetwork.java @@ -19,6 +19,7 @@ import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import lombok.extern.slf4j.Slf4j; import org.cobbzilla.util.collection.ArrayUtil; import org.cobbzilla.wizard.model.Identifiable; import org.cobbzilla.wizard.model.IdentifiableBase; @@ -51,7 +52,8 @@ import static org.cobbzilla.wizard.model.crypto.EncryptedTypes.ENC_PAD; @ECTypeChildren(uriPrefix=EP_NETWORKS+"/{BubbleNetwork.name}", value={ @ECTypeChild(type=BubbleNode.class, backref="network") }) -@Entity @NoArgsConstructor @Accessors(chain=true) @ToString(of={"name", "domainName", "installType"}) +@Entity @NoArgsConstructor @Accessors(chain=true) +@Slf4j @ToString(of={"name", "domainName", "installType"}) @ECIndexes({ @ECIndex(unique=true, of={"account", "name"}), @ECIndex(unique=true, of={"name", "domainName"}) @@ -202,12 +204,14 @@ public class BubbleNetwork extends IdentifiableBase implements HasNetwork, HasBu if (network != null && !network.getUuid().equals(request.getNetwork())) { continue; } else { - final Account acct = accountDAO.findByName(name); + final Account acct = accountDAO.findByName(tryName); if (acct != null && !acct.getUuid().equals(request.getAccount())) { continue; } } - return tryName.equals(name) ? errors : errors.setSuggestedName(tryName); + if (tryName.equals(name)) return errors; + log.info("validateHostname: setting suggested name='"+tryName+"'"); + return errors.setSuggestedName(tryName); } errors.addViolation("err.name.alreadyInUse"); } diff --git a/bubble-server/src/main/java/bubble/resources/bill/AccountPlansResource.java b/bubble-server/src/main/java/bubble/resources/bill/AccountPlansResource.java index 4e5b0047..730e3909 100644 --- a/bubble-server/src/main/java/bubble/resources/bill/AccountPlansResource.java +++ b/bubble-server/src/main/java/bubble/resources/bill/AccountPlansResource.java @@ -66,11 +66,15 @@ public class AccountPlansResource extends AccountOwnedResource