From ebb11adc6fb5a1f3ac75aa7069abb2298a938bce Mon Sep 17 00:00:00 2001 From: Kristijan Mitrovic Date: Mon, 13 Apr 2020 16:01:10 +0200 Subject: [PATCH] Add proper constructor for new class --- .../model/bill/AccountPaymentArchived.java | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/bubble-server/src/main/java/bubble/model/bill/AccountPaymentArchived.java b/bubble-server/src/main/java/bubble/model/bill/AccountPaymentArchived.java index 6bb97c16..edccbbed 100644 --- a/bubble-server/src/main/java/bubble/model/bill/AccountPaymentArchived.java +++ b/bubble-server/src/main/java/bubble/model/bill/AccountPaymentArchived.java @@ -8,8 +8,10 @@ import bubble.model.account.Account; import com.fasterxml.jackson.annotation.JsonIgnore; import lombok.Getter; import lombok.NoArgsConstructor; +import lombok.NonNull; import lombok.Setter; import lombok.experimental.Accessors; +import org.cobbzilla.util.reflect.ReflectionUtil; import org.cobbzilla.wizard.model.IdentifiableBase; import org.cobbzilla.wizard.model.entityconfig.EntityFieldType; import org.cobbzilla.wizard.model.entityconfig.annotations.*; @@ -20,14 +22,34 @@ import javax.persistence.*; import static bubble.model.bill.Bill.PERIOD_FIELDS_MAX_LENGTH; import static bubble.model.bill.BubblePlan.PLAN_NAME_MAX_LENGTH; import static bubble.model.cloud.BubbleNetwork.NETWORK_NAME_MAXLEN; +import static org.cobbzilla.util.reflect.ReflectionUtil.copy; import static org.cobbzilla.wizard.model.NamedEntity.NAME_MAXLEN; import static org.cobbzilla.wizard.model.crypto.EncryptedTypes.*; @ECType(root=true) @ECTypeCreate(method="DISABLED") @ECTypeURIs(listFields={"accountName", "paymentMethodMaskedInfo", "amount"}) -@Entity @NoArgsConstructor @Accessors(chain=true) +@Entity @Accessors(chain=true) public class AccountPaymentArchived extends IdentifiableBase { + /** + * List of properties from AccountPayment class which will not be used in this class the same way. Those foreign + * keys (uuids) will not be available within referenced tables, and so here the other unique data from those + * elements is extracted. + */ + private static final String[] ALTERED_FIELDS = { "account", "paymentMethod", "plan", "accountPlan", "bill" }; + + public AccountPaymentArchived(@NonNull final AccountPayment original, @NonNull final String accountName, + @NonNull final String paymentMethodMaskedInfo, @NonNull final String bubblePlanName, + @NonNull final String accountPlanName, @NonNull final String billPeriodStart) { + this.accountName = accountName; + this.paymentMethodMaskedInfo = paymentMethodMaskedInfo; + this.bubblePlanName = bubblePlanName; + this.accountPlanName = accountPlanName; + this.billPeriodStart = billPeriodStart; + + copy(this, original, null, ALTERED_FIELDS); + } + @ECSearchable @ECField(index=0) @Id @Column(unique=true, updatable=false, nullable=false, length=UUID_MAXLEN) @Getter @Setter private volatile String uuid;