How do I weave a field into a BLC core class?
Create an interface for the class that will have the getter/setters:
public interface SequenceSkuPriceDataTier { /** * set the sequence of tiers (order of applying tiers) * @param sequence */ void setSequence(BigDecimal sequence); /** * get the sequence of tiers (order of applying tiers) * @return */ BigDecimal getSequence(); }
Create an @Embeddable
implementation class that will use the @Parent
to the class that will be woven into. In this class, you will create any/all the field that will be woven in:
@Embeddable public class SequenceSkuPriceDataTierImpl implements SequenceSkuPriceDataTier { /** * This is a reference to the price data tier which these SequencePriceDataTier attributes get weaved into */ @Parent protected SkuPriceDataTier skuPriceDataTier; @Column(name = "SEQUENCE") @AdminPresentation(friendlyName = "BillingCyclePriceDataTierImpl_SEQUENCE", group = SkuPriceDataTierAdminPresentation.GroupName.PriceDataTier, order = 1001, gridOrder = 1, prominent = true, requiredOverride = RequiredOverride.REQUIRED ) private BigDecimal sequence; public SkuPriceDataTier getSkuPriceDataTier() { return skuPriceDataTier; } public void setSkuPriceDataTier(SkuPriceDataTier skuPriceDataTier) { this.skuPriceDataTier = skuPriceDataTier; } @Override public BigDecimal getSequence() { return sequence; } @Override public void setSequence(BigDecimal sequence) { this.sequence = sequence; } }
Create a weave class that will embed the class:
public class WeaveSkuPriceDataTierImpl { @Embedded public SequenceSkuPriceDataTierImpl embeddableSequencePriceDataTier; public SequenceSkuPriceDataTierImpl getEmbeddableSequencePriceDataTier(boolean assign) { SequenceSkuPriceDataTierImpl temp = embeddableSequencePriceDataTier; if (temp == null) { temp = new SequenceSkuPriceDataTierImpl(); if (assign) { embeddableSequencePriceDataTier = temp; } } if (temp.getSkuPriceDataTier() == null) { temp.setSkuPriceDataTier((SkuPriceDataTier) this); } return temp; } @Override public Address getAddress() { return getEmbeddableLazyFulfillmentGroup(false).getAddress(); } @Override public void setAddress(Address address) { getEmbeddableLazyFulfillmentGroup(true).setAddress(address); } @Override public Phone getPhone() { return getEmbeddableLazyFulfillmentGroup(false).getPhone(); } @Override public void setPhone(Phone phone) { getEmbeddableLazyFulfillmentGroup(true).setPhone(phone); } }
In CoreConfig
add the configuration needed to weave in the class:
@Merge(targetRef = "blMergedClassTransformers", early = true) public List<DirectCopyClassTransformer> mySequenceSkuPriceDataTierTransformers() { return Arrays.asList(new DirectCopyClassTransformer("Core") .addXformTemplate("com.broadleafcommerce.pricelist.domain.SkuPriceDataTierImpl", "com.weave.WeaveSkuPriceDataTierImpl")); }