I'm studying BLC 4.0.
and I performing BLC tutorial(http://www.broadleafcommerce.com/docs/c ... -selection) now.
I've extended Customer entity, and I've switched default customer type by HcCustomerController like below.
(I tested various situation, so my custom customer entity looks so funny )
Code: Select all
@Controller("customHcCustomerController")
@RequestMapping("/"+HcCustomerController.SECTION_KEY)
public class HcCustomerController extends AdminBasicEntityController {
protected static final String SECTION_KEY = "customer";
@Override
protected String getSectionKey(Map<String, String> pathVars) {
if (super.getSectionKey(pathVars) != null){
return super.getSectionKey(pathVars);
}
return SECTION_KEY;
}
protected String getDefaultEntityType(){
return HcCustomerImpl.class.getName();
}
}
Here is HcCustomerImpl(it extends HcCustomer - it was omitted)
Code: Select all
@Entity
@Table(name = "HC_CUSTOMER")
@AdminPresentationClass(populateToOneFields = PopulateToOneFieldsEnum.TRUE, friendlyName = "CustomerImpl_baseCustomer")
@DirectCopyTransform({
@DirectCopyTransformMember(templateTokens = DirectCopyTransformTypes.PREVIEW, skipOverlaps=true),
@DirectCopyTransformMember(templateTokens = DirectCopyTransformTypes.MULTITENANT_SITE)
})
public class HcCustomerImpl extends CustomerImpl implements HcCustomer {
private static final Log LOG = LogFactory.getLog(HcCustomerImpl.class);
private static final long serialVersionUID = 6545097668293683751L;
@Column(name = "NUM_SAUCES_BOUGHT")
@AdminPresentation(friendlyName = "CustomerImpl_NUM_SAUCES_BOUGHT", order = 1000, group = "CustomerImpl_Customer2",
prominent = true, gridOrder = 500)
protected Integer numSaucesBought = 0;
@Column(name = "TOTAL_HEAT_RATING")
@AdminPresentation(friendlyName = "CustomerImpl_TOTAL_HEAT_RATING", order = 2000, group = "CustomerImpl_Customer2",
prominent = true, gridOrder = 900)
protected Integer totalHeatRating = 0;
@Override
public Integer getAverageHeatRatingBought() {
if (numSaucesBought == null || numSaucesBought == 0) {
return 0;
}
return totalHeatRating / numSaucesBought;
}
@Override
public Integer getTotalHeatRating() {
return totalHeatRating;
}
@Override
public void setTotalHeatRating(Integer totalHeatRating) {
this.totalHeatRating = totalHeatRating;
}
@Override
public Integer getNumSaucesBought() {
return numSaucesBought;
}
@Override
public void setNumSaucesBought(Integer numSaucesBought) {
this.numSaucesBought = numSaucesBought;
}
@OneToMany(mappedBy = "customer", targetEntity = HcCustomerAttrImpl.class, cascade = { CascadeType.ALL }, orphanRemoval = true)
@Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE, region="blStandardElements")
@MapKey(name="name")
@BatchSize(size = 50)
@AdminPresentationMap(friendlyName = "HcCustomerAttrImpl_Attribute_Name",
deleteEntityUponRemove = true
, keyPropertyFriendlyName = "HcCustomerAttrImpl_Attribute_Key"
, valuePropertyFriendlyName = "HcCustomerAttrImpl_Attribute_Value"
, forceFreeFormKeys = false
, keys={
@AdminPresentationMapKey(keyName = "ON", friendlyKeyName="HcCustomerAttrImpl_Attribute_Key_ON"),
@AdminPresentationMapKey(keyName = "OFF", friendlyKeyName="HcCustomerAttrImpl_Attribute_Key_OFF")
}
)
protected Map<String, HcCustomerAttr> hcCustomerAttr = new HashMap<String, HcCustomerAttr>();
@Override
public Map<String, HcCustomerAttr> getHcCustomerAttr() {
return hcCustomerAttr;
}
@Override
public void setHcCustomerAttr(Map<String, HcCustomerAttr> hcCustomerAttr) {
this.hcCustomerAttr = hcCustomerAttr;
}
@Column(name = "TEST_BOOL")
@AdminPresentation(friendlyName = "HcCustomerAttrImpl_TEST_BOOL", order = 4000, prominent = false)
protected boolean customerTestBool = true;
@Override
public boolean getCustomerTestBool(){
return customerTestBool;
};
@Override
public void setCustomerTestBool(boolean customerTestBool){
this.customerTestBool = customerTestBool;
};
@ManyToOne(targetEntity = LocaleImpl.class, optional = false)
@JoinColumn(name = "LOCALE_CODE")
@AdminPresentation(friendlyName = "HcCustomerAttrImpl_LOCALE", order = 2, prominent = false)
@AdminPresentationToOneLookup(lookupDisplayProperty = "friendlyName", lookupType = LookupType.DROPDOWN)
protected Locale hcCustomerLocale;
@Override
public Locale getHcCustomerLocale() {
return customerLocale;
}
@Override
public void setHcCustomerLocale(Locale customerLocale) {
this.customerLocale = customerLocale;
}
@ManyToOne(targetEntity = PageTemplateImpl.class)
@JoinColumn(name = "PAGE_TMPLT_ID")
@AdminPresentation(friendlyName = "PageImpl_Page_Template", order = 4000,
group = "Custom Page", groupOrder = 100, prominent = false,
requiredOverride = RequiredOverride.REQUIRED)
@AdminPresentationToOneLookup(lookupDisplayProperty = "templateName")
protected PageTemplate pageTemplate;
@Override
public PageTemplate getHCPageTemplate() {
return pageTemplate;
}
@Override
public void setHCPageTemplate(PageTemplate pageTemplate) {
this.pageTemplate = pageTemplate;
}
@OneToMany(mappedBy = "hcCustomer", targetEntity = HcCustomerAssetImpl.class, cascade = { CascadeType.ALL }, orphanRemoval = true)
@MapKey(name = "key")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE, region = "hcCustomer")
@BatchSize(size = 50)
@AdminPresentationMap(friendlyName = "HcCustomerImpl_Asset",
keyPropertyFriendlyName = "HcCustomerImpl_Asset_Key",
deleteEntityUponRemove = true,
mediaField = "media.url",
toOneTargetProperty = "media",
toOneParentProperty = "hcCustomer",
forceFreeFormKeys = true,
excluded = true
)
@AdminPresentationMapFields(
toOneTargetProperty = "media",
toOneParentProperty = "hcCustomer",
mapDisplayFields = {
@AdminPresentationMapField(
fieldName = "primary", // old_value is primary
fieldPresentation = @AdminPresentation(fieldType = SupportedFieldType.MEDIA,
group = "HcCustomerImpl_Asset_customer_photo",
groupOrder = 1000,
order = 3000,
friendlyName = "HcCustomerImpl_Asset_customer")
)
})
protected Map<String, HcCustomerAsset> hcCustomerAssetMap = new HashMap<String, HcCustomerAsset>();
@Override
public Map<String, HcCustomerAsset> getHcCustomerAssetMap() {
return hcCustomerAssetMap;
}
@Override
public void setHcCustomerAssetMap(Map<String, HcCustomerAsset> hcCustomerAssetMap) {
this.hcCustomerAssetMap = hcCustomerAssetMap;
}
}
And when I tried to add customer in Admin, I didn't need to select any type.
It was successful.
But there is another problem.
I couldn't add customer entity, cause of E-mail validation.
When I tried to click save button to submit entity-form, re-builded Entityform shown Error msg like below.
A customer already exists with this username
But the email address was not duplicated(I wrote a fresh email-address!)
The attempt to save customer entity was success, when I did'nt perform entity-type-selection.
However, once I attach new controller for customer entity - it's failed to save.
If I didn't fill Email address field, It committed successfully.
And update/delete works very well, too.
(But when update, Email duplicate validation did'nt work)
Sorry to too long article.
Now let me ask, is there an additional code or setting for entity-type-selection?
or did I mistake?
Thanks.
and Thanks to BLC.